Skip to content

Commit d04af19

Browse files
committed
Remove SyntaxContext from {ast, hir}::{GlobalAsm, InlineAsm}
We now store it in the `Span` of the expression or item.
1 parent f70c90c commit d04af19

File tree

10 files changed

+18
-25
lines changed

10 files changed

+18
-25
lines changed

src/librustc/hir/lowering/expr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,6 @@ impl LoweringContext<'_> {
984984
volatile: asm.volatile,
985985
alignstack: asm.alignstack,
986986
dialect: asm.dialect,
987-
ctxt: asm.ctxt,
988987
};
989988

990989
let outputs = asm.outputs

src/librustc/hir/lowering/item.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -750,10 +750,7 @@ impl LoweringContext<'_> {
750750
}
751751

752752
fn lower_global_asm(&mut self, ga: &GlobalAsm) -> P<hir::GlobalAsm> {
753-
P(hir::GlobalAsm {
754-
asm: ga.asm,
755-
ctxt: ga.ctxt,
756-
})
753+
P(hir::GlobalAsm { asm: ga.asm })
757754
}
758755

759756
fn lower_variant(&mut self, v: &Variant) -> hir::Variant {

src/librustc/hir/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc_target::spec::abi::Abi;
2323
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
2424
use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy};
2525
use syntax::attr::{InlineAttr, OptimizeAttr};
26-
use syntax::ext::hygiene::SyntaxContext;
2726
use syntax::symbol::{Symbol, kw};
2827
use syntax::tokenstream::TokenStream;
2928
use syntax::util::parser::ExprPrecedence;
@@ -2004,8 +2003,6 @@ pub struct InlineAsm {
20042003
pub volatile: bool,
20052004
pub alignstack: bool,
20062005
pub dialect: AsmDialect,
2007-
#[stable_hasher(ignore)] // This is used for error reporting
2008-
pub ctxt: SyntaxContext,
20092006
}
20102007

20112008
/// Represents an argument in a function header.
@@ -2184,8 +2181,6 @@ pub struct ForeignMod {
21842181
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
21852182
pub struct GlobalAsm {
21862183
pub asm: Symbol,
2187-
#[stable_hasher(ignore)] // This is used for error reporting
2188-
pub ctxt: SyntaxContext,
21892184
}
21902185

21912186
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]

src/librustc_codegen_llvm/asm.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use crate::value::Value;
66

77
use rustc::hir;
88
use rustc_codegen_ssa::traits::*;
9-
109
use rustc_codegen_ssa::mir::place::PlaceRef;
1110
use rustc_codegen_ssa::mir::operand::OperandValue;
11+
use syntax_pos::Span;
1212

1313
use std::ffi::{CStr, CString};
1414
use libc::{c_uint, c_char};
@@ -19,7 +19,8 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
1919
&mut self,
2020
ia: &hir::InlineAsm,
2121
outputs: Vec<PlaceRef<'tcx, &'ll Value>>,
22-
mut inputs: Vec<&'ll Value>
22+
mut inputs: Vec<&'ll Value>,
23+
span: Span,
2324
) -> bool {
2425
let mut ext_constraints = vec![];
2526
let mut output_types = vec![];
@@ -102,7 +103,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
102103
let kind = llvm::LLVMGetMDKindIDInContext(self.llcx,
103104
key.as_ptr() as *const c_char, key.len() as c_uint);
104105

105-
let val: &'ll Value = self.const_i32(ia.ctxt.outer_expn().as_u32() as i32);
106+
let val: &'ll Value = self.const_i32(span.ctxt().outer_expn().as_u32() as i32);
106107

107108
llvm::LLVMSetMetadata(r, kind,
108109
llvm::LLVMMDNodeInContext(self.llcx, &val, 1));

src/librustc_codegen_ssa/mir/statement.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
8989
});
9090

