11use serde:: { Deserialize , Serialize } ;
22
3- pub const LOWERING_RECORD_SCHEMA : & str = "cellscript-verified-lowering-record-v2 " ;
4- pub const TYPED_SEMANTICS_SCHEMA : & str = "cellscript-typed-semantics-v1 " ;
3+ pub const LOWERING_RECORD_SCHEMA : & str = "cellscript-verified-lowering-record-v3 " ;
4+ pub const TYPED_SEMANTICS_SCHEMA : & str = "cellscript-typed-semantics-v2 " ;
55pub const SOURCE_MAP_SCHEMA : & str = "cellscript-source-artifact-map-v1" ;
66pub const CHECKER_POLICY_SCHEMA : & str = "cellscript-artifact-checker-policy-v1" ;
77pub const CHECKER_REPORT_SCHEMA : & str = "cellscript-artifact-checker-report-v1" ;
8- pub const LOWERING_RECORD_VERSION : u32 = 2 ;
8+ pub const LOWERING_RECORD_VERSION : u32 = 3 ;
9+ pub const TYPED_SEMANTICS_VERSION : u32 = 2 ;
910pub const SOURCE_MAP_VERSION : u32 = 1 ;
1011pub const CHECKER_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
1112
@@ -68,6 +69,11 @@ impl VerifiedLoweringRecord {
6869 entry. proof_ids . dedup ( ) ;
6970 entry. capabilities . sort ( ) ;
7071 entry. capabilities . dedup ( ) ;
72+ entry. typed_blocks . sort_by_key ( |block| block. id ) ;
73+ for block in & mut entry. typed_blocks {
74+ block. machine_block_ids . sort ( ) ;
75+ block. machine_block_ids . dedup ( ) ;
76+ }
7177 }
7278 self . blocks . sort_by ( |a, b| a. id . cmp ( & b. id ) ) ;
7379 for block in & mut self . blocks {
@@ -104,6 +110,10 @@ impl TypedSemanticRecord {
104110 self . types . sort_by ( |left, right| left. name . cmp ( & right. name ) ) ;
105111 for ty in & mut self . types {
106112 ty. fields . sort_by ( |left, right| left. offset . cmp ( & right. offset ) . then ( left. name . cmp ( & right. name ) ) ) ;
113+ ty. variants . sort_by ( |left, right| left. tag . cmp ( & right. tag ) . then ( left. name . cmp ( & right. name ) ) ) ;
114+ for variant in & mut ty. variants {
115+ variant. fields . sort_by_key ( |field| field. index ) ;
116+ }
107117 ty. capabilities . sort ( ) ;
108118 ty. capabilities . dedup ( ) ;
109119 }
@@ -133,7 +143,10 @@ pub struct TypedSemanticType {
133143 pub kind : String ,
134144 pub encoded_size : Option < u32 > ,
135145 pub fields : Vec < TypedSemanticField > ,
146+ pub tag_width_bytes : Option < u32 > ,
147+ pub variants : Vec < TypedSemanticVariant > ,
136148 pub capabilities : Vec < String > ,
149+ pub identity_policy : String ,
137150 pub layout_hash : String ,
138151}
139152
@@ -146,6 +159,25 @@ pub struct TypedSemanticField {
146159 pub width_bytes : Option < u32 > ,
147160}
148161
162+ #[ derive( Debug , Clone , Default , PartialEq , Eq , Serialize , Deserialize ) ]
163+ #[ serde( deny_unknown_fields) ]
164+ pub struct TypedSemanticVariant {
165+ pub name : String ,
166+ pub tag : u32 ,
167+ pub payload_width_bytes : u32 ,
168+ pub fields : Vec < TypedSemanticVariantField > ,
169+ }
170+
171+ #[ derive( Debug , Clone , Default , PartialEq , Eq , Serialize , Deserialize ) ]
172+ #[ serde( deny_unknown_fields) ]
173+ pub struct TypedSemanticVariantField {
174+ pub index : u32 ,
175+ pub ty : String ,
176+ pub offset : u32 ,
177+ pub width_bytes : u32 ,
178+ pub linear : bool ,
179+ }
180+
149181#[ derive( Debug , Clone , Default , PartialEq , Eq , Serialize , Deserialize ) ]
150182#[ serde( deny_unknown_fields) ]
151183pub struct TypedSemanticEntry {
@@ -155,6 +187,7 @@ pub struct TypedSemanticEntry {
155187 pub params : Vec < TypedSemanticParam > ,
156188 pub return_type : String ,
157189 pub effect : String ,
190+ pub entry_block : u32 ,
158191 pub locals : Vec < TypedSemanticLocal > ,
159192 pub blocks : Vec < TypedSemanticBlock > ,
160193 pub borrows : Vec < TypedSemanticBorrow > ,
@@ -178,6 +211,7 @@ pub struct TypedSemanticParam {
178211#[ serde( deny_unknown_fields) ]
179212pub struct TypedSemanticLocal {
180213 pub id : u32 ,
214+ pub source_id : u64 ,
181215 pub name : String ,
182216 pub ty : String ,
183217}
@@ -189,14 +223,24 @@ pub struct TypedSemanticBlock {
189223 pub operations : Vec < TypedSemanticOperation > ,
190224 pub successors : Vec < u32 > ,
191225 pub terminator : String ,
226+ pub runtime_error : Option < TypedSemanticRuntimeError > ,
227+ }
228+
229+ #[ derive( Debug , Clone , Default , PartialEq , Eq , Serialize , Deserialize ) ]
230+ #[ serde( deny_unknown_fields) ]
231+ pub struct TypedSemanticRuntimeError {
232+ pub code : u64 ,
233+ pub name : String ,
192234}
193235
194236#[ derive( Debug , Clone , Default , PartialEq , Eq , Serialize , Deserialize ) ]
195237#[ serde( deny_unknown_fields) ]
196238pub struct TypedSemanticOperation {
239+ pub index : u32 ,
197240 pub opcode : String ,
198241 pub destinations : Vec < u32 > ,
199242 pub operands : Vec < TypedSemanticOperand > ,
243+ pub detail : TypedSemanticOperationDetail ,
200244 pub call : Option < TypedSemanticCall > ,
201245}
202246
@@ -205,6 +249,90 @@ pub struct TypedSemanticOperation {
205249pub struct TypedSemanticOperand {
206250 pub local : Option < u32 > ,
207251 pub ty : String ,
252+ pub constant : Option < TypedSemanticConstant > ,
253+ }
254+
255+ #[ derive( Debug , Clone , Default , PartialEq , Eq , Serialize , Deserialize ) ]
256+ #[ serde( tag = "kind" , rename_all = "kebab-case" , deny_unknown_fields) ]
257+ pub enum TypedSemanticOperationDetail {
258+ #[ default]
259+ None ,
260+ Constant {
261+ value : TypedSemanticConstant ,
262+ } ,
263+ Binding {
264+ name : String ,
265+ } ,
266+ BinaryOperator {
267+ operator : String ,
268+ } ,
269+ UnaryOperator {
270+ operator : String ,
271+ } ,
272+ Field {
273+ name : String ,
274+ } ,
275+ Collection {
276+ declared_type : String ,
277+ } ,
278+ Reference {
279+ declared_type : String ,
280+ } ,
281+ EnumConstruct {
282+ enum_name : String ,
283+ variant : String ,
284+ } ,
285+ EnumTag {
286+ enum_name : String ,
287+ } ,
288+ EnumPayload {
289+ enum_name : String ,
290+ variant : String ,
291+ field_index : u32 ,
292+ } ,
293+ Create {
294+ pattern : TypedSemanticCreatePattern ,
295+ } ,
296+ Destroy {
297+ policy : String ,
298+ } ,
299+ CreateUnique {
300+ pattern : TypedSemanticCreatePattern ,
301+ identity : String ,
302+ } ,
303+ ReplaceUnique {
304+ pattern : TypedSemanticCreatePattern ,
305+ identity : String ,
306+ } ,
307+ CellMetadata {
308+ field : String ,
309+ } ,
310+ }
311+
312+ #[ derive( Debug , Clone , Default , PartialEq , Eq , Serialize , Deserialize ) ]
313+ #[ serde( deny_unknown_fields) ]
314+ pub struct TypedSemanticCreatePattern {
315+ pub operation : String ,
316+ pub ty : String ,
317+ pub binding : String ,
318+ pub field_names : Vec < String > ,
319+ pub has_lock : bool ,
320+ pub identity : String ,
321+ }
322+
323+ #[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
324+ #[ serde( tag = "kind" , content = "value" , rename_all = "kebab-case" , deny_unknown_fields) ]
325+ pub enum TypedSemanticConstant {
326+ Unit ,
327+ U8 ( String ) ,
328+ U16 ( String ) ,
329+ U32 ( String ) ,
330+ U64 ( String ) ,
331+ U128 ( String ) ,
332+ Bool ( bool ) ,
333+ Address ( String ) ,
334+ Hash ( String ) ,
335+ Array ( Vec < TypedSemanticConstant > ) ,
208336}
209337
210338#[ derive( Debug , Clone , Default , PartialEq , Eq , Serialize , Deserialize ) ]
@@ -225,6 +353,10 @@ pub struct TypedSemanticBorrow {
225353 pub binding : String ,
226354 pub root_type : String ,
227355 pub view_type : String ,
356+ pub start_block : u32 ,
357+ pub start_operation : u32 ,
358+ pub end_block : Option < u32 > ,
359+ pub end_operation : Option < u32 > ,
228360 pub escapes : bool ,
229361}
230362
@@ -242,10 +374,16 @@ pub struct TypedSemanticOwnership {
242374#[ serde( deny_unknown_fields) ]
243375pub struct TypedSemanticInstantiation {
244376 pub kind : String ,
377+ pub module : String ,
245378 pub template : String ,
379+ pub concrete_name : String ,
246380 pub identity : String ,
247381 pub type_arguments : Vec < String > ,
382+ pub value_ability_registry_version : u32 ,
248383 pub constraints_verified : bool ,
384+ pub fixed_layout_required : bool ,
385+ pub cell_backed_layout_rejected : bool ,
386+ pub identity_includes_phantom_arguments : bool ,
249387}
250388
251389#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
@@ -262,6 +400,15 @@ pub struct LoweringEntry {
262400 pub proof_ids : Vec < String > ,
263401 pub frame_size_bytes : u32 ,
264402 pub outgoing_argument_bytes : u32 ,
403+ pub typed_blocks : Vec < TypedBlockBinding > ,
404+ }
405+
406+ #[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
407+ #[ serde( deny_unknown_fields) ]
408+ pub struct TypedBlockBinding {
409+ pub id : u32 ,
410+ pub hash : String ,
411+ pub machine_block_ids : Vec < String > ,
265412}
266413
267414#[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Serialize , Deserialize ) ]
@@ -302,6 +449,7 @@ pub struct LoweringBlock {
302449 pub owner_entry : String ,
303450 pub reachable : bool ,
304451 pub lowering_block_id : Option < u32 > ,
452+ pub typed_block_hash : Option < String > ,
305453 pub machine_label : Option < String > ,
306454 pub terminator : MachineTerminator ,
307455 pub range : MachineRange ,
0 commit comments