Skip to content

Commit 2d6f7ec

Browse files
committed
---
yaml --- r: 124847 b: refs/heads/auto c: 94d92e6 h: refs/heads/master i: 124845: 58ac8a2 124843: dbbbe55 124839: fcc77a0 124831: 0185f56 v: v3
1 parent 98a824d commit 2d6f7ec

File tree

5 files changed

+298
-237
lines changed

5 files changed

+298
-237
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: aa0e35bc64b2b1f4b21bc653e74ba986e98610e2
16+
refs/heads/auto: 94d92e6830768cc026348766f7f74fc3fd510888
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libcore/iter.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,19 +1962,7 @@ pub struct Range<A> {
19621962
one: A
19631963
}
19641964

1965-
/// Returns an iterator over the given range [start, stop) (that is, starting
1966-
/// at start (inclusive), and ending at stop (exclusive)).
1967-
///
1968-
/// # Example
1969-
///
1970-
/// ```rust
1971-
/// let array = [0, 1, 2, 3, 4];
1972-
///
1973-
/// for i in range(0, 5u) {
1974-
/// println!("{}", i);
1975-
/// assert_eq!(i, array[i]);
1976-
/// }
1977-
/// ```
1965+
/// Return an iterator over the range [start, stop)
19781966
#[inline]
19791967
pub fn range<A: Add<A, A> + PartialOrd + Clone + One>(start: A, stop: A) -> Range<A> {
19801968
Range{state: start, stop: stop, one: One::one()}

branches/auto/src/librustc/middle/trans/_match.rs

Lines changed: 83 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ use middle::resolve::DefMap;
202202
use middle::trans::adt;
203203
use middle::trans::base::*;
204204
use middle::trans::build::*;
205-
use middle::trans::build;
206205
use middle::trans::callee;
207206
use middle::trans::cleanup;
208207
use middle::trans::cleanup::CleanupMethods;
209208
use middle::trans::common::*;
210209
use middle::trans::consts;
210+
use middle::trans::controlflow;
211211
use middle::trans::datum::*;
212212
use middle::trans::expr::Dest;
213213
use middle::trans::expr;
@@ -220,12 +220,14 @@ use util::ppaux::{Repr, vec_map_to_string};
220220

221221
use std;
222222
use std::collections::HashMap;
223+
use std::cell::Cell;
223224
use std::rc::Rc;
224225
use std::gc::{Gc};
225226
use syntax::ast;
226227
use syntax::ast::Ident;
227228
use syntax::codemap::Span;
228229
use syntax::fold::Folder;
230+
use syntax::parse::token::InternedString;
229231

230232
#[deriving(PartialEq)]
231233
pub enum VecLenOpt {
@@ -299,6 +301,20 @@ fn trans_opt<'a>(mut bcx: &'a Block<'a>, o: &Opt) -> opt_result<'a> {
299301
}
300302
}
301303

304+
fn variant_opt(bcx: &Block, pat_id: ast::NodeId) -> Opt {
305+
let ccx = bcx.ccx();
306+
let def = ccx.tcx.def_map.borrow().get_copy(&pat_id);
307+
match def {
308+
def::DefVariant(enum_id, var_id, _) => {
309+
let variant = ty::enum_variant_with_id(ccx.tcx(), enum_id, var_id);
310+
var(variant.disr_val, adt::represent_node(bcx, pat_id), var_id)
311+
}
312+
_ => {
313+
ccx.sess().bug("non-variant or struct in variant_opt()");
314+
}
315+
}
316+
}
317+
302318
#[deriving(Clone)]
303319
pub enum TransBindingMode {
304320
TrByCopy(/* llbinding */ ValueRef),
@@ -614,15 +630,26 @@ fn get_options(bcx: &Block, m: &[Match], col: uint) -> Vec<Opt> {
614630
ast::PatLit(l) => {
615631
add_to_set(ccx.tcx(), &mut found, lit(l));
616632
}
617-
ast::PatIdent(..) | ast::PatEnum(..) | ast::PatStruct(..) => {
633+
ast::PatIdent(..) => {
618634
// This is either an enum variant or a variable binding.
619635
let opt_def = ccx.tcx.def_map.borrow().find_copy(&cur.id);
620636
match opt_def {
621-
Some(def::DefVariant(enum_id, var_id, _)) => {
622-
let variant = ty::enum_variant_with_id(ccx.tcx(), enum_id, var_id);
637+
Some(def::DefVariant(..)) => {
638+
add_to_set(ccx.tcx(), &mut found,
639+
variant_opt(bcx, cur.id));
640+
}
641+
_ => {}
642+
}
643+
}
644+
ast::PatEnum(..) | ast::PatStruct(..) => {
645+
// This could be one of: a tuple-like enum variant, a
646+
// struct-like enum variant, or a struct.
647+
let opt_def = ccx.tcx.def_map.borrow().find_copy(&cur.id);
648+
match opt_def {
649+
Some(def::DefFn(..)) |
650+
Some(def::DefVariant(..)) => {
623651
add_to_set(ccx.tcx(), &mut found,
624-
var(variant.disr_val,
625-
adt::represent_node(bcx, cur.id), var_id));
652+
variant_opt(bcx, cur.id));
626653
}
627654
_ => {}
628655
}
@@ -768,33 +795,56 @@ fn any_irrefutable_adt_pat(bcx: &Block, m: &[Match], col: uint) -> bool {
768795
})
769796
}
770797

798+
struct DynamicFailureHandler<'a> {
799+
bcx: &'a Block<'a>,
800+
sp: Span,
801+
msg: InternedString,
802+
finished: Cell<Option<BasicBlockRef>>,
803+
}
804+
805+
impl<'a> DynamicFailureHandler<'a> {
806+
fn handle_fail(&self) -> BasicBlockRef {
807+
match self.finished.get() {
808+
Some(bb) => return bb,
809+
_ => (),
810+
}
811+
812+
let fcx = self.bcx.fcx;
813+
let fail_cx = fcx.new_block(false, "case_fallthrough", None);
814+
controlflow::trans_fail(fail_cx, self.sp, self.msg.clone());
815+
self.finished.set(Some(fail_cx.llbb));
816+
fail_cx.llbb
817+
}
818+
}
819+
771820
/// What to do when the pattern match fails.
772821
enum FailureHandler<'a> {
773822
Infallible,
774823
JumpToBasicBlock(BasicBlockRef),
775-
Unreachable
824+
DynamicFailureHandlerClass(Box<DynamicFailureHandler<'a>>),
776825
}
777826

778827
impl<'a> FailureHandler<'a> {
779828
fn is_infallible(&self) -> bool {
780829
match *self {
781830
Infallible => true,
782-
_ => false
831+
_ => false,
783832
}
784833
}
785834

786835
fn is_fallible(&self) -> bool {
787836
!self.is_infallible()
788837
}
789838

790-
fn handle_fail(&self, bcx: &Block) {
839+
fn handle_fail(&self) -> BasicBlockRef {
791840
match *self {
792-
Infallible =>
793-
fail!("attempted to fail in infallible failure handler!"),
794-
JumpToBasicBlock(basic_block) =>
795-
Br(bcx, basic_block),
796-
Unreachable =>
797-
build::Unreachable(bcx)
841+
Infallible => {
842+
fail!("attempted to fail in infallible failure handler!")
843+
}
844+
JumpToBasicBlock(basic_block) => basic_block,
845+
DynamicFailureHandlerClass(ref dynamic_failure_handler) => {
846+
dynamic_failure_handler.handle_fail()
847+
}
798848
}
799849
}
800850
}
@@ -955,7 +1005,7 @@ fn compile_guard<'a, 'b>(
9551005
// condition explicitly rather than (possibly) falling back to
9561006
// the default arm.
9571007
&JumpToBasicBlock(_) if m.len() == 1 && has_genuine_default => {
958-
chk.handle_fail(bcx);
1008+
Br(bcx, chk.handle_fail());
9591009
}
9601010
_ => {
9611011
compile_submatch(bcx, m, vals, chk, has_genuine_default);
@@ -980,7 +1030,7 @@ fn compile_submatch<'a, 'b>(
9801030
let mut bcx = bcx;
9811031
if m.len() == 0u {
9821032
if chk.is_fallible() {
983-
chk.handle_fail(bcx);
1033+
Br(bcx, chk.handle_fail());
9841034
}
9851035
return;
9861036
}
@@ -1251,7 +1301,7 @@ fn compile_submatch_continue<'a, 'b>(
12511301
// condition explicitly rather than (eventually) falling back to
12521302
// the last default arm.
12531303
&JumpToBasicBlock(_) if defaults.len() == 1 && has_genuine_default => {
1254-
chk.handle_fail(else_cx);
1304+
Br(else_cx, chk.handle_fail());
12551305
}
12561306
_ => {
12571307
compile_submatch(else_cx,
@@ -1345,10 +1395,21 @@ fn trans_match_inner<'a>(scope_cx: &'a Block<'a>,
13451395
}
13461396

13471397
let t = node_id_type(bcx, discr_expr.id);
1348-
let chk = if ty::type_is_empty(tcx, t) {
1349-
Unreachable
1350-
} else {
1351-
Infallible
1398+
let chk = {
1399+
if ty::type_is_empty(tcx, t) {
1400+
// Special case for empty types
1401+
let fail_cx = Cell::new(None);
1402+
let fail_handler = box DynamicFailureHandler {
1403+
bcx: scope_cx,
1404+
sp: discr_expr.span,
1405+
msg: InternedString::new("scrutinizing value that can't \
1406+
exist"),
1407+
finished: fail_cx,
1408+
};
1409+
DynamicFailureHandlerClass(fail_handler)
1410+
} else {
1411+
Infallible
1412+
}
13521413
};
13531414

13541415
let arm_datas: Vec<ArmData> = arms.iter().map(|arm| ArmData {

branches/auto/src/libsyntax/ext/base.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use ext::mtwt;
2323

2424
use std::collections::HashMap;
2525
use std::gc::{Gc, GC};
26+
use std::rc::Rc;
2627

2728
// new-style macro! tt code:
2829
//
@@ -104,9 +105,9 @@ pub type IdentMacroExpanderFn =
104105
/// just into the compiler's internal macro table, for `make_def`).
105106
pub trait MacResult {
106107
/// Define a new macro.
107-
// this particular flavor should go away; the idea that a macro might
108-
// expand into either a macro definition or an expression, depending
109-
// on what the context wants, is kind of silly.
108+
// this should go away; the idea that a macro might expand into
109+
// either a macro definition or an expression, depending on what
110+
// the context wants, is kind of silly.
110111
fn make_def(&self) -> Option<MacroDef> {
111112
None
112113
}
@@ -314,7 +315,7 @@ impl BlockInfo {
314315

315316
/// The base map of methods for expanding syntax extension
316317
/// AST nodes into full ASTs
317-
pub fn syntax_expander_table() -> SyntaxEnv {
318+
fn initial_syntax_expander_table() -> SyntaxEnv {
318319
// utility function to simplify creating NormalTT syntax extensions
319320
fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
320321
NormalTT(box BasicMacroExpander {
@@ -431,7 +432,9 @@ pub struct ExtCtxt<'a> {
431432

432433
pub mod_path: Vec<ast::Ident> ,
433434
pub trace_mac: bool,
434-
pub exported_macros: Vec<Gc<ast::Item>>
435+
pub exported_macros: Vec<Gc<ast::Item>>,
436+
437+
pub syntax_env: SyntaxEnv,
435438
}
436439

437440
impl<'a> ExtCtxt<'a> {
@@ -445,6 +448,7 @@ impl<'a> ExtCtxt<'a> {
445448
ecfg: ecfg,
446449
trace_mac: false,
447450
exported_macros: Vec::new(),
451+
syntax_env: initial_syntax_expander_table(),
448452
}
449453
}
450454

@@ -453,7 +457,6 @@ impl<'a> ExtCtxt<'a> {
453457
match e.node {
454458
ast::ExprMac(..) => {
455459
let mut expander = expand::MacroExpander {
456-
extsbox: syntax_expander_table(),
457460
cx: self,
458461
};
459462
e = expand::expand_expr(e, &mut expander);
@@ -642,10 +645,13 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
642645
/// In order to have some notion of scoping for macros,
643646
/// we want to implement the notion of a transformation
644647
/// environment.
645-
648+
///
646649
/// This environment maps Names to SyntaxExtensions.
650+
pub struct SyntaxEnv {
651+
chain: Vec<MapChainFrame> ,
652+
}
647653

648-
//impl question: how to implement it? Initially, the
654+
// impl question: how to implement it? Initially, the
649655
// env will contain only macros, so it might be painful
650656
// to add an empty frame for every context. Let's just
651657
// get it working, first....
@@ -657,15 +663,11 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
657663

658664
struct MapChainFrame {
659665
info: BlockInfo,
660-
map: HashMap<Name, SyntaxExtension>,
661-
}
662-
663-
pub struct SyntaxEnv {
664-
chain: Vec<MapChainFrame> ,
666+
map: HashMap<Name, Rc<SyntaxExtension>>,
665667
}
666668

667669
impl SyntaxEnv {
668-
pub fn new() -> SyntaxEnv {
670+
fn new() -> SyntaxEnv {
669671
let mut map = SyntaxEnv { chain: Vec::new() };
670672
map.push_frame();
671673
map
@@ -692,18 +694,18 @@ impl SyntaxEnv {
692694
unreachable!()
693695
}
694696

695-
pub fn find<'a>(&'a self, k: &Name) -> Option<&'a SyntaxExtension> {
697+
pub fn find(&self, k: &Name) -> Option<Rc<SyntaxExtension>> {
696698
for frame in self.chain.iter().rev() {
697699
match frame.map.find(k) {
698-
Some(v) => return Some(v),
700+
Some(v) => return Some(v.clone()),
699701
None => {}
700702
}
701703
}
702704
None
703705
}
704706

705707
pub fn insert(&mut self, k: Name, v: SyntaxExtension) {
706-
self.find_escape_frame().map.insert(k, v);
708+
self.find_escape_frame().map.insert(k, Rc::new(v));
707709
}
708710

709711
pub fn info<'a>(&'a mut self) -> &'a mut BlockInfo {

0 commit comments

Comments
 (0)