Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #70351

Merged
merged 46 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b90edfc
Fix sequence of Type and Trait in optin-builtin-traits in Unstable Book
ArekPiekarz Mar 6, 2020
c54ce49
Remove unused `ModuleConfig::emit_lto_bc` field.
nnethercote Mar 19, 2020
d8448d2
infer: export methods on `InferCtxt` instead of `ShallowResolver`.
eddyb Mar 21, 2020
40f73e7
traits/fulfill: allow `stalled_on` to track `ty::Const::Infer(_)` (un…
eddyb Mar 21, 2020
78c178b
traits/fulfill: add a couple FIXME comments about potential optimizat…
eddyb Mar 21, 2020
4f40511
Resolve worsened debug build codegen
wesleywiser Mar 22, 2020
61d3be8
Use Reveal::All in MIR inliner
wesleywiser Mar 22, 2020
645fedd
correctly handle const params in type_of
lcnr Mar 22, 2020
d156bf6
Remove some local variables.
nnethercote Mar 20, 2020
47c8f3f
Combine `ModuleConfig::embed_bitcode{,_marker}`.
nnethercote Mar 20, 2020
e4b36ba
Remove an unnecessary block scope.
nnethercote Mar 20, 2020
f8261b4
Factor out a repeated `config.obj_is_bitcode` test.
nnethercote Mar 20, 2020
a147cd0
Introduce a local variable `config_emit_normal_obj`.
nnethercote Mar 20, 2020
ca0f997
Factor out a repeated `config.no_integrated_as` test.
nnethercote Mar 20, 2020
96e2d03
Store idents for `DefPathData` into crate metadata
Aaron1011 Mar 17, 2020
86b8dea
Ignore tests on some platforms due to #53081
Aaron1011 Mar 23, 2020
6a7106c
type_of AnonConst AssocTy does not require parent
lcnr Mar 23, 2020
0a17c4c
fix comment
lcnr Mar 23, 2020
e8f0a64
Make the `type_of` return a generic type for generators
Zoxc Jan 14, 2020
47a84f2
Update tests
Zoxc Feb 6, 2020
0f2d968
rustc_expand::base: nix panictry! uses
Centril Mar 17, 2020
0a8db69
nix panictry! in ParserAnyMacro::make
Centril Mar 17, 2020
b7909b2
nix remaining rustc_expand::panictry! uses.
Centril Mar 17, 2020
b0537e2
generic_extension: defatalize Error case
Centril Mar 17, 2020
35cca74
defatalize BangProcMacro::expand
Centril Mar 17, 2020
ce8880d
defatalize AttrProcMacro::expand
Centril Mar 17, 2020
c1ef1b3
defatalize ProcMacroDerive::expand
Centril Mar 17, 2020
ad26401
remove ExtCxt::struct_span_warn
Centril Mar 17, 2020
df9cec2
mbe::transcribe: defatalize errors.
Centril Mar 17, 2020
1bfa248
defatalize `compile_declarative_macro`
Centril Mar 17, 2020
2868045
expand: nix unused method
Centril Mar 17, 2020
0e0f931
defatalize get_test_runner
Centril Mar 17, 2020
3979964
defatalize expand_test_or_bench
Centril Mar 17, 2020
21944b3
expand: add recovery for parse_nt
Centril Mar 17, 2020
d8080d8
expand: address review comments
Centril Mar 18, 2020
d071035
fix rebase fallout
Centril Mar 20, 2020
c415f12
fix rebase fallout due to #69497.
Centril Mar 21, 2020
470e163
pacify missing sysroot spans issue
Centril Mar 23, 2020
a130954
Rollup merge of #68884 - Zoxc:gen-type, r=nikomatsakis
Centril Mar 24, 2020
0a39964
Rollup merge of #69788 - ArekPiekarz:unstable_book_optin_builtin_trai…
Centril Mar 24, 2020
3d8b961
Rollup merge of #70074 - Centril:unpanictry, r=petrochenkov
Centril Mar 24, 2020
d626f5b
Rollup merge of #70077 - Aaron1011:feature/new-def-path-ident, r=petr…
Centril Mar 24, 2020
7bd86ce
Rollup merge of #70213 - eddyb:stalled-on-ty-or-const, r=nikomatsakis
Centril Mar 24, 2020
0d5b83d
Rollup merge of #70259 - wesleywiser:use_reveal_all, r=eddyb
Centril Mar 24, 2020
d309058
Rollup merge of #70284 - lcnr:issue70273-what-the-heck-git, r=eddyb
Centril Mar 24, 2020
170112c
Rollup merge of #70289 - nnethercote:refactor-codegen, r=eddyb
Centril Mar 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ has explicitly opted out via a negative impl.
[`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html

```rust,ignore
impl !Type for Trait
impl !Trait for Type
```

Example:
Expand Down
9 changes: 7 additions & 2 deletions src/librustc_builtin_macros/cmdline_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use rustc_ast::ast::{self, AttrItem, AttrStyle};
use rustc_ast::attr::mk_attr;
use rustc_ast::token;
use rustc_expand::panictry;
use rustc_session::parse::ParseSess;
use rustc_span::FileName;

Expand All @@ -16,7 +15,13 @@ pub fn inject(mut krate: ast::Crate, parse_sess: &ParseSess, attrs: &[String]) -
);

let start_span = parser.token.span;
let AttrItem { path, args } = panictry!(parser.parse_attr_item());
let AttrItem { path, args } = match parser.parse_attr_item() {
Ok(ai) => ai,
Err(mut err) => {
err.emit();
continue;
}
};
let end_span = parser.token.span;
if parser.token != token::Eof {
parse_sess.span_diagnostic.span_err(start_span.to(end_span), "invalid crate attribute");
Expand Down
24 changes: 11 additions & 13 deletions src/librustc_builtin_macros/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use rustc_ast::tokenstream::TokenStream;
use rustc_ast_pretty::pprust;
use rustc_expand::base::{self, *};
use rustc_expand::module::DirectoryOwnership;
use rustc_expand::panictry;
use rustc_parse::{self, new_parser_from_file, parser::Parser};
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
use rustc_span::symbol::Symbol;
Expand Down Expand Up @@ -126,7 +125,7 @@ pub fn expand_include<'cx>(
}
impl<'a> base::MacResult for ExpandResult<'a> {
fn make_expr(mut self: Box<ExpandResult<'a>>) -> Option<P<ast::Expr>> {
let r = panictry!(self.p.parse_expr());
let r = base::parse_expr(&mut self.p)?;
if self.p.token != token::Eof {
self.p.sess.buffer_lint(
&INCOMPLETE_INCLUDE,
Expand All @@ -141,18 +140,17 @@ pub fn expand_include<'cx>(
fn make_items(mut self: Box<ExpandResult<'a>>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
let mut ret = SmallVec::new();
while self.p.token != token::Eof {
match panictry!(self.p.parse_item()) {
Some(item) => ret.push(item),
None => {
match self.p.parse_item() {
Err(mut err) => {
err.emit();
break;
}
Ok(Some(item)) => ret.push(item),
Ok(None) => {
let token = pprust::token_to_string(&self.p.token);
self.p
.sess
.span_diagnostic
.span_fatal(
self.p.token.span,
&format!("expected item, found `{}`", token),
)
.raise();
let msg = format!("expected item, found `{}`", token);
self.p.struct_span_err(self.p.token.span, &msg).emit();
break;
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_builtin_macros/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ pub fn expand_test_or_bench(
return vec![];
}

let item = if let Annotatable::Item(i) = item {
i
} else {
cx.parse_sess
.span_diagnostic
.span_fatal(
item.span(),
let item = match item {
Annotatable::Item(i) => i,
other => {
cx.struct_span_err(
other.span(),
"`#[test]` attribute is only allowed on non associated functions",
)
.raise();
.emit();
return vec![other];
}
};

