@@ -3,7 +3,7 @@ use crate::erase::{ErasureHints, ResolvedCall};
3
3
use crate :: rust_to_vir_base:: {
4
4
def_id_to_vir_path, local_to_var, mid_ty_const_to_vir, mid_ty_to_vir_datatype,
5
5
} ;
6
- use crate :: rust_to_vir_expr:: get_adt_res;
6
+ use crate :: rust_to_vir_expr:: { field_name_to_vir_ident , get_adt_res} ;
7
7
use crate :: verus_items:: { PervasiveItem , RustItem , VerusItem , VerusItems } ;
8
8
use crate :: { lifetime_ast:: * , verus_items} ;
9
9
use air:: ast_util:: str_ident;
@@ -77,6 +77,7 @@ pub(crate) struct State {
77
77
datatype_worklist : Vec < DefId > ,
78
78
imported_fun_worklist : Vec < DefId > ,
79
79
id_to_name : HashMap < String , Id > ,
80
+ field_to_name : HashMap < String , Id > ,
80
81
typ_param_to_name : HashMap < ( String , Option < u32 > ) , Id > ,
81
82
lifetime_to_name : HashMap < ( String , Option < u32 > ) , Id > ,
82
83
fun_to_name : HashMap < Fun , Id > ,
@@ -99,6 +100,7 @@ impl State {
99
100
datatype_worklist : Vec :: new ( ) ,
100
101
imported_fun_worklist : Vec :: new ( ) ,
101
102
id_to_name : HashMap :: new ( ) ,
103
+ field_to_name : HashMap :: new ( ) ,
102
104
typ_param_to_name : HashMap :: new ( ) ,
103
105
lifetime_to_name : HashMap :: new ( ) ,
104
106
fun_to_name : HashMap :: new ( ) ,
@@ -137,6 +139,12 @@ impl State {
137
139
Self :: id ( & mut self . rename_count , & mut self . id_to_name , IdKind :: Local , & raw_id, f)
138
140
}
139
141
142
+ fn field < S : Into < String > > ( & mut self , raw_id : S ) -> Id {
143
+ let raw_id = raw_id. into ( ) ;
144
+ let f = || raw_id. clone ( ) ;
145
+ Self :: id ( & mut self . rename_count , & mut self . field_to_name , IdKind :: Field , & raw_id, f)
146
+ }
147
+
140
148
fn typ_param < S : Into < String > > ( & mut self , raw_id : S , maybe_impl_index : Option < u32 > ) -> Id {
141
149
let raw_id = raw_id. into ( ) ;
142
150
let ( is_impl, impl_index) = match ( raw_id. starts_with ( "impl " ) , maybe_impl_index) {
@@ -495,7 +503,7 @@ fn erase_pat<'tcx>(ctxt: &Context<'tcx>, state: &mut State, pat: &Pat) -> Patter
495
503
let name = state. datatype_name ( & vir_path) ;
496
504
let mut binders: Vec < ( Id , Pattern ) > = Vec :: new ( ) ;
497
505
for pat in pats. iter ( ) {
498
- let field = state. local ( pat. ident . to_string ( ) ) ;
506
+ let field = state. field ( pat. ident . to_string ( ) ) ;
499
507
let pattern = erase_pat ( ctxt, state, & pat. pat ) ;
500
508
binders. push ( ( field, pattern) ) ;
501
509
}
@@ -1114,9 +1122,9 @@ fn erase_expr<'tcx>(
1114
1122
let variant = datatype. x . get_variant ( & variant_name) ;
1115
1123
let mut fs: Vec < ( Id , Exp ) > = Vec :: new ( ) ;
1116
1124
for f in fields. iter ( ) {
1117
- let field_name = Arc :: new ( f. ident . as_str ( ) . to_string ( ) ) ;
1118
- let ( _, field_mode, _) = get_field ( & variant. a , & field_name ) . a ;
1119
- let name = state. local ( f. ident . to_string ( ) ) ;
1125
+ let vir_field_name = field_name_to_vir_ident ( f. ident . as_str ( ) ) ;
1126
+ let ( _, field_mode, _) = get_field ( & variant. a , & vir_field_name ) . a ;
1127
+ let name = state. field ( f. ident . to_string ( ) ) ;
1120
1128
let e = if field_mode == Mode :: Spec {
1121
1129
phantom_data_expr ( ctxt, state, & f. expr )
1122
1130
} else {
@@ -1204,12 +1212,7 @@ fn erase_expr<'tcx>(
1204
1212
if expect_spec {
1205
1213
erase_spec_exps ( ctxt, state, expr, vec ! [ exp1] )
1206
1214
} else {
1207
- let field_name = field. to_string ( ) ;
1208
- let field_id = if field_name. chars ( ) . all ( char:: is_numeric) {
1209
- Id :: new ( IdKind :: Builtin , 0 , field_name)
1210
- } else {
1211
- state. local ( field. to_string ( ) )
1212
- } ;
1215
+ let field_id = state. field ( field. to_string ( ) ) ;
1213
1216
mk_exp ( ExpX :: Field ( exp1. expect ( "expr" ) , field_id) )
1214
1217
}
1215
1218
}
@@ -2067,7 +2070,7 @@ fn erase_variant_data<'tcx>(
2067
2070
None => {
2068
2071
let mut fields: Vec < Field > = Vec :: new ( ) ;
2069
2072
for field in & variant. fields {
2070
- let name = state. local ( field. ident ( ctxt. tcx ) . to_string ( ) ) ;
2073
+ let name = state. field ( field. ident ( ctxt. tcx ) . to_string ( ) ) ;
2071
2074
let typ = erase_ty ( ctxt, state, & ctxt. tcx . type_of ( field. did ) . skip_binder ( ) ) ;
2072
2075
fields. push ( Field { name, typ : revise_typ ( field. did , typ) } ) ;
2073
2076
}
0 commit comments