@@ -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
+ /// Unspecified value
171
+ Unspecified = 0 ,
172
+ /// Don't collapse debuginfo for the macro
173
+ No = 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,7 +499,8 @@ 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;
@@ -477,7 +513,10 @@ impl HygieneData {
477
513
let expn_data = self . expn_data ( outer_expn) ;
478
514
debug ! ( "walk_chain_collapsed({:?}): expn_data={:?}" , span, expn_data) ;
479
515
span = expn_data. call_site ;
480
- if !collapse_debuginfo_enabled || expn_data. collapse_debuginfo {
516
+ let is_ext = !expn_data. macro_def_id . map_or ( false , |v| v. is_local ( ) ) ;
517
+ if !collapse_debuginfo_feature_enabled
518
+ || expn_data. collapse_debuginfo . should_collapse ( collapse_debuginfo_flag, is_ext)
519
+ {
481
520
ret_span = span;
482
521
}
483
522
}
@@ -601,8 +640,20 @@ pub fn walk_chain(span: Span, to: SyntaxContext) -> Span {
601
640
HygieneData :: with ( |data| data. walk_chain ( span, to) )
602
641
}
603
642
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) )
643
+ pub fn walk_chain_collapsed (
644
+ span : Span ,
645
+ to : Span ,
646
+ collapse_debuginfo_feature_enabled : bool ,
647
+ collapse_debuginfo_flag : CollapseDebuginfo ,
648
+ ) -> Span {
649
+ HygieneData :: with ( |hdata| {
650
+ hdata. walk_chain_collapsed (
651
+ span,
652
+ to,
653
+ collapse_debuginfo_feature_enabled,
654
+ collapse_debuginfo_flag,
655
+ )
656
+ } )
606
657
}
607
658
608
659
pub fn update_dollar_crate_names ( mut get_name : impl FnMut ( SyntaxContext ) -> Symbol ) {
@@ -957,7 +1008,7 @@ pub struct ExpnData {
957
1008
pub local_inner_macros : bool ,
958
1009
/// Should debuginfo for the macro be collapsed to the outermost expansion site (in other
959
1010
/// words, was the macro definition annotated with `#[collapse_debuginfo]`)?
960
- pub ( crate ) collapse_debuginfo : bool ,
1011
+ pub ( crate ) collapse_debuginfo : CollapseDebuginfo ,
961
1012
}
962
1013
963
1014
impl !PartialEq for ExpnData { }
@@ -975,7 +1026,7 @@ impl ExpnData {
975
1026
parent_module : Option < DefId > ,
976
1027
allow_internal_unsafe : bool ,
977
1028
local_inner_macros : bool ,
978
- collapse_debuginfo : bool ,
1029
+ collapse_debuginfo : CollapseDebuginfo ,
979
1030
) -> ExpnData {
980
1031
ExpnData {
981
1032
kind,
@@ -1013,7 +1064,7 @@ impl ExpnData {
1013
1064
disambiguator : 0 ,
1014
1065
allow_internal_unsafe : false ,
1015
1066
local_inner_macros : false ,
1016
- collapse_debuginfo : false ,
1067
+ collapse_debuginfo : CollapseDebuginfo :: Unspecified ,
1017
1068
}
1018
1069
}
1019
1070
0 commit comments