Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renumber AST nodes after expansion #9040

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ pub fn phase_2_configure_and_expand(sess: Session,
crate = time(time_passes, ~"std injection", ||
front::std_inject::maybe_inject_libstd_ref(sess, crate));

crate = time(time_passes, ~"renumbering AST", ||
front::renumber::renumber_crate(sess, crate));

return crate;
}

Expand All @@ -207,6 +210,7 @@ pub fn phase_3_run_analysis_passes(sess: Session,
crate: @ast::Crate) -> CrateAnalysis {

let time_passes = sess.time_passes();

let ast_map = time(time_passes, ~"ast indexing", ||
syntax::ast_map::map_crate(sess.diagnostic(), crate));

Expand Down
33 changes: 33 additions & 0 deletions src/librustc/front/renumber.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use driver::session::Session;

use syntax::ast;
use syntax::fold;

static STD_VERSION: &'static str = "0.8-pre";

pub fn renumber_crate(_sess: Session, crate: @ast::Crate) -> @ast::Crate {
let counter = @mut 0;

let precursor = @fold::AstFoldFns {
new_id: |_old_id| {
let new_id = *counter;
*counter += 1;
new_id
},
..*fold::default_ast_fold()
};

let fold = fold::make_fold(precursor);

@fold.fold_crate(crate)
}
10 changes: 9 additions & 1 deletion src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5401,7 +5401,15 @@ impl Resolver {

pub fn record_def(@mut self, node_id: NodeId, def: Def) {
debug!("(recording def) recording %? for %?", def, node_id);
self.def_map.insert(node_id, def);
do self.def_map.insert_or_update_with(node_id, def) |_, old_value| {
// Resolve appears to "resolve" the same ID multiple
// times, so here is a sanity check it at least comes to
// the same conclusion! - nmatsakis
if def != *old_value {
self.session.bug(fmt!("node_id %? resolved first to %? \
and then %?", node_id, *old_value, def));
}
};
}

pub fn enforce_default_binding_mode(@mut self,
Expand Down
1 change: 1 addition & 0 deletions src/librustc/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub mod front {
pub mod config;
pub mod test;
pub mod std_inject;
pub mod renumber;
}

pub mod back {
Expand Down
Loading