Skip to content

Commit c458c1c

Browse files
committed
---
yaml --- r: 24529 b: refs/heads/try2 c: bfbc847 h: refs/heads/master i: 24527: 5358239 v: v3
1 parent 9464c44 commit c458c1c

File tree

2 files changed

+59
-35
lines changed

2 files changed

+59
-35
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: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: e1ee1982160d2b7846b97d790db6961c022bde3b
8+
refs/heads/try2: bfbc847f635437cf1be00837903939ef3bd27a52
99
refs/heads/incoming: 05543fd04dfb3f63b453a331e239ceb1a9a219f9
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/src/rustc/middle/resolve3.rs

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import syntax::ast::{ty_u8, ty_uint, variant, view_item, view_item_export};
2424
import syntax::ast::{view_item_import, view_item_use, view_path_glob};
2525
import syntax::ast::{view_path_list, view_path_simple};
2626
import syntax::ast_util::{def_id_of_def, local_def, new_def_hash, walk_pat};
27+
import syntax::attr::{attr_metas, contains_name};
2728
import syntax::codemap::span;
2829
import syntax::visit::{default_visitor, fk_method, mk_vt, visit_block};
2930
import syntax::visit::{visit_crate, visit_expr, visit_expr_opt, visit_fn};
@@ -125,11 +126,6 @@ enum ResolveResult<T> {
125126
Success(T) // Successfully resolved the import.
126127
}
127128

