From f5aa1bceb92ce2207a2f3db07c3fe892fa196086 Mon Sep 17 00:00:00 2001 From: Nathan Nguyen Date: Thu, 18 Feb 2021 23:18:20 -0600 Subject: [PATCH 1/2] nhwn: use Option in DebugLoc --- .../src/debuginfo/create_scope_map.rs | 4 ++-- .../src/debuginfo/metadata.rs | 4 ++-- .../rustc_codegen_llvm/src/debuginfo/mod.rs | 17 +++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs index 7673dfb744c5a..6febfc9abd668 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs @@ -102,8 +102,8 @@ fn make_mir_scope( DIB(cx), parent_scope.dbg_scope.unwrap(), file_metadata, - loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), - loc.col.unwrap_or(UNKNOWN_COLUMN_NUMBER), + loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), + loc.col.map_or(UNKNOWN_COLUMN_NUMBER, |n| n.get()), ) }, }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 6e7c0b3e3478a..42a0db54d418d 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1841,7 +1841,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> { let loc = cx.lookup_debug_loc(span.lo()); return Some(SourceInfo { file: file_metadata(cx, &loc.file), - line: loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), + line: loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), }); } } @@ -2504,7 +2504,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global linkage_name.as_ptr().cast(), linkage_name.len(), file_metadata, - line_number.unwrap_or(UNKNOWN_LINE_NUMBER), + line_number.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), type_metadata, is_local_to_unit, global, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 955e739b2c126..f10cc1f4f590a 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -38,6 +38,7 @@ use rustc_target::abi::{LayoutOf, Primitive, Size}; use libc::c_uint; use smallvec::SmallVec; use std::cell::RefCell; +use std::num::NonZeroU32; use tracing::debug; mod create_scope_map; @@ -224,9 +225,9 @@ pub struct DebugLoc { /// Information about the original source file. pub file: Lrc, /// The (1-based) line number. - pub line: Option, + pub line: Option, /// The (1-based) column number. - pub col: Option, + pub col: Option, } impl CodegenCx<'ll, '_> { @@ -243,7 +244,7 @@ impl CodegenCx<'ll, '_> { let line = (line + 1) as u32; let col = (pos - line_pos).to_u32() + 1; - (file, Some(line), Some(col)) + (file, NonZeroU32::new(line), NonZeroU32::new(col)) } Err(file) => (file, None, None), }; @@ -358,9 +359,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { linkage_name.as_ptr().cast(), linkage_name.len(), file_metadata, - loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), + loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), function_type_metadata, - scope_line.unwrap_or(UNKNOWN_LINE_NUMBER), + scope_line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), flags, spflags, maybe_definition_llfn, @@ -552,8 +553,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { unsafe { llvm::LLVMRustDIBuilderCreateDebugLocation( - line.unwrap_or(UNKNOWN_LINE_NUMBER), - col.unwrap_or(UNKNOWN_COLUMN_NUMBER), + line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), + col.map_or(UNKNOWN_COLUMN_NUMBER, |n| n.get()), scope, inlined_at, ) @@ -606,7 +607,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { name.as_ptr().cast(), name.len(), file_metadata, - loc.line.unwrap_or(UNKNOWN_LINE_NUMBER), + loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), type_metadata, true, DIFlags::FlagZero, From 408d4027d0c469be4ab442b8d0223565cdb09229 Mon Sep 17 00:00:00 2001 From: Nathan Nguyen Date: Fri, 19 Feb 2021 14:50:15 -0600 Subject: [PATCH 2/2] nhwn: use plain u32 in DebugLoc --- .../src/debuginfo/create_scope_map.rs | 6 ++--- .../src/debuginfo/metadata.rs | 9 +++---- .../rustc_codegen_llvm/src/debuginfo/mod.rs | 26 +++++++------------ 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs index 6febfc9abd668..c2725b83f50d6 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs @@ -1,4 +1,4 @@ -use super::metadata::{file_metadata, UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER}; +use super::metadata::file_metadata; use super::utils::DIB; use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext}; use rustc_codegen_ssa::traits::*; @@ -102,8 +102,8 @@ fn make_mir_scope( DIB(cx), parent_scope.dbg_scope.unwrap(), file_metadata, - loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), - loc.col.map_or(UNKNOWN_COLUMN_NUMBER, |n| n.get()), + loc.line, + loc.col, ) }, }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 42a0db54d418d..d6873af0522b8 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1839,10 +1839,7 @@ impl<'tcx> VariantInfo<'_, 'tcx> { .span; if !span.is_dummy() { let loc = cx.lookup_debug_loc(span.lo()); - return Some(SourceInfo { - file: file_metadata(cx, &loc.file), - line: loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), - }); + return Some(SourceInfo { file: file_metadata(cx, &loc.file), line: loc.line }); } } _ => {} @@ -2481,7 +2478,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global let loc = cx.lookup_debug_loc(span.lo()); (file_metadata(cx, &loc.file), loc.line) } else { - (unknown_file_metadata(cx), None) + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) }; let is_local_to_unit = is_node_local_to_unit(cx, def_id); @@ -2504,7 +2501,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global linkage_name.as_ptr().cast(), linkage_name.len(), file_metadata, - line_number.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), + line_number, type_metadata, is_local_to_unit, global, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index f10cc1f4f590a..1429b4ff21781 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -38,7 +38,6 @@ use rustc_target::abi::{LayoutOf, Primitive, Size}; use libc::c_uint; use smallvec::SmallVec; use std::cell::RefCell; -use std::num::NonZeroU32; use tracing::debug; mod create_scope_map; @@ -225,9 +224,9 @@ pub struct DebugLoc { /// Information about the original source file. pub file: Lrc, /// The (1-based) line number. - pub line: Option, + pub line: u32, /// The (1-based) column number. - pub col: Option, + pub col: u32, } impl CodegenCx<'ll, '_> { @@ -244,16 +243,16 @@ impl CodegenCx<'ll, '_> { let line = (line + 1) as u32; let col = (pos - line_pos).to_u32() + 1; - (file, NonZeroU32::new(line), NonZeroU32::new(col)) + (file, line, col) } - Err(file) => (file, None, None), + Err(file) => (file, UNKNOWN_LINE_NUMBER, UNKNOWN_COLUMN_NUMBER), }; // For MSVC, omit the column number. // Otherwise, emit it. This mimics clang behaviour. // See discussion in https://github.com/rust-lang/rust/issues/42921 if self.sess().target.is_like_msvc { - DebugLoc { file, line, col: None } + DebugLoc { file, line, col: UNKNOWN_COLUMN_NUMBER } } else { DebugLoc { file, line, col } } @@ -359,9 +358,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { linkage_name.as_ptr().cast(), linkage_name.len(), file_metadata, - loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), + loc.line, function_type_metadata, - scope_line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), + scope_line, flags, spflags, maybe_definition_llfn, @@ -551,14 +550,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { ) -> &'ll DILocation { let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo()); - unsafe { - llvm::LLVMRustDIBuilderCreateDebugLocation( - line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), - col.map_or(UNKNOWN_COLUMN_NUMBER, |n| n.get()), - scope, - inlined_at, - ) - } + unsafe { llvm::LLVMRustDIBuilderCreateDebugLocation(line, col, scope, inlined_at) } } fn create_vtable_metadata(&self, ty: Ty<'tcx>, vtable: Self::Value) { @@ -607,7 +599,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { name.as_ptr().cast(), name.len(), file_metadata, - loc.line.map_or(UNKNOWN_LINE_NUMBER, |n| n.get()), + loc.line, type_metadata, true, DIFlags::FlagZero,