@@ -11,7 +11,7 @@ use self::metadata::{type_metadata, file_metadata, TypeMap};
1111use self :: source_loc:: InternalDebugLocation :: { self , UnknownLocation } ;
1212
1313use crate :: llvm;
14- use crate :: llvm:: debuginfo:: { DIFile , DIType , DIScope , DIBuilder , DISubprogram , DIArray , DIFlags ,
14+ use crate :: llvm:: debuginfo:: { DIFile , DIType , DIScope , DIBuilder , DIArray , DIFlags ,
1515 DISPFlags , DILexicalBlock } ;
1616use rustc:: hir:: CodegenFnAttrFlags ;
1717use rustc:: hir:: def_id:: { DefId , CrateNum , LOCAL_CRATE } ;
@@ -29,13 +29,13 @@ use rustc_data_structures::small_c_str::SmallCStr;
2929use rustc_index:: vec:: IndexVec ;
3030use rustc_codegen_ssa:: debuginfo:: type_names;
3131use rustc_codegen_ssa:: mir:: debuginfo:: { FunctionDebugContext , DebugScope , VariableAccess ,
32- VariableKind , FunctionDebugContextData } ;
32+ VariableKind } ;
3333
3434use libc:: c_uint;
3535use std:: cell:: RefCell ;
3636use std:: ffi:: { CStr , CString } ;
3737
38- use syntax_pos:: { self , Span , Pos } ;
38+ use syntax_pos:: { self , BytePos , Span , Pos } ;
3939use syntax:: ast;
4040use syntax:: symbol:: Symbol ;
4141use rustc:: ty:: layout:: { self , LayoutOf , HasTyCtxt } ;
@@ -48,7 +48,7 @@ pub mod metadata;
4848mod create_scope_map;
4949mod source_loc;
5050
51- pub use self :: create_scope_map:: { create_mir_scopes } ;
51+ pub use self :: create_scope_map:: compute_mir_scopes ;
5252pub use self :: metadata:: create_global_var_metadata;
5353pub use self :: metadata:: extend_scope_to_file;
5454pub use self :: source_loc:: set_source_location;
@@ -149,21 +149,21 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
149149impl DebugInfoBuilderMethods < ' tcx > for Builder < ' a , ' ll , ' tcx > {
150150 fn declare_local (
151151 & mut self ,
152- dbg_context : & FunctionDebugContext < & ' ll DISubprogram > ,
152+ dbg_context : & FunctionDebugContext < & ' ll DIScope > ,
153153 variable_name : ast:: Name ,
154154 variable_type : Ty < ' tcx > ,
155155 scope_metadata : & ' ll DIScope ,
156156 variable_access : VariableAccess < ' _ , & ' ll Value > ,
157157 variable_kind : VariableKind ,
158158 span : Span ,
159159 ) {
160- assert ! ( !dbg_context. get_ref ( span ) . source_locations_enabled) ;
160+ assert ! ( !dbg_context. source_locations_enabled) ;
161161 let cx = self . cx ( ) ;
162162
163163 let file = span_start ( cx, span) . file ;
164164 let file_metadata = file_metadata ( cx,
165165 & file. name ,
166- dbg_context. get_ref ( span ) . defining_crate ) ;
166+ dbg_context. defining_crate ) ;
167167
168168 let loc = span_start ( cx, span) ;
169169 let type_metadata = type_metadata ( cx, variable_type, span) ;
@@ -215,8 +215,8 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
215215
216216 fn set_source_location (
217217 & mut self ,
218- debug_context : & mut FunctionDebugContext < & ' ll DISubprogram > ,
219- scope : Option < & ' ll DIScope > ,
218+ debug_context : & mut FunctionDebugContext < & ' ll DIScope > ,
219+ scope : & ' ll DIScope ,
220220 span : Span ,
221221 ) {
222222 set_source_location ( debug_context, & self , scope, span)
@@ -269,14 +269,14 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
269269 sig : ty:: FnSig < ' tcx > ,
270270 llfn : & ' ll Value ,
271271 mir : & mir:: Body < ' _ > ,
272- ) -> FunctionDebugContext < & ' ll DISubprogram > {
272+ ) -> Option < FunctionDebugContext < & ' ll DIScope > > {
273273 if self . sess ( ) . opts . debuginfo == DebugInfo :: None {
274- return FunctionDebugContext :: DebugInfoDisabled ;
274+ return None ;
275275 }
276276
277277 if let InstanceDef :: Item ( def_id) = instance. def {
278278 if self . tcx ( ) . codegen_fn_attrs ( def_id) . flags . contains ( CodegenFnAttrFlags :: NO_DEBUG ) {
279- return FunctionDebugContext :: FunctionWithoutDebugInfo ;
279+ return None ;
280280 }
281281 }
282282
@@ -285,7 +285,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
285285 // This can be the case for functions inlined from another crate
286286 if span. is_dummy ( ) {
287287 // FIXME(simulacrum): Probably can't happen; remove.
288- return FunctionDebugContext :: FunctionWithoutDebugInfo ;
288+ return None ;
289289 }
290290
291291 let def_id = instance. def_id ( ) ;
@@ -358,14 +358,23 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
358358 None )
359359 } ;
360360
361- // Initialize fn debug context (including scope map and namespace map)
362- let fn_debug_context = FunctionDebugContextData {
363- fn_metadata,
361+ // Initialize fn debug context (including scopes).
362+ // FIXME(eddyb) figure out a way to not need `Option` for `scope_metadata`.
363+ let null_scope = DebugScope {
364+ scope_metadata : None ,
365+ file_start_pos : BytePos ( 0 ) ,
366+ file_end_pos : BytePos ( 0 )
367+ } ;
368+ let mut fn_debug_context = FunctionDebugContext {
369+ scopes : IndexVec :: from_elem ( null_scope, & mir. source_scopes ) ,
364370 source_locations_enabled : false ,
365371 defining_crate : def_id. krate ,
366372 } ;
367373
368- return FunctionDebugContext :: RegularContext ( fn_debug_context) ;
374+ // Fill in all the scopes, with the information from the MIR body.
375+ compute_mir_scopes ( self , mir, fn_metadata, & mut fn_debug_context) ;
376+
377+ return Some ( fn_debug_context) ;
369378
370379 fn get_function_signature < ' ll , ' tcx > (
371380 cx : & CodegenCx < ' ll , ' tcx > ,
@@ -550,14 +559,6 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
550559 metadata:: create_vtable_metadata ( self , ty, vtable)
551560 }
552561
553- fn create_mir_scopes (
554- & self ,
555- mir : & mir:: Body < ' _ > ,
556- debug_context : & mut FunctionDebugContext < & ' ll DISubprogram > ,
557- ) -> IndexVec < mir:: SourceScope , DebugScope < & ' ll DIScope > > {
558- create_scope_map:: create_mir_scopes ( self , mir, debug_context)
559- }
560-
561562 fn extend_scope_to_file (
562563 & self ,
563564 scope_metadata : & ' ll DIScope ,
0 commit comments