/** * emit-shared-go-typed.ts — Go typed 共有 emit エンジン(旧 emit-straightline-typed-go.ts, bc#47 / Layer B2)。 * #90/#99 で go-typed emitter plugin surface は撤去。この module は native(go) が消費する共有 typed * ヘルパ(goTypedInternals: typedFieldAccess/materializeExpr/emitMarshallers/emitTypeDecls/serializeTyped 等)のみ。 * * typed-codegen.md §4.3/§4.4 の Go 具体化。**最初のコンパイル言語の typed emitter**であり、B2-ts で * decls-only だった {@link TypedMaterializer} seam を **runtime-materialization 対応に拡張(co-design)** * した上で、その拡張 hook を Go で実装する(rust #48 が同じ拡張 seam に乗る)。 * * ── TS oracle との決定的な違い(実 de-box)─────────────────────────────────────── * TS は型消去のため runtime の脱box が無い(生成モジュールの runtime は straight-line と byte-identical)。 * **Go は違う**: `outType`/`outputType` を持つノード/component の exec 経路は、動的 `Value` / * `map[string]interface{}` ではなく **outType 由来の具体 Go struct**(`T0`/`T1`/…)で値を保持する * (=Phase B 脱box の実体を Go で)。生成物の構成: * * 1. **straight-line 本体**(`go-straightline` と byte 同一の `run_*`): 生の scope(`*Obj` = 動的 Value)を * 組む。handler は境界注入で Value を返す mock(bc conformance では "raw" = この Value)。 * 2. **struct 宣言**(typed のみ): 型プランの named obj を Go struct へ(決定的名+hash-dedup — typed.ts 共有)。 * 3. **raw→typed marshaller**(§4.4): 各 struct に `marshal_T*(Value) (T*, error)` を emit。動的 Value の * 各 field を **typed に読み出して具体 struct を組む**(generic Value 走査を exec から除去する de-box)。 * 4. **typed view 関数**(実 exec 経路): `typedView_(scope *Obj) (Value, error)`。straight-line が * 組んだ生 scope の各 typed node を marshaller で **具体 struct へ materialize**(typed ローカル)し、 * `ref` は **struct field 直参照**(map lookup でない)で辿り、output を **具体 struct/scalar/slice として * 組み立て**、境界で canonical Value へ戻す(観測等価 pin)。この関数は Bind から**実際に呼ばれる** * (dead な struct 宣言ではない — AC の「手抜き禁止」)。 * 5. **Bind**: typed component は typedView 経路(実 de-box)、untyped component は straight-line 経路。 * * ── 後方互換 ──────────────────────────────────────────────────────────────────── * `outType`/`outputType` が IR のどこにも無ければ typed 層は emit されず、出力は `go-straightline` と * byte-identical(後方互換 pin)。 */ import type { EmitContext } from "./core.js"; import { type SlotRefLowering, type TypePlan, type TypeRef } from "./typed.js"; import { setGoForceRunPlanHelpers } from "./emit-shared-go.js"; import type { Component } from "../behavior.js"; /** 可搬スカラ → Go の具体型名(de-box 後の struct field 型)。int/float は int64/float64 で区別。 */ declare function goScalar(scalar: "string" | "int" | "float" | "bool" | "null"): string; export declare function setGoWireValueName(name: string): void; /** TypeRef を Go の具体型名へ(named→struct 名、arr→slice、opt→ポインタ、scalar→具体型)。 */ declare function renderTypeRef(ref: TypeRef): string; /** 型プランの named obj を Go struct 宣言へ(decls 順=決定的)。field は宣言順・export 名。gofmt と同じ * 列アラインで綴じる(field 名列・型列を最大幅に揃える — 生成物が gofmt clean になるよう)。 */ declare function emitTypeDecls(plan: TypePlan): string; /** wire field 名 → Go の export struct field 名(決定的・一意)。元名は struct コメント/marshaller で保持。 */ declare function goFieldName(wire: string): string; /** * emitMarshallers — 各 named struct の raw→typed marshaller(§4.4)。動的 Value(`*Obj` 期待)を受け、 * 各 field を typed に読み出して具体 struct を組む。generic Value 走査を exec 経路から除去する de-box の実体。 * field 型ごとに再帰: named→marshal_T*、arr→要素ループ、opt→null 分岐、scalar→型 assert。 */ declare function emitMarshallers(plan: TypePlan): string; /** * materializeExpr — raw な Value 式 `rawExpr` を型 `ref` の具体 typed 値へ変換する **単一式**(exec 経路の * de-box)。named→`mustMarshal_T*`(marshaller 経由で具体 struct へ)、scalar→型 assert helper、arr/opt→ * 具体 slice/pointer helper。呼び側(typed view の output assembly / node materialize)が typed ローカルへ束ねる。 * これが seam の runtime-materialization hook の Go 実装本体(rust #48 は同型の hook を返す)。 */ declare function materializeExpr(rawExpr: string, ref: TypeRef, _plan: TypePlan): string; /** * typedFieldAccess — typed base 式 `baseExpr`(型 `baseRef`)に field path を **struct field 直参照**で辿る。 * map lookup ではなく `.FieldName` 連結(=de-box されている証拠)。辿り着いた TypeRef も返す。 */ declare function typedFieldAccess(baseExpr: string, baseRef: TypeRef, fields: string[], plan: TypePlan): { expr: string; ref: TypeRef; }; /** * serializeTyped — 具体 typed 値式を canonical 直列化用の動的 Value へ戻す式(観測等価 pin)。exec は * typed のまま進み、component 境界でだけ Value 化して golden と突き合わせる。named→ser_T*、scalar は * そのまま Value、arr→要素 ser ループ helper、opt→null 分岐 helper。式一発で返せるよう helper を通す。 */ declare function serializeTyped(typedExpr: string, ref: TypeRef, _plan: TypePlan): string; /** component 名 → Go 関数名(straight-line と同規律)。 */ declare function sanitize(name: string): string; /** 生成コード内の typed ローカル変数名(materialize 済み struct)。 */ declare function typedLocal(nodeId: string): string; /** * emitTypedValue — output(Φ 合流式)IR を、期待型 `expected` の **具体 Go typed 値**式へ再帰 lower し、 * `{ expr, ref }` を返す。これが AC2 の「exec が具体 struct を保持」の実体: * - `{ref:[typedNode, …fields]}` → typed struct field 直参照(typedFieldAccess — map lookup でない)。 * - `{ref:[input/非 typed node]}` → 型付け不能な生 Value。expected があれば materialize(de-box)。 * - `{obj:{…}}` → 具体 struct literal(expected が named のとき各 field を期待型で lower)。 * - `{arr:[…]}` → 具体 slice literal(要素は要素型で lower)。 * - scalar literal → 具体 Go 値。 * - 演算子(concat/…)→ straight-line 生値を expected へ materialize(意味論は SSoT が持つ)。 * * `slotRef`({@link SlotRefLowering})は node 結果参照位置の per-emitter lowering seam。**この 1 本の再帰が * 降りる全スロット**(component 出力 / struct field / 配列要素 / 演算子オペランド)で自分の `ref` 処理より * 先に consult される。produced-aware 出力 lowering(#86 pt1)はこれで乗る — 以前は obj 分岐を逐語コピー * した **2 本目の再帰**で、配列要素に届かなかった(#293/#295)。 */ declare function emitTypedValue(node: unknown, expected: TypeRef | undefined, typedNodes: Map, plan: TypePlan, compName?: string, fieldPath?: string, slotRef?: SlotRefLowering): { expr: string; ref: TypeRef | undefined; }; /** * collectTypedNodes — component の body ノードで outType を持つもの(componentRef / map / cond)を * id → 結果 TypeRef に index 化する。map/cond も struct 空間で結果を保持する(#66 de-box 拡張)。 */ declare function collectTypedNodes(comp: Component, plan: TypePlan): Map; /** arr/opt helper 名の決定的キー(要素型で一意化)。 */ declare function arrHelperKey(ref: TypeRef): string; declare function hasAnyTypeAnnotation(ctx: EmitContext): boolean; /** typed component(typedView 経路で駆動するもの)か。 */ declare function isTypedComponent(comp: Component): boolean; /** * emitArrOptNodeHelpers — arr/opt を outType に持つ **node**(named でない node)用の materialize helper * `mustArr_*` / `mustOpt_*` を、IR に現れる arr/opt node outType 集合から決定的に emit する。要素/inner が * named なら marshaller を、scalar なら型 assert を、ネスト arr/opt なら再帰 helper を呼ぶ(具体 slice/ptr へ de-box)。 */ declare function emitArrOptNodeHelpers(ctx: EmitContext, plan: TypePlan): string; /** * goTypedInternals — shared Go typed-emit helpers the native emitter (emit-typed-native-go.ts) * reuses so the native de-box path shares one implementation of the type-plan/naming/serializer/ * marshaller discipline. This module carries NO emitter plugin (#90/#99): the go-typed and * go-straightline emitter surfaces were removed — go converges to the native target only. */ export declare const goTypedInternals: { PKG: string; sanitize: typeof sanitize; goFieldName: typeof goFieldName; renderTypeRef: typeof renderTypeRef; setGoWireValueName: typeof setGoWireValueName; goScalar: typeof goScalar; typedLocal: typeof typedLocal; isTypedComponent: typeof isTypedComponent; collectTypedNodes: typeof collectTypedNodes; hasAnyTypeAnnotation: typeof hasAnyTypeAnnotation; emitTypeDecls: typeof emitTypeDecls; emitMarshallers: typeof emitMarshallers; materializeExpr: typeof materializeExpr; serializeTyped: typeof serializeTyped; typedFieldAccess: typeof typedFieldAccess; emitTypedValue: typeof emitTypedValue; checkOutputFieldType: import("./typed.js").OutputFieldTypeCheck; arrHelperKey: typeof arrHelperKey; emitArrOptNodeHelpers: typeof emitArrOptNodeHelpers; buildComponentPlanForTyped: (comp: Component) => import("./straightline.js").ComponentPlan; emitOpsLiteral: (plan: import("./straightline.js").ComponentPlan) => string; emitBehaviorPlanLiteral: (plan: unknown) => string; goPortVar: (name: string) => string; setGoForceRunPlanHelpers: typeof setGoForceRunPlanHelpers; }; export {}; //# sourceMappingURL=emit-shared-go-typed.d.ts.map