@@ -98,14 +98,6 @@ impl SyntaxContextData {
98
98
}
99
99
}
100
100
101
- fn decode_placeholder ( ) -> SyntaxContextData {
102
- SyntaxContextData { dollar_crate_name : kw:: Empty , ..SyntaxContextData :: root ( ) }
103
- }
104
-
105
- fn is_decode_placeholder ( & self ) -> bool {
106
- self . dollar_crate_name == kw:: Empty
107
- }
108
-
109
101
fn key ( & self ) -> SyntaxContextKey {
110
102
( self . parent , self . outer_expn , self . outer_transparency )
111
103
}
@@ -460,28 +452,23 @@ impl HygieneData {
460
452
}
461
453
462
454
fn normalize_to_macros_2_0 ( & self , ctxt : SyntaxContext ) -> SyntaxContext {
463
- debug_assert ! ( !self . syntax_context_data[ ctxt. 0 as usize ] . is_decode_placeholder( ) ) ;
464
455
self . syntax_context_data [ ctxt. 0 as usize ] . opaque
465
456
}
466
457
467
458
fn normalize_to_macro_rules ( & self , ctxt : SyntaxContext ) -> SyntaxContext {
468
- debug_assert ! ( !self . syntax_context_data[ ctxt. 0 as usize ] . is_decode_placeholder( ) ) ;
469
459
self . syntax_context_data [ ctxt. 0 as usize ] . opaque_and_semiopaque
470
460
}
471
461
472
462
fn outer_expn ( & self , ctxt : SyntaxContext ) -> ExpnId {
473
- debug_assert ! ( !self . syntax_context_data[ ctxt. 0 as usize ] . is_decode_placeholder( ) ) ;
474
463
self . syntax_context_data [ ctxt. 0 as usize ] . outer_expn
475
464
}
476
465
477
466
fn outer_mark ( & self , ctxt : SyntaxContext ) -> ( ExpnId , Transparency ) {
478
- debug_assert ! ( !self . syntax_context_data[ ctxt. 0 as usize ] . is_decode_placeholder( ) ) ;
479
467
let data = & self . syntax_context_data [ ctxt. 0 as usize ] ;
480
468
( data. outer_expn , data. outer_transparency )
481
469
}
482
470
483
471
fn parent_ctxt ( & self , ctxt : SyntaxContext ) -> SyntaxContext {
484
- debug_assert ! ( !self . syntax_context_data[ ctxt. 0 as usize ] . is_decode_placeholder( ) ) ;
485
472
self . syntax_context_data [ ctxt. 0 as usize ] . parent
486
473
}
487
474
@@ -592,25 +579,27 @@ impl HygieneData {
592
579
expn_id : ExpnId ,
593
580
transparency : Transparency ,
594
581
) -> SyntaxContext {
595
- debug_assert ! ( !self . syntax_context_data[ parent. 0 as usize ] . is_decode_placeholder( ) ) ;
596
-
597
582
// Look into the cache first.
598
583
let key = ( parent, expn_id, transparency) ;
599
584
if let Some ( ctxt) = self . syntax_context_map . get ( & key) {
600
585
return * ctxt;
601
586
}
602
587
603
588
// Reserve a new syntax context.
589
+ // The inserted dummy data can only be potentially accessed by nested `alloc_ctxt` calls,
590
+ // the assert below ensures that it doesn't happen.
604
591
let ctxt = SyntaxContext :: from_usize ( self . syntax_context_data . len ( ) ) ;
605
- self . syntax_context_data . push ( SyntaxContextData :: decode_placeholder ( ) ) ;
592
+ self . syntax_context_data
593
+ . push ( SyntaxContextData { dollar_crate_name : sym:: dummy, ..SyntaxContextData :: root ( ) } ) ;
606
594
self . syntax_context_map . insert ( key, ctxt) ;
607
595
608
596
// Opaque and semi-opaque versions of the parent. Note that they may be equal to the
609
597
// parent itself. E.g. `parent_opaque` == `parent` if the expn chain contains only opaques,
610
598
// and `parent_opaque_and_semiopaque` == `parent` if the expn contains only (semi-)opaques.
611
- let parent_opaque = self . syntax_context_data [ parent. 0 as usize ] . opaque ;
612
- let parent_opaque_and_semiopaque =
613
- self . syntax_context_data [ parent. 0 as usize ] . opaque_and_semiopaque ;
599
+ let parent_data = & self . syntax_context_data [ parent. 0 as usize ] ;
600
+ assert_ne ! ( parent_data. dollar_crate_name, sym:: dummy) ;
601
+ let parent_opaque = parent_data. opaque ;
602
+ let parent_opaque_and_semiopaque = parent_data. opaque_and_semiopaque ;
614
603
615
604
// Evaluate opaque and semi-opaque versions of the new syntax context.
616
605
let ( opaque, opaque_and_semiopaque) = match transparency {
@@ -650,13 +639,12 @@ pub fn walk_chain_collapsed(span: Span, to: Span) -> Span {
650
639
651
640
pub fn update_dollar_crate_names ( mut get_name : impl FnMut ( SyntaxContext ) -> Symbol ) {
652
641
// The new contexts that need updating are at the end of the list and have `$crate` as a name.
653
- // Also decoding placeholders can be encountered among both old and new contexts.
654
642
let mut to_update = vec ! [ ] ;
655
643
HygieneData :: with ( |data| {
656
644
for ( idx, scdata) in data. syntax_context_data . iter ( ) . enumerate ( ) . rev ( ) {
657
645
if scdata. dollar_crate_name == kw:: DollarCrate {
658
646
to_update. push ( ( idx, kw:: DollarCrate ) ) ;
659
- } else if !scdata . is_decode_placeholder ( ) {
647
+ } else {
660
648
break ;
661
649
}
662
650
}
@@ -922,10 +910,7 @@ impl SyntaxContext {
922
910
}
923
911
924
912
pub ( crate ) fn dollar_crate_name ( self ) -> Symbol {
925
- HygieneData :: with ( |data| {
926
- debug_assert ! ( !data. syntax_context_data[ self . 0 as usize ] . is_decode_placeholder( ) ) ;
927
- data. syntax_context_data [ self . 0 as usize ] . dollar_crate_name
928
- } )
913
+ HygieneData :: with ( |data| data. syntax_context_data [ self . 0 as usize ] . dollar_crate_name )
929
914
}
930
915
931
916
pub fn edition ( self ) -> Edition {
@@ -1447,15 +1432,7 @@ fn for_all_ctxts_in<F: FnMut(u32, SyntaxContext, &SyntaxContextKey)>(
1447
1432
mut f : F ,
1448
1433
) {
1449
1434
let all_data: Vec < _ > = HygieneData :: with ( |data| {
1450
- ctxts
1451
- . map ( |ctxt| {
1452
- ( ctxt, {
1453
- let item = data. syntax_context_data [ ctxt. 0 as usize ] ;
1454
- debug_assert ! ( !item. is_decode_placeholder( ) ) ;
1455
- item. key ( )
1456
- } )
1457
- } )
1458
- . collect ( )
1435
+ ctxts. map ( |ctxt| ( ctxt, data. syntax_context_data [ ctxt. 0 as usize ] . key ( ) ) ) . collect ( )
1459
1436
} ) ;
1460
1437
for ( ctxt, data) in all_data. into_iter ( ) {
1461
1438
f ( ctxt. 0 , ctxt, & data) ;
0 commit comments