@@ -11,12 +11,17 @@ open Ast
1111open Wasm
1212
1313(* * Ownership kind for typed-wasm schema annotations.
14- Maps AffineScript ownership qualifiers to typed-wasm Level 7/10 verification. *)
15- type ownership_kind =
16- | Unrestricted (* * Plain value, no ownership constraint (Wasm i32/f64 etc.) *)
17- | Linear (* * TyOwn / own — consumed exactly once (typed-wasm Level 10 linearity) *)
18- | SharedBorrow (* * TyRef / ref — read-only aliasing safety (typed-wasm Level 7) *)
19- | ExclBorrow (* * TyMut / mut — exclusive mutable aliasing safety (typed-wasm Level 7) *)
14+
15+ Re-exported from [Tw_ownership_section] (the dedicated home,
16+ extracted 2026-05-24 per A3 of TYPED-WASM-ROADMAP.adoc). The
17+ type equation preserves constructor accessibility so
18+ [Codegen.Linear] etc. continue to resolve and [open Codegen]
19+ in [Tw_verify] / [Tw_interface] / [Test_e2e] is unaffected. *)
20+ type ownership_kind = Tw_ownership_section .ownership_kind =
21+ | Unrestricted
22+ | Linear
23+ | SharedBorrow
24+ | ExclBorrow
2025
2126(* * Code generation context *)
2227type context = {
@@ -111,19 +116,9 @@ let create_context () : context = {
111116 wasi_func_indices = [] ;
112117}
113118
114- (* * Extract ownership kind from a parameter declaration.
115- Checks p_ownership first; falls back to the shape of p_ty. *)
116- let ownership_kind_of_param (p : param ) : ownership_kind =
117- match p.p_ownership with
118- | Some Own -> Linear
119- | Some Ref -> SharedBorrow
120- | Some Mut -> ExclBorrow
121- | None ->
122- match p.p_ty with
123- | TyOwn _ -> Linear
124- | TyRef _ -> SharedBorrow
125- | TyMut _ -> ExclBorrow
126- | _ -> Unrestricted
119+ (* * Extract ownership kind from a parameter declaration. Re-exported
120+ from [Tw_ownership_section] (A3 refactor, 2026-05-24). *)
121+ let ownership_kind_of_param = Tw_ownership_section. ownership_kind_of_param
127122
128123(* * If [ty] names a known struct (through any number of own/ref/mut wrappers),
129124 return that struct's name. Lets us recover a struct's field layout from
@@ -136,45 +131,21 @@ let rec struct_name_of_ty (ty : type_expr) : string option =
136131 | TyOwn inner | TyRef inner | TyMut inner -> struct_name_of_ty inner
137132 | _ -> None
138133
139- (* * Extract ownership kind from an optional return type expression *)
140- let ownership_kind_of_ret (ret : type_expr option ) : ownership_kind =
141- match ret with
142- | Some (TyOwn _ ) -> Linear
143- | Some (TyRef _ ) -> SharedBorrow
144- | Some (TyMut _ ) -> ExclBorrow
145- | _ -> Unrestricted
134+ (* * Extract ownership kind from an optional return type expression.
135+ Re-exported from [Tw_ownership_section]. *)
136+ let ownership_kind_of_ret = Tw_ownership_section. ownership_kind_of_ret
146137
147- (* * Encode an ownership_kind as a single byte (0–3) *)
148- let ownership_kind_byte = function
149- | Unrestricted -> 0 | Linear -> 1 | SharedBorrow -> 2 | ExclBorrow -> 3
138+ (* * Encode an ownership_kind as a single byte (0–3).
139+ Re-exported from [Tw_ownership_section]. *)
140+ let ownership_kind_byte = Tw_ownership_section. ownership_kind_byte
150141
151142(* * Build the payload for the [affinescript.ownership] Wasm custom section.
152- Encoding (all little-endian):
153- u32 entry_count
154- per entry:
155- u32 func_index
156- u8 param_count
157- u8* param_kind (one per param, see kind encoding above)
158- u8 return_kind *)
159- let build_ownership_section (annots : (int * ownership_kind list * ownership_kind) list ) : bytes =
160- if annots = [] then Bytes. empty
161- else
162- let buf = Buffer. create 64 in
163- let write_u32_le n =
164- Buffer. add_char buf (Char. chr (n land 0xff ));
165- Buffer. add_char buf (Char. chr ((n lsr 8 ) land 0xff ));
166- Buffer. add_char buf (Char. chr ((n lsr 16 ) land 0xff ));
167- Buffer. add_char buf (Char. chr ((n lsr 24 ) land 0xff ))
168- in
169- let write_u8 n = Buffer. add_char buf (Char. chr (n land 0xff )) in
170- write_u32_le (List. length annots);
171- List. iter (fun (func_idx , param_kinds , ret_kind ) ->
172- write_u32_le func_idx;
173- write_u8 (List. length param_kinds);
174- List. iter (fun k -> write_u8 (ownership_kind_byte k)) param_kinds;
175- write_u8 (ownership_kind_byte ret_kind)
176- ) annots;
177- Buffer. to_bytes buf
143+ Re-exported from [Tw_ownership_section.build_section] (A3 refactor,
144+ 2026-05-24). The dedicated module is the home for the on-wire format;
145+ this alias preserves the [Codegen.build_ownership_section] public
146+ API surface that downstream callers (lib/tw_verify.ml,
147+ lib/tw_interface.ml, test/test_e2e.ml) rely on. *)
148+ let build_ownership_section = Tw_ownership_section. build_section
178149
179150(* * Map AffineScript type to WASM value type *)
180151let type_to_wasm (ty : type_expr ) : value_type result =
0 commit comments