Skip to content

Commit 87f8696

Browse files
committed
Allocate HIR on an arena
1 parent c2d381d commit 87f8696

File tree

111 files changed

+2551
-4201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+2551
-4201
lines changed

src/bootstrap/bin/rustc.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,6 @@ fn main() {
258258
}
259259
}
260260

261-
// Force all crates compiled by this compiler to (a) be unstable and (b)
262-
// allow the `rustc_private` feature to link to other unstable crates
263-
// also in the sysroot.
264-
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
265-
cmd.arg("-Z").arg("force-unstable-if-unmarked");
266-
}
267-
268261
if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") {
269262
cmd.arg("--remap-path-prefix").arg(&map);
270263
}
@@ -284,6 +277,13 @@ fn main() {
284277
}
285278
}
286279

280+
// Force all crates compiled by this compiler to (a) be unstable and (b)
281+
// allow the `rustc_private` feature to link to other unstable crates
282+
// also in the sysroot.
283+
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
284+
cmd.arg("-Z").arg("force-unstable-if-unmarked");
285+
}
286+
287287
if env::var_os("RUSTC_PARALLEL_QUERIES").is_some() {
288288
cmd.arg("--cfg").arg("parallel_queries");
289289
}

src/bootstrap/check.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl Step for Std {
4242
true);
4343

4444
let libdir = builder.sysroot_libdir(compiler, target);
45-
add_to_sysroot(&builder, &libdir, &libstd_stamp(builder, compiler, target));
45+
add_to_sysroot(&builder, &libdir, &libstd_stamp(builder, compiler, target), None);
4646
}
4747
}
4848

@@ -87,8 +87,14 @@ impl Step for Rustc {
8787
&librustc_stamp(builder, compiler, target),
8888
true);
8989

90+
let stage_out = builder.build.stage_out(compiler, Mode::Rustc);
9091
let libdir = builder.sysroot_libdir(compiler, target);
91-
add_to_sysroot(&builder, &libdir, &librustc_stamp(builder, compiler, target));
92+
add_to_sysroot(
93+
&builder,
94+
&libdir,
95+
&librustc_stamp(builder, compiler, target),
96+
Some(&stage_out),
97+
);
9298
}
9399
}
94100

@@ -175,7 +181,7 @@ impl Step for Test {
175181
true);
176182

177183
let libdir = builder.sysroot_libdir(compiler, target);
178-
add_to_sysroot(builder, &libdir, &libtest_stamp(builder, compiler, target));
184+
add_to_sysroot(builder, &libdir, &libtest_stamp(builder, compiler, target), None);
179185
}
180186
}
181187

@@ -222,7 +228,7 @@ impl Step for Rustdoc {
222228
true);
223229

224230
let libdir = builder.sysroot_libdir(compiler, target);
225-
add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target));
231+
add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target), None);
226232
builder.cargo(compiler, Mode::ToolRustc, target, "clean");
227233
}
228234
}

src/bootstrap/compile.rs

+38-9
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl Step for StdLink {
211211
target_compiler.host,
212212
target));
213213
let libdir = builder.sysroot_libdir(target_compiler, target);
214-
add_to_sysroot(builder, &libdir, &libstd_stamp(builder, compiler, target));
214+
add_to_sysroot(builder, &libdir, &libstd_stamp(builder, compiler, target), None);
215215

216216
if builder.config.sanitizers && compiler.stage != 0 && target == "x86_64-apple-darwin" {
217217
// The sanitizers are only built in stage1 or above, so the dylibs will
@@ -414,7 +414,7 @@ impl Step for TestLink {
414414
target_compiler.host,
415415
target));
416416
add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target),
417-
&libtest_stamp(builder, compiler, target));
417+
&libtest_stamp(builder, compiler, target), None);
418418

