@@ -163,6 +163,41 @@ pub enum Transparency {
163
163
Opaque ,
164
164
}
165
165
166
+ /// How to perform collapse macros debug info
167
+ #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Hash , Debug , Encodable , Decodable ) ]
168
+ #[ derive( HashStable_Generic ) ]
169
+ pub enum CollapseDebuginfo {
170
+ /// Don't collapse debuginfo for the macro
171
+ No = 0 ,
172
+ /// Unspecified value
173
+ Unspecified = 1 ,
174
+ /// Collapse debuginfo if command line flag enables collapsing
175
+ External = 2 ,
176
+ /// Collapse debuginfo for the macro
177
+ Yes = 3 ,
178
+ }
179
+
180
+ /// if-ext - if macro from different crate (related to callsite code)
181
+ /// | cmd \ attr | no | (unspecified) | external | yes |
182
+ /// | no | no | no | no | no |
183
+ /// | (unspecified) | no | no | if-ext | yes |
184
+ /// | external | no | if-ext | if-ext | yes |
185
+ /// | yes | yes | yes | yes | yes |
186
+ impl CollapseDebuginfo {
187
+ pub fn should_collapse ( self , flag : CollapseDebuginfo , ext : bool ) -> bool {
188
+ const NO : bool = false ;
189
+ const YES : bool = true ;
190
+ #[ rustfmt:: skip]
191
+ let collapse_table = [
192
+ [ NO , NO , NO , NO ] ,
193
+ [ NO , NO , ext, YES ] ,
194
+ [ NO , ext, ext, YES ] ,
195
+ [ YES , YES , YES , YES ] ,
196
+ ] ;
197
+ collapse_table[ flag as usize ] [ self as usize ]
198
+ }
199
+ }
200
+
166
201
impl LocalExpnId {
167
202
/// The ID of the theoretical expansion that generates freshly parsed, unexpanded AST.
168
203
pub const ROOT : LocalExpnId = LocalExpnId :: from_u32 ( 0 ) ;
@@ -464,20 +499,25 @@ impl HygieneData {
464
499
& self ,
465
500
mut span : Span ,
466
501
to : Span ,
467
- collapse_debuginfo_enabled : bool ,
502
+ collapse_debuginfo_feature_enabled : bool ,
503
+ collapse_debuginfo_flag : CollapseDebuginfo ,
468
504
) -> Span {
469
505
let orig_span = span;
470
506
let mut ret_span = span;
471
507
472
- debug ! ( "walk_chain_collapsed({:?}, {:?})" , span, to) ;
508
+ debug ! ( "walk_chain_collapsed({:?}, {:?}), feature_enable={}, cmd_flag={:?}" ,
509
+ span, to, collapse_debuginfo_feature_enabled, collapse_debuginfo_flag) ;
473
510
debug ! ( "walk_chain_collapsed: span ctxt = {:?}" , span. ctxt( ) ) ;
474
511
while !span. eq_ctxt ( to) && span. from_expansion ( ) {
475
512
let outer_expn = self . outer_expn ( span. ctxt ( ) ) ;
476
513
debug ! ( "walk_chain_collapsed({:?}): outer_expn={:?}" , span, outer_expn) ;
477
514
let expn_data = self . expn_data ( outer_expn) ;
478
515
debug ! ( "walk_chain_collapsed({:?}): expn_data={:?}" , span, expn_data) ;
479
516
span = expn_data. call_site ;
480
- if !collapse_debuginfo_enabled || expn_data. collapse_debuginfo {
517
+ let is_ext = !expn_data. macro_def_id . map_or ( false , |v| v. is_local ( ) ) ;
518
+ if !collapse_debuginfo_feature_enabled
519
+ || expn_data. collapse_debuginfo . should_collapse ( collapse_debuginfo_flag, is_ext)
520
+ {
481
521
ret_span = span;
482
522
}
483
523
}
@@ -601,8 +641,20 @@ pub fn walk_chain(span: Span, to: SyntaxContext) -> Span {
601
641
HygieneData :: with ( |data| data. walk_chain ( span, to) )
602
642
}
603
643
604
- pub fn walk_chain_collapsed ( span : Span , to : Span , collapse_debuginfo_enabled : bool ) -> Span {
605
- HygieneData :: with ( |hdata| hdata. walk_chain_collapsed ( span, to, collapse_debuginfo_enabled) )
644
+ pub fn walk_chain_collapsed (
645
+ span : Span ,
646
+ to : Span ,
647
+ collapse_debuginfo_feature_enabled : bool ,
648
+ collapse_debuginfo_flag : CollapseDebuginfo ,
649
+ ) -> Span {
650
+ HygieneData :: with ( |hdata| {
651
+ hdata. walk_chain_collapsed (
652
+ span,
653
+ to,
654
+ collapse_debuginfo_feature_enabled,
655
+ collapse_debuginfo_flag,
656
+ )
657
+ } )
606
658
}
607
659
608
660
pub fn update_dollar_crate_names ( mut get_name : impl FnMut ( SyntaxContext ) -> Symbol ) {
@@ -957,7 +1009,7 @@ pub struct ExpnData {
957
1009
pub local_inner_macros : bool ,
958
1010
/// Should debuginfo for the macro be collapsed to the outermost expansion site (in other
959
1011
/// words, was the macro definition annotated with `#[collapse_debuginfo]`)?
960
- pub ( crate ) collapse_debuginfo : bool ,
1012
+ pub ( crate ) collapse_debuginfo : CollapseDebuginfo ,
961
1013
}
962
1014
963
1015
impl !PartialEq for ExpnData { }
@@ -975,7 +1027,7 @@ impl ExpnData {
975
1027
parent_module : Option < DefId > ,
976
1028
allow_internal_unsafe : bool ,
977
1029
local_inner_macros : bool ,
978
- collapse_debuginfo : bool ,
1030
+ collapse_debuginfo : CollapseDebuginfo ,
979
1031
) -> ExpnData {
980
1032
ExpnData {
981
1033
kind,
@@ -1013,7 +1065,7 @@ impl ExpnData {
1013
1065
disambiguator : 0 ,
1014
1066
allow_internal_unsafe : false ,
1015
1067
local_inner_macros : false ,
1016
- collapse_debuginfo : false ,
1068
+ collapse_debuginfo : CollapseDebuginfo :: Unspecified ,
1017
1069
}
1018
1070
}
1019
1071
0 commit comments