Skip to content

Commit 2704f0f

Browse files
committed
---
yaml --- r: 138713 b: refs/heads/try2 c: f7ae9b1 h: refs/heads/master i: 138711: 6b639ef v: v3
1 parent 1957a25 commit 2704f0f

File tree

15 files changed

+227
-265
lines changed

15 files changed

+227
-265
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 9ec7f3fa2252261b647c99ead9d6ebec0b959e05
8+
refs/heads/try2: f7ae9b1759501c38e80bc912f9c39bf6660fd15d
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/trie.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<T> TrieNode<T> {
230230
pure fn each_reverse(&self, f: fn(&(uint, &self/T)) -> bool) {
231231
for uint::range_rev(self.children.len(), 0) |idx| {
232232
match self.children[idx - 1] {
233-
Internal(ref x) => x.each(f),
233+
Internal(ref x) => x.each_reverse(f),
234234
External(k, ref v) => if !f(&(k, v)) { return },
235235
Nothing => ()
236236
}
@@ -366,4 +366,40 @@ mod tests {
366366
check_integrity(&trie.root);
367367
}
368368
}
369+
370+
#[test]
371+
fn test_each() {
372+
let mut m = TrieMap::new();
373+
374+
assert m.insert(3, 6);
375+
assert m.insert(0, 0);
376+
assert m.insert(4, 8);
377+
assert m.insert(2, 4);
378+
assert m.insert(1, 2);
379+
380+
let mut n = 0;
381+
for m.each |&(k, v)| {
382+
assert k == n;
383+
assert *v == n * 2;
384+
n += 1;
385+
}
386+
}
387+
388+
#[test]
389+
fn test_each_reverse() {
390+
let mut m = TrieMap::new();
391+
392+
assert m.insert(3, 6);
393+
assert m.insert(0, 0);
394+
assert m.insert(4, 8);
395+
assert m.insert(2, 4);
396+
assert m.insert(1, 2);
397+
398+
let mut n = 4;
399+
for m.each_reverse |&(k, v)| {
400+
assert k == n;
401+
assert *v == n * 2;
402+
n -= 1;
403+
}
404+
}
369405
}

branches/try2/src/librustc/middle/check_const.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use middle::ty;
1616
use middle::typeck;
1717
use util::ppaux;
1818

19+
use core::option;
1920
use syntax::ast::*;
2021
use syntax::codemap;
2122
use syntax::{visit, ast_util, ast_map};

branches/try2/src/librustc/middle/check_match.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use middle::typeck::method_map;
1919
use middle::moves;
2020
use util::ppaux::ty_to_str;
2121

22+
use core::option;
2223
use core::uint;
2324
use core::vec;
2425
use std::sort;

branches/try2/src/librustc/middle/kind.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use middle::ty;
1818
use middle::typeck;
1919
use util::ppaux::{ty_to_str, tys_to_str};
2020

21+
use core::option;
2122
use core::str;
2223
use core::vec;
2324
use std::oldmap::HashMap;

branches/try2/src/librustc/middle/region.rs

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,9 @@ pub struct DetermineRpCtxt {
416416
item_id: ast::node_id,
417417

418418
// true when we are within an item but not within a method.
419-
// see long discussion on region_is_relevant().
419+
// see long discussion on region_is_relevant()
420420
anon_implies_rp: bool,
421421

422-
// true when we are not within an &self method.
423-
// see long discussion on region_is_relevant().
424-
self_implies_rp: bool,
425-
426422
// encodes the context of the current type; invariant if
427423
// mutable, covariant otherwise
428424
ambient_variance: region_variance,
@@ -462,14 +458,14 @@ pub fn add_variance(+ambient_variance: region_variance,
462458
}
463459

464460
pub impl DetermineRpCtxt {
465-
fn add_variance(&self, variance: region_variance) -> region_variance {
461+
fn add_variance(@mut self, variance: region_variance) -> region_variance {
466462
add_variance(self.ambient_variance, variance)
467463
}
468464

469465
/// Records that item `id` is region-parameterized with the
470466
/// variance `variance`. If `id` was already parameterized, then
471467
/// the new variance is joined with the old variance.
472-
fn add_rp(&mut self, id: ast::node_id, variance: region_variance) {
468+
fn add_rp(@mut self, id: ast::node_id, variance: region_variance) {
473469
assert id != 0;
474470
let old_variance = self.region_paramd_items.find(&id);
475471
let joined_variance = match old_variance {
@@ -494,7 +490,7 @@ pub impl DetermineRpCtxt {
494490
/// `from`. Put another way, it indicates that the current item
495491
/// contains a value of type `from`, so if `from` is
496492
/// region-parameterized, so is the current item.
497-
fn add_dep(&mut self, from: ast::node_id) {
493+
fn add_dep(@mut self, from: ast::node_id) {
498494
debug!("add dependency from %d -> %d (%s -> %s) with variance %?",
499495
from, self.item_id,
500496
ast_map::node_id_to_str(self.ast_map, from,
@@ -519,46 +515,42 @@ pub impl DetermineRpCtxt {
519515
}
520516

521517
// Determines whether a reference to a region that appears in the
522-
// AST implies that the enclosing type is region-parameterized (RP).
523-
// This point is subtle. Here are some examples to make it more
518+
// AST implies that the enclosing type is region-parameterized.
519+
//
520+
// This point is subtle. Here are four examples to make it more
524521
// concrete.
525522
//
526523
// 1. impl foo for &int { ... }
527524
// 2. impl foo for &self/int { ... }
528-
// 3. impl foo for bar { fn m(@self) -> &self/int { ... } }
529-
// 4. impl foo for bar { fn m(&self) -> &self/int { ... } }
530-
// 5. impl foo for bar { fn m(&self) -> &int { ... } }
525+
// 3. impl foo for bar { fn m() -> &self/int { ... } }
526+
// 4. impl foo for bar { fn m() -> &int { ... } }
531527
//
532528
// In case 1, the anonymous region is being referenced,
533529
// but it appears in a context where the anonymous region
534-
// resolves to self, so the impl foo is RP.
530+
// resolves to self, so the impl foo is region-parameterized.
535531
//
536532
// In case 2, the self parameter is written explicitly.
537533
//
538-
// In case 3, the method refers to the region `self`, so that
539-
// implies that the impl must be region parameterized. (If the
540-
// type bar is not region parameterized, that is an error, because
541-
// the self region is effectively unconstrained, but that is
542-
// detected elsewhere).
543-
//
544-
// In case 4, the method refers to the region `self`, but the
545-
// `self` region is bound by the `&self` receiver, and so this
546-
// does not require that `bar` be RP.
534+
// In case 3, the method refers to self, so that implies that the
535+
// impl must be region parameterized. (If the type bar is not
536+
// region parameterized, that is an error, because the self region
537+
// is effectively unconstrained, but that is detected elsewhere).
547538
//
548-
// In case 5, the anonymous region is referenced, but it
539+
// In case 4, the anonymous region is referenced, but it
549540
// bound by the method, so it does not refer to self. This impl
550541
// need not be region parameterized.
551542
//
552-
// Normally, & or &self implies that the enclosing item is RP.
553-
// However, within a function, & is always bound. Within a method
554-
// with &self type, &self is also bound. We detect those last two
555-
// cases via flags (anon_implies_rp and self_implies_rp) that are
556-
// true when the anon or self region implies RP.
557-
fn region_is_relevant(&self, r: @ast::region) -> bool {
543+
// So the rules basically are: the `self` region always implies
544+
// that the enclosing type is region parameterized. The anonymous
545+
// region also does, unless it appears within a method, in which
546+
// case it is bound. We handle this by setting a flag
547+
// (anon_implies_rp) to true when we enter an item and setting
548+
// that flag to false when we enter a method.
549+
fn region_is_relevant(@mut self, r: @ast::region) -> bool {
558550
match r.node {
559551
ast::re_static => false,
560552
ast::re_anon => self.anon_implies_rp,
561-
ast::re_self => self.self_implies_rp,
553+
ast::re_self => true,
562554
ast::re_named(_) => false
563555
}
564556
}
@@ -569,7 +561,7 @@ pub impl DetermineRpCtxt {
569561
//
570562
// If the region is explicitly specified, then we follows the
571563
// normal rules.
572-
fn opt_region_is_relevant(&self,
564+
fn opt_region_is_relevant(@mut self,
573565
opt_r: Option<@ast::region>)
574566
-> bool {
575567
debug!("opt_region_is_relevant: %? (anon_implies_rp=%b)",
@@ -583,23 +575,16 @@ pub impl DetermineRpCtxt {
583575
fn with(@mut self,
584576
item_id: ast::node_id,
585577
anon_implies_rp: bool,
586-
self_implies_rp: bool,
587578
f: &fn()) {
588579
let old_item_id = self.item_id;
589580
let old_anon_implies_rp = self.anon_implies_rp;
590-
let old_self_implies_rp = self.self_implies_rp;
591581
self.item_id = item_id;
592582
self.anon_implies_rp = anon_implies_rp;
593-
self.self_implies_rp = self_implies_rp;
594-
debug!("with_item_id(%d, %b, %b)",
595-
item_id,
596-
anon_implies_rp,
597-
self_implies_rp);
583+
debug!("with_item_id(%d, %b)", item_id, anon_implies_rp);
598584
let _i = ::util::common::indenter();
599585
f();
600586
self.item_id = old_item_id;
601587
self.anon_implies_rp = old_anon_implies_rp;
602-
self.self_implies_rp = old_self_implies_rp;
603588
}
604589

605590
fn with_ambient_variance(@mut self, variance: region_variance, f: &fn()) {
@@ -613,7 +598,7 @@ pub impl DetermineRpCtxt {
613598
pub fn determine_rp_in_item(item: @ast::item,
614599
&&cx: @mut DetermineRpCtxt,
615600
visitor: visit::vt<@mut DetermineRpCtxt>) {
616-
do cx.with(item.id, true, true) {
601+
do cx.with(item.id, true) {
617602
visit::visit_item(item, cx, visitor);
618603
}
619604
}
@@ -625,12 +610,7 @@ pub fn determine_rp_in_fn(fk: &visit::fn_kind,
625610
_: ast::node_id,
626611
&&cx: @mut DetermineRpCtxt,
627612
visitor: visit::vt<@mut DetermineRpCtxt>) {
628-
let self_implies_rp = match fk {
629-
&visit::fk_method(_, _, m) => !m.self_ty.node.is_borrowed(),
630-
_ => true
631-
};
632-
633-
do cx.with(cx.item_id, false, self_implies_rp) {
613+
do cx.with(cx.item_id, false) {
634614
do cx.with_ambient_variance(rv_contravariant) {
635615
for decl.inputs.each |a| {
636616
(visitor.visit_ty)(a.ty, cx, visitor);
@@ -646,7 +626,7 @@ pub fn determine_rp_in_fn(fk: &visit::fn_kind,
646626
pub fn determine_rp_in_ty_method(ty_m: &ast::ty_method,
647627
&&cx: @mut DetermineRpCtxt,
648628
visitor: visit::vt<@mut DetermineRpCtxt>) {
649-
do cx.with(cx.item_id, false, !ty_m.self_ty.node.is_borrowed()) {
629+
do cx.with(cx.item_id, false) {
650630
visit::visit_ty_method(ty_m, cx, visitor);
651631
}
652632
}
@@ -755,7 +735,7 @@ pub fn determine_rp_in_ty(ty: @ast::Ty,
755735
ast::ty_bare_fn(@ast::TyBareFn {decl: ref decl, _}) => {
756736
// fn() binds the & region, so do not consider &T types that
757737
// appear *inside* a fn() type to affect the enclosing item:
758-
do cx.with(cx.item_id, false, true) {
738+
do cx.with(cx.item_id, false) {
759739
// parameters are contravariant
760740
do cx.with_ambient_variance(rv_contravariant) {
761741
for decl.inputs.each |a| {
@@ -816,7 +796,6 @@ pub fn determine_rp_in_crate(sess: Session,
816796
worklist: ~[],
817797
item_id: 0,
818798
anon_implies_rp: false,
819-
self_implies_rp: true,
820799
ambient_variance: rv_covariant
821800
};
822801

branches/try2/src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ use core::hash;
6969
use core::int;
7070
use core::io;
7171
use core::libc::{c_uint, c_ulonglong};
72+
use core::option;
7273
use core::uint;
7374
use std::oldmap::HashMap;
7475
use std::{oldmap, time, list};

0 commit comments

Comments
 (0)