128-
enum PrivacyFilter {
129-
PrivateOrPublic, //< Will match both public and private items.
130-
PublicOnly //< Will match only public items.
131-
}
132-
133129
enum TypeParameters/& {
134130
NoTypeParameters, //< No type parameters.
135131
HasTypeParameters(&~[ty_param], //< Type parameters.
@@ -161,6 +157,18 @@ enum RibKind {
161157
FunctionRibKind(node_id)
162158
}
163159

160+
// The X-ray flag indicates that a context has the X-ray privilege, which
161+
// allows it to reference private names. Currently, this is used for the test
162+
// runner.
163+
//
164+
// XXX: The X-ray flag is kind of questionable in the first place. It might
165+
// be better to introduce an expr_xray_path instead.
166+
167+
enum XrayFlag {
168+
NoXray, //< Private items cannot be accessed.
169+
Xray //< Private items can be accessed.
170+
}
171+
164172
// FIXME (issue #2550): Should be a class but then it becomes not implicitly
165173
// copyable due to a kind bug.
166174

@@ -380,17 +388,6 @@ class Module {
380388
}
381389
}
382390

383-
pure fn is_crate_root(module: @Module) -> bool {
384-
alt module.def_id {
385-
none => {
386-
ret false;
387-
}
388-
some(def_id) => {
389-
ret def_id.crate == 0 && def_id.node == 0;
390-
}
391-
}
392-
}
393-
394391
// XXX: This is a workaround due to is_none in the standard library mistakenly
395392
// requiring a T:copy.
396393

@@ -566,6 +563,10 @@ class Resolver {
566563
// The current set of local scopes, for types.
567564
let type_ribs: @dvec<@Rib>;
568565

566+
// Whether the current context is an X-ray context. An X-ray context is
567+
// allowed to access private names of any module.
568+
let mut xray_context: XrayFlag;
569+
569570
// The atom for the keyword "self".
570571
let self_atom: Atom;
571572

@@ -598,6 +599,7 @@ class Resolver {
598599
self.current_module = (*self.graph_root).get_module();
599600
self.value_ribs = @dvec();
600601
self.type_ribs = @dvec();
602+
self.xray_context = NoXray;
601603

602604
self.self_atom = (*self.atom_table).intern(@"self");
603605
self.primitive_type_table = @PrimitiveTypeTable(self.atom_table);
@@ -1442,7 +1444,10 @@ class Resolver {
14421444
import_directive);
14431445
} else {
14441446
// First, resolve the module path for the directive, if necessary.
1445-
alt self.resolve_module_path_for_import(module, module_path) {
1447+
alt self.resolve_module_path_for_import(module,
1448+
module_path,
1449+
NoXray) {
1450+
14461451
Failed {
14471452
resolution_result = Failed;
14481453
}
@@ -1869,8 +1874,10 @@ class Resolver {
18691874

18701875
fn resolve_module_path_from_root(module: @Module,
18711876
module_path: @dvec<Atom>,
1872-
index: uint)
1877+
index: uint,
1878+
xray: XrayFlag)
18731879
-> ResolveResult<@Module> {
1880+
18741881
let mut search_module = module;
18751882
let mut index = index;
18761883
let module_path_len = (*module_path).len();
@@ -1882,7 +1889,7 @@ class Resolver {
18821889
while index < module_path_len {
18831890
let name = (*module_path).get_elt(index);
18841891
alt self.resolve_name_in_module(search_module, name, ModuleNS,
1885-
PublicOnly) {
1892+
xray) {
18861893

18871894
Failed {
18881895
// XXX: span_err
@@ -1925,7 +1932,8 @@ class Resolver {
19251932
the given module.
19261933
"]
19271934
fn resolve_module_path_for_import(module: @Module,
1928-
module_path: @dvec<Atom>)
1935+
module_path: @dvec<Atom>,
1936+
xray: XrayFlag)
19291937
-> ResolveResult<@Module> {
19301938

19311939
let module_path_len = (*module_path).len();
@@ -1961,7 +1969,8 @@ class Resolver {
19611969

19621970
ret self.resolve_module_path_from_root(search_module,
19631971
module_path,
1964-
1u);
1972+
1u,
1973+
xray);
19651974
}
19661975

19671976
fn resolve_item_in_lexical_scope(module: @Module,
@@ -2030,7 +2039,7 @@ class Resolver {
20302039

20312040
// Resolve the name in the parent module.
20322041
alt self.resolve_name_in_module(search_module, name, namespace,
2033-
PrivateOrPublic) {
2042+
Xray) {
20342043
Failed {
20352044
// Continue up the search chain.
20362045
}
@@ -2092,16 +2101,14 @@ class Resolver {
20922101
fn resolve_name_in_module(module: @Module,
20932102
name: Atom,
20942103
namespace: Namespace,
2095-
privacy_filter: PrivacyFilter)
2104+
xray: XrayFlag)
20962105
-> ResolveResult<Target> {
20972106

20982107
#debug("(resolving name in module) resolving '%s' in '%s'",
20992108
*(*self.atom_table).atom_to_str(name),
21002109
self.module_to_str(module));
21012110

2102-
if privacy_filter == PublicOnly &&
2103-
!self.name_is_exported(module, name) {
2104-
2111+
if xray == NoXray && !self.name_is_exported(module, name) {
21052112
#debug("(resolving name in module) name '%s' is unexported",
21062113
*(*self.atom_table).atom_to_str(name));
21072114
ret Failed;
@@ -2711,6 +2718,13 @@ class Resolver {
27112718
fn resolve_item(item: @item, visitor: ResolveVisitor) {
27122719
#debug("(resolving item) resolving %s", *item.ident);
27132720

2721+
// Items with the !resolve_unexported attribute are X-ray contexts.
2722+
// This is used to allow the test runner to run unexported tests.
2723+
let orig_xray_flag = self.xray_context;
2724+
if contains_name(attr_metas(item.attrs), "!resolve_unexported") {
2725+
self.xray_context = Xray;
2726+
}
2727+
27142728
alt item.node {
27152729
item_enum(_, type_parameters, _) |
27162730
item_ty(_, type_parameters, _) {
@@ -2821,7 +2835,6 @@ class Resolver {
28212835

28222836
if !self.session.building_library &&
28232837
is_none(self.session.main_fn) &&
2824-
is_crate_root(self.current_module) &&
28252838
str::eq(*item.ident, "main") {
28262839

28272840
self.session.main_fn = some((item.id, item.span));
@@ -2842,10 +2855,11 @@ class Resolver {
28422855
visit_item(item, (), visitor);
28432856
}
28442857
}
2858+
2859+
self.xray_context = orig_xray_flag;
28452860
}
28462861

28472862
fn with_type_parameter_rib(type_parameters: TypeParameters, f: fn()) {
2848-
28492863
alt type_parameters {
28502864
HasTypeParameters(type_parameters, node_id, initial_index)
28512865
if (*type_parameters).len() >= 1u {
@@ -3496,11 +3510,15 @@ class Resolver {
34963510
}
34973511

34983512
if path.global {
3499-
ret self.resolve_crate_relative_path(path, namespace);
3513+
ret self.resolve_crate_relative_path(path,
3514+
self.xray_context,
3515+
namespace);
35003516
}
35013517

35023518
if path.idents.len() > 1u {
3503-
ret self.resolve_module_relative_path(path, namespace);
3519+
ret self.resolve_module_relative_path(path,
3520+
self.xray_context,
3521+
namespace);
35043522
}
35053523

35063524
ret self.resolve_identifier(path.idents.last(),
@@ -3593,14 +3611,17 @@ class Resolver {
35933611
ret module_path_atoms;
35943612
}
35953613

3596-
fn resolve_module_relative_path(path: @path, namespace: Namespace)
3614+
fn resolve_module_relative_path(path: @path,
3615+
+xray: XrayFlag,
3616+
namespace: Namespace)
35973617
-> option<def> {
35983618

35993619
let module_path_atoms = self.intern_module_part_of_path(path);
36003620

36013621
let mut containing_module;
36023622
alt self.resolve_module_path_for_import(self.current_module,
3603-
module_path_atoms) {
3623+
module_path_atoms,
3624+
xray) {
36043625

36053626
Failed {
36063627
self.session.span_err(path.span,
@@ -3640,7 +3661,9 @@ class Resolver {
36403661
}
36413662
}
36423663

3643-
fn resolve_crate_relative_path(path: @path, namespace: Namespace)
3664+
fn resolve_crate_relative_path(path: @path,
3665+
+xray: XrayFlag,
3666+
namespace: Namespace)
36443667
-> option<def> {
36453668

36463669
let module_path_atoms = self.intern_module_part_of_path(path);
@@ -3650,7 +3673,8 @@ class Resolver {
36503673
let mut containing_module;
36513674
alt self.resolve_module_path_from_root(root_module,
36523675
module_path_atoms,
3653-
0u) {
3676+
0u,
3677+
xray) {
36543678

36553679
Failed {
36563680
self.session.span_err(path.span,

0 commit comments

Comments
 (0)