change type of ExprLoop and ExprBreak elts from ident->name.
Lots of downstream changes in librustc, should be infinitesimally faster.
This commit is contained in:
parent
917d3c28b6
commit
422cf1adc5
13 changed files with 37 additions and 27 deletions
|
@ -488,7 +488,7 @@ impl CFGBuilder {
|
||||||
|
|
||||||
fn find_scope(&self,
|
fn find_scope(&self,
|
||||||
expr: @ast::Expr,
|
expr: @ast::Expr,
|
||||||
label: Option<ast::Ident>) -> LoopScope {
|
label: Option<ast::Name>) -> LoopScope {
|
||||||
match label {
|
match label {
|
||||||
None => {
|
None => {
|
||||||
return *self.loop_scopes.last();
|
return *self.loop_scopes.last();
|
||||||
|
|
|
@ -867,7 +867,7 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
|
||||||
|
|
||||||
fn find_scope<'a>(&self,
|
fn find_scope<'a>(&self,
|
||||||
expr: @ast::Expr,
|
expr: @ast::Expr,
|
||||||
label: Option<ast::Ident>,
|
label: Option<ast::Name>,
|
||||||
loop_scopes: &'a mut ~[LoopScope]) -> &'a mut LoopScope {
|
loop_scopes: &'a mut ~[LoopScope]) -> &'a mut LoopScope {
|
||||||
let index = match label {
|
let index = match label {
|
||||||
None => {
|
None => {
|
||||||
|
|
|
@ -756,7 +756,7 @@ impl Liveness {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_loop_scope(&self,
|
pub fn find_loop_scope(&self,
|
||||||
opt_label: Option<Ident>,
|
opt_label: Option<Name>,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
sp: Span)
|
sp: Span)
|
||||||
-> NodeId {
|
-> NodeId {
|
||||||
|
|
|
@ -5157,15 +5157,13 @@ impl Resolver {
|
||||||
ExprForLoop(*) => fail!("non-desugared expr_for_loop"),
|
ExprForLoop(*) => fail!("non-desugared expr_for_loop"),
|
||||||
|
|
||||||
ExprBreak(Some(label)) | ExprAgain(Some(label)) => {
|
ExprBreak(Some(label)) | ExprAgain(Some(label)) => {
|
||||||
let name = label.name;
|
match self.search_ribs(self.label_ribs, label, expr.span,
|
||||||
match self.search_ribs(self.label_ribs, name, expr.span,
|
|
||||||
DontAllowCapturingSelf) {
|
DontAllowCapturingSelf) {
|
||||||
None =>
|
None =>
|
||||||
self.resolve_error(expr.span,
|
self.resolve_error(expr.span,
|
||||||
fmt!("use of undeclared label \
|
fmt!("use of undeclared label \
|
||||||
`%s`",
|
`%s`",
|
||||||
self.session.str_of(
|
interner_get(label))),
|
||||||
label))),
|
|
||||||
Some(DlDef(def @ DefLabel(_))) => {
|
Some(DlDef(def @ DefLabel(_))) => {
|
||||||
self.record_def(expr.id, def)
|
self.record_def(expr.id, def)
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ use std::vec;
|
||||||
use std::local_data;
|
use std::local_data;
|
||||||
use extra::time;
|
use extra::time;
|
||||||
use extra::sort;
|
use extra::sort;
|
||||||
use syntax::ast::Ident;
|
use syntax::ast::Name;
|
||||||
use syntax::ast_map::{path, path_elt_to_str, path_name, path_pretty_name};
|
use syntax::ast_map::{path, path_elt_to_str, path_name, path_pretty_name};
|
||||||
use syntax::ast_util::{local_def};
|
use syntax::ast_util::{local_def};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
|
@ -1189,7 +1189,7 @@ pub fn scope_block(bcx: @mut Block,
|
||||||
|
|
||||||
pub fn loop_scope_block(bcx: @mut Block,
|
pub fn loop_scope_block(bcx: @mut Block,
|
||||||
loop_break: @mut Block,
|
loop_break: @mut Block,
|
||||||
loop_label: Option<Ident>,
|
loop_label: Option<Name>,
|
||||||
n: &str,
|
n: &str,
|
||||||
opt_node_info: Option<NodeInfo>) -> @mut Block {
|
opt_node_info: Option<NodeInfo>) -> @mut Block {
|
||||||
return new_block(bcx.fcx, Some(bcx), Some(@mut ScopeInfo {
|
return new_block(bcx.fcx, Some(bcx), Some(@mut ScopeInfo {
|
||||||
|
|
|
@ -38,7 +38,7 @@ use std::cast;
|
||||||
use std::hashmap::{HashMap};
|
use std::hashmap::{HashMap};
|
||||||
use std::libc::{c_uint, c_longlong, c_ulonglong, c_char};
|
use std::libc::{c_uint, c_longlong, c_ulonglong, c_char};
|
||||||
use std::vec;
|
use std::vec;
|
||||||
use syntax::ast::Ident;
|
use syntax::ast::{Name,Ident};
|
||||||
use syntax::ast_map::{path, path_elt, path_pretty_name};
|
use syntax::ast_map::{path, path_elt, path_pretty_name};
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
|
@ -463,7 +463,7 @@ pub fn block_cleanups(bcx: @mut Block) -> ~[cleanup] {
|
||||||
pub struct ScopeInfo {
|
pub struct ScopeInfo {
|
||||||
parent: Option<@mut ScopeInfo>,
|
parent: Option<@mut ScopeInfo>,
|
||||||
loop_break: Option<@mut Block>,
|
loop_break: Option<@mut Block>,
|
||||||
loop_label: Option<Ident>,
|
loop_label: Option<Name>,
|
||||||
// A list of functions that must be run at when leaving this
|
// A list of functions that must be run at when leaving this
|
||||||
// block, cleaning up any variables that were introduced in the
|
// block, cleaning up any variables that were introduced in the
|
||||||
// block.
|
// block.
|
||||||
|
|
|
@ -22,7 +22,7 @@ use util::ppaux;
|
||||||
use middle::trans::type_::Type;
|
use middle::trans::type_::Type;
|
||||||
|
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ast::Ident;
|
use syntax::ast::Name;
|
||||||
use syntax::ast_util;
|
use syntax::ast_util;
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ pub fn trans_while(bcx: @mut Block, cond: @ast::Expr, body: &ast::Block) -> @mut
|
||||||
|
|
||||||
pub fn trans_loop(bcx:@mut Block,
|
pub fn trans_loop(bcx:@mut Block,
|
||||||
body: &ast::Block,
|
body: &ast::Block,
|
||||||
opt_label: Option<Ident>)
|
opt_label: Option<Name>)
|
||||||
-> @mut Block {
|
-> @mut Block {
|
||||||
let _icx = push_ctxt("trans_loop");
|
let _icx = push_ctxt("trans_loop");
|
||||||
let next_bcx = sub_block(bcx, "next");
|
let next_bcx = sub_block(bcx, "next");
|
||||||
|
@ -201,7 +201,7 @@ pub fn trans_loop(bcx:@mut Block,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trans_break_cont(bcx: @mut Block,
|
pub fn trans_break_cont(bcx: @mut Block,
|
||||||
opt_label: Option<Ident>,
|
opt_label: Option<Name>,
|
||||||
to_end: bool)
|
to_end: bool)
|
||||||
-> @mut Block {
|
-> @mut Block {
|
||||||
let _icx = push_ctxt("trans_break_cont");
|
let _icx = push_ctxt("trans_break_cont");
|
||||||
|
@ -254,11 +254,11 @@ pub fn trans_break_cont(bcx: @mut Block,
|
||||||
return bcx;
|
return bcx;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trans_break(bcx: @mut Block, label_opt: Option<Ident>) -> @mut Block {
|
pub fn trans_break(bcx: @mut Block, label_opt: Option<Name>) -> @mut Block {
|
||||||
return trans_break_cont(bcx, label_opt, true);
|
return trans_break_cont(bcx, label_opt, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trans_cont(bcx: @mut Block, label_opt: Option<Ident>) -> @mut Block {
|
pub fn trans_cont(bcx: @mut Block, label_opt: Option<Name>) -> @mut Block {
|
||||||
return trans_break_cont(bcx, label_opt, false);
|
return trans_break_cont(bcx, label_opt, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -617,7 +617,8 @@ fn trans_rvalue_stmt_unadjusted(bcx: @mut Block, expr: @ast::Expr) -> @mut Block
|
||||||
return controlflow::trans_while(bcx, cond, body);
|
return controlflow::trans_while(bcx, cond, body);
|
||||||
}
|
}
|
||||||
ast::ExprLoop(ref body, opt_label) => {
|
ast::ExprLoop(ref body, opt_label) => {
|
||||||
return controlflow::trans_loop(bcx, body, opt_label);
|
// FIXME #6993: map can go away when ast.rs is changed
|
||||||
|
return controlflow::trans_loop(bcx, body, opt_label.map(|x| x.name));
|
||||||
}
|
}
|
||||||
ast::ExprAssign(dst, src) => {
|
ast::ExprAssign(dst, src) => {
|
||||||
let src_datum = unpack_datum!(
|
let src_datum = unpack_datum!(
|
||||||
|
|
|
@ -522,10 +522,12 @@ pub enum Expr_ {
|
||||||
ExprCast(@Expr, Ty),
|
ExprCast(@Expr, Ty),
|
||||||
ExprIf(@Expr, Block, Option<@Expr>),
|
ExprIf(@Expr, Block, Option<@Expr>),
|
||||||
ExprWhile(@Expr, Block),
|
ExprWhile(@Expr, Block),
|
||||||
|
// FIXME #6993: change to Option<Name>
|
||||||
ExprForLoop(@Pat, @Expr, Block, Option<Ident>),
|
ExprForLoop(@Pat, @Expr, Block, Option<Ident>),
|
||||||
/* Conditionless loop (can be exited with break, cont, or ret)
|
/* Conditionless loop (can be exited with break, cont, or ret)
|
||||||
Same semantics as while(true) { body }, but typestate knows that the
|
Same semantics as while(true) { body }, but typestate knows that the
|
||||||
(implicit) condition is always true. */
|
(implicit) condition is always true. */
|
||||||
|
// FIXME #6993: change to Option<Name>
|
||||||
ExprLoop(Block, Option<Ident>),
|
ExprLoop(Block, Option<Ident>),
|
||||||
ExprMatch(@Expr, ~[Arm]),
|
ExprMatch(@Expr, ~[Arm]),
|
||||||
ExprFnBlock(fn_decl, Block),
|
ExprFnBlock(fn_decl, Block),
|
||||||
|
@ -541,8 +543,8 @@ pub enum Expr_ {
|
||||||
/// The special identifier `self`.
|
/// The special identifier `self`.
|
||||||
ExprSelf,
|
ExprSelf,
|
||||||
ExprAddrOf(Mutability, @Expr),
|
ExprAddrOf(Mutability, @Expr),
|
||||||
ExprBreak(Option<Ident>),
|
ExprBreak(Option<Name>),
|
||||||
ExprAgain(Option<Ident>),
|
ExprAgain(Option<Name>),
|
||||||
ExprRet(Option<@Expr>),
|
ExprRet(Option<@Expr>),
|
||||||
|
|
||||||
/// Gets the log level for the enclosing module
|
/// Gets the log level for the enclosing module
|
||||||
|
|
|
@ -113,6 +113,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
|
||||||
|
|
||||||
// Desugar expr_for_loop
|
// Desugar expr_for_loop
|
||||||
// From: `['<ident>:] for <src_pat> in <src_expr> <src_loop_block>`
|
// From: `['<ident>:] for <src_pat> in <src_expr> <src_loop_block>`
|
||||||
|
// FIXME #6993 : change type of opt_ident to Option<Name>
|
||||||
ast::ExprForLoop(src_pat, src_expr, ref src_loop_block, opt_ident) => {
|
ast::ExprForLoop(src_pat, src_expr, ref src_loop_block, opt_ident) => {
|
||||||
// Expand any interior macros etc.
|
// Expand any interior macros etc.
|
||||||
// NB: we don't fold pats yet. Curious.
|
// NB: we don't fold pats yet. Curious.
|
||||||
|
@ -144,7 +145,8 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
|
||||||
|
|
||||||
// `None => break ['<ident>];`
|
// `None => break ['<ident>];`
|
||||||
let none_arm = {
|
let none_arm = {
|
||||||
let break_expr = cx.expr(span, ast::ExprBreak(opt_ident));
|
// FIXME #6993: this map goes away:
|
||||||
|
let break_expr = cx.expr(span, ast::ExprBreak(opt_ident.map(|x| x.name)));
|
||||||
let none_pat = cx.pat_ident(span, none_ident);
|
let none_pat = cx.pat_ident(span, none_ident);
|
||||||
cx.arm(span, ~[none_pat], break_expr)
|
cx.arm(span, ~[none_pat], break_expr)
|
||||||
};
|
};
|
||||||
|
|
|
@ -688,10 +688,13 @@ pub fn noop_fold_expr(e: &Expr_, fld: @ast_fold) -> Expr_ {
|
||||||
ExprPath(ref pth) => ExprPath(fld.fold_path(pth)),
|
ExprPath(ref pth) => ExprPath(fld.fold_path(pth)),
|
||||||
ExprSelf => ExprSelf,
|
ExprSelf => ExprSelf,
|
||||||
ExprBreak(ref opt_ident) => {
|
ExprBreak(ref opt_ident) => {
|
||||||
ExprBreak(opt_ident.map_move(|x| fld.fold_ident(x)))
|
// FIXME #6993: add fold_name to fold.... then cut out the
|
||||||
|
// bogus Name->Ident->Name conversion.
|
||||||
|
ExprBreak(opt_ident.map_move(|x| fld.fold_ident(Ident::new(x)).name))
|
||||||
}
|
}
|
||||||
ExprAgain(ref opt_ident) => {
|
ExprAgain(ref opt_ident) => {
|
||||||
ExprAgain(opt_ident.map_move(|x| fld.fold_ident(x)))
|
// FIXME #6993: add fold_name to fold....
|
||||||
|
ExprAgain(opt_ident.map_move(|x| fld.fold_ident(Ident::new(x)).name))
|
||||||
}
|
}
|
||||||
ExprRet(ref e) => {
|
ExprRet(ref e) => {
|
||||||
ExprRet(e.map_move(|x| fld.fold_expr(x)))
|
ExprRet(e.map_move(|x| fld.fold_expr(x)))
|
||||||
|
|
|
@ -1849,7 +1849,7 @@ impl Parser {
|
||||||
if self.token_is_lifetime(&*self.token) {
|
if self.token_is_lifetime(&*self.token) {
|
||||||
let lifetime = self.get_lifetime(&*self.token);
|
let lifetime = self.get_lifetime(&*self.token);
|
||||||
self.bump();
|
self.bump();
|
||||||
ex = ExprBreak(Some(lifetime));
|
ex = ExprBreak(Some(lifetime.name));
|
||||||
} else {
|
} else {
|
||||||
ex = ExprBreak(None);
|
ex = ExprBreak(None);
|
||||||
}
|
}
|
||||||
|
@ -2585,7 +2585,7 @@ impl Parser {
|
||||||
let ex = if self.token_is_lifetime(&*self.token) {
|
let ex = if self.token_is_lifetime(&*self.token) {
|
||||||
let lifetime = self.get_lifetime(&*self.token);
|
let lifetime = self.get_lifetime(&*self.token);
|
||||||
self.bump();
|
self.bump();
|
||||||
ExprAgain(Some(lifetime))
|
ExprAgain(Some(lifetime.name))
|
||||||
} else {
|
} else {
|
||||||
ExprAgain(None)
|
ExprAgain(None)
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,7 +19,7 @@ use codemap::{CodeMap, BytePos};
|
||||||
use codemap;
|
use codemap;
|
||||||
use diagnostic;
|
use diagnostic;
|
||||||
use parse::classify::expr_is_simple_block;
|
use parse::classify::expr_is_simple_block;
|
||||||
use parse::token::{ident_interner, ident_to_str};
|
use parse::token::{ident_interner, ident_to_str, interner_get};
|
||||||
use parse::{comments, token};
|
use parse::{comments, token};
|
||||||
use parse;
|
use parse;
|
||||||
use print::pp::{break_offset, word, space, zerobreak, hardbreak};
|
use print::pp::{break_offset, word, space, zerobreak, hardbreak};
|
||||||
|
@ -1394,7 +1394,7 @@ pub fn print_expr(s: @ps, expr: &ast::Expr) {
|
||||||
space(s.s);
|
space(s.s);
|
||||||
for ident in opt_ident.iter() {
|
for ident in opt_ident.iter() {
|
||||||
word(s.s, "'");
|
word(s.s, "'");
|
||||||
print_ident(s, *ident);
|
print_name(s, *ident);
|
||||||
space(s.s);
|
space(s.s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1403,7 +1403,7 @@ pub fn print_expr(s: @ps, expr: &ast::Expr) {
|
||||||
space(s.s);
|
space(s.s);
|
||||||
for ident in opt_ident.iter() {
|
for ident in opt_ident.iter() {
|
||||||
word(s.s, "'");
|
word(s.s, "'");
|
||||||
print_ident(s, *ident);
|
print_name(s, *ident);
|
||||||
space(s.s)
|
space(s.s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1503,6 +1503,10 @@ pub fn print_ident(s: @ps, ident: ast::Ident) {
|
||||||
word(s.s, ident_to_str(&ident));
|
word(s.s, ident_to_str(&ident));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn print_name(s: @ps, name: ast::Name) {
|
||||||
|
word(s.s, interner_get(name));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn print_for_decl(s: @ps, loc: &ast::Local, coll: &ast::Expr) {
|
pub fn print_for_decl(s: @ps, loc: &ast::Local, coll: &ast::Expr) {
|
||||||
print_local_decl(s, loc);
|
print_local_decl(s, loc);
|
||||||
space(s.s);
|
space(s.s);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue