-
Notifications
You must be signed in to change notification settings - Fork 128
feat(rust,python,java): 基礎的なインターフェイスを取り揃える #1100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(rust,python,java): 基礎的なインターフェイスを取り揃える #1100
Conversation
@sevenc-nanashi 今review requestをヒホさんと名無し。さんの二人に出していますが、どちらかと言うとRustとPythonとJavaの知識が揃っている名無し。さんの意見を伺えたらなと思っています。 [追記] 実装の判断基準をこのPRのdescriptionに書いたので、先に読むとわかりやすいかも |
_marker: PhantomData<fn(A) -> A>, | ||
} | ||
|
||
#[derive(derive_more::Debug)] | ||
#[debug(bounds())] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここって意味あるんですかね?derive_moreの説明読んでるんですけどあまりよくわからなく
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[derive(std::fmt::Debug)]
と同じような挙動をすると考えると、where A: Debug
という不必要なトレイト境界が足されちゃうからですね。
Rustのderiveはあまり頭がよくない - 簡潔なQ
…と思ったけど、このbounds()
消しても動きますね。#[derive(std::fmt::Debug)]
と挙動が違う。ドキュメントではuse derive_more::Debug; #[derive(Debug)]
と紹介されていたところderive_moreを完全に信用しきれずに#[derive(derive_more::Debug)]
と書いてきたわけですが、マジで非互換性があったとは!
we’ll try our best to infer trait bounds
いやいやいや…
考えたのですが、"our best"というのもよくわからないのでbounds()
は明示的に指定しておきたいなという気持ちになりました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"our best"というのもよくわからないので
bounds()
は明示的に指定しておきたい
ちょっと考えなおして、郷に入れば郷に従うようにしました。use derive_more::Debug
せずに#[derive(derive_more::Debug)]
と書くなら大丈夫なはず…?
b0981a0
(#1100)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ということでご指摘ありがとうございました!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
特に問題なさそう。
以下の一点だけ入れてマージしようと思います。
|
内容
Rust API GuidelinesのInteroperabilityの章に従って基礎的なトレイトを実装する。またPythonの特殊メソッドおよびJavaのインターフェイスについても、適切と考えられるものは全部実装してしまう。
Debug
/__repr__
(Partial)Eq
/__eq__
/Object.equals
(Partial)Ord
(Rustのnewtypeやenumにのみ実装)Hash
(Rustのnewtypeやenumにのみ実装)Clone
/Clonable
,Copy
Default
From
/Into
AsRef
/AsMut
std::fmt::UpperHex
std::fmt::LowerHex
std::fmt::Octal
std::fmt::Binary
最終的に実装したのは以下の通り。
Debug
forAudioQuery
UserDictWordBuilder
{blocking,nonblocking}.onnxruntime.LoadOnce
{blocking,nonblocking}.VoiceModelFile
{blocking,nonblocking}.OpenJtalk
{blocking,nonblocking}.Synthesizer
{blocking,nonblocking}.synthesizer.*
PartialEq
forStyleMeta
AudioQuery
UserDictWord
{PartialOrd,Ord}
forAccelerationMode
UserDictWordType
Hash
forCharacterVersion
AccelerationMode
{AsRef,AsMut}
forCharacterVersion
{UpperHex,LowerHex,Octal,Binary}
forStyleId
Into<u32>
forStyleId
(viaFrom
)__repr__
for{blocking,asyncio}.VoiceModelFile
{blocking,asyncio}.Onnxruntime
{blocking,asyncio}.VoiceModelFile
{blocking,asyncio}.OpenJtalk
{blocking,asyncio}.UserDict
Object.equals
forSupportedDevices
StyleMeta
CharacterMeta
Mora
AccentPhrase
AudioQuery
Cloneable
forSupportedDevices
StyleMeta
CharacterMeta
Mora
また
AudioFeature
にも色々実装。以下判断メモ。
==
/equals
はできる限り実装する。Rust以外の言語ではあらゆるオブジェクトを==
/equals
で比較してしまえるためDefault
の実装には慎重に(Partial)Ord
の実装も慎重にPartial
じゃないEq
、およびHash
の実装も慎重に。f32
などを入れたくなったときに困るためDebug
だけ実装しておくDebug
をどうするかは悩みどころ。標準ライブラリのドキュメントでは"Generally speaking, you should justderive
aDebug
implementation"とは言われているが、実際の慣習としてはカスタマイズは普通に行われている。標準ライブラリにおいてすら、例えばVec
やRc
はcapacity
とか{strong,weak}_count
といった情報も持っているはずだがそれらの表示はされない。[a, b, c]
のように表示される。では常に簡略化される方向なのかというとそうでもなく、各ライブラリの作者の思想に依る。特にstruct Newtype(i32)
みたいなやつをNewtype(42)
と表示するか42
と表示するかは、下手すると同じライブラリ内ですらブレている例があったりする (e.g. ndarray)Denug
実装があるStyleId
とかについては、別PRで変更を行うことにするSession
内のLoadedModels
については、Session
については表示せずマップキー側のVoiceModelId
だけ表示するようにする。ONNXとしての入出力シグネチャまで含まれてしまいかなり邪魔なためAudioFeature::internal_state
の表示も_
にしておく__repr__
の実装は作法に従う。どう書くかは悩むが、とりあえず<voicevox_core.blocking.型名 rust_api=<'RustのDebug表示'>>
のようにする関連 Issue
その他