Skip to content

Commit 90e99a5

Browse files
committed
---
yaml --- r: 276821 b: refs/heads/try c: 953c3b5 h: refs/heads/master i: 276819: 9537f9d
1 parent 0b302f1 commit 90e99a5

File tree

8 files changed

+231
-276
lines changed

8 files changed

+231
-276
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 6dbb0e86aec11050480beb76eade6fb805010ba7
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
4-
refs/heads/try: e17c48bb243163e22f4d5a3b42499c642ae41dec
4+
refs/heads/try: 953c3b5f502437398711ca442be0a10ad575b667
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/librustc/ty/fold.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
116116
pub trait TypeFolder<'tcx> : Sized {
117117
fn tcx<'a>(&'a self) -> &'a TyCtxt<'tcx>;
118118

119-
/// Invoked by the `super_*` routines when we enter a region
120-
/// binding level (for example, when entering a function
121-
/// signature). This is used by clients that want to track the
122-
/// Debruijn index nesting level.
123-
fn enter_region_binder(&mut self) { }
124-
125-
/// Invoked by the `super_*` routines when we exit a region
126-
/// binding level. This is used by clients that want to
127-
/// track the Debruijn index nesting level.
128-
fn exit_region_binder(&mut self) { }
129-
130119
fn fold_binder<T>(&mut self, t: &Binder<T>) -> Binder<T>
131120
where T : TypeFoldable<'tcx>
132121
{
133-
// FIXME(#20526) this should replace `enter_region_binder`/`exit_region_binder`.
134122
t.super_fold_with(self)
135123
}
136124

@@ -197,8 +185,9 @@ pub trait TypeFolder<'tcx> : Sized {
197185
}
198186

199187
pub trait TypeVisitor<'tcx> : Sized {
200-
fn enter_region_binder(&mut self) { }
201-
fn exit_region_binder(&mut self) { }
188+
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> bool {
189+
t.super_visit_with(self)
190+
}
202191

203192
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
204193
t.super_visit_with(self)
@@ -296,12 +285,11 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx>
296285
{
297286
fn tcx(&self) -> &TyCtxt<'tcx> { self.tcx }
298287

299-
fn enter_region_binder(&mut self) {
288+
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
300289
self.current_depth += 1;
301-
}
302-
303-
fn exit_region_binder(&mut self) {
290+
let t = t.super_fold_with(self);
304291
self.current_depth -= 1;
292+
t
305293
}
306294

307295
fn fold_region(&mut self, r: ty::Region) -> ty::Region {
@@ -438,12 +426,11 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionReplacer<'a, 'tcx>
438426
{
439427
fn tcx(&self) -> &TyCtxt<'tcx> { self.tcx }
440428

441-
fn enter_region_binder(&mut self) {
429+
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
442430
self.current_depth += 1;
443-
}
444-
445-
fn exit_region_binder(&mut self) {
431+
let t = t.super_fold_with(self);
446432
self.current_depth -= 1;
433+
t
447434
}
448435

449436
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
@@ -596,12 +583,11 @@ struct HasEscapingRegionsVisitor {
596583
}
597584

598585
impl<'tcx> TypeVisitor<'tcx> for HasEscapingRegionsVisitor {
599-
fn enter_region_binder(&mut self) {
586+
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> bool {
600587
self.depth += 1;
601-
}
602-
603-
fn exit_region_binder(&mut self) {
588+
let result = t.super_visit_with(self);
604589
self.depth -= 1;
590+
result
605591
}
606592

607593
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {

branches/try/src/librustc/ty/structural_impls.rs

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,19 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
190190

191191
impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
192192
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
193-
folder.enter_region_binder();
194-
let result = ty::Binder(self.0.fold_with(folder));
195-
folder.exit_region_binder();
196-
result
193+
ty::Binder(self.0.fold_with(folder))
197194
}
198195

199196
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
200197
folder.fold_binder(self)
201198
}
202199

203200
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
204-
visitor.enter_region_binder();
205-
if self.0.visit_with(visitor) { return true }
206-
visitor.exit_region_binder();
207-
false
201+
self.0.visit_with(visitor)
202+
}
203+
204+
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
205+
visitor.visit_binder(self)
208206
}
209207
}
210208

@@ -220,39 +218,11 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for P<[T]> {
220218

221219
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for VecPerParamSpace<T> {
222220
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
223-
224-
// Things in the Fn space take place under an additional level
225-
// of region binding relative to the other spaces. This is
226-
// because those entries are attached to a method, and methods
227-
// always introduce a level of region binding.
228-
229-
let result = self.map_enumerated(|(space, index, elem)| {
230-
if space == subst::FnSpace && index == 0 {
231-
// enter new level when/if we reach the first thing in fn space
232-
folder.enter_region_binder();
233-
}
234-
elem.fold_with(folder)
235-
});
236-
if result.len(subst::FnSpace) > 0 {
237-
// if there was anything in fn space, exit the region binding level
238-
folder.exit_region_binder();
239-
}
240-
result
221+
self.map(|elem| elem.fold_with(folder))
241222
}
242223

243224
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
244-
let mut entered_region_binder = false;
245-
let result = self.iter_enumerated().any(|(space, index, t)| {
246-
if space == subst::FnSpace && index == 0 {
247-
visitor.enter_region_binder();
248-
entered_region_binder = true;
249-
}
250-
t.visit_with(visitor)
251-
});
252-
if entered_region_binder {
253-
visitor.exit_region_binder();
254-
}
255-
result
225+
self.iter().any(|elem| elem.visit_with(visitor))
256226
}
257227
}
258228

