@@ -54,42 +54,42 @@ impl Eip712Args {
54
54
let mut sess = Session :: builder ( ) . with_stderr_emitter ( ) . build ( ) ;
55
55
sess. dcx = sess. dcx . set_flags ( |flags| flags. track_diagnostics = false ) ;
56
56
57
- let result = sess. enter ( || -> Result < ( ) > {
57
+ sess. enter_parallel ( || -> Result < ( ) > {
58
58
// Set up the parsing context with the project paths and sources.
59
59
let parsing_context =
60
60
solar_pcx_from_build_opts ( & sess, self . build , Some ( vec ! [ self . target_path] ) ) ?;
61
61
62
62
// Parse and resolve
63
63
let hir_arena = ThreadLocal :: new ( ) ;
64
- if let Ok ( Some ( gcx) ) = parsing_context. parse_and_lower ( & hir_arena) {
65
- let resolver = Resolver :: new ( gcx ) ;
66
-
67
- let outputs = resolver
68
- . struct_ids ( )
69
- . iter ( )
70
- . filter_map ( |id| {
71
- let resolved = resolver . resolve_struct_eip712 ( * id ) ? ;
72
- Some ( Eip712Output {
73
- path : resolver . get_struct_path ( * id ) ,
74
- hash : keccak256 ( resolved . as_bytes ( ) ) ,
75
- typ : resolved,
76
- } )
64
+ let Ok ( Some ( gcx) ) = parsing_context. parse_and_lower ( & hir_arena) else {
65
+ return Err ( eyre :: eyre! ( "failed parsing" ) ) ;
66
+ } ;
67
+ let resolver = Resolver :: new ( gcx ) ;
68
+
69
+ let outputs = resolver
70
+ . struct_ids ( )
71
+ . filter_map ( |id| {
72
+ let resolved = resolver . resolve_struct_eip712 ( id ) ? ;
73
+ Some ( Eip712Output {
74
+ path : resolver . get_struct_path ( id ) ,
75
+ hash : keccak256 ( resolved. as_bytes ( ) ) ,
76
+ typ : resolved ,
77
77
} )
78
- . collect :: < Vec < _ > > ( ) ;
79
-
80
- if self . json {
81
- sh_println ! ( "{ json}" , json = serde_json :: to_string_pretty ( & outputs ) ? ) ? ;
82
- } else {
83
- for output in & outputs {
84
- sh_println ! ( "{output}" ) ? ;
85
- }
78
+ } )
79
+ . collect :: < Vec < _ > > ( ) ;
80
+
81
+ if self . json {
82
+ sh_println ! ( "{json}" , json = serde_json :: to_string_pretty ( & outputs ) ? ) ? ;
83
+ } else {
84
+ for output in & outputs {
85
+ sh_println ! ( "{output}" ) ? ;
86
86
}
87
87
}
88
88
89
89
Ok ( ( ) )
90
- } ) ;
90
+ } ) ? ;
91
91
92
- eyre:: ensure!( result . is_ok ( ) && sess. dcx. has_errors( ) . is_ok( ) , "failed parsing " ) ;
92
+ eyre:: ensure!( sess. dcx. has_errors( ) . is_ok( ) , "errors occurred " ) ;
93
93
94
94
Ok ( ( ) )
95
95
}
@@ -99,25 +99,29 @@ impl Eip712Args {
99
99
///
100
100
/// Requires a reference to the source HIR.
101
101
pub struct Resolver < ' hir > {
102
- hir : & ' hir Hir < ' hir > ,
103
102
gcx : GcxWrapper < ' hir > ,
104
103
}
105
104
106
105
impl < ' hir > Resolver < ' hir > {
107
106
/// Constructs a new [`Resolver`] for the supplied [`Hir`] instance.
108
107
pub fn new ( gcx : GcxWrapper < ' hir > ) -> Self {
109
- Self { hir : & gcx. get ( ) . hir , gcx }
108
+ Self { gcx }
109
+ }
110
+
111
+ #[ inline]
112
+ fn hir ( & self ) -> & ' hir Hir < ' hir > {
113
+ & self . gcx . get ( ) . hir
110
114
}
111
115
112
116
/// Returns the [`StructId`]s of every user-defined struct in source order.
113
- pub fn struct_ids ( & self ) -> Vec < StructId > {
114
- self . hir . strukt_ids ( ) . collect ( )
117
+ pub fn struct_ids ( & self ) -> impl Iterator < Item = StructId > {
118
+ self . hir ( ) . strukt_ids ( )
115
119
}
116
120
117
121
/// Returns the path for a struct, with the format: `file.sol > MyContract > MyStruct`
118
122
pub fn get_struct_path ( & self , id : StructId ) -> String {
119
- let strukt = self . hir . strukt ( id) . name . as_str ( ) ;
120
- match self . hir . strukt ( id) . contract {
123
+ let strukt = self . hir ( ) . strukt ( id) . name . as_str ( ) ;
124
+ match self . hir ( ) . strukt ( id) . contract {
121
125
Some ( cid) => {
122
126
let full_name = self . gcx . get ( ) . contract_fully_qualified_name ( cid) . to_string ( ) ;
123
127
let relevant = Path :: new ( & full_name)
@@ -141,7 +145,7 @@ impl<'hir> Resolver<'hir> {
141
145
/// not supported by EIP-712 (mappings, function types, errors, etc).
142
146
pub fn resolve_struct_eip712 ( & self , id : StructId ) -> Option < String > {
143
147
let mut subtypes = BTreeMap :: new ( ) ;
144
- subtypes. insert ( self . hir . strukt ( id) . name . as_str ( ) . into ( ) , id) ;
148
+ subtypes. insert ( self . hir ( ) . strukt ( id) . name . as_str ( ) . into ( ) , id) ;
145
149
self . resolve_eip712_inner ( id, & mut subtypes, true , None )
146
150
}
147
151
@@ -152,11 +156,11 @@ impl<'hir> Resolver<'hir> {
152
156
append_subtypes : bool ,
153
157
rename : Option < & str > ,
154
158
) -> Option < String > {
155
- let def = self . hir . strukt ( id) ;
159
+ let def = self . hir ( ) . strukt ( id) ;
156
160
let mut result = format ! ( "{}(" , rename. unwrap_or( def. name. as_str( ) ) ) ;
157
161
158
162
for ( idx, field_id) in def. fields . iter ( ) . enumerate ( ) {
159
- let field = self . hir . variable ( * field_id) ;
163
+ let field = self . hir ( ) . variable ( * field_id) ;
160
164
let ty = self . resolve_type ( self . gcx . get ( ) . type_of_hir_ty ( & field. ty ) , subtypes) ?;
161
165
162
166
write ! ( result, "{ty} {name}" , name = field. name?. as_str( ) ) . ok ( ) ?;
@@ -204,7 +208,7 @@ impl<'hir> Resolver<'hir> {
204
208
}
205
209
TyKind :: Udvt ( ty, _) => self . resolve_type ( ty, subtypes) ,
206
210
TyKind :: Struct ( id) => {
207
- let def = self . hir . strukt ( id) ;
211
+ let def = self . hir ( ) . strukt ( id) ;
208
212
let name = match subtypes. iter ( ) . find ( |( _, cached_id) | id == * * cached_id) {
209
213
Some ( ( name, _) ) => name. to_string ( ) ,
210
214
None => {
@@ -219,9 +223,8 @@ impl<'hir> Resolver<'hir> {
219
223
subtypes. insert ( name. clone ( ) , id) ;
220
224
221
225
// Recursively resolve fields to populate subtypes
222
- for field_id in def. fields {
223
- let field_ty =
224
- self . gcx . get ( ) . type_of_hir_ty ( & self . hir . variable ( * field_id) . ty ) ;
226
+ for & field_id in def. fields {
227
+ let field_ty = self . gcx . get ( ) . type_of_item ( field_id. into ( ) ) ;
225
228
self . resolve_type ( field_ty, subtypes) ?;
226
229
}
227
230
name
0 commit comments