Skip to content

Commit ed9751a

Browse files
committed
Auto merge of #47682 - MaloJaffre:beta-backport, r=alexcrichton
[beta] Backports Cherry-picked into beta: - #47401 - #47494 - #47503 - #47507
2 parents c7037ff + 590924b commit ed9751a

File tree

19 files changed

+374
-84
lines changed

19 files changed

+374
-84
lines changed

src/bootstrap/check.rs

+5
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,11 @@ static HOST_COMPILETESTS: &[Test] = &[
568568
mode: "compile-fail",
569569
suite: "compile-fail-fulldeps",
570570
},
571+
Test {
572+
path: "src/test/incremental-fulldeps",
573+
mode: "incremental",
574+
suite: "incremental-fulldeps",
575+
},
571576
Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
572577
Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
573578

src/librustc/session/mod.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
pub use self::code_stats::{CodeStats, DataTypeKind, FieldInfo};
1212
pub use self::code_stats::{SizeKind, TypeSizeInfo, VariantInfo};
1313

14-
use hir::def_id::{CrateNum, DefIndex};
14+
use hir::def_id::CrateNum;
1515
use ich::Fingerprint;
1616

1717
use lint;
@@ -558,18 +558,16 @@ impl Session {
558558

559559
/// Returns the symbol name for the registrar function,
560560
/// given the crate Svh and the function DefIndex.
561-
pub fn generate_plugin_registrar_symbol(&self, disambiguator: CrateDisambiguator,
562-
index: DefIndex)
561+
pub fn generate_plugin_registrar_symbol(&self,
562+
disambiguator: CrateDisambiguator)
563563
-> String {
564-
format!("__rustc_plugin_registrar__{}_{}", disambiguator.to_fingerprint().to_hex(),
565-
index.as_usize())
564+
format!("__rustc_plugin_registrar_{}__", disambiguator.to_fingerprint().to_hex())
566565
}
567566

568-
pub fn generate_derive_registrar_symbol(&self, disambiguator: CrateDisambiguator,
569-
index: DefIndex)
567+
pub fn generate_derive_registrar_symbol(&self,
568+
disambiguator: CrateDisambiguator)
570569
-> String {
571-
format!("__rustc_derive_registrar__{}_{}", disambiguator.to_fingerprint().to_hex(),
572-
index.as_usize())
570+
format!("__rustc_derive_registrar_{}__", disambiguator.to_fingerprint().to_hex())
573571
}
574572

575573
pub fn sysroot<'a>(&'a self) -> &'a Path {

src/librustc_metadata/creader.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use locator::{self, CratePaths};
1515
use native_libs::relevant_lib;
1616
use schema::CrateRoot;
1717

18-
use rustc::hir::def_id::{CrateNum, DefIndex, CRATE_DEF_INDEX};
18+
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX};
1919
use rustc::hir::svh::Svh;
2020
use rustc::middle::allocator::AllocatorKind;
2121
use rustc::middle::cstore::DepKind;
@@ -532,8 +532,7 @@ impl<'a> CrateLoader<'a> {
532532
Err(err) => self.sess.span_fatal(span, &err),
533533
};
534534

