@@ -5,9 +5,6 @@ use crate::{
55 error:: { Error , Result , SierraAssertError } ,
66 metadata:: { runtime_bindings:: RuntimeBindingsMeta , MetadataStorage } ,
77 native_assert,
8- types:: array:: {
9- calc_metadata_align, calc_metadata_size, load_data_ptr, store_data_ptr, store_max_len,
10- } ,
118 utils:: ProgramRegistryExt ,
129} ;
1310use cairo_lang_sierra:: {
@@ -189,25 +186,7 @@ pub fn build_span_from_tuple<'ctx, 'this>(
189186 // data_ptr aliases the input box: both are arena-backed.
190187 let data_ptr: Value = entry. argument ( 0 ) ?. into ( ) ;
191188
192- // Allocate metadata struct from the arena.
193- let metadata_size = entry. const_int ( context, location, calc_metadata_size ( ) , 64 ) ?;
194- let metadata_align_val = entry. const_int ( context, location, calc_metadata_align ( ) , 64 ) ?;
195- let metadata_ptr = {
196- let rtb = metadata. get_or_insert_with ( RuntimeBindingsMeta :: default) ;
197- rtb. arena_alloc (
198- context,
199- helper. module ,
200- entry,
201- location,
202- metadata_size,
203- metadata_align_val,
204- ) ?
205- } ;
206-
207- store_max_len ( context, entry, location, metadata_ptr, array_len) ?;
208- store_data_ptr ( context, entry, location, metadata_ptr, data_ptr) ?;
209-
210- // Build the array representation (4 fields: metadata_ptr, start, end, capacity)
189+ // Build the array representation (4 fields: data_ptr, start, end, capacity)
211190 let value = entry. append_op_result ( llvm:: undef (
212191 llvm:: r#type:: r#struct ( context, & [ ptr_ty, len_ty, len_ty, len_ty] , false ) ,
213192 location,
@@ -216,7 +195,7 @@ pub fn build_span_from_tuple<'ctx, 'this>(
216195 context,
217196 location,
218197 value,
219- & [ metadata_ptr , k0, array_len, array_len] ,
198+ & [ data_ptr , k0, array_len, array_len] ,
220199 ) ?;
221200
222201 helper. br ( entry, 0 , & [ value] , location)
@@ -265,8 +244,7 @@ pub fn build_tuple_from_span<'ctx, 'this>(
265244 let len_ty = IntegerType :: new ( context, 32 ) . into ( ) ;
266245 let ( _, elem_layout) = registry. build_type_with_layout ( context, helper, metadata, elem_id) ?;
267246
268- let metadata_ptr =
269- entry. extract_value ( context, location, entry. argument ( 0 ) ?. into ( ) , ptr_ty, 0 ) ?;
247+ let data_ptr = entry. extract_value ( context, location, entry. argument ( 0 ) ?. into ( ) , ptr_ty, 0 ) ?;
270248 let array_start =
271249 entry. extract_value ( context, location, entry. argument ( 0 ) ?. into ( ) , len_ty, 1 ) ?;
272250 let array_end = entry. extract_value ( context, location, entry. argument ( 0 ) ?. into ( ) , len_ty, 2 ) ?;
@@ -306,8 +284,6 @@ pub fn build_tuple_from_span<'ctx, 'this>(
306284 location,
307285 ) ) ?;
308286
309- let data_ptr = load_data_ptr ( context, valid_block, location, metadata_ptr) ?;
310-
311287 let array_data_start_ptr = valid_block. gep (
312288 context,
313289 location,
@@ -376,21 +352,19 @@ pub fn build_append<'ctx, 'this>(
376352 Result :: Ok ( ( realloc_len, realloc_size) )
377353 }
378354
379- let metadata_ptr =
380- entry. extract_value ( context, location, entry. argument ( 0 ) ?. into ( ) , ptr_ty, 0 ) ?;
355+ let data_ptr = entry. extract_value ( context, location, entry. argument ( 0 ) ?. into ( ) , ptr_ty, 0 ) ?;
381356 let null_ptr = entry. append_op_result ( llvm:: zero ( ptr_ty, location) ) ?;
382357 let is_empty = entry. append_op_result (
383358 ods:: llvm:: icmp (
384359 context,
385360 IntegerType :: new ( context, 1 ) . into ( ) ,
386- metadata_ptr ,
361+ data_ptr ,
387362 null_ptr,
388363 IntegerAttribute :: new ( IntegerType :: new ( context, 64 ) . into ( ) , 0 ) . into ( ) ,
389364 location,
390365 )
391366 . into ( ) ,
392367 ) ?;
393- let k0 = entry. const_int_from_type ( context, location, 0 , len_ty) ?;
394368 let array_obj = entry. append_op_result ( scf:: r#if (
395369 is_empty,
396370 & [ self_ty] ,
@@ -416,28 +390,8 @@ pub fn build_append<'ctx, 'this>(
416390 ) ?
417391 } ;
418392
419- // Allocate metadata struct from the arena.
420- let metadata_size = block. const_int ( context, location, calc_metadata_size ( ) , 64 ) ?;
421- let metadata_align_val =
422- block. const_int ( context, location, calc_metadata_align ( ) , 64 ) ?;
423- let metadata_ptr = {
424- let rtb = metadata. get_or_insert_with ( RuntimeBindingsMeta :: default) ;
425- rtb. arena_alloc (
426- context,
427- helper. module ,
428- & block,
429- location,
430- metadata_size,
431- metadata_align_val,
432- ) ?
433- } ;
434-
435- store_max_len ( context, & block, location, metadata_ptr, k0) ?;
436- store_data_ptr ( context, & block, location, metadata_ptr, data_ptr) ?;
437-
438- // Build 4-field struct with capacity
439393 let array_obj = entry. argument ( 0 ) ?. into ( ) ;
440- let array_obj = block. insert_value ( context, location, array_obj, metadata_ptr , 0 ) ?;
394+ let array_obj = block. insert_value ( context, location, array_obj, data_ptr , 0 ) ?;
441395 let array_obj = block. insert_value ( context, location, array_obj, array_capacity, 3 ) ?;
442396 block. append_operation ( scf:: r#yield ( & [ array_obj] , location) ) ;
443397 region
@@ -480,22 +434,15 @@ pub fn build_append<'ctx, 'this>(
480434 array_capacity,
481435 ) ?;
482436
483- let metadata_ptr = block. extract_value (
484- context,
485- location,
486- entry. argument ( 0 ) ?. into ( ) ,
487- ptr_ty,
488- 0 ,
489- ) ?;
490- let data_ptr = load_data_ptr ( context, & block, location, metadata_ptr) ?;
491-
492437 // Only [0, array_end) holds live data; the tail up to capacity is unused.
493438 let array_end_64 =
494439 block. extui ( array_end, IntegerType :: new ( context, 64 ) . into ( ) , location) ?;
495440 let copy_size = block. muli ( array_end_64, elem_stride, location) ?;
496441 let data_align = block. const_int ( context, location, elem_align, 64 ) ?;
497442
498443 // Arena-realloc the data (old buffer is abandoned in the arena).
444+ // Pre-existing snapshots keep pointing at the old buffer, which remains
445+ // alive in the arena; the memcpy preserves their visible prefix.
499446 let new_data_ptr = {
500447 let rtb = metadata. get_or_insert_with ( RuntimeBindingsMeta :: default) ;
501448 rtb. arena_alloc (
@@ -509,11 +456,9 @@ pub fn build_append<'ctx, 'this>(
509456 } ;
510457 block. memcpy ( context, location, data_ptr, new_data_ptr, copy_size) ;
511458
512- // Update data_ptr in metadata
513- store_data_ptr ( context, & block, location, metadata_ptr, new_data_ptr) ?;
514-
515- // Update capacity in struct field 3
516459 let array_obj = entry. argument ( 0 ) ?. into ( ) ;
460+ let array_obj =
461+ block. insert_value ( context, location, array_obj, new_data_ptr, 0 ) ?;
517462 let array_obj =
518463 block. insert_value ( context, location, array_obj, new_capacity, 3 ) ?;
519464 block. append_operation ( scf:: r#yield ( & [ array_obj] , location) ) ;
@@ -528,8 +473,7 @@ pub fn build_append<'ctx, 'this>(
528473 location,
529474 ) ) ?;
530475
531- let metadata_ptr = entry. extract_value ( context, location, array_obj, ptr_ty, 0 ) ?;
532- let data_ptr = load_data_ptr ( context, entry, location, metadata_ptr) ?;
476+ let data_ptr = entry. extract_value ( context, location, array_obj, ptr_ty, 0 ) ?;
533477
534478 // Insert the value.
535479 let target_offset = entry. extract_value ( context, location, array_obj, len_ty, 2 ) ?;
@@ -555,8 +499,6 @@ pub fn build_append<'ctx, 'this>(
555499 let array_end = entry. addi ( array_end, k1, location) ?;
556500 let array_obj = entry. insert_value ( context, location, array_obj, array_end, 2 ) ?;
557501
558- store_max_len ( context, entry, location, metadata_ptr, array_end) ?;
559-
560502 helper. br ( entry, 0 , & [ array_obj] , location)
561503}
562504
@@ -656,9 +598,7 @@ fn build_pop<'ctx, 'this, const CONSUME: bool, const REVERSE: bool>(
656598 {
657599 let mut branch_values = branch_values. clone ( ) ;
658600
659- let metadata_ptr = valid_block. extract_value ( context, location, array_obj, ptr_ty, 0 ) ?;
660-
661- let data_ptr = load_data_ptr ( context, valid_block, location, metadata_ptr) ?;
601+ let data_ptr = valid_block. extract_value ( context, location, array_obj, ptr_ty, 0 ) ?;
662602
663603 let elem_stride =
664604 valid_block. const_int ( context, location, elem_layout. pad_to_align ( ) . size ( ) , 64 ) ?;
@@ -790,9 +730,8 @@ pub fn build_get<'ctx, 'this>(
790730 ) ?;
791731 let source_offset = valid_block. muli ( source_offset, elem_stride, location) ?;
792732
793- let metadata_ptr =
733+ let data_ptr =
794734 valid_block. extract_value ( context, location, entry. argument ( 1 ) ?. into ( ) , ptr_ty, 0 ) ?;
795- let data_ptr = load_data_ptr ( context, valid_block, location, metadata_ptr) ?;
796735
797736 let source_ptr = valid_block. gep (
798737 context,
0 commit comments