@@ -2,7 +2,7 @@ use itertools::Itertools;
22use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet , IndexEntry } ;
33use rustc_middle:: mir;
44use rustc_middle:: mir:: coverage:: { BasicCoverageBlock , BranchSpan } ;
5- use rustc_span:: { ExpnId , ExpnKind , Span } ;
5+ use rustc_span:: { ExpnKind , Span , SyntaxContext } ;
66
77use crate :: coverage:: from_mir;
88use crate :: coverage:: graph:: CoverageGraph ;
@@ -17,31 +17,31 @@ pub(crate) struct SpanWithBcb {
1717
1818#[ derive( Debug ) ]
1919pub ( crate ) struct ExpnTree {
20- nodes : FxIndexMap < ExpnId , ExpnNode > ,
20+ nodes : FxIndexMap < SyntaxContext , ExpnNode > ,
2121}
2222
2323impl ExpnTree {
24- pub ( crate ) fn get ( & self , expn_id : ExpnId ) -> Option < & ExpnNode > {
25- self . nodes . get ( & expn_id )
24+ pub ( crate ) fn get ( & self , context : SyntaxContext ) -> Option < & ExpnNode > {
25+ self . nodes . get ( & context )
2626 }
2727}
2828
2929#[ derive( Debug ) ]
3030pub ( crate ) struct ExpnNode {
31- /// Storing the expansion ID in its own node is not strictly necessary,
31+ /// Storing the syntax context in its own node is not strictly necessary,
3232 /// but is helpful for debugging and might be useful later.
3333 #[ expect( dead_code) ]
34- pub ( crate ) expn_id : ExpnId ,
34+ pub ( crate ) context : SyntaxContext ,
3535 /// Index of this node in a depth-first traversal from the root.
3636 pub ( crate ) dfs_rank : usize ,
3737
3838 // Useful info extracted from `ExpnData`.
3939 pub ( crate ) expn_kind : ExpnKind ,
4040 /// Non-dummy `ExpnData::call_site` span.
4141 pub ( crate ) call_site : Option < Span > ,
42- /// Expansion ID of `call_site`, if present.
42+ /// Syntax context of `call_site`, if present.
4343 /// This links an expansion node to its parent in the tree.
44- pub ( crate ) call_site_expn_id : Option < ExpnId > ,
44+ pub ( crate ) call_site_context : Option < SyntaxContext > ,
4545
4646 /// Holds the function signature span, if it belongs to this expansion.
4747 /// Used by special-case code in span refinement.
@@ -53,7 +53,7 @@ pub(crate) struct ExpnNode {
5353 /// Spans (and their associated BCBs) belonging to this expansion.
5454 pub ( crate ) spans : Vec < SpanWithBcb > ,
5555 /// Expansions whose call-site is in this expansion.
56- pub ( crate ) child_expn_ids : FxIndexSet < ExpnId > ,
56+ pub ( crate ) child_contexts : FxIndexSet < SyntaxContext > ,
5757 /// The "minimum" and "maximum" BCBs (in dominator order) of ordinary spans
5858 /// belonging to this tree node and all of its descendants. Used when
5959 /// creating a single code mapping representing an entire child expansion.
@@ -68,25 +68,25 @@ pub(crate) struct ExpnNode {
6868}
6969
7070impl ExpnNode {
71- fn new ( expn_id : ExpnId ) -> Self {
72- let expn_data = expn_id . expn_data ( ) ;
71+ fn for_context ( context : SyntaxContext ) -> Self {
72+ let expn_data = context . outer_expn_data ( ) ;
7373
7474 let call_site = Some ( expn_data. call_site ) . filter ( |sp| !sp. is_dummy ( ) ) ;
75- let call_site_expn_id = try { call_site?. ctxt ( ) . outer_expn ( ) } ;
75+ let call_site_context = try { call_site?. ctxt ( ) } ;
7676
7777 Self {
78- expn_id ,
78+ context ,
7979 dfs_rank : usize:: MAX ,
8080
8181 expn_kind : expn_data. kind ,
8282 call_site,
83- call_site_expn_id ,
83+ call_site_context ,
8484
8585 fn_sig_span : None ,
8686 body_span : None ,
8787
8888 spans : vec ! [ ] ,
89- child_expn_ids : FxIndexSet :: default ( ) ,
89+ child_contexts : FxIndexSet :: default ( ) ,
9090 minmax_bcbs : None ,
9191
9292 branch_spans : vec ! [ ] ,
@@ -106,32 +106,32 @@ pub(crate) fn build_expn_tree(
106106 let raw_spans = from_mir:: extract_raw_spans_from_mir ( mir_body, graph) ;
107107
108108 let mut nodes = FxIndexMap :: default ( ) ;
109- let new_node = |& expn_id : & ExpnId | ExpnNode :: new ( expn_id ) ;
109+ let new_node = |& context : & SyntaxContext | ExpnNode :: for_context ( context ) ;
110110
111111 for from_mir:: RawSpanFromMir { raw_span, bcb } in raw_spans {
112112 let span_with_bcb = SpanWithBcb { span : raw_span, bcb } ;
113113
114114 // Create a node for this span's enclosing expansion, and add the span to it.
115- let expn_id = span_with_bcb. span . ctxt ( ) . outer_expn ( ) ;
116- let node = nodes. entry ( expn_id ) . or_insert_with_key ( new_node) ;
115+ let context = span_with_bcb. span . ctxt ( ) ;
116+ let node = nodes. entry ( context ) . or_insert_with_key ( new_node) ;
117117 node. spans . push ( span_with_bcb) ;
118118
119119 // Now walk up the expansion call-site chain, creating nodes and registering children.
120- let mut prev = expn_id ;
121- let mut curr_expn_id = node. call_site_expn_id ;
122- while let Some ( expn_id ) = curr_expn_id {
123- let entry = nodes. entry ( expn_id ) ;
120+ let mut prev = context ;
121+ let mut curr_context = node. call_site_context ;
122+ while let Some ( context ) = curr_context {
123+ let entry = nodes. entry ( context ) ;
124124 let node_existed = matches ! ( entry, IndexEntry :: Occupied ( _) ) ;
125125
126126 let node = entry. or_insert_with_key ( new_node) ;
127- node. child_expn_ids . insert ( prev) ;
127+ node. child_contexts . insert ( prev) ;
128128
129129 if node_existed {
130130 break ;
131131 }
132132
133- prev = expn_id ;
134- curr_expn_id = node. call_site_expn_id ;
133+ prev = context ;
134+ curr_context = node. call_site_context ;
135135 }
136136 }
137137
@@ -152,30 +152,30 @@ pub(crate) fn build_expn_tree(
152152 // If we have a span for the function signature, associate it with the
153153 // corresponding expansion tree node.
154154 if let Some ( fn_sig_span) = hir_info. fn_sig_span
155- && let Some ( node) = nodes. get_mut ( & fn_sig_span. ctxt ( ) . outer_expn ( ) )
155+ && let Some ( node) = nodes. get_mut ( & fn_sig_span. ctxt ( ) )
156156 {
157157 node. fn_sig_span = Some ( fn_sig_span) ;
158158 }
159159
160160 // Also associate the body span with its expansion tree node.
161161 let body_span = hir_info. body_span ;
162- if let Some ( node) = nodes. get_mut ( & body_span. ctxt ( ) . outer_expn ( ) ) {
162+ if let Some ( node) = nodes. get_mut ( & body_span. ctxt ( ) ) {
163163 node. body_span = Some ( body_span) ;
164164 }
165165
166166 // Associate each hole span (extracted from HIR) with its corresponding
167167 // expansion tree node.
168168 for & hole_span in & hir_info. hole_spans {
169- let expn_id = hole_span. ctxt ( ) . outer_expn ( ) ;
170- let Some ( node) = nodes. get_mut ( & expn_id ) else { continue } ;
169+ let context = hole_span. ctxt ( ) ;
170+ let Some ( node) = nodes. get_mut ( & context ) else { continue } ;
171171 node. hole_spans . push ( hole_span) ;
172172 }
173173
174174 // Associate each branch span (recorded during MIR building) with its
175175 // corresponding expansion tree node.
176176 if let Some ( coverage_info_hi) = mir_body. coverage_info_hi . as_deref ( ) {
177177 for branch_span in & coverage_info_hi. branch_spans {
178- if let Some ( node) = nodes. get_mut ( & branch_span. span . ctxt ( ) . outer_expn ( ) ) {
178+ if let Some ( node) = nodes. get_mut ( & branch_span. span . ctxt ( ) ) {
179179 node. branch_spans . push ( BranchSpan :: clone ( branch_span) ) ;
180180 }
181181 }
@@ -188,17 +188,19 @@ pub(crate) fn build_expn_tree(
188188///
189189/// This allows subsequent operations to iterate over all nodes, while assuming
190190/// that every node occurs before all of its descendants.
191- fn sort_nodes_depth_first ( nodes : & mut FxIndexMap < ExpnId , ExpnNode > ) -> Result < ( ) , MappingsError > {
192- let mut dfs_stack = vec ! [ ExpnId :: root( ) ] ;
191+ fn sort_nodes_depth_first (
192+ nodes : & mut FxIndexMap < SyntaxContext , ExpnNode > ,
193+ ) -> Result < ( ) , MappingsError > {
194+ let mut dfs_stack = vec ! [ SyntaxContext :: root( ) ] ;
193195 let mut next_dfs_rank = 0usize ;
194- while let Some ( expn_id ) = dfs_stack. pop ( ) {
195- if let Some ( node) = nodes. get_mut ( & expn_id ) {
196+ while let Some ( context ) = dfs_stack. pop ( ) {
197+ if let Some ( node) = nodes. get_mut ( & context ) {
196198 node. dfs_rank = next_dfs_rank;
197199 next_dfs_rank += 1 ;
198- dfs_stack. extend ( node. child_expn_ids . iter ( ) . rev ( ) . copied ( ) ) ;
200+ dfs_stack. extend ( node. child_contexts . iter ( ) . rev ( ) . copied ( ) ) ;
199201 }
200202 }
201- nodes. sort_by_key ( |_expn_id , node| node. dfs_rank ) ;
203+ nodes. sort_by_key ( |_context , node| node. dfs_rank ) ;
202204
203205 // Verify that the depth-first search visited each node exactly once.
204206 for ( i, & ExpnNode { dfs_rank, .. } ) in nodes. values ( ) . enumerate ( ) {
@@ -222,12 +224,12 @@ pub(crate) struct MinMaxBcbs {
222224/// and the min/max of its immediate children.
223225fn minmax_bcbs_for_expn_tree_node (
224226 graph : & CoverageGraph ,
225- nodes : & FxIndexMap < ExpnId , ExpnNode > ,
227+ nodes : & FxIndexMap < SyntaxContext , ExpnNode > ,
226228 node : & ExpnNode ,
227229) -> Option < MinMaxBcbs > {
228230 let immediate_span_bcbs = node. spans . iter ( ) . map ( |sp : & SpanWithBcb | sp. bcb ) ;
229231 let child_minmax_bcbs = node
230- . child_expn_ids
232+ . child_contexts
231233 . iter ( )
232234 . flat_map ( |id| nodes. get ( id) )
233235 . flat_map ( |child| child. minmax_bcbs )
0 commit comments