Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix performance regression in debuginfo file_metadata. #70803

Merged
merged 1 commit into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/create_scope_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn make_mir_scope(
}

let loc = cx.lookup_debug_loc(scope_data.span.lo());
let file_metadata = file_metadata(cx, &loc.file.name, debug_context.defining_crate);
let file_metadata = file_metadata(cx, &loc.file, debug_context.defining_crate);

let scope_metadata = unsafe {
Some(llvm::LLVMRustDIBuilderCreateLexicalBlock(
Expand Down
15 changes: 7 additions & 8 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use rustc_middle::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
use rustc_middle::{bug, span_bug};
use rustc_session::config::{self, DebugInfo};
use rustc_span::symbol::{Interner, Symbol};
use rustc_span::{self, FileName, SourceFileHash, Span};
use rustc_span::{self, SourceFile, SourceFileHash, Span};
use rustc_target::abi::{Abi, Align, DiscriminantKind, HasDataLayout, Integer, LayoutOf};
use rustc_target::abi::{Int, Pointer, F32, F64};
use rustc_target::abi::{Primitive, Size, VariantIdx, Variants};
Expand Down Expand Up @@ -761,14 +761,13 @@ fn hex_encode(data: &[u8]) -> String {

pub fn file_metadata(
cx: &CodegenCx<'ll, '_>,
file_name: &FileName,
source_file: &SourceFile,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, I think I did this (plus removing defining_crate and relying on the more accurate source_file.is_imported()) in one of my PRs that has been sitting around.

defining_crate: CrateNum,
) -> &'ll DIFile {
debug!("file_metadata: file_name: {}, defining_crate: {}", file_name, defining_crate);
debug!("file_metadata: file_name: {}, defining_crate: {}", source_file.name, defining_crate);

let source_file = cx.sess().source_map().get_source_file(file_name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I missed this during review! This is indeed unnecessarily slow.

let hash = source_file.as_ref().map(|f| &f.src_hash);
let file_name = Some(file_name.to_string());
let hash = Some(&source_file.src_hash);
let file_name = Some(source_file.name.to_string());
let directory = if defining_crate == LOCAL_CRATE {
Some(cx.sess().working_dir.0.to_string_lossy().to_string())
} else {
Expand Down Expand Up @@ -2331,7 +2330,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global

let (file_metadata, line_number) = if !span.is_dummy() {
let loc = cx.lookup_debug_loc(span.lo());
(file_metadata(cx, &loc.file.name, LOCAL_CRATE), loc.line)
(file_metadata(cx, &loc.file, LOCAL_CRATE), loc.line)
} else {
(unknown_file_metadata(cx), None)
};
Expand Down Expand Up @@ -2440,6 +2439,6 @@ pub fn extend_scope_to_file(
file: &rustc_span::SourceFile,
defining_crate: CrateNum,
) -> &'ll DILexicalBlock {
let file_metadata = file_metadata(cx, &file.name, defining_crate);
let file_metadata = file_metadata(cx, &file, defining_crate);
unsafe { llvm::LLVMRustDIBuilderCreateLexicalBlockFile(DIB(cx), scope_metadata, file_metadata) }
}
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let def_id = instance.def_id();
let containing_scope = get_containing_scope(self, instance);
let loc = self.lookup_debug_loc(span.lo());
let file_metadata = file_metadata(self, &loc.file.name, def_id.krate);
let file_metadata = file_metadata(self, &loc.file, def_id.krate);

let function_type_metadata = unsafe {
let fn_signature = get_function_signature(self, fn_abi);
Expand Down Expand Up @@ -536,7 +536,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
span: Span,
) -> &'ll DIVariable {
let loc = self.lookup_debug_loc(span.lo());
let file_metadata = file_metadata(self, &loc.file.name, dbg_context.defining_crate);
let file_metadata = file_metadata(self, &loc.file, dbg_context.defining_crate);

let type_metadata = type_metadata(self, variable_type, span);

Expand Down