9191
if input_vals.len() == asm.inputs.len() {
92-
let res = bx.codegen_inline_asm(&asm.asm, outputs, input_vals);
92+
let res = bx.codegen_inline_asm(
93+
&asm.asm,
94+
outputs,
95+
input_vals,
96+
statement.source_info.span,
97+
);
9398
if !res {
9499
span_err!(bx.sess(), statement.source_info.span, E0668,
95100
"malformed inline assembly");

src/librustc_codegen_ssa/traits/asm.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::BackendTypes;
22
use crate::mir::place::PlaceRef;
33
use rustc::hir::{GlobalAsm, InlineAsm};
4+
use syntax_pos::Span;
45

56
pub trait AsmBuilderMethods<'tcx>: BackendTypes {
67
/// Take an inline assembly expression and splat it out via LLVM
@@ -9,6 +10,7 @@ pub trait AsmBuilderMethods<'tcx>: BackendTypes {
910
ia: &InlineAsm,
1011
outputs: Vec<PlaceRef<'tcx, Self::Value>>,
1112
inputs: Vec<Self::Value>,
13+
span: Span,
1214
) -> bool;
1315
}
1416

src/libsyntax/ast.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub use UnsafeSource::*;
55
pub use crate::symbol::{Ident, Symbol as Name};
66
pub use crate::util::parser::ExprPrecedence;
77

8-
use crate::ext::hygiene::{ExpnId, SyntaxContext};
8+
use crate::ext::hygiene::ExpnId;
99
use crate::parse::token::{self, DelimToken};
1010
use crate::print::pprust;
1111
use crate::ptr::P;
@@ -1782,7 +1782,6 @@ pub struct InlineAsm {
17821782
pub volatile: bool,
17831783
pub alignstack: bool,
17841784
pub dialect: AsmDialect,
1785-
pub ctxt: SyntaxContext,
17861785
}
17871786

17881787
/// An argument in a function header.
@@ -2030,7 +2029,6 @@ pub struct ForeignMod {
20302029
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy)]
20312030
pub struct GlobalAsm {
20322031
pub asm: Symbol,
2033-
pub ctxt: SyntaxContext,
20342032
}
20352033

20362034
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]

src/libsyntax/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ pub fn noop_visit_expr<T: MutVisitor>(Expr { node, id, span, attrs }: &mut Expr,
11821182
}
11831183
ExprKind::InlineAsm(asm) => {
11841184
let InlineAsm { asm: _, asm_str_style: _, outputs, inputs, clobbers: _, volatile: _,
1185-
alignstack: _, dialect: _, ctxt: _ } = asm.deref_mut();
1185+
alignstack: _, dialect: _ } = asm.deref_mut();
11861186
for out in outputs {
11871187
let InlineAsmOutput { constraint: _, expr, is_rw: _, is_indirect: _ } = out;
11881188
vis.visit_expr(expr);

src/libsyntax_ext/asm.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
6363
MacEager::expr(P(ast::Expr {
6464
id: ast::DUMMY_NODE_ID,
6565
node: ast::ExprKind::InlineAsm(P(inline_asm)),
66-
span: sp,
66+
span: sp.with_ctxt(cx.backtrace()),
6767
attrs: ThinVec::new(),
6868
}))
6969
}
@@ -277,6 +277,5 @@ fn parse_inline_asm<'a>(
277277
volatile,
278278
alignstack,
279279
dialect,
280-
ctxt: cx.backtrace(),
281280
}))
282281
}

src/libsyntax_ext/global_asm.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
3030
id: ast::DUMMY_NODE_ID,
3131
node: ast::ItemKind::GlobalAsm(P(global_asm)),
3232
vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited),
33-
span: sp,
33+
span: sp.with_ctxt(cx.backtrace()),
3434
tokens: None,
3535
})])
3636
}
@@ -61,8 +61,5 @@ fn parse_global_asm<'a>(
6161
None => return Ok(None),
6262
};
6363

64-
Ok(Some(ast::GlobalAsm {
65-
asm,
66-
ctxt: cx.backtrace(),
67-
}))
64+
Ok(Some(ast::GlobalAsm { asm }))
6865
}

0 commit comments

Comments
 (0)