Skip to content

Commit

Permalink
Remove SyntaxContext from {ast, hir}::{GlobalAsm, InlineAsm}
Browse files Browse the repository at this point in the history
We now store it in the `Span` of the expression or item.
  • Loading branch information
matthewjasper committed Aug 17, 2019
1 parent f70c90c commit d04af19
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/librustc/hir/lowering/expr.rs
Expand Up @@ -984,7 +984,6 @@ impl LoweringContext<'_> {
volatile: asm.volatile,
alignstack: asm.alignstack,
dialect: asm.dialect,
ctxt: asm.ctxt,
};

let outputs = asm.outputs
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/hir/lowering/item.rs
Expand Up @@ -750,10 +750,7 @@ impl LoweringContext<'_> {
}

fn lower_global_asm(&mut self, ga: &GlobalAsm) -> P<hir::GlobalAsm> {
P(hir::GlobalAsm {
asm: ga.asm,
ctxt: ga.ctxt,
})
P(hir::GlobalAsm { asm: ga.asm })
}

fn lower_variant(&mut self, v: &Variant) -> hir::Variant {
Expand Down
5 changes: 0 additions & 5 deletions src/librustc/hir/mod.rs
Expand Up @@ -23,7 +23,6 @@ use rustc_target::spec::abi::Abi;
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy};
use syntax::attr::{InlineAttr, OptimizeAttr};
use syntax::ext::hygiene::SyntaxContext;
use syntax::symbol::{Symbol, kw};
use syntax::tokenstream::TokenStream;
use syntax::util::parser::ExprPrecedence;
Expand Down Expand Up @@ -2004,8 +2003,6 @@ pub struct InlineAsm {
pub volatile: bool,
pub alignstack: bool,
pub dialect: AsmDialect,
#[stable_hasher(ignore)] // This is used for error reporting
pub ctxt: SyntaxContext,
}

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

#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_codegen_llvm/asm.rs
Expand Up @@ -6,9 +6,9 @@ use crate::value::Value;

use rustc::hir;
use rustc_codegen_ssa::traits::*;

use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::mir::operand::OperandValue;
use syntax_pos::Span;

use std::ffi::{CStr, CString};
use libc::{c_uint, c_char};
Expand All @@ -19,7 +19,8 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
&mut self,
ia: &hir::InlineAsm,
outputs: Vec<PlaceRef<'tcx, &'ll Value>>,
mut inputs: Vec<&'ll Value>
mut inputs: Vec<&'ll Value>,
span: Span,
) -> bool {
let mut ext_constraints = vec![];
let mut output_types = vec![];
Expand Down Expand Up @@ -102,7 +103,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
let kind = llvm::LLVMGetMDKindIDInContext(self.llcx,
key.as_ptr() as *const c_char, key.len() as c_uint);

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

llvm::LLVMSetMetadata(r, kind,
llvm::LLVMMDNodeInContext(self.llcx, &val, 1));
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_codegen_ssa/mir/statement.rs
Expand Up @@ -89,7 +89,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
});

if input_vals.len() == asm.inputs.len() {
let res = bx.codegen_inline_asm(&asm.asm, outputs, input_vals);
let res = bx.codegen_inline_asm(
&asm.asm,
outputs,
input_vals,
statement.source_info.span,
);
if !res {
span_err!(bx.sess(), statement.source_info.span, E0668,
"malformed inline assembly");
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_codegen_ssa/traits/asm.rs
@@ -1,6 +1,7 @@
use super::BackendTypes;
use crate::mir::place::PlaceRef;
use rustc::hir::{GlobalAsm, InlineAsm};
use syntax_pos::Span;

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

Expand Down
4 changes: 1 addition & 3 deletions src/libsyntax/ast.rs
Expand Up @@ -5,7 +5,7 @@ pub use UnsafeSource::*;
pub use crate::symbol::{Ident, Symbol as Name};
pub use crate::util::parser::ExprPrecedence;

use crate::ext::hygiene::{ExpnId, SyntaxContext};
use crate::ext::hygiene::ExpnId;
use crate::parse::token::{self, DelimToken};
use crate::print::pprust;
use crate::ptr::P;
Expand Down Expand Up @@ -1782,7 +1782,6 @@ pub struct InlineAsm {
pub volatile: bool,
pub alignstack: bool,
pub dialect: AsmDialect,
pub ctxt: SyntaxContext,
}

/// An argument in a function header.
Expand Down Expand Up @@ -2030,7 +2029,6 @@ pub struct ForeignMod {
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy)]
pub struct GlobalAsm {
pub asm: Symbol,
pub ctxt: SyntaxContext,
}

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/mut_visit.rs
Expand Up @@ -1182,7 +1182,7 @@ pub fn noop_visit_expr<T: MutVisitor>(Expr { node, id, span, attrs }: &mut Expr,
}
ExprKind::InlineAsm(asm) => {
let InlineAsm { asm: _, asm_str_style: _, outputs, inputs, clobbers: _, volatile: _,
alignstack: _, dialect: _, ctxt: _ } = asm.deref_mut();
alignstack: _, dialect: _ } = asm.deref_mut();
for out in outputs {
let InlineAsmOutput { constraint: _, expr, is_rw: _, is_indirect: _ } = out;
vis.visit_expr(expr);
Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax_ext/asm.rs
Expand Up @@ -63,7 +63,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
MacEager::expr(P(ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::InlineAsm(P(inline_asm)),
span: sp,
span: sp.with_ctxt(cx.backtrace()),
attrs: ThinVec::new(),
}))
}
Expand Down Expand Up @@ -277,6 +277,5 @@ fn parse_inline_asm<'a>(
volatile,
alignstack,
dialect,
ctxt: cx.backtrace(),
}))
}
7 changes: 2 additions & 5 deletions src/libsyntax_ext/global_asm.rs
Expand Up @@ -30,7 +30,7 @@ pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
id: ast::DUMMY_NODE_ID,
node: ast::ItemKind::GlobalAsm(P(global_asm)),
vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited),
span: sp,
span: sp.with_ctxt(cx.backtrace()),
tokens: None,
})])
}
Expand Down Expand Up @@ -61,8 +61,5 @@ fn parse_global_asm<'a>(
None => return Ok(None),
};

Ok(Some(ast::GlobalAsm {
asm,
ctxt: cx.backtrace(),
}))
Ok(Some(ast::GlobalAsm { asm }))
}

0 comments on commit d04af19

Please sign in to comment.