@@ -26,20 +26,11 @@ use crate::semantic_index::semantic_index;
26
26
/// ```
27
27
#[ derive( Debug , salsa:: Update , get_size2:: GetSize ) ]
28
28
pub ( crate ) struct AstIds {
29
- /// Maps expressions to their expression id.
30
- expressions_map : FxHashMap < ExpressionNodeKey , ScopedExpressionId > ,
31
29
/// Maps expressions which "use" a place (that is, [`ast::ExprName`], [`ast::ExprAttribute`] or [`ast::ExprSubscript`]) to a use id.
32
30
uses_map : FxHashMap < ExpressionNodeKey , ScopedUseId > ,
33
31
}
34
32
35
33
impl AstIds {
36
- fn expression_id ( & self , key : impl Into < ExpressionNodeKey > ) -> ScopedExpressionId {
37
- let key = & key. into ( ) ;
38
- * self . expressions_map . get ( key) . unwrap_or_else ( || {
39
- panic ! ( "Could not find expression ID for {key:?}" ) ;
40
- } )
41
- }
42
-
43
34
fn use_id ( & self , key : impl Into < ExpressionNodeKey > ) -> ScopedUseId {
44
35
self . uses_map [ & key. into ( ) ]
45
36
}
@@ -94,90 +85,12 @@ impl HasScopedUseId for ast::ExprRef<'_> {
94
85
}
95
86
}
96
87
97
- /// Uniquely identifies an [`ast::Expr`] in a [`crate::semantic_index::place::FileScopeId`].
98
- #[ newtype_index]
99
- #[ derive( salsa:: Update , get_size2:: GetSize ) ]
100
- pub struct ScopedExpressionId ;
101
-
102
- pub trait HasScopedExpressionId {
103
- /// Returns the ID that uniquely identifies the node in `scope`.
104
- fn scoped_expression_id ( & self , db : & dyn Db , scope : ScopeId ) -> ScopedExpressionId ;
105
- }
106
-
107
- impl < T : HasScopedExpressionId > HasScopedExpressionId for Box < T > {
108
- fn scoped_expression_id ( & self , db : & dyn Db , scope : ScopeId ) -> ScopedExpressionId {
109
- self . as_ref ( ) . scoped_expression_id ( db, scope)
110
- }
111
- }
112
-
113
- macro_rules! impl_has_scoped_expression_id {
114
- ( $ty: ty) => {
115
- impl HasScopedExpressionId for $ty {
116
- fn scoped_expression_id( & self , db: & dyn Db , scope: ScopeId ) -> ScopedExpressionId {
117
- let expression_ref = ExprRef :: from( self ) ;
118
- expression_ref. scoped_expression_id( db, scope)
119
- }
120
- }
121
- } ;
122
- }
123
-
124
- impl_has_scoped_expression_id ! ( ast:: ExprBoolOp ) ;
125
- impl_has_scoped_expression_id ! ( ast:: ExprName ) ;
126
- impl_has_scoped_expression_id ! ( ast:: ExprBinOp ) ;
127
- impl_has_scoped_expression_id ! ( ast:: ExprUnaryOp ) ;
128
- impl_has_scoped_expression_id ! ( ast:: ExprLambda ) ;
129
- impl_has_scoped_expression_id ! ( ast:: ExprIf ) ;
130
- impl_has_scoped_expression_id ! ( ast:: ExprDict ) ;
131
- impl_has_scoped_expression_id ! ( ast:: ExprSet ) ;
132
- impl_has_scoped_expression_id ! ( ast:: ExprListComp ) ;
133
- impl_has_scoped_expression_id ! ( ast:: ExprSetComp ) ;
134
- impl_has_scoped_expression_id ! ( ast:: ExprDictComp ) ;
135
- impl_has_scoped_expression_id ! ( ast:: ExprGenerator ) ;
136
- impl_has_scoped_expression_id ! ( ast:: ExprAwait ) ;
137
- impl_has_scoped_expression_id ! ( ast:: ExprYield ) ;
138
- impl_has_scoped_expression_id ! ( ast:: ExprYieldFrom ) ;
139
- impl_has_scoped_expression_id ! ( ast:: ExprCompare ) ;
140
- impl_has_scoped_expression_id ! ( ast:: ExprCall ) ;
141
- impl_has_scoped_expression_id ! ( ast:: ExprFString ) ;
142
- impl_has_scoped_expression_id ! ( ast:: ExprStringLiteral ) ;
143
- impl_has_scoped_expression_id ! ( ast:: ExprBytesLiteral ) ;
144
- impl_has_scoped_expression_id ! ( ast:: ExprNumberLiteral ) ;
145
- impl_has_scoped_expression_id ! ( ast:: ExprBooleanLiteral ) ;
146
- impl_has_scoped_expression_id ! ( ast:: ExprNoneLiteral ) ;
147
- impl_has_scoped_expression_id ! ( ast:: ExprEllipsisLiteral ) ;
148
- impl_has_scoped_expression_id ! ( ast:: ExprAttribute ) ;
149
- impl_has_scoped_expression_id ! ( ast:: ExprSubscript ) ;
150
- impl_has_scoped_expression_id ! ( ast:: ExprStarred ) ;
151
- impl_has_scoped_expression_id ! ( ast:: ExprNamed ) ;
152
- impl_has_scoped_expression_id ! ( ast:: ExprList ) ;
153
- impl_has_scoped_expression_id ! ( ast:: ExprTuple ) ;
154
- impl_has_scoped_expression_id ! ( ast:: ExprSlice ) ;
155
- impl_has_scoped_expression_id ! ( ast:: ExprIpyEscapeCommand ) ;
156
- impl_has_scoped_expression_id ! ( ast:: Expr ) ;
157
-
158
- impl HasScopedExpressionId for ast:: ExprRef < ' _ > {
159
- fn scoped_expression_id ( & self , db : & dyn Db , scope : ScopeId ) -> ScopedExpressionId {
160
- let ast_ids = ast_ids ( db, scope) ;
161
- ast_ids. expression_id ( * self )
162
- }
163
- }
164
-
165
88
#[ derive( Debug , Default ) ]
166
89
pub ( super ) struct AstIdsBuilder {
167
- expressions_map : FxHashMap < ExpressionNodeKey , ScopedExpressionId > ,
168
90
uses_map : FxHashMap < ExpressionNodeKey , ScopedUseId > ,
169
91
}
170
92
171
93
impl AstIdsBuilder {
172
- /// Adds `expr` to the expression ids map and returns its id.
173
- pub ( super ) fn record_expression ( & mut self , expr : & ast:: Expr ) -> ScopedExpressionId {
174
- let expression_id = self . expressions_map . len ( ) . into ( ) ;
175
-
176
- self . expressions_map . insert ( expr. into ( ) , expression_id) ;
177
-
178
- expression_id
179
- }
180
-
181
94
/// Adds `expr` to the use ids map and returns its id.
182
95
pub ( super ) fn record_use ( & mut self , expr : impl Into < ExpressionNodeKey > ) -> ScopedUseId {
183
96
let use_id = self . uses_map . len ( ) . into ( ) ;
@@ -188,11 +101,9 @@ impl AstIdsBuilder {
188
101
}
189
102
190
103
pub ( super ) fn finish ( mut self ) -> AstIds {
191
- self . expressions_map . shrink_to_fit ( ) ;
192
104
self . uses_map . shrink_to_fit ( ) ;
193
105
194
106
AstIds {
195
- expressions_map : self . expressions_map ,
196
107
uses_map : self . uses_map ,
197
108
}
198
109
}
@@ -219,6 +130,12 @@ pub(crate) mod node_key {
219
130
}
220
131
}
221
132
133
+ impl From < & ast:: ExprCall > for ExpressionNodeKey {
134
+ fn from ( value : & ast:: ExprCall ) -> Self {
135
+ Self ( NodeKey :: from_node ( value) )
136
+ }
137
+ }
138
+
222
139
impl From < & ast:: Identifier > for ExpressionNodeKey {
223
140
fn from ( value : & ast:: Identifier ) -> Self {
224
141
Self ( NodeKey :: from_node ( value) )
0 commit comments