@@ -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,27 @@ 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 ! (
509
+ "walk_chain_collapsed({:?}, {:?}), feature_enable={}, cmd_flag={:?}" ,
510
+ span, to, collapse_debuginfo_feature_enabled, collapse_debuginfo_flag
511
+ ) ;
473
512
debug ! ( "walk_chain_collapsed: span ctxt = {:?}" , span. ctxt( ) ) ;
474
513
while !span. eq_ctxt ( to) && span. from_expansion ( ) {
475
514
let outer_expn = self . outer_expn ( span. ctxt ( ) ) ;
476
515
debug ! ( "walk_chain_collapsed({:?}): outer_expn={:?}" , span, outer_expn) ;
477
516
let expn_data = self . expn_data ( outer_expn) ;
478
517
debug ! ( "walk_chain_collapsed({:?}): expn_data={:?}" , span, expn_data) ;
479
518
span = expn_data. call_site ;
480
- if !collapse_debuginfo_enabled || expn_data. collapse_debuginfo {
519
+ let is_ext = !expn_data. macro_def_id . map_or ( false , |v| v. is_local ( ) ) ;
520
+ if !collapse_debuginfo_feature_enabled
521
+ || expn_data. collapse_debuginfo . should_collapse ( collapse_debuginfo_flag, is_ext)
522
+ {
481
523
ret_span = span;
482
524
}
483
525
}
@@ -601,8 +643,20 @@ pub fn walk_chain(span: Span, to: SyntaxContext) -> Span {
601
643
HygieneData :: with ( |data| data. walk_chain ( span, to) )
602
644
}
603
645
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) )
646
+ pub fn walk_chain_collapsed (
647
+ span : Span ,
648
+ to : Span ,
649
+ collapse_debuginfo_feature_enabled : bool ,
650
+ collapse_debuginfo_flag : CollapseDebuginfo ,
651
+ ) -> Span {
652
+ HygieneData :: with ( |hdata| {
653
+ hdata. walk_chain_collapsed (
654
+ span,
655
+ to,
656
+ collapse_debuginfo_feature_enabled,
657
+ collapse_debuginfo_flag,
658
+ )
659
+ } )
606
660
}
607
661
608
662
pub fn update_dollar_crate_names ( mut get_name : impl FnMut ( SyntaxContext ) -> Symbol ) {
@@ -957,7 +1011,7 @@ pub struct ExpnData {
957
1011
pub local_inner_macros : bool ,
958
1012
/// Should debuginfo for the macro be collapsed to the outermost expansion site (in other
959
1013
/// words, was the macro definition annotated with `#[collapse_debuginfo]`)?
960
- pub ( crate ) collapse_debuginfo : bool ,
1014
+ pub ( crate ) collapse_debuginfo : CollapseDebuginfo ,
961
1015
}
962
1016
963
1017
impl !PartialEq for ExpnData { }
@@ -975,7 +1029,7 @@ impl ExpnData {
975
1029
parent_module : Option < DefId > ,
976
1030
allow_internal_unsafe : bool ,
977
1031
local_inner_macros : bool ,
978
- collapse_debuginfo : bool ,
1032
+ collapse_debuginfo : CollapseDebuginfo ,
979
1033
) -> ExpnData {
980
1034
ExpnData {
981
1035
kind,
@@ -1013,7 +1067,7 @@ impl ExpnData {
1013
1067
disambiguator : 0 ,
1014
1068
allow_internal_unsafe : false ,
1015
1069
local_inner_macros : false ,
1016
- collapse_debuginfo : false ,
1070
+ collapse_debuginfo : CollapseDebuginfo :: Unspecified ,
1017
1071
}
1018
1072
}
1019
1073
0 commit comments