419419
builder.cargo(target_compiler, Mode::ToolTest, target, "clean");
420420
}
@@ -574,8 +574,13 @@ impl Step for RustcLink {
574574
&compiler.host,
575575
target_compiler.host,
576576
target));
577-
add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target),
578-
&librustc_stamp(builder, compiler, target));
577+
let stage_out = builder.build.stage_out(target_compiler, Mode::Rustc);
578+
add_to_sysroot(
579+
builder,
580+
&builder.sysroot_libdir(target_compiler, target),
581+
&librustc_stamp(builder, compiler, target),
582+
if compiler.stage == 0 { Some(&stage_out) } else { None },
583+
);
579584
builder.cargo(target_compiler, Mode::ToolRustc, target, "clean");
580585
}
581586
}
@@ -982,10 +987,26 @@ impl Step for Assemble {
982987
///
983988
/// For a particular stage this will link the file listed in `stamp` into the
984989
/// `sysroot_dst` provided.
985-
pub fn add_to_sysroot(builder: &Builder, sysroot_dst: &Path, stamp: &Path) {
990+
pub fn add_to_sysroot(
991+
builder: &Builder,
992+
sysroot_dst: &Path,
993+
stamp: &Path,
994+
stage_out: Option<&Path>) {
986995
t!(fs::create_dir_all(&sysroot_dst));
987996
for path in builder.read_stamp_file(stamp) {
988-
builder.copy(&path, &sysroot_dst.join(path.file_name().unwrap()));
997+
let file_dir = path.parent().unwrap() // chop off base name
998+
.parent().unwrap() // chop off `release`
999+
.parent().unwrap(); // chop off `release`
1000+
if stage_out == Some(file_dir) {
1001+
// We are copying a build file. We need to add the build triple to it
1002+
let rustlib_dir = sysroot_dst.parent().unwrap() // chop off `lib`
1003+
.parent().unwrap(); // chop off `$target`
1004+
let build_dir = rustlib_dir.join(builder.build.build).join("lib");
1005+
t!(fs::create_dir_all(&build_dir));
1006+
builder.copy(&path, &build_dir.join(path.file_name().unwrap()));
1007+
} else {
1008+
builder.copy(&path, &sysroot_dst.join(path.file_name().unwrap()));
1009+
}
9891010
}
9901011
}
9911012

@@ -1014,8 +1035,12 @@ pub fn run_cargo(builder: &Builder,
10141035
let mut deps = Vec::new();
10151036
let mut toplevel = Vec::new();
10161037
let ok = stream_cargo(builder, cargo, &mut |msg| {
1017-
let filenames = match msg {
1018-
CargoMessage::CompilerArtifact { filenames, .. } => filenames,
1038+
let (filenames, package_id) = match msg {
1039+
CargoMessage::CompilerArtifact {
1040+
filenames,
1041+
package_id,
1042+
..
1043+
} => (filenames, package_id),
10191044
_ => return,
10201045
};
10211046
for filename in filenames {
@@ -1030,8 +1055,12 @@ pub fn run_cargo(builder: &Builder,
10301055
let filename = Path::new(&*filename);
10311056

10321057
// If this was an output file in the "host dir" we don't actually
1033-
// worry about it, it's not relevant for us.
1058+
// worry about it, it's not relevant for us
10341059
if filename.starts_with(&host_root_dir) {
1060+
// Unless it's a proc macro used in the compiler
1061+
if package_id.starts_with("rustc_macros ") {
1062+
deps.push(filename.to_path_buf());
1063+
}
10351064
continue;
10361065
}
10371066

src/libarena/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ path = "lib.rs"
99
crate-type = ["dylib"]
1010

1111
[dependencies]
12-
rustc_data_structures = { path = "../librustc_data_structures" }
12+
rustc_data_structures = { path = "../librustc_data_structures" }
13+
smallvec = { version = "0.6.7", features = ["union", "may_dangle"] }

src/libarena/lib.rs

+47-11
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
#![allow(deprecated)]
2424

2525
extern crate alloc;
26+
extern crate smallvec;
2627
extern crate rustc_data_structures;
2728

2829
use rustc_data_structures::sync::MTLock;
30+
use smallvec::SmallVec;
2931

3032
use std::cell::{Cell, RefCell};
3133
use std::cmp;
@@ -151,6 +153,22 @@ impl<T> TypedArena<T> {
151153
}
152154
}
153155

156+
#[inline]
157+
fn alloc_raw_slice(&self, len: usize) -> *mut T {
158+
assert!(mem::size_of::<T>() != 0);
159+
assert!(len != 0);
160+
161+
let available_capacity_bytes = self.end.get() as usize - self.ptr.get() as usize;
162+
let at_least_bytes = len * mem::size_of::<T>();
163+
if available_capacity_bytes < at_least_bytes {
164+
self.grow(len);
165+
}
166+
167+
let start_ptr = self.ptr.get();
168+
self.ptr.set(unsafe { start_ptr.add(len) });
169+
start_ptr
170+
}
171+
154172
/// Allocates a slice of objects that are copied into the `TypedArena`, returning a mutable
155173
/// reference to it. Will panic if passed a zero-sized types.
156174
///
@@ -163,21 +181,39 @@ impl<T> TypedArena<T> {
163181
where
164182
T: Copy,
165183
{
166-
assert!(mem::size_of::<T>() != 0);
167-
assert!(slice.len() != 0);
184+
unsafe {
185+
let len = slice.len();
186+
let start_ptr = self.alloc_raw_slice(len);
187+
slice.as_ptr().copy_to_nonoverlapping(start_ptr, len);
188+
slice::from_raw_parts_mut(start_ptr, len)
189+
}
190+
}
168191

169-
let available_capacity_bytes = self.end.get() as usize - self.ptr.get() as usize;
170-
let at_least_bytes = slice.len() * mem::size_of::<T>();
171-
if available_capacity_bytes < at_least_bytes {
172-
self.grow(slice.len());
192+
pub fn alloc_from_iter<I: IntoIterator<Item=T>>(&self, iter: I) -> &[T] where T: Clone {
193+
assert!(mem::size_of::<T>() != 0);
194+
let vec: Vec<_> = iter.into_iter().collect();
195+
if vec.is_empty() {
196+
return &[]
197+
}
198+
let vec2 = vec.clone();
199+
for a in vec {
200+
self.alloc(a);
201+
}
202+
let result = &vec2[..] as *const [T];
203+
mem::forget(vec2);// FIXME: Remove
204+
unsafe {
205+
return &*result;
173206
}
174207

208+
// Move the content to the arena by copying and them forgetting the content of the SmallVec
175209
unsafe {
176-
let start_ptr = self.ptr.get();
177-
let arena_slice = slice::from_raw_parts_mut(start_ptr, slice.len());
178-
self.ptr.set(start_ptr.add(arena_slice.len()));
179-
arena_slice.copy_from_slice(slice);
180-
arena_slice
210+
let len = vec.len();
211+
let start_ptr = self.alloc_raw_slice(len);
212+
vec.as_ptr().copy_to_nonoverlapping(start_ptr, len);
213+
mem::forget(vec);// FIXME: Remove
214+
//mem::forget(vec.drain());
215+
216+
slice::from_raw_parts_mut(start_ptr, len)
181217
}
182218
}
183219

src/librustc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ rustc-rayon = "0.1.1"
2222
rustc-rayon-core = "0.1.1"
2323
rustc_apfloat = { path = "../librustc_apfloat" }
2424
rustc_target = { path = "../librustc_target" }
25+
rustc_macros = { path = "../librustc_macros" }
2526
rustc_data_structures = { path = "../librustc_data_structures" }
2627
rustc_errors = { path = "../librustc_errors" }
2728
serialize = { path = "../libserialize" }

0 commit comments

Comments
 (0)