Skip to content

Commit a9ac272

Browse files
committed
auto merge of #9103 : jbclements/rust/let-var-hygiene, r=erickt
update AST so that ExprBreak and ExprCont expressions contain names, not idents. Fixes #9047 and makes progress on #6993. Simplifies the compiler very slightly, should make it (infinitesimally) faster.
2 parents 917d3c2 + 969181b commit a9ac272

File tree

14 files changed

+56
-27
lines changed

14 files changed

+56
-27
lines changed

src/librustc/middle/cfg/construct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl CFGBuilder {
488488

489489
fn find_scope(&self,
490490
expr: @ast::Expr,
491-
label: Option<ast::Ident>) -> LoopScope {
491+
label: Option<ast::Name>) -> LoopScope {
492492
match label {
493493
None => {
494494
return *self.loop_scopes.last();

src/librustc/middle/dataflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
867867

868868
fn find_scope<'a>(&self,
869869
expr: @ast::Expr,
870-
label: Option<ast::Ident>,
870+
label: Option<ast::Name>,
871871
loop_scopes: &'a mut ~[LoopScope]) -> &'a mut LoopScope {
872872
let index = match label {
873873
None => {

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ impl Liveness {
756756
}
757757

758758
pub fn find_loop_scope(&self,
759-
opt_label: Option<Ident>,
759+
opt_label: Option<Name>,
760760
id: NodeId,
761761
sp: Span)
762762
-> NodeId {

src/librustc/middle/resolve.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5157,15 +5157,13 @@ impl Resolver {
51575157
ExprForLoop(*) => fail!("non-desugared expr_for_loop"),
51585158

51595159
ExprBreak(Some(label)) | ExprAgain(Some(label)) => {
5160-
let name = label.name;
5161-
match self.search_ribs(self.label_ribs, name, expr.span,
5160+
match self.search_ribs(self.label_ribs, label, expr.span,
51625161
DontAllowCapturingSelf) {
51635162
None =>
51645163
self.resolve_error(expr.span,
51655164
fmt!("use of undeclared label \
51665165
`%s`",
5167-
self.session.str_of(
5168-
label))),
5166+
interner_get(label))),
51695167
Some(DlDef(def @ DefLabel(_))) => {
51705168
self.record_def(expr.id, def)
51715169
}

src/librustc/middle/trans/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ use std::vec;
7676
use std::local_data;
7777
use extra::time;
7878
use extra::sort;
79-
use syntax::ast::Ident;
79+
use syntax::ast::Name;
8080
use syntax::ast_map::{path, path_elt_to_str, path_name, path_pretty_name};
8181
use syntax::ast_util::{local_def};
8282
use syntax::attr;
@@ -1189,7 +1189,7 @@ pub fn scope_block(bcx: @mut Block,
11891189

11901190
pub fn loop_scope_block(bcx: @mut Block,
11911191
loop_break: @mut Block,
1192-
loop_label: Option<Ident>,
1192+
loop_label: Option<Name>,
11931193
n: &str,
11941194
opt_node_info: Option<NodeInfo>) -> @mut Block {
11951195
return new_block(bcx.fcx, Some(bcx), Some(@mut ScopeInfo {

src/librustc/middle/trans/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use std::cast;
3838
use std::hashmap::{HashMap};
3939
use std::libc::{c_uint, c_longlong, c_ulonglong, c_char};
4040
use std::vec;
41-
use syntax::ast::Ident;
41+
use syntax::ast::{Name,Ident};
4242
use syntax::ast_map::{path, path_elt, path_pretty_name};
4343
use syntax::codemap::Span;
4444
use syntax::parse::token;
@@ -463,7 +463,7 @@ pub fn block_cleanups(bcx: @mut Block) -> ~[cleanup] {
463463
pub struct ScopeInfo {
464464
parent: Option<@mut ScopeInfo>,
465465
loop_break: Option<@mut Block>,
466-
loop_label: Option<Ident>,
466+
loop_label: Option<Name>,
467467
// A list of functions that must be run at when leaving this
468468
// block, cleaning up any variables that were introduced in the
469469
// block.

src/librustc/middle/trans/controlflow.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use util::ppaux;
2222
use middle::trans::type_::Type;
2323

2424
use syntax::ast;
25-
use syntax::ast::Ident;
25+
use syntax::ast::Name;
2626
use syntax::ast_util;
2727
use syntax::codemap::Span;
2828

@@ -188,7 +188,7 @@ pub fn trans_while(bcx: @mut Block, cond: @ast::Expr, body: &ast::Block) -> @mut
188188

189189
pub fn trans_loop(bcx:@mut Block,
190190
body: &ast::Block,
191-
opt_label: Option<Ident>)
191+
opt_label: Option<Name>)
192192
-> @mut Block {
193193
let _icx = push_ctxt("trans_loop");
194194
let next_bcx = sub_block(bcx, "next");
@@ -201,7 +201,7 @@ pub fn trans_loop(bcx:@mut Block,
201201
}
202202

203203
pub fn trans_break_cont(bcx: @mut Block,
204-
opt_label: Option<Ident>,
204+
opt_label: Option<Name>,
205205
to_end: bool)
206206
-> @mut Block {
207207
let _icx = push_ctxt("trans_break_cont");
@@ -254,11 +254,11 @@ pub fn trans_break_cont(bcx: @mut Block,
254254
return bcx;
255255
}
256256

257-
pub fn trans_break(bcx: @mut Block, label_opt: Option<Ident>) -> @mut Block {
257+
pub fn trans_break(bcx: @mut Block, label_opt: Option<Name>) -> @mut Block {
258258
return trans_break_cont(bcx, label_opt, true);
259259
}
260260

261-
pub fn trans_cont(bcx: @mut Block, label_opt: Option<Ident>) -> @mut Block {
261+
pub fn trans_cont(bcx: @mut Block, label_opt: Option<Name>) -> @mut Block {
262262
return trans_break_cont(bcx, label_opt, false);
263263
}
264264

src/librustc/middle/trans/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,8 @@ fn trans_rvalue_stmt_unadjusted(bcx: @mut Block, expr: @ast::Expr) -> @mut Block
617617
return controlflow::trans_while(bcx, cond, body);
618618
}
619619
ast::ExprLoop(ref body, opt_label) => {
620-
return controlflow::trans_loop(bcx, body, opt_label);
620+
// FIXME #6993: map can go away when ast.rs is changed
621+
return controlflow::trans_loop(bcx, body, opt_label.map(|x| x.name));
621622
}
622623
ast::ExprAssign(dst, src) => {
623624
let src_datum = unpack_datum!(

src/libsyntax/ast.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,12 @@ pub enum Expr_ {
522522
ExprCast(@Expr, Ty),
523523
ExprIf(@Expr, Block, Option<@Expr>),
524524
ExprWhile(@Expr, Block),
525+
// FIXME #6993: change to Option<Name>
525526
ExprForLoop(@Pat, @Expr, Block, Option<Ident>),
526527
/* Conditionless loop (can be exited with break, cont, or ret)
527528
Same semantics as while(true) { body }, but typestate knows that the
528529
(implicit) condition is always true. */
530+
// FIXME #6993: change to Option<Name>
529531
ExprLoop(Block, Option<Ident>),
530532
ExprMatch(@Expr, ~[Arm]),
531533
ExprFnBlock(fn_decl, Block),
@@ -541,8 +543,8 @@ pub enum Expr_ {
541543
/// The special identifier `self`.
542544
ExprSelf,
543545
ExprAddrOf(Mutability, @Expr),
544-
ExprBreak(Option<Ident>),
545-
ExprAgain(Option<Ident>),
546+
ExprBreak(Option<Name>),
547+
ExprAgain(Option<Name>),
546548
ExprRet(Option<@Expr>),
547549

548550
/// Gets the log level for the enclosing module

src/libsyntax/ext/expand.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
113113

114114
// Desugar expr_for_loop
115115
// From: `['<ident>:] for <src_pat> in <src_expr> <src_loop_block>`
116+
// FIXME #6993 : change type of opt_ident to Option<Name>
116117
ast::ExprForLoop(src_pat, src_expr, ref src_loop_block, opt_ident) => {
117118
// Expand any interior macros etc.
118119
// NB: we don't fold pats yet. Curious.
@@ -144,7 +145,8 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
144145

145146
// `None => break ['<ident>];`
146147
let none_arm = {
147-
let break_expr = cx.expr(span, ast::ExprBreak(opt_ident));
148+
// FIXME #6993: this map goes away:
149+
let break_expr = cx.expr(span, ast::ExprBreak(opt_ident.map(|x| x.name)));
148150
let none_pat = cx.pat_ident(span, none_ident);
149151
cx.arm(span, ~[none_pat], break_expr)
150152
};

0 commit comments

Comments
 (0)