if let ast::ItemKind::MacCall(_) = item.kind {
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_builtin_macros/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,14 @@ fn is_test_case(i: &ast::Item) -> bool {

fn get_test_runner(sd: &rustc_errors::Handler, krate: &ast::Crate) -> Option<ast::Path> {
let test_attr = attr::find_by_name(&krate.attrs, sym::test_runner)?;
test_attr.meta_item_list().map(|meta_list| {
if meta_list.len() != 1 {
sd.span_fatal(test_attr.span, "`#![test_runner(..)]` accepts exactly 1 argument")
.raise()
}
match meta_list[0].meta_item() {
Some(meta_item) if meta_item.is_word() => meta_item.path.clone(),
_ => sd.span_fatal(test_attr.span, "`test_runner` argument must be a path").raise(),
}
})
let meta_list = test_attr.meta_item_list()?;
let span = test_attr.span;
match &*meta_list {
[single] => match single.meta_item() {
Some(meta_item) if meta_item.is_word() => return Some(meta_item.path.clone()),
_ => sd.struct_span_err(span, "`test_runner` argument must be a path").emit(),
},
_ => sd.struct_span_err(span, "`#![test_runner(..)]` accepts exactly 1 argument").emit(),
}
None
}
174 changes: 82 additions & 92 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::ModuleLlvm;
use log::debug;
use rustc::bug;
use rustc::ty::TyCtxt;
use rustc_codegen_ssa::back::write::{run_assembler, CodegenContext, ModuleConfig};
use rustc_codegen_ssa::back::write::{run_assembler, CodegenContext, EmbedBitcode, ModuleConfig};
use rustc_codegen_ssa::traits::*;
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen, RLIB_BYTECODE_EXTENSION};
use rustc_data_structures::small_c_str::SmallCStr;
Expand Down Expand Up @@ -634,30 +634,24 @@ pub(crate) unsafe fn codegen(
f(cpm)
}

// If we don't have the integrated assembler, then we need to emit asm
// from LLVM and use `gcc` to create the object file.
let asm_to_obj = config.emit_obj && config.no_integrated_as;

// Change what we write and cleanup based on whether obj files are
// just llvm bitcode. In that case write bitcode, and possibly
// delete the bitcode if it wasn't requested. Don't generate the
// machine code, instead copy the .o file from the .bc
let write_bc = config.emit_bc || config.obj_is_bitcode;
let rm_bc = !config.emit_bc && config.obj_is_bitcode;
let write_obj = config.emit_obj && !config.obj_is_bitcode && !asm_to_obj;
let copy_bc_to_obj = config.emit_obj && config.obj_is_bitcode;
// Two things to note:
// - If object files are just LLVM bitcode we write bitcode, copy it to
// the .o file, and delete the bitcode if it wasn't otherwise
// requested.
// - If we don't have the integrated assembler then we need to emit
// asm from LLVM and use `gcc` to create the object file.

let bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name);
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, module_name);

