@@ -68,18 +68,22 @@ pub struct VTableMap {
6868}
6969
7070impl VTableMap {
71+ const OFFSET : usize = 1000 ; // We should add some offset to ids to make 0 (null) an invalid id.
72+
7173 fn id ( & mut self , ty : Ty ) -> usize {
7274 if let Some ( it) = self . ty_to_id . get ( & ty) {
7375 return * it;
7476 }
75- let id = self . id_to_ty . len ( ) ;
77+ let id = self . id_to_ty . len ( ) + VTableMap :: OFFSET ;
7678 self . id_to_ty . push ( ty. clone ( ) ) ;
7779 self . ty_to_id . insert ( ty, id) ;
7880 id
7981 }
8082
8183 pub ( crate ) fn ty ( & self , id : usize ) -> Result < & Ty > {
82- self . id_to_ty . get ( id) . ok_or ( MirEvalError :: InvalidVTableId ( id) )
84+ id. checked_sub ( VTableMap :: OFFSET )
85+ . and_then ( |id| self . id_to_ty . get ( id) )
86+ . ok_or ( MirEvalError :: InvalidVTableId ( id) )
8387 }
8488
8589 fn ty_of_bytes ( & self , bytes : & [ u8 ] ) -> Result < & Ty > {
@@ -467,6 +471,10 @@ impl DropFlags {
467471
468472 fn remove_place ( & mut self , p : & Place ) -> bool {
469473 // FIXME: replace parents with parts
474+ if let Some ( parent) = p. iterate_over_parents ( ) . find ( |it| self . need_drop . contains ( & it) ) {
475+ self . need_drop . remove ( & parent) ;
476+ return true ;
477+ }
470478 self . need_drop . remove ( p)
471479 }
472480}
@@ -511,6 +519,11 @@ pub fn interpret_mir(
511519 )
512520}
513521
522+ #[ cfg( test) ]
523+ const EXECUTION_LIMIT : usize = 100_000 ;
524+ #[ cfg( not( test) ) ]
525+ const EXECUTION_LIMIT : usize = 10_000_000 ;
526+
514527impl Evaluator < ' _ > {
515528 pub fn new < ' a > (
516529 db : & ' a dyn HirDatabase ,
@@ -534,7 +547,7 @@ impl Evaluator<'_> {
534547 stderr : vec ! [ ] ,
535548 assert_placeholder_ty_is_unused,
536549 stack_depth_limit : 100 ,
537- execution_limit : 1000_000 ,
550+ execution_limit : EXECUTION_LIMIT ,
538551 memory_limit : 1000_000_000 , // 2GB, 1GB for stack and 1GB for heap
539552 layout_cache : RefCell :: new ( HashMap :: default ( ) ) ,
540553 }
@@ -683,8 +696,10 @@ impl Evaluator<'_> {
683696 . offset ( u32:: from ( f. local_id . into_raw ( ) ) as usize )
684697 . bytes_usize ( ) ;
685698 addr = addr. offset ( offset) ;
686- // FIXME: support structs with unsized fields
687- metadata = None ;
699+ // Unsized field metadata is equal to the metadata of the struct
700+ if self . size_align_of ( & ty, locals) ?. is_some ( ) {
701+ metadata = None ;
702+ }
688703 }
689704 ProjectionElem :: OpaqueCast ( _) => not_supported ! ( "opaque cast" ) ,
690705 }
@@ -1803,6 +1818,17 @@ impl Evaluator<'_> {
18031818 }
18041819 }
18051820 }
1821+ chalk_ir:: TyKind :: Array ( inner, len) => {
1822+ let len = match try_const_usize ( this. db , & len) {
1823+ Some ( it) => it as usize ,
1824+ None => not_supported ! ( "non evaluatable array len in patching addresses" ) ,
1825+ } ;
1826+ let size = this. size_of_sized ( inner, locals, "inner of array" ) ?;
1827+ for i in 0 ..len {
1828+ let offset = i * size;
1829+ rec ( this, & bytes[ offset..offset + size] , inner, locals, mm) ?;
1830+ }
1831+ }
18061832 chalk_ir:: TyKind :: Tuple ( _, subst) => {
18071833 let layout = this. layout ( ty) ?;
18081834 for ( id, ty) in subst. iter ( Interner ) . enumerate ( ) {
@@ -1911,10 +1937,31 @@ impl Evaluator<'_> {
19111937 AdtId :: UnionId ( _) => ( ) ,
19121938 AdtId :: EnumId ( _) => ( ) ,
19131939 } ,
1940+ TyKind :: Tuple ( _, subst) => {
1941+ for ( id, ty) in subst. iter ( Interner ) . enumerate ( ) {
1942+ let ty = ty. assert_ty_ref ( Interner ) ; // Tuple only has type argument
1943+ let offset = layout. fields . offset ( id) . bytes_usize ( ) ;
1944+ self . patch_addresses ( patch_map, old_vtable, addr. offset ( offset) , ty, locals) ?;
1945+ }
1946+ }
1947+ TyKind :: Array ( inner, len) => {
1948+ let len = match try_const_usize ( self . db , & len) {
1949+ Some ( it) => it as usize ,
1950+ None => not_supported ! ( "non evaluatable array len in patching addresses" ) ,
1951+ } ;
1952+ let size = self . size_of_sized ( inner, locals, "inner of array" ) ?;
1953+ for i in 0 ..len {
1954+ self . patch_addresses (
1955+ patch_map,
1956+ old_vtable,
1957+ addr. offset ( i * size) ,
1958+ inner,
1959+ locals,
1960+ ) ?;
1961+ }
1962+ }
19141963 TyKind :: AssociatedType ( _, _)
19151964 | TyKind :: Scalar ( _)
1916- | TyKind :: Tuple ( _, _)
1917- | TyKind :: Array ( _, _)
19181965 | TyKind :: Slice ( _)
19191966 | TyKind :: Raw ( _, _)
19201967 | TyKind :: OpaqueType ( _, _)
0 commit comments