Skip to content

Commit 6a045b9

Browse files
committed
Move tracking of the next NodeId from syntax's ParseSess to rustc's Session.
1 parent 222cd73 commit 6a045b9

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

src/librustc/session/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ pub struct Session {
6464
/// operations such as auto-dereference and monomorphization.
6565
pub recursion_limit: Cell<usize>,
6666

67-
pub can_print_warnings: bool
67+
pub can_print_warnings: bool,
68+
69+
next_node_id: Cell<ast::NodeId>
6870
}
6971

7072
impl Session {
@@ -213,10 +215,17 @@ impl Session {
213215
lints.insert(id, vec!((lint_id, sp, msg)));
214216
}
215217
pub fn next_node_id(&self) -> ast::NodeId {
216-
self.parse_sess.next_node_id()
218+
self.reserve_node_ids(1)
217219
}
218220
pub fn reserve_node_ids(&self, count: ast::NodeId) -> ast::NodeId {
219-
self.parse_sess.reserve_node_ids(count)
221+
let id = self.next_node_id.get();
222+
223+
match id.checked_add(count) {
224+
Some(next) => self.next_node_id.set(next),
225+
None => self.bug("Input too large, ran out of node ids!")
226+
}
227+
228+
id
220229
}
221230
pub fn diagnostic<'a>(&'a self) -> &'a diagnostic::SpanHandler {
222231
&self.parse_sess.span_diagnostic
@@ -421,7 +430,8 @@ pub fn build_session_(sopts: config::Options,
421430
delayed_span_bug: RefCell::new(None),
422431
features: RefCell::new(feature_gate::Features::new()),
423432
recursion_limit: Cell::new(64),
424-
can_print_warnings: can_print_warnings
433+
can_print_warnings: can_print_warnings,
434+
next_node_id: Cell::new(1)
425435
};
426436

427437
sess

src/libsyntax/parse/mod.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use parse::parser::Parser;
1818
use ptr::P;
1919
use str::char_at;
2020

21-
use std::cell::{Cell, RefCell};
21+
use std::cell::RefCell;
2222
use std::fs::File;
2323
use std::io::Read;
2424
use std::iter;
@@ -44,38 +44,19 @@ pub struct ParseSess {
4444
pub span_diagnostic: SpanHandler, // better be the same as the one in the reader!
4545
/// Used to determine and report recursive mod inclusions
4646
included_mod_stack: RefCell<Vec<PathBuf>>,
47-
pub node_id: Cell<ast::NodeId>,
4847
}
4948

5049
pub fn new_parse_sess() -> ParseSess {
5150
ParseSess {
5251
span_diagnostic: mk_span_handler(default_handler(Auto, None, true), CodeMap::new()),
5352
included_mod_stack: RefCell::new(Vec::new()),
54-
node_id: Cell::new(1),
5553
}
5654
}
5755

5856
pub fn new_parse_sess_special_handler(sh: SpanHandler) -> ParseSess {
5957
ParseSess {
6058
span_diagnostic: sh,
6159
included_mod_stack: RefCell::new(Vec::new()),
62-
node_id: Cell::new(1),
63-
}
64-
}
65-
66-
impl ParseSess {
67-
pub fn next_node_id(&self) -> ast::NodeId {
68-
self.reserve_node_ids(1)
69-
}
70-
pub fn reserve_node_ids(&self, count: ast::NodeId) -> ast::NodeId {
71-
let v = self.node_id.get();
72-
73-
match v.checked_add(count) {
74-
Some(next) => { self.node_id.set(next); }
75-
None => panic!("Input too large, ran out of node ids!")
76-
}
77-
78-
v
7960
}
8061
}
8162

0 commit comments

Comments
 (0)