branches/try/src/librustc/ty/subst.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,12 +582,11 @@ struct SubstFolder<'a, 'tcx: 'a> {
582582
impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
583583
fn tcx(&self) -> &TyCtxt<'tcx> { self.tcx }
584584

585-
fn enter_region_binder(&mut self) {
585+
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
586586
self.region_binders_passed += 1;
587-
}
588-
589-
fn exit_region_binder(&mut self) {
587+
let t = t.super_fold_with(self);
590588
self.region_binders_passed -= 1;
589+
t
591590
}
592591

593592
fn fold_region(&mut self, r: ty::Region) -> ty::Region {

branches/try/src/librustc_resolve/build_reduced_graph.rs

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
//! any imports resolved.
1515
1616
use DefModifiers;
17-
use resolve_imports::ImportDirective;
18-
use resolve_imports::ImportDirectiveSubclass::{self, SingleImport, GlobImport};
17+
use resolve_imports::ImportDirectiveSubclass::{self, GlobImport};
1918
use Module;
2019
use Namespace::{self, TypeNS, ValueNS};
2120
use {NameBinding, NameBindingKind};
@@ -28,7 +27,7 @@ use rustc::middle::def::*;
2827
use rustc::middle::def_id::{CRATE_DEF_INDEX, DefId};
2928
use rustc::ty::VariantKind;
3029

31-
use syntax::ast::{Name, NodeId};
30+
use syntax::ast::Name;
3231
use syntax::attr::AttrMetaMethods;
3332
use syntax::parse::token::special_idents;
3433
use syntax::codemap::{Span, DUMMY_SP};
@@ -152,8 +151,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
152151
}
153152

