Skip to content

Commit eb789de

Browse files
committed
Do MTWT resolution during lowering to HIR
1 parent 68c15be commit eb789de

File tree

17 files changed

+156
-86
lines changed

17 files changed

+156
-86
lines changed

src/librustc/middle/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
247247
let def = cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def());
248248
if let Some(DefLocal(..)) = def {
249249
if edef.variants.iter().any(|variant|
250-
variant.name == ident.node.name
250+
variant.name == ident.node.unhygienic_name
251251
&& variant.kind() == VariantKind::Unit
252252
) {
253253
span_warn!(cx.tcx.sess, p.span, E0170,

src/librustc/middle/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15961596
self.ir.tcx.sess.add_lint(lint::builtin::UNUSED_VARIABLES, id, sp,
15971597
format!("variable `{}` is assigned to, but never used",
15981598
name));
1599-
} else {
1599+
} else if name != "self" {
16001600
self.ir.tcx.sess.add_lint(lint::builtin::UNUSED_VARIABLES, id, sp,
16011601
format!("unused variable: `{}`", name));
16021602
}

src/librustc/middle/pat_util.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use middle::ty;
1414
use util::nodemap::FnvHashMap;
1515

1616
use syntax::ast;
17-
use syntax::ext::mtwt;
1817
use rustc_front::hir;
1918
use rustc_front::util::walk_pat;
2019
use syntax::codemap::{respan, Span, Spanned, DUMMY_SP};
@@ -27,8 +26,8 @@ pub type PatIdMap = FnvHashMap<ast::Name, ast::NodeId>;
2726
// use the NodeId of their namesake in the first pattern.
2827
pub fn pat_id_map(dm: &RefCell<DefMap>, pat: &hir::Pat) -> PatIdMap {
2928
let mut map = FnvHashMap();
30-
pat_bindings_hygienic(dm, pat, |_bm, p_id, _s, path1| {
31-
map.insert(mtwt::resolve(path1.node), p_id);
29+
pat_bindings(dm, pat, |_bm, p_id, _s, path1| {
30+
map.insert(path1.node, p_id);
3231
});
3332
map
3433
}
@@ -124,9 +123,8 @@ pub fn pat_bindings<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
124123
true
125124
});
126125
}
127-
128-
pub fn pat_bindings_hygienic<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
129-
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Ident>),
126+
pub fn pat_bindings_ident<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
127+
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<hir::Ident>),
130128
{
131129
walk_pat(pat, |p| {
132130
match p.node {
@@ -214,7 +212,7 @@ pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> hir::Path {
214212
tcx.with_path(id, |path| hir::Path {
215213
global: false,
216214
segments: path.last().map(|elem| hir::PathSegment {
217-
identifier: ast::Ident::with_empty_ctxt(elem.name()),
215+
identifier: hir::Ident::from_name(elem.name()),
218216
parameters: hir::PathParameters::none(),
219217
}).into_iter().collect(),
220218
span: DUMMY_SP,

src/librustc/middle/resolve_lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v hir::Block) {
426426
fn expression_label(ex: &hir::Expr) -> Option<ast::Name> {
427427
match ex.node {
428428
hir::ExprWhile(_, _, Some(label)) |
429-
hir::ExprLoop(_, Some(label)) => Some(label.name),
429+
hir::ExprLoop(_, Some(label)) => Some(label.unhygienic_name),
430430
_ => None,
431431
}
432432
}

src/librustc_driver/driver.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ pub fn compile_input(sess: Session,
112112
let mut hir_forest = time(sess.time_passes(),
113113
"lowering ast -> hir",
114114
|| hir_map::Forest::new(lower_crate(&lcx, &expanded_crate)));
115+
116+
// Discard MTWT tables that aren't required past lowering to HIR.
117+
if !sess.opts.debugging_opts.keep_mtwt_tables &&
118+
!sess.opts.debugging_opts.save_analysis {
119+
syntax::ext::mtwt::clear_tables();
120+
}
121+
115122
let arenas = ty::CtxtArenas::new();
116123
let ast_map = make_map(&sess, &mut hir_forest);
117124

@@ -704,12 +711,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
704711
"resolution",
705712
|| resolve::resolve_crate(sess, &ast_map, make_glob_map));
706713

707-
// Discard MTWT tables that aren't required past resolution.
708-
// FIXME: get rid of uses of MTWT tables in typeck, mir and trans and clear them
709-
if !sess.opts.debugging_opts.keep_mtwt_tables {
710-
// syntax::ext::mtwt::clear_tables();
711-
}
712-
713714
let named_region_map = time(time_passes,
714715
"lifetime resolution",
715716
|| middle::resolve_lifetime::krate(sess, krate, &def_map.borrow()));

src/librustc_front/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! and returns a piece of the same type.
1313
1414
use hir::*;
15-
use syntax::ast::{Ident, Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_, MetaItem};
15+
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_, MetaItem};
1616
use syntax::ast::{MetaWord, MetaList, MetaNameValue};
1717
use syntax::attr::ThinAttributesExt;
1818
use hir;

src/librustc_front/hir.rs

+54-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use intravisit::Visitor;
3939
use std::collections::BTreeMap;
4040
use syntax::codemap::{self, Span, Spanned, DUMMY_SP, ExpnId};
4141
use syntax::abi::Abi;
42-
use syntax::ast::{Name, Ident, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
42+
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
4343
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, CrateConfig};
4444
use syntax::attr::ThinAttributes;
4545
use syntax::owned_slice::OwnedSlice;
@@ -50,7 +50,59 @@ use print::pprust;
5050
use util;
5151

5252
use std::fmt;
53-
use serialize::{Encodable, Encoder, Decoder};
53+
use std::hash::{Hash, Hasher};
54+
use serialize::{Encodable, Decodable, Encoder, Decoder};
55+
56+
/// Identifier in HIR
57+
#[derive(Clone, Copy, Eq)]
58+
pub struct Ident {
59+
/// Hygienic name (renamed), should be used by default
60+
pub name: Name,
61+
/// Unhygienic name (original, not renamed), needed in few places in name resolution
62+
pub unhygienic_name: Name,
63+
}
64+
65+
impl Ident {
66+
pub fn from_name(name: Name) -> Ident {
67+
Ident { name: name, unhygienic_name: name }
68+
}
69+
}
70+
71+
impl PartialEq for Ident {
72+
fn eq(&self, other: &Ident) -> bool {
73+
self.name == other.name
74+
}
75+
}
76+
77+
impl Hash for Ident {
78+
fn hash<H: Hasher>(&self, state: &mut H) {
79+
self.name.hash(state)
80+
}
81+
}
82+
83+
impl fmt::Debug for Ident {
84+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
85+
fmt::Debug::fmt(&self.name, f)
86+
}
87+
}
88+
89+
impl fmt::Display for Ident {
90+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
91+
fmt::Display::fmt(&self.name, f)
92+
}
93+
}
94+
95+
impl Encodable for Ident {
96+
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
97+
self.name.encode(s)
98+
}
99+
}
100+
101+
impl Decodable for Ident {
102+
fn decode<D: Decoder>(d: &mut D) -> Result<Ident, D::Error> {
103+
Ok(Ident::from_name(try!(Name::decode(d))))
104+
}
105+
}
54106

55107
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
56108
pub struct Lifetime {

src/librustc_front/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! property.
2727
2828
use syntax::abi::Abi;
29-
use syntax::ast::{Ident, NodeId, CRATE_NODE_ID, Name, Attribute};
29+
use syntax::ast::{NodeId, CRATE_NODE_ID, Name, Attribute};
3030
use syntax::codemap::Span;
3131
use hir::*;
3232

0 commit comments

Comments
 (0)