if write_bc || config.emit_bc_compressed || config.embed_bitcode {
if config.bitcode_needed() {
let _timer = cgcx
.prof
.generic_activity_with_arg("LLVM_module_codegen_make_bitcode", &module.name[..]);
let thin = ThinBuffer::new(llmod);
let data = thin.data();

if write_bc {
if config.emit_bc || config.obj_is_bitcode {
let _timer = cgcx.prof.generic_activity_with_arg(
"LLVM_module_codegen_emit_bitcode",
&module.name[..],
Expand All @@ -668,7 +662,7 @@ pub(crate) unsafe fn codegen(
}
}

if config.embed_bitcode {
if config.embed_bitcode == EmbedBitcode::Full {
let _timer = cgcx.prof.generic_activity_with_arg(
"LLVM_module_codegen_embed_bitcode",
&module.name[..],
Expand All @@ -688,81 +682,75 @@ pub(crate) unsafe fn codegen(
diag_handler.err(&msg);
}
}
} else if config.embed_bitcode_marker {
} else if config.embed_bitcode == EmbedBitcode::Marker {
embed_bitcode(cgcx, llcx, llmod, None);
}

{
if config.emit_ir {
let _timer = cgcx
.prof
.generic_activity_with_arg("LLVM_module_codegen_emit_ir", &module.name[..]);
let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
let out_c = path_to_c_string(&out);

extern "C" fn demangle_callback(
input_ptr: *const c_char,
input_len: size_t,
output_ptr: *mut c_char,
output_len: size_t,
) -> size_t {
let input = unsafe {
slice::from_raw_parts(input_ptr as *const u8, input_len as usize)
};

let input = match str::from_utf8(input) {
Ok(s) => s,
Err(_) => return 0,
};

let output = unsafe {
slice::from_raw_parts_mut(output_ptr as *mut u8, output_len as usize)
};
let mut cursor = io::Cursor::new(output);

let demangled = match rustc_demangle::try_demangle(input) {
Ok(d) => d,
Err(_) => return 0,
};

if write!(cursor, "{:#}", demangled).is_err() {
// Possible only if provided buffer is not big enough
return 0;
}

cursor.position() as size_t
if config.emit_ir {
let _timer = cgcx
.prof
.generic_activity_with_arg("LLVM_module_codegen_emit_ir", &module.name[..]);
let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
let out_c = path_to_c_string(&out);

extern "C" fn demangle_callback(
input_ptr: *const c_char,
input_len: size_t,
output_ptr: *mut c_char,
output_len: size_t,
) -> size_t {
let input =
unsafe { slice::from_raw_parts(input_ptr as *const u8, input_len as usize) };

let input = match str::from_utf8(input) {
Ok(s) => s,
Err(_) => return 0,
};

let output = unsafe {
slice::from_raw_parts_mut(output_ptr as *mut u8, output_len as usize)
};
let mut cursor = io::Cursor::new(output);

let demangled = match rustc_demangle::try_demangle(input) {
Ok(d) => d,
Err(_) => return 0,
};

if write!(cursor, "{:#}", demangled).is_err() {
// Possible only if provided buffer is not big enough
return 0;
}

let result = llvm::LLVMRustPrintModule(llmod, out_c.as_ptr(), demangle_callback);
result.into_result().map_err(|()| {
let msg = format!("failed to write LLVM IR to {}", out.display());
llvm_err(diag_handler, &msg)
})?;
cursor.position() as size_t
}

if config.emit_asm || asm_to_obj {
let _timer = cgcx
.prof
.generic_activity_with_arg("LLVM_module_codegen_emit_asm", &module.name[..]);
let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
let result = llvm::LLVMRustPrintModule(llmod, out_c.as_ptr(), demangle_callback);
result.into_result().map_err(|()| {
let msg = format!("failed to write LLVM IR to {}", out.display());
llvm_err(diag_handler, &msg)
})?;
}

// We can't use the same module for asm and binary output, because that triggers
// various errors like invalid IR or broken binaries, so we might have to clone the
// module to produce the asm output
let llmod = if config.emit_obj { llvm::LLVMCloneModule(llmod) } else { llmod };
with_codegen(tm, llmod, config.no_builtins, |cpm| {
write_output_file(
diag_handler,
tm,
cpm,
llmod,
&path,
llvm::FileType::AssemblyFile,
)
})?;
}
let config_emit_normal_obj = config.emit_obj && !config.obj_is_bitcode;

if write_obj {
if config.emit_asm || (config_emit_normal_obj && config.no_integrated_as) {
let _timer = cgcx
.prof
.generic_activity_with_arg("LLVM_module_codegen_emit_asm", &module.name[..]);
let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);

// We can't use the same module for asm and binary output, because that triggers
// various errors like invalid IR or broken binaries, so we might have to clone the
// module to produce the asm output
let llmod = if config.emit_obj { llvm::LLVMCloneModule(llmod) } else { llmod };
with_codegen(tm, llmod, config.no_builtins, |cpm| {
write_output_file(diag_handler, tm, cpm, llmod, &path, llvm::FileType::AssemblyFile)
})?;
}

if config_emit_normal_obj {
if !config.no_integrated_as {
let _timer = cgcx
.prof
.generic_activity_with_arg("LLVM_module_codegen_emit_obj", &module.name[..]);
Expand All @@ -776,7 +764,7 @@ pub(crate) unsafe fn codegen(
llvm::FileType::ObjectFile,
)
})?;
} else if asm_to_obj {
} else {
let _timer = cgcx
.prof
.generic_activity_with_arg("LLVM_module_codegen_asm_to_obj", &module.name[..]);
Expand All @@ -789,17 +777,19 @@ pub(crate) unsafe fn codegen(
}
}

if copy_bc_to_obj {
debug!("copying bitcode {:?} to obj {:?}", bc_out, obj_out);
if let Err(e) = link_or_copy(&bc_out, &obj_out) {
diag_handler.err(&format!("failed to copy bitcode to object file: {}", e));
if config.obj_is_bitcode {
if config.emit_obj {
debug!("copying bitcode {:?} to obj {:?}", bc_out, obj_out);
if let Err(e) = link_or_copy(&bc_out, &obj_out) {
diag_handler.err(&format!("failed to copy bitcode to object file: {}", e));
}
}
}

if rm_bc {
debug!("removing_bitcode {:?}", bc_out);
if let Err(e) = fs::remove_file(&bc_out) {
diag_handler.err(&format!("failed to remove bitcode: {}", e));
if !config.emit_bc {
debug!("removing_bitcode {:?}", bc_out);
if let Err(e) = fs::remove_file(&bc_out) {
diag_handler.err(&format!("failed to remove bitcode: {}", e));
}
}
}

Expand Down
Loading