ADR-0033: Apply Extern Parameter Projection Rules Uniformly to Constructors
이 콘텐츠는 아직 번역되지 않았습니다.
Status
Section titled “Status”Accepted
Context
Section titled “Context”ADR-0031はextern methodのnormal returnとref/out parameterをlogical returnへ適応する規則を定めた。Reflection extern catalogはconstructorもconstructed valueをresult slotへ受け取るcallableとして扱えるが、宣言構文とstub rendererがconstructor parameterを通常argument listとして出力すると、ref/outのphysical ABI modeを表現できない。これによりcatalogが持つconstructor ABIと生成sourceが非対称になる。
ADR-0032はout Tのphysical ABIを保ったままlogical outputだけをMaybe<T>へ投影するmaybe outを定める。このparameter単位の規則もconstructorだけ例外にすべきではない。
Decision
Section titled “Decision”Constructorをimplicit primary outputを持つextern callableとして扱う
Section titled “Constructorをimplicit primary outputを持つextern callableとして扱う”constructorは特別なlogical parameter規則を持たず、Selfをimplicit primary logical outputとして持つextern callableとする。
method outputs = non-void normal return + ref/out outputsconstructor outputs = constructed Self + ref/out outputsparameter projectionはADR-0031と同一である。
normal parameter -> inputref parameter -> input + outputout parameter -> output onlyconstructor logical outputはSelfを先頭に置き、その後へparameter宣言順のref/out outputを追加する。refとoutを種類別に並べ替えない。
Foo(ref int value, out string name, ref float weight)pub static fn new(value: i32, weight: f32) -> (Self, i32, string, f32) = extern new Self( ref i32 value, out string name, ref f32 weight, )by-ref parameterがなければ従来どおり単一のSelfを返し、(Self,)へはしない。outだけならlogical inputは空で、returnは(Self, T)となる。
Constructorでもparameter projectionを適用する
Section titled “Constructorでもparameter projectionを適用する”ADR-0032のmaybe outをconstructor ABI parameterにも許可する。
pub static fn new() -> (Self, Maybe<GameObject>) = extern new Self( maybe out GameObject owner, )physical ABIはconstructed result slotとout GameObject slotのままであり、logical outputだけをMaybe<GameObject>へ投影する。overload selection、validity resolution、aggregate constructionはmethodと同じ仕組みを使う。
Catalogと実際のUdon ABIをsource of truthとする
Section titled “Catalogと実際のUdon ABIをsource of truthとする”Binderはconstructor targetとexplicit ABI parameter mode/typeをreflection extern catalogのconcrete constructor candidateへ照合する。IR Lowererは選択済みExternMethodSymbolのphysical argument順とresult slotを使用し、ADR例からPUSH順を再推測しない。
logical result assemblyのみをSelf + projected ref/out outputsとして共通化する。UASM backendは解決済みphysical callとflatten済みlogical resultをemitし、constructor semanticsやsource modifierを再解釈しない。
Stub rendererはby-ref constructorのABI signatureを出力する
Section titled “Stub rendererはby-ref constructorのABI signatureを出力する”constructorにby-ref parameterがある場合、stub generatorはmethodと同じく右辺へ型、名前、ref/out modeを含むphysical ABI signatureを生成する。左辺はlogical inputとlogical returnを生成する。
generatorはreference outを自動的にmaybe outへ変更しない。nullable inference、policy file、manual overrideは本決定の範囲外であり、defaultはraw outを維持する。
Alternatives
Section titled “Alternatives”- Constructorだけ
ref/outを生成対象外にする。catalog completenessとmethodとの対称性を失うため採用しない。 - Constructor専用のparameter adaptationとloweringを追加する。同じphysical/logical規則が二重化し、順序差分を生みやすいため採用しない。
- Constructor resultを
ref/outの後ろへ置く。ADR-0031のprimary outputモデルと通常のconstructor APIに反するため採用しない。 - Generatorへnullable policyを同時導入する。APIごとのpolicy設計は独立した判断であり、本ADRのconstructor対称性を越えるため採用しない。
Rationale
Section titled “Rationale”constructorとmethodの差をprimary outputだけに限定すれば、physical parameter matching、logical input selection、output ordering、Maybe projection、aggregate flatteningを共有できる。catalogをABIのsource of truthとして維持しながら、生成sourceも同じmetadataを損失なく表現できる。
本ADRはADR-0031のoutput orderingを変更せずconstructorへ適用し、ADR-0032のparameter projectionも同じ位置へ合成する。
Consequences
Section titled “Consequences”Positive
Section titled “Positive”- normal、
ref、out、mixed constructorを同じlogical API規則で公開できる。 - constructed
Selfとparameter outputsの順序が一意になる。 - methodとconstructorが共通のBinder/IR adapterを利用する。
- constructor stubがphysical by-ref ABI modeを保持し、Parserへ再入力できる。
- constructorの
maybe outも通常のMaybe aggregate loweringを利用できる。
Negative
Section titled “Negative”- constructorのgenerated declarationはby-ref parameterを右辺に重ねて記述する必要がある。
Selfを含むmulti-output constructorでは利用側のdestructuringが必要になる。- nullable constructor outputを自動生成するpolicyは引き続き未定である。
Non-goals
Section titled “Non-goals”- constructorまたは通常functionへの一般的なreference semantics
maybe ref、nullable reference type system、ownership、borrow、lifetime- generatorのpolicy-driven redesign、nullable API inference、configuration file
- static class変換、命名変換、documentation URL生成