Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ed9751a

Browse files
committedJan 23, 2018
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 7 additions & 9 deletions
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

Lines changed: 7 additions & 9 deletions
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

Lines changed: 51 additions & 23 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 60 additions & 12 deletions
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

‎src/librustc_trans/back/link.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ use std::char;
3636
use std::env;
3737
use std::ffi::OsString;
3838
use std::fmt;
39-
use std::fs::{self, File};
40-
use std::io::{self, Write, BufWriter};
39+
use std::fs;
40+
use std::io::{self, Write};
4141
use std::path::{Path, PathBuf};
4242
use std::process::{Output, Stdio};
4343
use std::str;
@@ -71,9 +71,7 @@ pub fn get_linker(sess: &Session) -> (PathBuf, Command, Vec<(OsString, OsString)
7171
let cmd = |linker: &Path| {
7272
if let Some(linker) = linker.to_str() {
7373
if cfg!(windows) && linker.ends_with(".bat") {
74-
let mut cmd = Command::new("cmd");
75-
cmd.arg("/c").arg(linker);
76-
return cmd
74+
return Command::bat_script(linker)
7775
}
7876
}
7977
Command::new(linker)
@@ -760,26 +758,26 @@ fn exec_linker(sess: &Session, cmd: &mut Command, tmpdir: &Path)
760758
// that contains all the arguments. The theory is that this is then
761759
// accepted on all linkers and the linker will read all its options out of
762760
// there instead of looking at the command line.
763-
match cmd.command().stdout(Stdio::piped()).stderr(Stdio::piped()).spawn() {
764-
Ok(child) => return child.wait_with_output(),
765-
Err(ref e) if command_line_too_big(e) => {}
766-
Err(e) => return Err(e)
761+
if !cmd.very_likely_to_exceed_some_spawn_limit() {
762+
match cmd.command().stdout(Stdio::piped()).stderr(Stdio::piped()).spawn() {
763+
Ok(child) => return child.wait_with_output(),
764+
Err(ref e) if command_line_too_big(e) => {}
765+
Err(e) => return Err(e)
766+
}
767767
}
768768

769-
let file = tmpdir.join("linker-arguments");
770-
let mut cmd2 = Command::new(cmd.get_program());
771-
cmd2.arg(format!("@{}", file.display()));
772-
for &(ref k, ref v) in cmd.get_env() {
773-
cmd2.env(k, v);
774-
}
775-
let mut f = BufWriter::new(File::create(&file)?);
776-
for arg in cmd.get_args() {
777-
writeln!(f, "{}", Escape {
769+
let mut cmd2 = cmd.clone();
770+
let mut args = String::new();
771+
for arg in cmd2.take_args() {
772+
args.push_str(&Escape {
778773
arg: arg.to_str().unwrap(),
779774
is_like_msvc: sess.target.target.options.is_like_msvc,
780-
})?;
775+
}.to_string());
776+
args.push_str("\n");
781777
}
782-
f.into_inner()?;
778+
let file = tmpdir.join("linker-arguments");
779+
fs::write(&file, args.as_bytes())?;
780+
cmd2.arg(format!("@{}", file.display()));
783781
return cmd2.output();
784782

785783
#[cfg(unix)]

‎src/librustc_trans/back/symbol_export.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ pub fn provide(providers: &mut Providers) {
115115

116116
if let Some(id) = tcx.sess.derive_registrar_fn.get() {
117117
let def_id = tcx.hir.local_def_id(id);
118-
let idx = def_id.index;
119118
let disambiguator = tcx.sess.local_crate_disambiguator();
120-
let registrar = tcx.sess.generate_derive_registrar_symbol(disambiguator, idx);
119+
let registrar = tcx.sess.generate_derive_registrar_symbol(disambiguator);
121120
local_crate.push((registrar, Some(def_id), SymbolExportLevel::C));
122121
}
123122

‎src/librustc_trans/back/symbol_names.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,12 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
257257

258258
if let Some(id) = node_id {
259259
if tcx.sess.plugin_registrar_fn.get() == Some(id) {
260-
let idx = def_id.index;
261260
let disambiguator = tcx.sess.local_crate_disambiguator();
262-
return tcx.sess.generate_plugin_registrar_symbol(disambiguator, idx);
261+
return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
263262
}
264263
if tcx.sess.derive_registrar_fn.get() == Some(id) {
265-
let idx = def_id.index;
266264
let disambiguator = tcx.sess.local_crate_disambiguator();
267-
return tcx.sess.generate_derive_registrar_symbol(disambiguator, idx);
265+
return tcx.sess.generate_derive_registrar_symbol(disambiguator);
268266
}
269267
}
270268

‎src/librustc_trans/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#![feature(box_patterns)]
2323
#![feature(box_syntax)]
2424
#![feature(custom_attribute)]
25+
#![feature(fs_read_write)]
2526
#![allow(unused_attributes)]
2627
#![feature(i128_type)]
2728
#![feature(i128)]

‎src/librustc_trans/mir/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ fn arg_local_refs<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
402402
for i in 0..tupled_arg_tys.len() {
403403
let arg = &mircx.fn_ty.args[idx];
404404
idx += 1;
405+
if arg.pad.is_some() {
406+
llarg_idx += 1;
407+
}
405408
arg.store_fn_arg(bcx, &mut llarg_idx, place.project_field(bcx, i));
406409
}
407410

‎src/test/codegen/issue-47278.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// -C no-prepopulate-passes
12+
#![crate_type="staticlib"]
13+
14+
#[repr(C)]
15+
pub struct Foo(u64);
16+
17+
// CHECK: define {{.*}} @foo(
18+
#[no_mangle]
19+
pub extern fn foo(_: Foo) -> Foo { loop {} }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// no-prefer-dynamic
12+
13+
#![crate_type = "proc-macro"]
14+
15+
extern crate proc_macro;
16+
17+
use proc_macro::TokenStream;
18+
19+
// Add a function to shift DefIndex of registrar function
20+
#[cfg(cfail2)]
21+
fn foo() {}
22+
23+
#[proc_macro_derive(IncrementalMacro)]
24+
pub fn derive(input: TokenStream) -> TokenStream {
25+
#[cfg(cfail2)]
26+
{
27+
foo();
28+
}
29+
30+
"".parse().unwrap()
31+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:incremental_proc_macro_aux.rs
12+
// ignore-stage1
13+
// revisions: cfail1 cfail2
14+
// must-compile-successfully
15+
16+
// This test makes sure that we still find the proc-macro registrar function
17+
// when we compile proc-macros incrementally (see #47292).
18+
19+
#![crate_type = "rlib"]
20+
21+
#[macro_use]
22+
extern crate incremental_proc_macro_aux;
23+
24+
#[derive(IncrementalMacro)]
25+
pub struct Foo {
26+
x: u32
27+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) foo.rs -g
5+
cp foo.bat $(TMPDIR)/
6+
OUT_DIR="$(TMPDIR)" RUSTC="$(RUSTC_ORIGINAL)" $(call RUN,foo)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
%MY_LINKER% %*
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Like the `long-linker-command-lines` test this test attempts to blow
12+
// a command line limit for running the linker. Unlike that test, however,
13+
// this test is testing `cmd.exe` specifically rather than the OS.
14+
//
15+
// Unfortunately `cmd.exe` has a 8192 limit which is relatively small
16+
// in the grand scheme of things and anyone sripting rustc's linker
17+
// is probably using a `*.bat` script and is likely to hit this limit.
18+
//
19+
// This test uses a `foo.bat` script as the linker which just simply
20+
// delegates back to this program. The compiler should use a lower
21+
// limit for arguments before passing everything via `@`, which
22+
// means that everything should still succeed here.
23+
24+
use std::env;
25+
use std::fs::{self, File};
26+
use std::io::{BufWriter, Write, Read};
27+
use std::path::PathBuf;
28+
use std::process::Command;
29+
30+
fn main() {
31+
if !cfg!(windows) {
32+
return
33+
}
34+
35+
let tmpdir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
36+
let ok = tmpdir.join("ok");
37+
let not_ok = tmpdir.join("not_ok");
38+
if env::var("YOU_ARE_A_LINKER").is_ok() {
39+
match env::args().find(|a| a.contains("@")) {
40+
Some(file) => { fs::copy(&file[1..], &ok).unwrap(); }
41+
None => { File::create(&not_ok).unwrap(); }
42+
}
43+
return
44+
}
45+
46+
let rustc = env::var_os("RUSTC").unwrap_or("rustc".into());
47+
let me = env::current_exe().unwrap();
48+
let bat = me.parent()
49+
.unwrap()
50+
.join("foo.bat");
51+
let bat_linker = format!("linker={}", bat.display());
52+
for i in (1..).map(|i| i * 10) {
53+
println!("attempt: {}", i);
54+
55+
let file = tmpdir.join("bar.rs");
56+
let mut f = BufWriter::new(File::create(&file).unwrap());
57+
let mut lib_name = String::new();
58+
for _ in 0..i {
59+
lib_name.push_str("foo");
60+
}
61+
for j in 0..i {
62+
writeln!(f, "#[link(name = \"{}{}\")]", lib_name, j).unwrap();
63+
}
64+
writeln!(f, "extern {{}}\nfn main() {{}}").unwrap();
65+
f.into_inner().unwrap();
66+
67+
drop(fs::remove_file(&ok));
68+
drop(fs::remove_file(&not_ok));
69+
let status = Command::new(&rustc)
70+
.arg(&file)
71+
.arg("-C").arg(&bat_linker)
72+
.arg("--out-dir").arg(&tmpdir)
73+
.env("YOU_ARE_A_LINKER", "1")
74+
.env("MY_LINKER", &me)
75+
.status()
76+
.unwrap();
77+
78+
if !status.success() {
79+
panic!("rustc didn't succeed: {}", status);
80+
}
81+
82+
if !ok.exists() {
83+
assert!(not_ok.exists());
84+
continue
85+
}
86+
87+
let mut contents = String::new();
88+
File::open(&ok).unwrap().read_to_string(&mut contents).unwrap();
89+
90+
for j in 0..i {
91+
assert!(contents.contains(&format!("{}{}", lib_name, j)));
92+
}
93+
94+
break
95+
}
96+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
const CURSOR_PARTITION_LABEL: &'static [u8] = b"partition";
12+
const CURSOR_EVENT_TYPE_LABEL: &'static [u8] = b"event_type";
13+
const BYTE_PATTERN: &'static [u8; 5] = b"hello";
14+
15+
fn match_slice(x: &[u8]) -> u32 {
16+
match x {
17+
CURSOR_PARTITION_LABEL => 0,
18+
CURSOR_EVENT_TYPE_LABEL => 1,
19+
_ => 2,
20+
}
21+
}
22+
23+
fn match_array(x: &[u8; 5]) -> bool {
24+
match x {
25+
BYTE_PATTERN => true,
26+
_ => false
27+
}
28+
}
29+
30+
fn main() {
31+
assert_eq!(match_slice(b"abcde"), 2);
32+
assert_eq!(match_slice(b"event_type"), 1);
33+
assert_eq!(match_slice(b"partition"), 0);
34+
35+
assert_eq!(match_array(b"hello"), true);
36+
assert_eq!(match_array(b"hella"), false);
37+
}

0 commit comments

Comments
 (0)
Please sign in to comment.