Skip to content

Commit 63c62be

Browse files
committed
auto merge of #8420 : blake2-ppc/rust/shrink-token, r=cmr
`enum Token` was 192 bytes (64-bit), as pointed out by pnkfelix; the only bloating variant being `INTERPOLATED(nonterminal)`. Updating `enum nonterminal` to use ~ where variants included big types, shrunk size_of(Token) to 32 bytes (64-bit). I am unsure if the `nt_ident` variant should have an indirection, with ast::ident being only 16 bytes (64-bit), but without this, enum Token would be 40 bytes. A dumb benchmark says that compilation time is unchanged, while peak memory usage for compiling std.rs is down 3% Before:: $ time ./x86_64-unknown-linux-gnu/stage1/bin/rustc --cfg stage1 src/libstd/std.rs 19.00user 0.39system 0:19.41elapsed 99%CPU (0avgtext+0avgdata 627820maxresident)k 0inputs+28896outputs (0major+228665minor)pagefaults 0swaps $ time ./x86_64-unknown-linux-gnu/stage1/bin/rustc -O --cfg stage1 src/libstd/std.rs 31.64user 0.34system 0:32.02elapsed 99%CPU (0avgtext+0avgdata 629876maxresident)k 0inputs+22432outputs (0major+229411minor)pagefaults 0swaps After:: $ time ./x86_64-unknown-linux-gnu/stage1/bin/rustc --cfg stage1 src/libstd/std.rs 19.07user 0.45system 0:19.55elapsed 99%CPU (0avgtext+0avgdata 609384maxresident)k 0inputs+28896outputs (0major+221997minor)pagefaults 0swaps $ time ./x86_64-unknown-linux-gnu/stage1/bin/rustc -O --cfg stage1 src/libstd/std.rs 31.90user 0.34system 0:32.28elapsed 99%CPU (0avgtext+0avgdata 612080maxresident)k 0inputs+22432outputs (0major+223726minor)pagefaults 0swaps
2 parents f08851e + 5cfad6f commit 63c62be

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,18 +419,18 @@ pub fn parse_nt(p: &Parser, name: &str) -> nonterminal {
419419
Some(i) => token::nt_item(i),
420420
None => p.fatal("expected an item keyword")
421421
},
422-
"block" => token::nt_block(p.parse_block()),
422+
"block" => token::nt_block(~p.parse_block()),
423423
"stmt" => token::nt_stmt(p.parse_stmt(~[])),
424424
"pat" => token::nt_pat(p.parse_pat()),
425425
"expr" => token::nt_expr(p.parse_expr()),
426-
"ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)),
426+
"ty" => token::nt_ty(~p.parse_ty(false /* no need to disambiguate*/)),
427427
// this could be handled like a token, since it is one
428428
"ident" => match *p.token {
429-
token::IDENT(sn,b) => { p.bump(); token::nt_ident(sn,b) }
429+
token::IDENT(sn,b) => { p.bump(); token::nt_ident(~sn,b) }
430430
_ => p.fatal(~"expected ident, found "
431431
+ token::to_str(get_ident_interner(), p.token))
432432
},
433-
"path" => token::nt_path(p.parse_path_with_tps(false)),
433+
"path" => token::nt_path(~p.parse_path_with_tps(false)),
434434
"attr" => token::nt_attr(@p.parse_attribute(false)),
435435
"tt" => {
436436
*p.quote_depth += 1u; //but in theory, non-quoted tts might be useful

src/libsyntax/ext/tt/transcribe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
279279
/* sidestep the interpolation tricks for ident because
280280
(a) idents can be in lots of places, so it'd be a pain
281281
(b) we actually can, since it's a token. */
282-
matched_nonterminal(nt_ident(sn,b)) => {
282+
matched_nonterminal(nt_ident(~sn,b)) => {
283283
r.cur_span = sp; r.cur_tok = IDENT(sn,b);
284284
r.stack.idx += 1u;
285285
return ret_val;

src/libsyntax/parse/parser.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ macro_rules! maybe_whole_expr (
146146
Some($p.mk_expr(
147147
($p).span.lo,
148148
($p).span.hi,
149-
expr_path(/* bad */ (*pt).clone())))
149+
expr_path(/* bad */ (**pt).clone())))
150150
}
151151
_ => None
152152
};
@@ -235,8 +235,8 @@ macro_rules! maybe_whole (
235235
_ => None
236236
};
237237
match __found__ {
238-
Some(INTERPOLATED(token::$constructor(x))) => {
239-
return (~[], x.clone())
238+
Some(INTERPOLATED(token::$constructor(ref x))) => {
239+
return (~[], (**x).clone())
240240
}
241241
_ => {}
242242
}
@@ -939,7 +939,7 @@ impl Parser {
939939
// Useless second parameter for compatibility with quasiquote macros.
940940
// Bleh!
941941
pub fn parse_ty(&self, _: bool) -> Ty {
942-
maybe_whole!(self, nt_ty);
942+
maybe_whole!(deref self, nt_ty);
943943

944944
let lo = self.span.lo;
945945

@@ -1293,7 +1293,7 @@ impl Parser {
12931293

12941294
// parse a path that doesn't have type parameters attached
12951295
pub fn parse_path_without_tps(&self) -> ast::Path {
1296-
maybe_whole!(self, nt_path);
1296+
maybe_whole!(deref self, nt_path);
12971297
let (ids,is_global,sp) = self.parse_path();
12981298
ast::Path { span: sp,
12991299
global: is_global,
@@ -1306,7 +1306,7 @@ impl Parser {
13061306
before_tps: Option<&fn()>) -> ast::Path {
13071307
debug!("parse_path_with_tps(colons=%b)", colons);
13081308

1309-
maybe_whole!(self, nt_path);
1309+
maybe_whole!(deref self, nt_path);
13101310
let lo = self.span.lo;
13111311
let path = self.parse_path_without_tps();
13121312
if colons && !self.eat(&token::MOD_SEP) {
@@ -3100,7 +3100,7 @@ impl Parser {
31003100

31013101
// parse a block. No inner attrs are allowed.
31023102
pub fn parse_block(&self) -> Block {
3103-
maybe_whole!(self, nt_block);
3103+
maybe_whole!(deref self, nt_block);
31043104

31053105
let lo = self.span.lo;
31063106
if self.eat_keyword(keywords::Unsafe) {

src/libsyntax/parse/token.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ pub enum Token {
9999
/// For interpolation during macro expansion.
100100
pub enum nonterminal {
101101
nt_item(@ast::item),
102-
nt_block(ast::Block),
102+
nt_block(~ast::Block),
103103
nt_stmt(@ast::stmt),
104104
nt_pat( @ast::pat),
105105
nt_expr(@ast::expr),
106-
nt_ty( ast::Ty),
107-
nt_ident(ast::ident, bool),
106+
nt_ty( ~ast::Ty),
107+
nt_ident(~ast::ident, bool),
108108
nt_attr(@ast::Attribute), // #[foo]
109-
nt_path( ast::Path),
109+
nt_path(~ast::Path),
110110
nt_tt( @ast::token_tree), //needs @ed to break a circularity
111111
nt_matchers(~[ast::matcher])
112112
}

0 commit comments

Comments
 (0)