From 1212fd8abc7602f6c506c936908a799c76549a14 Mon Sep 17 00:00:00 2001 From: Brian Brooks Date: Sat, 21 Feb 2015 06:56:46 -0500 Subject: [PATCH 1/2] Resolve includeme.fragment conflict. --- src/libcore/macros.rs | 5 +++-- src/liblog/macros.rs | 2 +- src/libstd/macros.rs | 4 ++-- src/libsyntax/ext/build.rs | 6 +++--- src/libsyntax/ext/source_util.rs | 5 +++-- .../syntax-extension-source-utils-files/includeme.fragment | 2 +- src/test/run-pass/syntax-extension-source-utils.rs | 2 +- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 943365d8454d4..d02ed7c25381d 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -15,7 +15,8 @@ macro_rules! panic { panic!("explicit panic") ); ($msg:expr) => ({ - static _MSG_FILE_LINE: (&'static str, &'static str, usize) = ($msg, file!(), line!()); + static _MSG_FILE_LINE: (&'static str, &'static str, usize) = + ($msg, file!(), line!() as usize); ::core::panicking::panic(&_MSG_FILE_LINE) }); ($fmt:expr, $($arg:tt)*) => ({ @@ -23,7 +24,7 @@ macro_rules! panic { // used inside a dead function. Just `#[allow(dead_code)]` is // insufficient, since the user may have // `#[forbid(dead_code)]` and which cannot be overridden. - static _FILE_LINE: (&'static str, usize) = (file!(), line!()); + static _FILE_LINE: (&'static str, usize) = (file!(), line!() as usize); ::core::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_FILE_LINE) }); } diff --git a/src/liblog/macros.rs b/src/liblog/macros.rs index 4a9a9bd40600b..787d9c470d41f 100644 --- a/src/liblog/macros.rs +++ b/src/liblog/macros.rs @@ -51,7 +51,7 @@ macro_rules! log { ($lvl:expr, $($arg:tt)+) => ({ static LOC: ::log::LogLocation = ::log::LogLocation { - line: line!(), + line: line!() as usize, file: file!(), module_path: module_path!(), }; diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 00bb7f86b170c..abdcca59c58f3 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -44,7 +44,7 @@ macro_rules! panic { ($msg:expr) => ({ $crate::rt::begin_unwind($msg, { // static requires less code at runtime, more constant data - static _FILE_LINE: (&'static str, usize) = (file!(), line!()); + static _FILE_LINE: (&'static str, usize) = (file!(), line!() as usize); &_FILE_LINE }) }); @@ -54,7 +54,7 @@ macro_rules! panic { // used inside a dead function. Just `#[allow(dead_code)]` is // insufficient, since the user may have // `#[forbid(dead_code)]` and which cannot be overridden. - static _FILE_LINE: (&'static str, usize) = (file!(), line!()); + static _FILE_LINE: (&'static str, usize) = (file!(), line!() as usize); &_FILE_LINE }) }); diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 5bfd4a9f6111c..454c21fdc572d 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -147,7 +147,7 @@ pub trait AstBuilder { fn expr_usize(&self, span: Span, i: usize) -> P; fn expr_int(&self, sp: Span, i: isize) -> P; - fn expr_u8(&self, sp: Span, u: u8) -> P; + fn expr_u32(&self, sp: Span, u: u32) -> P; fn expr_bool(&self, sp: Span, value: bool) -> P; fn expr_vec(&self, sp: Span, exprs: Vec>) -> P; @@ -701,8 +701,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs(false), ast::Sign::new(i)))) } - fn expr_u8(&self, sp: Span, u: u8) -> P { - self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU8))) + fn expr_u32(&self, sp: Span, u: u32) -> P { + self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU32))) } fn expr_bool(&self, sp: Span, value: bool) -> P { self.expr_lit(sp, ast::LitBool(value)) diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index c8d48750c7509..40e614c78c7cc 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -35,7 +35,7 @@ pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) let topmost = cx.original_span_in_file(); let loc = cx.codemap().lookup_char_pos(topmost.lo); - base::MacExpr::new(cx.expr_usize(topmost, loc.line)) + base::MacExpr::new(cx.expr_u32(topmost, loc.line as u32)) } /* column!(): expands to the current column number */ @@ -45,7 +45,8 @@ pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) let topmost = cx.original_span_in_file(); let loc = cx.codemap().lookup_char_pos(topmost.lo); - base::MacExpr::new(cx.expr_usize(topmost, loc.col.to_usize())) + + base::MacExpr::new(cx.expr_u32(topmost, loc.col.to_usize() as u32)) } /// file!(): expands to the current filename */ diff --git a/src/test/run-pass/syntax-extension-source-utils-files/includeme.fragment b/src/test/run-pass/syntax-extension-source-utils-files/includeme.fragment index dea7f99fcbace..70cd7b772920d 100644 --- a/src/test/run-pass/syntax-extension-source-utils-files/includeme.fragment +++ b/src/test/run-pass/syntax-extension-source-utils-files/includeme.fragment @@ -2,6 +2,6 @@ { assert!(file!().ends_with("includeme.fragment")); - assert!(line!() == 5_usize); + assert!(line!() == 5_u32); format!("victory robot {}", line!()) } diff --git a/src/test/run-pass/syntax-extension-source-utils.rs b/src/test/run-pass/syntax-extension-source-utils.rs index 349a676a433e3..d1dc02bce8d6e 100644 --- a/src/test/run-pass/syntax-extension-source-utils.rs +++ b/src/test/run-pass/syntax-extension-source-utils.rs @@ -23,7 +23,7 @@ macro_rules! indirect_line { () => ( line!() ) } pub fn main() { assert_eq!(line!(), 25); - //assert!((column!() == 11)); + assert!((column!() == 4_u32)); assert_eq!(indirect_line!(), 27); assert!((file!().ends_with("syntax-extension-source-utils.rs"))); assert_eq!(stringify!((2*3) + 5).to_string(), "( 2 * 3 ) + 5".to_string()); From fc9fa1a563c48cc928c8c5754597ffba6f53a635 Mon Sep 17 00:00:00 2001 From: Brian Brooks Date: Sat, 21 Feb 2015 17:26:29 -0500 Subject: [PATCH 2/2] Resolve barriers to changing column!() / line!() return type to u32 in #19284 . Address review comments in #21769 . --- src/libcore/macros.rs | 11 ++++-- src/libcore/panicking.rs | 39 ++++++++++++++++--- src/liblog/lib.rs | 4 +- src/liblog/macros.rs | 9 ++++- src/librustc_trans/trans/common.rs | 4 ++ src/librustc_trans/trans/controlflow.rs | 4 +- src/libsyntax/ext/build.rs | 4 ++ .../includeme.fragment | 2 +- .../run-pass/syntax-extension-source-utils.rs | 2 +- 9 files changed, 64 insertions(+), 15 deletions(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index d02ed7c25381d..92d50821592c6 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -15,8 +15,10 @@ macro_rules! panic { panic!("explicit panic") ); ($msg:expr) => ({ - static _MSG_FILE_LINE: (&'static str, &'static str, usize) = - ($msg, file!(), line!() as usize); + #[cfg(stage0)] + static _MSG_FILE_LINE: (&'static str, &'static str, usize) = ($msg, file!(), line!()); + #[cfg(not(stage0))] + static _MSG_FILE_LINE: (&'static str, &'static str, u32) = ($msg, file!(), line!()); ::core::panicking::panic(&_MSG_FILE_LINE) }); ($fmt:expr, $($arg:tt)*) => ({ @@ -24,7 +26,10 @@ macro_rules! panic { // used inside a dead function. Just `#[allow(dead_code)]` is // insufficient, since the user may have // `#[forbid(dead_code)]` and which cannot be overridden. - static _FILE_LINE: (&'static str, usize) = (file!(), line!() as usize); + #[cfg(stage0)] + static _FILE_LINE: (&'static str, usize) = (file!(), line!()); + #[cfg(not(stage0))] + static _FILE_LINE: (&'static str, u32) = (file!(), line!()); ::core::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_FILE_LINE) }); } diff --git a/src/libcore/panicking.rs b/src/libcore/panicking.rs index 61b4284e1dd9c..168dcf4978c46 100644 --- a/src/libcore/panicking.rs +++ b/src/libcore/panicking.rs @@ -34,26 +34,55 @@ use fmt; #[cold] #[inline(never)] // this is the slow path, always #[lang="panic"] -pub fn panic(expr_file_line: &(&'static str, &'static str, uint)) -> ! { +#[cfg(stage0)] +pub fn panic(expr_file_line: &(&'static str, &'static str, usize)) -> ! { + let (expr, file, line) = *expr_file_line; + panic_fmt(format_args!("{}", expr), &(file, line)) +} +#[cold] #[inline(never)] // this is the slow path, always +#[lang="panic"] +#[cfg(not(stage0))] +pub fn panic(expr_file_line: &(&'static str, &'static str, u32)) -> ! { let (expr, file, line) = *expr_file_line; panic_fmt(format_args!("{}", expr), &(file, line)) } #[cold] #[inline(never)] #[lang="panic_bounds_check"] -fn panic_bounds_check(file_line: &(&'static str, uint), - index: uint, len: uint) -> ! { +#[cfg(stage0)] +fn panic_bounds_check(file_line: &(&'static str, usize), + index: usize, len: usize) -> ! { + panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}", + len, index), file_line) +} +#[cold] #[inline(never)] +#[lang="panic_bounds_check"] +#[cfg(not(stage0))] +fn panic_bounds_check(file_line: &(&'static str, u32), + index: usize, len: usize) -> ! { panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}", len, index), file_line) } #[cold] #[inline(never)] -pub fn panic_fmt(fmt: fmt::Arguments, file_line: &(&'static str, uint)) -> ! { +#[cfg(stage0)] +pub fn panic_fmt(fmt: fmt::Arguments, file_line: &(&'static str, usize)) -> ! { + #[allow(improper_ctypes)] + extern { + #[lang = "panic_fmt"] + fn panic_impl(fmt: fmt::Arguments, file: &'static str, line: uint) -> !; + } + let (file, line) = *file_line; + unsafe { panic_impl(fmt, file, line as uint) } +} +#[cold] #[inline(never)] +#[cfg(not(stage0))] +pub fn panic_fmt(fmt: fmt::Arguments, file_line: &(&'static str, u32)) -> ! { #[allow(improper_ctypes)] extern { #[lang = "panic_fmt"] fn panic_impl(fmt: fmt::Arguments, file: &'static str, line: uint) -> !; } let (file, line) = *file_line; - unsafe { panic_impl(fmt, file, line) } + unsafe { panic_impl(fmt, file, line as uint) } } diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index c2c7f20ce9cdf..5c008d35cb3ff 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -342,7 +342,7 @@ pub struct LogRecord<'a> { pub file: &'a str, /// The line number of where the LogRecord originated. - pub line: uint, + pub line: u32, } #[doc(hidden)] @@ -350,7 +350,7 @@ pub struct LogRecord<'a> { pub struct LogLocation { pub module_path: &'static str, pub file: &'static str, - pub line: uint, + pub line: u32, } /// Tests whether a given module's name is enabled for a particular level of diff --git a/src/liblog/macros.rs b/src/liblog/macros.rs index 787d9c470d41f..b1d292ebaa883 100644 --- a/src/liblog/macros.rs +++ b/src/liblog/macros.rs @@ -50,8 +50,15 @@ #[macro_export] macro_rules! log { ($lvl:expr, $($arg:tt)+) => ({ + #[cfg(stage0)] static LOC: ::log::LogLocation = ::log::LogLocation { - line: line!() as usize, + line: line!() as u32, + file: file!(), + module_path: module_path!(), + }; + #[cfg(not(stage0))] + static LOC: ::log::LogLocation = ::log::LogLocation { + line: line!(), file: file!(), module_path: module_path!(), }; diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index a9cda94bebac5..a757aa9452d8a 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -774,6 +774,10 @@ pub fn C_i32(ccx: &CrateContext, i: i32) -> ValueRef { C_integral(Type::i32(ccx), i as u64, true) } +pub fn C_u32(ccx: &CrateContext, i: u32) -> ValueRef { + C_integral(Type::i32(ccx), i as u64, false) +} + pub fn C_u64(ccx: &CrateContext, i: u64) -> ValueRef { C_integral(Type::i64(ccx), i, false) } diff --git a/src/librustc_trans/trans/controlflow.rs b/src/librustc_trans/trans/controlflow.rs index 26e12a1af403d..631aa324f6ce2 100644 --- a/src/librustc_trans/trans/controlflow.rs +++ b/src/librustc_trans/trans/controlflow.rs @@ -370,7 +370,7 @@ pub fn trans_fail<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, let loc = bcx.sess().codemap().lookup_char_pos(call_info.span.lo); let filename = token::intern_and_get_ident(&loc.file.name[]); let filename = C_str_slice(ccx, filename); - let line = C_uint(ccx, loc.line); + let line = C_u32(ccx, loc.line as u32); let expr_file_line_const = C_struct(ccx, &[v_str, filename, line], false); let expr_file_line = consts::addr_of(ccx, expr_file_line_const, "panic_loc", call_info.id); @@ -399,7 +399,7 @@ pub fn trans_fail_bounds_check<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // Invoke the lang item let filename = C_str_slice(ccx, filename); - let line = C_uint(ccx, loc.line); + let line = C_u32(ccx, loc.line as u32); let file_line_const = C_struct(ccx, &[filename, line], false); let file_line = consts::addr_of(ccx, file_line_const, "panic_bounds_check_loc", call_info.id); diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 454c21fdc572d..7ba045f0eb034 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -147,6 +147,7 @@ pub trait AstBuilder { fn expr_usize(&self, span: Span, i: usize) -> P; fn expr_int(&self, sp: Span, i: isize) -> P; + fn expr_u8(&self, sp: Span, u: u8) -> P; fn expr_u32(&self, sp: Span, u: u32) -> P; fn expr_bool(&self, sp: Span, value: bool) -> P; @@ -701,6 +702,9 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs(false), ast::Sign::new(i)))) } + fn expr_u8(&self, sp: Span, u: u8) -> P { + self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU8))) + } fn expr_u32(&self, sp: Span, u: u32) -> P { self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU32))) } diff --git a/src/test/run-pass/syntax-extension-source-utils-files/includeme.fragment b/src/test/run-pass/syntax-extension-source-utils-files/includeme.fragment index 70cd7b772920d..61d6d3fdd3b71 100644 --- a/src/test/run-pass/syntax-extension-source-utils-files/includeme.fragment +++ b/src/test/run-pass/syntax-extension-source-utils-files/includeme.fragment @@ -2,6 +2,6 @@ { assert!(file!().ends_with("includeme.fragment")); - assert!(line!() == 5_u32); + assert!(line!() == 5u32); format!("victory robot {}", line!()) } diff --git a/src/test/run-pass/syntax-extension-source-utils.rs b/src/test/run-pass/syntax-extension-source-utils.rs index d1dc02bce8d6e..ddd8cd8be3d5c 100644 --- a/src/test/run-pass/syntax-extension-source-utils.rs +++ b/src/test/run-pass/syntax-extension-source-utils.rs @@ -23,7 +23,7 @@ macro_rules! indirect_line { () => ( line!() ) } pub fn main() { assert_eq!(line!(), 25); - assert!((column!() == 4_u32)); + assert!((column!() == 4u32)); assert_eq!(indirect_line!(), 27); assert!((file!().ends_with("syntax-extension-source-utils.rs"))); assert_eq!(stringify!((2*3) + 5).to_string(), "( 2 * 3 ) + 5".to_string());