535-
let sym = self.sess.generate_derive_registrar_symbol(root.disambiguator,
536-
root.macro_derive_registrar.unwrap());
535+
let sym = self.sess.generate_derive_registrar_symbol(root.disambiguator);
537536
let registrar = unsafe {
538537
let sym = match lib.symbol(&sym) {
539538
Ok(f) => f,
@@ -588,7 +587,7 @@ impl<'a> CrateLoader<'a> {
588587
pub fn find_plugin_registrar(&mut self,
589588
span: Span,
590589
name: &str)
591-
-> Option<(PathBuf, CrateDisambiguator, DefIndex)> {
590+
-> Option<(PathBuf, CrateDisambiguator)> {
592591
let name = Symbol::intern(name);
593592
let ekrate = self.read_extension_crate(span, name, name);
594593

@@ -603,11 +602,11 @@ impl<'a> CrateLoader<'a> {
603602
}
604603

605604
let root = ekrate.metadata.get_root();
606-
match (ekrate.dylib.as_ref(), root.plugin_registrar_fn) {
607-
(Some(dylib), Some(reg)) => {
608-
Some((dylib.to_path_buf(), root.disambiguator, reg))
605+
match ekrate.dylib.as_ref() {
606+
Some(dylib) => {
607+
Some((dylib.to_path_buf(), root.disambiguator))
609608
}
610-
(None, Some(_)) => {
609+
None => {
611610
span_err!(self.sess, span, E0457,
612611
"plugin `{}` only found in rlib format, but must be available \
613612
in dylib format",
@@ -616,7 +615,6 @@ impl<'a> CrateLoader<'a> {
616615
// empty dylib.
617616
None
618617
}
619-
_ => None,
620618
}
621619
}
622620

src/librustc_mir/build/matches/test.rs

+51-23
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,50 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
174174
}
175175
}
176176

177+
/// Convert a byte array or byte slice to a byte slice.
178+
fn to_slice_operand(&mut self,
179+
block: BasicBlock,
180+
source_info: SourceInfo,
181+
operand: Operand<'tcx>)
182+
-> Operand<'tcx>
183+
{
184+
let tcx = self.hir.tcx();
185+
let ty = operand.ty(&self.local_decls, tcx);
186+
debug!("to_slice_operand({:?}, {:?}: {:?})", block, operand, ty);
187+
match ty.sty {
188+
ty::TyRef(region, mt) => match mt.ty.sty {
189+
ty::TyArray(ety, _) => {
190+
let ty = tcx.mk_imm_ref(region, tcx.mk_slice(ety));
191+
let temp = self.temp(ty, source_info.span);
192+
self.cfg.push_assign(block, source_info, &temp,
193+
Rvalue::Cast(CastKind::Unsize, operand, ty));
194+
Operand::Move(temp)
195+
}
196+
ty::TySlice(_) => operand,
197+
_ => {
198+
span_bug!(source_info.span,
199+
"bad operand {:?}: {:?} to `to_slice_operand`", operand, ty)
200+
}
201+
}
202+
_ => {
203+
span_bug!(source_info.span,
204+
"bad operand {:?}: {:?} to `to_slice_operand`", operand, ty)
205+
}
206+
}
207+
208+
}
209+
177210
/// Generates the code to perform a test.
178211
pub fn perform_test(&mut self,
179212
block: BasicBlock,
180213
place: &Place<'tcx>,
181214
test: &Test<'tcx>)
182215
-> Vec<BasicBlock> {
216+
debug!("perform_test({:?}, {:?}: {:?}, {:?})",
217+
block,
218+
place,
219+
place.ty(&self.local_decls, self.hir.tcx()),
220+
test);
183221
let source_info = self.source_info(test.span);
184222
match test.kind {
185223
TestKind::Switch { adt_def, ref variants } => {
@@ -258,45 +296,35 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
258296
ret
259297
}
260298

261-
TestKind::Eq { value, mut ty } => {
299+
TestKind::Eq { value, ty } => {
300+
let tcx = self.hir.tcx();
262301
let mut val = Operand::Copy(place.clone());
263302

264303
// If we're using b"..." as a pattern, we need to insert an
265304
// unsizing coercion, as the byte string has the type &[u8; N].
266-
let expect = if let ConstVal::ByteStr(bytes) = value.val {
267-
let tcx = self.hir.tcx();
268-
269-
// Unsize the place to &[u8], too, if necessary.
270-
if let ty::TyRef(region, mt) = ty.sty {
271-
if let ty::TyArray(_, _) = mt.ty.sty {
272-
ty = tcx.mk_imm_ref(region, tcx.mk_slice(tcx.types.u8));
273-
let val_slice = self.temp(ty, test.span);
274-
self.cfg.push_assign(block, source_info, &val_slice,
275-
Rvalue::Cast(CastKind::Unsize, val, ty));
276-
val = Operand::Move(val_slice);
277-
}
278-
}
279-
280-
assert!(ty.is_slice());
281-
305+
//
306+
// We want to do this even when the scrutinee is a reference to an
307+
// array, so we can call `<[u8]>::eq` rather than having to find an
308+
// `<[u8; N]>::eq`.
309+
let (expect, val) = if let ConstVal::ByteStr(bytes) = value.val {
282310
let array_ty = tcx.mk_array(tcx.types.u8, bytes.data.len() as u64);
283311
let array_ref = tcx.mk_imm_ref(tcx.types.re_static, array_ty);
284312
let array = self.literal_operand(test.span, array_ref, Literal::Value {
285313
value
286314
});
287315

288-
let slice = self.temp(ty, test.span);
289-
self.cfg.push_assign(block, source_info, &slice,
290-
Rvalue::Cast(CastKind::Unsize, array, ty));
291-
Operand::Move(slice)
316+
let val = self.to_slice_operand(block, source_info, val);
317+
let slice = self.to_slice_operand(block, source_info, array);
318+
(slice, val)
292319
} else {
293-
self.literal_operand(test.span, ty, Literal::Value {
320+
(self.literal_operand(test.span, ty, Literal::Value {
294321
value
295-
})
322+
}), val)
296323
};
297324

298325
// Use PartialEq::eq for &str and &[u8] slices, instead of BinOp::Eq.
299326
let fail = self.cfg.start_new_block();
327+
let ty = expect.ty(&self.local_decls, tcx);
300328
if let ty::TyRef(_, mt) = ty.sty {
301329
assert!(ty.is_slice());
302330
let eq_def_id = self.hir.tcx().lang_items().eq_trait().unwrap();

src/librustc_plugin/load.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ impl<'a> PluginLoader<'a> {
100100
fn load_plugin(&mut self, span: Span, name: &str, args: Vec<ast::NestedMetaItem>) {
101101
let registrar = self.reader.find_plugin_registrar(span, name);
102102

103-
if let Some((lib, disambiguator, index)) = registrar {
104-
let symbol = self.sess.generate_plugin_registrar_symbol(disambiguator, index);
103+
if let Some((lib, disambiguator)) = registrar {
104+
let symbol = self.sess.generate_plugin_registrar_symbol(disambiguator);
105105
let fun = self.dylink_registrar(span, lib, symbol);
106106
self.plugins.push(PluginRegistrar {
107107
fun,

src/librustc_trans/abi.rs

-3
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,6 @@ impl<'a, 'tcx> ArgType<'tcx> {
608608
}
609609

610610
pub fn store_fn_arg(&self, bcx: &Builder<'a, 'tcx>, idx: &mut usize, dst: PlaceRef<'tcx>) {
611-
if self.pad.is_some() {
612-
*idx += 1;
613-
}
614611
let mut next = || {
615612
let val = llvm::get_param(bcx.llfn(), *idx as c_uint);
616613
*idx += 1;

src/librustc_trans/back/command.rs

+60-12
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,34 @@
1414
use std::ffi::{OsStr, OsString};
1515
use std::fmt;
1616
use std::io;
17+
use std::mem;
1718
use std::process::{self, Output, Child};
1819

20+
#[derive(Clone)]
1921
pub struct Command {
20-
program: OsString,
22+
program: Program,
2123
args: Vec<OsString>,
2224
env: Vec<(OsString, OsString)>,
2325
}
2426

27+
#[derive(Clone)]
28+
enum Program {
29+
Normal(OsString),
30+
CmdBatScript(OsString),
31+
}
32+
2533
impl Command {
2634
pub fn new<P: AsRef<OsStr>>(program: P) -> Command {
27-
Command::_new(program.as_ref())
35+
Command::_new(Program::Normal(program.as_ref().to_owned()))
36+
}
37+
38+
pub fn bat_script<P: AsRef<OsStr>>(program: P) -> Command {
39+
Command::_new(Program::CmdBatScript(program.as_ref().to_owned()))
2840
}
2941

30-
fn _new(program: &OsStr) -> Command {
42+
fn _new(program: Program) -> Command {
3143
Command {
32-
program: program.to_owned(),
44+
program,
3345
args: Vec::new(),
3446
env: Vec::new(),
3547
}
@@ -86,24 +98,60 @@ impl Command {
8698
}
8799

88100
pub fn command(&self) -> process::Command {
89-
let mut ret = process::Command::new(&self.program);
101+
let mut ret = match self.program {
102+
Program::Normal(ref p) => process::Command::new(p),
103+
Program::CmdBatScript(ref p) => {
104+
let mut c = process::Command::new("cmd");
105+
c.arg("/c").arg(p);
106+
c
107+
}
108+
};
90109
ret.args(&self.args);
91110
ret.envs(self.env.clone());
92111
return ret
93112
}
94113

95114
// extensions
96115

97-
pub fn get_program(&self) -> &OsStr {
98-
&self.program
116+
pub fn take_args(&mut self) -> Vec<OsString> {
117+
mem::replace(&mut self.args, Vec::new())
99118
}
100119

101-
pub fn get_args(&self) -> &[OsString] {
102-
&self.args
103-
}
120+
/// Returns a `true` if we're pretty sure that this'll blow OS spawn limits,
121+
/// or `false` if we should attempt to spawn and see what the OS says.
122+
pub fn very_likely_to_exceed_some_spawn_limit(&self) -> bool {
123+
// We mostly only care about Windows in this method, on Unix the limits
124+
// can be gargantuan anyway so we're pretty unlikely to hit them
125+
if cfg!(unix) {
126+
return false
127+
}
104128

105-
pub fn get_env(&self) -> &[(OsString, OsString)] {
106-
&self.env
129+
// Ok so on Windows to spawn a process is 32,768 characters in its
130+
// command line [1]. Unfortunately we don't actually have access to that
131+
// as it's calculated just before spawning. Instead we perform a
132+
// poor-man's guess as to how long our command line will be. We're
133+
// assuming here that we don't have to escape every character...
134+
//
135+
// Turns out though that `cmd.exe` has even smaller limits, 8192
136+
// characters [2]. Linkers can often be batch scripts (for example
137+
// Emscripten, Gecko's current build system) which means that we're
138+
// running through batch scripts. These linkers often just forward
139+
// arguments elsewhere (and maybe tack on more), so if we blow 8192
140+
// bytes we'll typically cause them to blow as well.
141+
//
142+
// Basically as a result just perform an inflated estimate of what our
143+
// command line will look like and test if it's > 8192 (we actually
144+
// test against 6k to artificially inflate our estimate). If all else
145+
// fails we'll fall back to the normal unix logic of testing the OS
146+
// error code if we fail to spawn and automatically re-spawning the
147+
// linker with smaller arguments.
148+
//
149+
// [1]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
150+
// [2]: https://blogs.msdn.microsoft.com/oldnewthing/20031210-00/?p=41553
151+
152+
let estimated_command_line_len =
153+
self.args.iter().map(|a| a.len()).sum::<usize>();
154+
estimated_command_line_len > 1024 * 6
107155
}
108156
}
109157

0 commit comments

Comments
 (0)