Skip to content

Commit a97927b

Browse files
committed
---
yaml --- r: 275637 b: refs/heads/master c: 9bba290 h: refs/heads/master i: 275635: 83ea178
1 parent d8b44f2 commit a97927b

File tree

6 files changed

+150
-119
lines changed

6 files changed

+150
-119
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 02538d463a350f5c3658f7aabefca16eb599d31c
2+
refs/heads/master: 9bba2907ee712753e44d7e248560031c190724e0
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
44
refs/heads/try: 49312a405e14a449b98fe0056b12a40ac128be4a
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

trunk/src/bootstrap/rustc.rs

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,15 @@ fn main() {
3636
let args = env::args_os().skip(1).collect::<Vec<_>>();
3737
// Detect whether or not we're a build script depending on whether --target
3838
// is passed (a bit janky...)
39-
let is_build_script = args.iter()
40-
.position(|i| i.to_str() == Some("--target"))
41-
.is_none();
39+
let target = args.windows(2).find(|w| &*w[0] == "--target")
40+
.and_then(|w| w[1].to_str());
4241

4342
// Build scripts always use the snapshot compiler which is guaranteed to be
4443
// able to produce an executable, whereas intermediate compilers may not
4544
// have the standard library built yet and may not be able to produce an
4645
// executable. Otherwise we just use the standard compiler we're
4746
// bootstrapping with.
48-
let rustc = if is_build_script {
47+
let rustc = if target.is_none() {
4948
env::var_os("RUSTC_SNAPSHOT").unwrap()
5049
} else {
5150
env::var_os("RUSTC_REAL").unwrap()
@@ -55,7 +54,7 @@ fn main() {
5554
cmd.args(&args)
5655
.arg("--cfg").arg(format!("stage{}", env::var("RUSTC_STAGE").unwrap()));
5756

58-
if is_build_script {
57+
if target.is_none() {
5958
// Build scripts are always built with the snapshot compiler, so we need
6059
// to be sure to set up the right path information for the OS dynamic
6160
// linker to find the libraries in question.
@@ -85,19 +84,57 @@ fn main() {
8584

8685
// Set various options from config.toml to configure how we're building
8786
// code.
88-
if env::var("RUSTC_DEBUGINFO") == Ok("true".to_string()) {
89-
cmd.arg("-g");
90-
}
91-
if env::var("RUSTC_RPATH") == Ok("true".to_string()) {
92-
cmd.arg("-Crpath");
93-
}
94-
let debug_assertions = match env::var("RUSTC_DEBUG_ASSERTIONS") {
95-
Ok(s) => if s == "true" {"y"} else {"n"},
96-
Err(..) => "n",
97-
};
98-
cmd.arg("-C").arg(format!("debug-assertions={}", debug_assertions));
99-
if let Ok(s) = env::var("RUSTC_CODEGEN_UNITS") {
100-
cmd.arg("-C").arg(format!("codegen-units={}", s));
87+
if let Some(target) = target {
88+
if env::var("RUSTC_DEBUGINFO") == Ok("true".to_string()) {
89+
cmd.arg("-g");
90+
}
91+
let debug_assertions = match env::var("RUSTC_DEBUG_ASSERTIONS") {
92+
Ok(s) => if s == "true" {"y"} else {"n"},
93+
Err(..) => "n",
94+
};
95+
cmd.arg("-C").arg(format!("debug-assertions={}", debug_assertions));
96+
if let Ok(s) = env::var("RUSTC_CODEGEN_UNITS") {
97+
cmd.arg("-C").arg(format!("codegen-units={}", s));
98+
}
99+
100+
// Dealing with rpath here is a little special, so let's go into some
101+
// detail. First off, `-rpath` is a linker option on Unix platforms
102+
// which adds to the runtime dynamic loader path when looking for
103+
// dynamic libraries. We use this by default on Unix platforms to ensure
104+
// that our nightlies behave the same on Windows, that is they work out
105+
// of the box. This can be disabled, of course, but basically that's why
106+
// we're gated on RUSTC_RPATH here.
107+
//
108+
// Ok, so the astute might be wondering "why isn't `-C rpath` used
109+
// here?" and that is indeed a good question to task. This codegen
110+
// option is the compiler's current interface to generating an rpath.
111+
// Unfortunately it doesn't quite suffice for us. The flag currently
112+
// takes no value as an argument, so the compiler calculates what it
113+
// should pass to the linker as `-rpath`. This unfortunately is based on
114+
// the **compile time** directory structure which when building with
115+
// Cargo will be very different than the runtime directory structure.
116+
//
117+
// All that's a really long winded way of saying that if we use
118+
// `-Crpath` then the executables generated have the wrong rpath of
119+
// something like `$ORIGIN/deps` when in fact the way we distribute
120+
// rustc requires the rpath to be `$ORIGIN/../lib`.
121+
//
122+
// So, all in all, to set up the correct rpath we pass the linker
123+
// argument manually via `-C link-args=-Wl,-rpath,...`. Plus isn't it
124+
// fun to pass a flag to a tool to pass a flag to pass a flag to a tool
125+
// to change a flag in a binary?
126+
if env::var("RUSTC_RPATH") == Ok("true".to_string()) {
127+
let rpath = if target.contains("apple") {
128+
Some("-Wl,-rpath,@loader_path/../lib")
129+
} else if !target.contains("windows") {
130+
Some("-Wl,-rpath,$ORIGIN/../lib")
131+
} else {
132+
None
133+
};
134+
if let Some(rpath) = rpath {
135+
cmd.arg("-C").arg(format!("link-args={}", rpath));
136+
}
137+
}
101138
}
102139

103140
// Actually run the compiler!

trunk/src/libcore/char.rs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,20 @@ impl CharExt for char {
299299

300300
#[inline]
301301
fn escape_unicode(self) -> EscapeUnicode {
302-
EscapeUnicode { c: self, state: EscapeUnicodeState::Backslash }
302+
let c = self as u32;
303+
304+
// or-ing 1 ensures that for c==0 the code computes that one
305+
// digit should be printed and (which is the same) avoids the
306+
// (31 - 32) underflow
307+
let msb = 31 - (c | 1).leading_zeros();
308+
309+
// the index of the most significant hex digit
310+
let ms_hex_digit = msb / 4;
311+
EscapeUnicode {
312+
c: self,
313+
state: EscapeUnicodeState::Backslash,
314+
hex_digit_idx: ms_hex_digit as usize,
315+
}
303316
}
304317

305318
#[inline]
@@ -392,15 +405,20 @@ impl CharExt for char {
392405
#[stable(feature = "rust1", since = "1.0.0")]
393406
pub struct EscapeUnicode {
394407
c: char,
395-
state: EscapeUnicodeState
408+
state: EscapeUnicodeState,
409+
410+
// The index of the next hex digit to be printed (0 if none),
411+
// i.e. the number of remaining hex digits to be printed;
412+
// increasing from the least significant digit: 0x543210
413+
hex_digit_idx: usize,
396414
}
397415

398416
#[derive(Clone, Debug)]
399417
enum EscapeUnicodeState {
400418
Backslash,
401419
Type,
402420
LeftBrace,
403-
Value(usize),
421+
Value,
404422
RightBrace,
405423
Done,
406424
}
@@ -420,19 +438,16 @@ impl Iterator for EscapeUnicode {
420438
Some('u')
421439
}
422440
EscapeUnicodeState::LeftBrace => {
423-
let mut n = 0;
424-
while (self.c as u32) >> (4 * (n + 1)) != 0 {
425-
n += 1;
426-
}
427-
self.state = EscapeUnicodeState::Value(n);
441+
self.state = EscapeUnicodeState::Value;
428442
Some('{')
429443
}
430-
EscapeUnicodeState::Value(offset) => {
431-
let c = from_digit(((self.c as u32) >> (offset * 4)) & 0xf, 16).unwrap();
432-
if offset == 0 {
444+
EscapeUnicodeState::Value => {
445+
let hex_digit = ((self.c as u32) >> (self.hex_digit_idx * 4)) & 0xf;
446+
let c = from_digit(hex_digit, 16).unwrap();
447+
if self.hex_digit_idx == 0 {
433448
self.state = EscapeUnicodeState::RightBrace;
434449
} else {
435-
self.state = EscapeUnicodeState::Value(offset - 1);
450+
self.hex_digit_idx -= 1;
436451
}
437452
Some(c)
438453
}
@@ -445,18 +460,15 @@ impl Iterator for EscapeUnicode {
445460
}
446461

447462
fn size_hint(&self) -> (usize, Option<usize>) {
448-
let mut n = 0;
449-
while (self.c as usize) >> (4 * (n + 1)) != 0 {
450-
n += 1;
451-
}
452463
let n = match self.state {
453-
EscapeUnicodeState::Backslash => n + 5,
454-
EscapeUnicodeState::Type => n + 4,
455-
EscapeUnicodeState::LeftBrace => n + 3,
456-
EscapeUnicodeState::Value(offset) => offset + 2,
464+
EscapeUnicodeState::Backslash => 5,
465+
EscapeUnicodeState::Type => 4,
466+
EscapeUnicodeState::LeftBrace => 3,
467+
EscapeUnicodeState::Value => 2,
457468
EscapeUnicodeState::RightBrace => 1,
458469
EscapeUnicodeState::Done => 0,
459470
};
471+
let n = n + self.hex_digit_idx;
460472
(n, Some(n))
461473
}
462474
}

trunk/src/librustc_resolve/build_reduced_graph.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,9 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
177177
}
178178

179179
let subclass = ImportDirectiveSubclass::single(binding, source_name);
180+
let span = view_path.span;
181+
parent.add_import_directive(module_path, subclass, span, item.id, vis);
180182
self.unresolved_imports += 1;
181-
parent.add_import_directive(module_path,
182-
subclass,
183-
view_path.span,
184-
item.id,
185-
vis,
186-
is_prelude);
187183
}
188184
ViewPathList(_, ref source_items) => {
189185
// Make sure there's at most one `mod` import in the list.
@@ -228,23 +224,16 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
228224
}
229225
};
230226
let subclass = ImportDirectiveSubclass::single(rename, name);
227+
let (span, id) = (source_item.span, source_item.node.id());
228+
parent.add_import_directive(module_path, subclass, span, id, vis);
231229
self.unresolved_imports += 1;
232-
parent.add_import_directive(module_path,
233-
subclass,
234-
source_item.span,
235-
source_item.node.id(),
236-
vis,
237-
is_prelude);
238230
}
239231
}
240232
ViewPathGlob(_) => {
233+
let subclass = GlobImport { is_prelude: is_prelude };
234+
let span = view_path.span;
235+
parent.add_import_directive(module_path, subclass, span, item.id, vis);
241236
self.unresolved_imports += 1;
242-
parent.add_import_directive(module_path,
243-
GlobImport,
244-
view_path.span,
245-
item.id,
246-
vis,
247-
is_prelude);
248237
}
249238
}
250239
}
@@ -271,7 +260,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
271260
let def = Def::Mod(self.ast_map.local_def_id(item.id));
272261
let module = self.new_module(parent_link, Some(def), false, vis);
273262
self.define(parent, name, TypeNS, (module, sp));
274-
parent.module_children.borrow_mut().insert(item.id, module);
263+
self.module_map.insert(item.id, module);
275264
*parent_ref = module;
276265
}
277266

@@ -409,7 +398,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
409398

410399
let parent_link = BlockParentLink(parent, block_id);
411400
let new_module = self.new_module(parent_link, None, false, parent.vis);
412-
parent.module_children.borrow_mut().insert(block_id, new_module);
401+
self.module_map.insert(block_id, new_module);
413402
*parent = new_module;
414403
}
415404
}

trunk/src/librustc_resolve/lib.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -827,22 +827,6 @@ pub struct ModuleS<'a> {
827827
resolutions: RefCell<HashMap<(Name, Namespace), &'a RefCell<NameResolution<'a>>>>,
828828
unresolved_imports: RefCell<Vec<&'a ImportDirective<'a>>>,
829829

830-
// The module children of this node, including normal modules and anonymous modules.
831-
// Anonymous children are pseudo-modules that are implicitly created around items
832-
// contained within blocks.
833-
//
834-
// For example, if we have this:
835-
//
836-
// fn f() {
837-
// fn g() {
838-
// ...
839-
// }
840-
// }
841-
//
842-
// There will be an anonymous module created around `g` with the ID of the
843-
// entry block for `f`.
844-
module_children: RefCell<NodeMap<Module<'a>>>,
845-
846830
prelude: RefCell<Option<Module<'a>>>,
847831

848832
glob_importers: RefCell<Vec<(Module<'a>, &'a ImportDirective<'a>)>>,
@@ -874,7 +858,6 @@ impl<'a> ModuleS<'a> {
874858
extern_crate_id: None,
875859
resolutions: RefCell::new(HashMap::new()),
876860
unresolved_imports: RefCell::new(Vec::new()),
877-
module_children: RefCell::new(NodeMap()),
878861
prelude: RefCell::new(None),
879862
glob_importers: RefCell::new(Vec::new()),
880863
globs: RefCell::new((Vec::new())),
@@ -1082,6 +1065,22 @@ pub struct Resolver<'a, 'tcx: 'a> {
10821065
export_map: ExportMap,
10831066
trait_map: TraitMap,
10841067

1068+
// A map from nodes to modules, both normal (`mod`) modules and anonymous modules.
1069+
// Anonymous modules are pseudo-modules that are implicitly created around items
1070+
// contained within blocks.
1071+
//
1072+
// For example, if we have this:
1073+
//
1074+
// fn f() {
1075+
// fn g() {
1076+
// ...
1077+
// }
1078+
// }
1079+
//
1080+
// There will be an anonymous module created around `g` with the ID of the
1081+
// entry block for `f`.
1082+
module_map: NodeMap<Module<'a>>,
1083+
10851084
// Whether or not to print error messages. Can be set to true
10861085
// when getting additional info for error message suggestions,
10871086
// so as to avoid printing duplicate errors
@@ -1107,14 +1106,22 @@ pub struct Resolver<'a, 'tcx: 'a> {
11071106

11081107
struct ResolverArenas<'a> {
11091108
modules: arena::TypedArena<ModuleS<'a>>,
1109+
local_modules: RefCell<Vec<Module<'a>>>,
11101110
name_bindings: arena::TypedArena<NameBinding<'a>>,
11111111
import_directives: arena::TypedArena<ImportDirective<'a>>,
11121112
name_resolutions: arena::TypedArena<RefCell<NameResolution<'a>>>,
11131113
}
11141114

11151115
impl<'a> ResolverArenas<'a> {
11161116
fn alloc_module(&'a self, module: ModuleS<'a>) -> Module<'a> {
1117-
self.modules.alloc(module)
1117+
let module = self.modules.alloc(module);
1118+
if module.def_id().map(|def_id| def_id.is_local()).unwrap_or(true) {
1119+
self.local_modules.borrow_mut().push(module);
1120+
}
1121+
module
1122+
}
1123+
fn local_modules(&'a self) -> ::std::cell::Ref<'a, Vec<Module<'a>>> {
1124+
self.local_modules.borrow()
11181125
}
11191126
fn alloc_name_binding(&'a self, name_binding: NameBinding<'a>) -> &'a NameBinding<'a> {
11201127
self.name_bindings.alloc(name_binding)
@@ -1175,6 +1182,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
11751182
freevars_seen: NodeMap(),
11761183
export_map: NodeMap(),
11771184
trait_map: NodeMap(),
1185+
module_map: NodeMap(),
11781186
used_imports: HashSet::new(),
11791187
used_crates: HashSet::new(),
11801188

@@ -1193,6 +1201,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
11931201
fn arenas() -> ResolverArenas<'a> {
11941202
ResolverArenas {
11951203
modules: arena::TypedArena::new(),
1204+
local_modules: RefCell::new(Vec::new()),
11961205
name_bindings: arena::TypedArena::new(),
11971206
import_directives: arena::TypedArena::new(),
11981207
name_resolutions: arena::TypedArena::new(),
@@ -1573,7 +1582,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15731582
fn with_scope<F>(&mut self, id: NodeId, f: F)
15741583
where F: FnOnce(&mut Resolver)
15751584
{
1576-
if let Some(module) = self.current_module.module_children.borrow().get(&id) {
1585+
let module = self.module_map.get(&id).cloned(); // clones a reference
1586+
if let Some(module) = module {
15771587
// Move down in the graph.
15781588
let orig_module = ::std::mem::replace(&mut self.current_module, module);
15791589
self.value_ribs.push(Rib::new(ModuleRibKind(module)));
@@ -2124,8 +2134,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
21242134
debug!("(resolving block) entering block");
21252135
// Move down in the graph, if there's an anonymous module rooted here.
21262136
let orig_module = self.current_module;
2127-
let anonymous_module =
2128-
orig_module.module_children.borrow().get(&block.id).map(|module| *module);
2137+
let anonymous_module = self.module_map.get(&block.id).cloned(); // clones a reference
21292138

21302139
if let Some(anonymous_module) = anonymous_module {
21312140
debug!("(resolving block) found anonymous module, moving down");

0 commit comments

Comments
 (0)