154153
let subclass = ImportDirectiveSubclass::single(binding, source_name);
155-
self.build_import_directive(parent,
156-
module_path,
154+
self.unresolved_imports += 1;
155+
parent.add_import_directive(module_path,
157156
subclass,
158157
view_path.span,
159158
item.id,
@@ -203,8 +202,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
203202
}
204203
};
205204
let subclass = ImportDirectiveSubclass::single(rename, name);
206-
self.build_import_directive(parent,
207-
module_path,
205+
self.unresolved_imports += 1;
206+
parent.add_import_directive(module_path,
208207
subclass,
209208
source_item.span,
210209
source_item.node.id(),
@@ -213,8 +212,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
213212
}
214213
}
215214
ViewPathGlob(_) => {
216-
self.build_import_directive(parent,
217-
module_path,
215+
self.unresolved_imports += 1;
216+
parent.add_import_directive(module_path,
218217
GlobImport,
219218
view_path.span,
220219
item.id,
@@ -521,39 +520,6 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
521520
}
522521
}
523522

524-
/// Creates and adds an import directive to the given module.
525-
fn build_import_directive(&mut self,
526-
module_: Module<'b>,
527-
module_path: Vec<Name>,
528-
subclass: ImportDirectiveSubclass,
529-
span: Span,
530-
id: NodeId,
531-
is_public: bool,
532-
is_prelude: bool) {
533-
// Bump the reference count on the name. Or, if this is a glob, set
534-
// the appropriate flag.
535-
536-
match subclass {
537-
SingleImport { target, .. } => {
538-
module_.increment_outstanding_references_for(target, ValueNS, is_public);
539-
module_.increment_outstanding_references_for(target, TypeNS, is_public);
540-
}
541-
GlobImport if !is_prelude => {
542-
// Set the glob flag. This tells us that we don't know the
543-
// module's exports ahead of time.
544-
module_.inc_glob_count(is_public)
545-
}
546-
// Prelude imports are not included in the glob counts since they do not get added to
547-
// `resolved_globs` -- they are handled separately in `resolve_imports`.
548-
GlobImport => {}
549-
}
550-
551-
let directive =
552-
ImportDirective::new(module_path, subclass, span, id, is_public, is_prelude);
553-
module_.add_import_directive(directive);
554-
self.unresolved_imports += 1;
555-
}
556-
557523
/// Ensures that the reduced graph rooted at the given external module
558524
/// is built, building it if it is not.
559525
pub fn populate_module_if_necessary(&mut self, module: Module<'b>) {

branches/try/src/librustc_resolve/lib.rs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,8 @@ pub struct ModuleS<'a> {
828828
// is the NodeId of the local `extern crate` item (otherwise, `extern_crate_id` is None).
829829
extern_crate_id: Option<NodeId>,
830830

831-
resolutions: RefCell<HashMap<(Name, Namespace), NameResolution<'a>>>,
832-
unresolved_imports: RefCell<Vec<&'a ImportDirective>>,
831+
resolutions: RefCell<HashMap<(Name, Namespace), &'a RefCell<NameResolution<'a>>>>,
832+
unresolved_imports: RefCell<Vec<&'a ImportDirective<'a>>>,
833833

834834
// The module children of this node, including normal modules and anonymous modules.
835835
// Anonymous children are pseudo-modules that are implicitly created around items
@@ -849,14 +849,8 @@ pub struct ModuleS<'a> {
849849

850850
prelude: RefCell<Option<Module<'a>>>,
851851

852-
glob_importers: RefCell<Vec<(Module<'a>, &'a ImportDirective)>>,
853-
resolved_globs: RefCell<(Vec<Module<'a>> /* public */, Vec<Module<'a>> /* private */)>,
854-
855-
// The number of public glob imports in this module.
856-
public_glob_count: Cell<usize>,
857-
858-
// The number of private glob imports in this module.
859-
private_glob_count: Cell<usize>,
852+
glob_importers: RefCell<Vec<(Module<'a>, &'a ImportDirective<'a>)>>,
853+
globs: RefCell<Vec<&'a ImportDirective<'a>>>,
860854

861855
// Whether this module is populated. If not populated, any attempt to
862856
// access the children must be preceded with a
@@ -884,22 +878,15 @@ impl<'a> ModuleS<'a> {
884878
module_children: RefCell::new(NodeMap()),
885879
prelude: RefCell::new(None),
886880
glob_importers: RefCell::new(Vec::new()),
887-
resolved_globs: RefCell::new((Vec::new(), Vec::new())),
888-
public_glob_count: Cell::new(0),
889-
private_glob_count: Cell::new(0),
881+
globs: RefCell::new((Vec::new())),
890882
populated: Cell::new(!external),
891883
arenas: arenas
892884
}
893885
}
894886

895-
fn add_import_directive(&self, import_directive: ImportDirective) {
896-
let import_directive = self.arenas.alloc_import_directive(import_directive);
897-
self.unresolved_imports.borrow_mut().push(import_directive);
898-
}
899-
900887
fn for_each_child<F: FnMut(Name, Namespace, &'a NameBinding<'a>)>(&self, mut f: F) {
901888
for (&(name, ns), name_resolution) in self.resolutions.borrow().iter() {
902-
name_resolution.binding.map(|binding| f(name, ns, binding));
889+
name_resolution.borrow().binding.map(|binding| f(name, ns, binding));
903890
}
904891
}
905892

@@ -929,11 +916,6 @@ impl<'a> ModuleS<'a> {
929916
_ => false,
930917
}
931918
}
932-
933-
fn inc_glob_count(&self, is_public: bool) {
934-
let glob_count = if is_public { &self.public_glob_count } else { &self.private_glob_count };
935-
glob_count.set(glob_count.get() + 1);
936-
}
937919
}
938920

939921
impl<'a> fmt::Debug for ModuleS<'a> {
@@ -1135,7 +1117,8 @@ pub struct Resolver<'a, 'tcx: 'a> {
11351117
struct ResolverArenas<'a> {
11361118
modules: arena::TypedArena<ModuleS<'a>>,
11371119
name_bindings: arena::TypedArena<NameBinding<'a>>,
1138-
import_directives: arena::TypedArena<ImportDirective>,
1120+
import_directives: arena::TypedArena<ImportDirective<'a>>,
1121+
name_resolutions: arena::TypedArena<RefCell<NameResolution<'a>>>,
11391122
}
11401123

11411124
impl<'a> ResolverArenas<'a> {
@@ -1145,9 +1128,13 @@ impl<'a> ResolverArenas<'a> {
11451128
fn alloc_name_binding(&'a self, name_binding: NameBinding<'a>) -> &'a NameBinding<'a> {
11461129
self.name_bindings.alloc(name_binding)
11471130
}
1148-
fn alloc_import_directive(&'a self, import_directive: ImportDirective) -> &'a ImportDirective {
1131+
fn alloc_import_directive(&'a self, import_directive: ImportDirective<'a>)
1132+
-> &'a ImportDirective {
11491133
self.import_directives.alloc(import_directive)
11501134
}
1135+
fn alloc_name_resolution(&'a self) -> &'a RefCell<NameResolution<'a>> {
1136+
self.name_resolutions.alloc(Default::default())
1137+
}
11511138
}
11521139

11531140
#[derive(PartialEq)]
@@ -1216,6 +1203,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12161203
modules: arena::TypedArena::new(),
12171204
name_bindings: arena::TypedArena::new(),
12181205
import_directives: arena::TypedArena::new(),
1206+
name_resolutions: arena::TypedArena::new(),
12191207
}
12201208
}
12211209

0 commit comments

Comments
 (0)