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 #70348

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 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
c7c2fa1
Make `needs_drop` less pessimistic on generators
jonas-schievink Mar 14, 2020
9ebc72f
Adjust mir-opt test and make it drop something
jonas-schievink Mar 15, 2020
47a84f2
Update tests
Zoxc Feb 6, 2020
1df7641
Fix rebase fallout
jonas-schievink Mar 23, 2020
3ef1dd3
Rollup merge of #68884 - Zoxc:gen-type, r=nikomatsakis
Centril Mar 24, 2020
4c313c7
Rollup merge of #69788 - ArekPiekarz:unstable_book_optin_builtin_trai…
Centril Mar 24, 2020
7df8bba
Rollup merge of #70015 - jonas-schievink:gen-needs-drop, r=matthewjasper
Centril Mar 24, 2020
dd8ef75
Rollup merge of #70077 - Aaron1011:feature/new-def-path-ident, r=petr…
Centril Mar 24, 2020
a62fd3a
Rollup merge of #70213 - eddyb:stalled-on-ty-or-const, r=nikomatsakis
Centril Mar 24, 2020
b306b1e
Rollup merge of #70259 - wesleywiser:use_reveal_all, r=eddyb
Centril Mar 24, 2020
a813cf9
Rollup merge of #70284 - lcnr:issue70273-what-the-heck-git, r=eddyb
Centril Mar 24, 2020
6e587a4
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
8 changes: 3 additions & 5 deletions src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,7 @@ pub fn needs_drop_components(
// Foreign types can never have destructors.
ty::Foreign(..) => Ok(SmallVec::new()),

// Pessimistically assume that all generators will require destructors
// as we don't know if a destructor is a noop or not until after the MIR
// state transformation pass.
ty::Generator(..) | ty::Dynamic(..) | ty::Error => Err(AlwaysRequiresDrop),
ty::Dynamic(..) | ty::Error => Err(AlwaysRequiresDrop),

ty::Slice(ty) => needs_drop_components(ty, target_layout),
ty::Array(elem_ty, size) => {
Expand Down Expand Up @@ -1083,7 +1080,8 @@ pub fn needs_drop_components(
| ty::Placeholder(..)
| ty::Opaque(..)
| ty::Infer(_)
| ty::Closure(..) => Ok(smallvec![ty]),
| ty::Closure(..)
| ty::Generator(..) => Ok(smallvec![ty]),
}
}

Expand Down
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
39 changes: 22 additions & 17 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ use std::thread;

const PRE_LTO_BC_EXT: &str = "pre-lto.bc";

/// The kind of bitcode to embed in object files.
#[derive(PartialEq)]
pub enum EmbedBitcode {
None,
Marker,
Full,
}

/// Module-specific configuration for `optimize_and_codegen`.
pub struct ModuleConfig {
/// Names of additional optimization passes to run.
Expand All @@ -74,7 +82,6 @@ pub struct ModuleConfig {
pub emit_no_opt_bc: bool,
pub emit_bc: bool,
pub emit_bc_compressed: bool,
pub emit_lto_bc: bool,
pub emit_ir: bool,
pub emit_asm: bool,
pub emit_obj: bool,
Expand All @@ -94,8 +101,7 @@ pub struct ModuleConfig {
// emscripten's ecc compiler, when used as the linker.
pub obj_is_bitcode: bool,
pub no_integrated_as: bool,
pub embed_bitcode: bool,
pub embed_bitcode_marker: bool,
pub embed_bitcode: EmbedBitcode,
}

impl ModuleConfig {
Expand All @@ -116,13 +122,11 @@ impl ModuleConfig {
emit_pre_lto_bc: false,
emit_bc: false,
emit_bc_compressed: false,
emit_lto_bc: false,
emit_ir: false,
emit_asm: false,
emit_obj: false,
obj_is_bitcode: false,
embed_bitcode: false,
embed_bitcode_marker: false,
embed_bitcode: EmbedBitcode::None,
no_integrated_as: false,

verify_llvm_ir: false,
Expand All @@ -145,16 +149,15 @@ impl ModuleConfig {
self.new_llvm_pass_manager = sess.opts.debugging_opts.new_llvm_pass_manager;
self.obj_is_bitcode =
sess.target.target.options.obj_is_bitcode || sess.opts.cg.linker_plugin_lto.enabled();
let embed_bitcode =
sess.target.target.options.embed_bitcode || sess.opts.debugging_opts.embed_bitcode;
if embed_bitcode {
match sess.opts.optimize {
config::OptLevel::No | config::OptLevel::Less => {
self.embed_bitcode_marker = embed_bitcode;
self.embed_bitcode =
if sess.target.target.options.embed_bitcode || sess.opts.debugging_opts.embed_bitcode {
match sess.opts.optimize {
config::OptLevel::No | config::OptLevel::Less => EmbedBitcode::Marker,
_ => EmbedBitcode::Full,
}
_ => self.embed_bitcode = embed_bitcode,
}
}
} else {
EmbedBitcode::None
};

// Copy what clang does by turning on loop vectorization at O2 and
// slp vectorization at O3. Otherwise configure other optimization aspects
Expand Down Expand Up @@ -190,7 +193,10 @@ impl ModuleConfig {
}

pub fn bitcode_needed(&self) -> bool {
self.emit_bc || self.obj_is_bitcode || self.emit_bc_compressed || self.embed_bitcode
self.emit_bc
|| self.obj_is_bitcode
|| self.emit_bc_compressed
|| self.embed_bitcode == EmbedBitcode::Full
}
}

Expand Down Expand Up @@ -379,7 +385,6 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
modules_config.emit_no_opt_bc = true;
modules_config.emit_pre_lto_bc = true;
modules_config.emit_bc = true;
modules_config.emit_lto_bc = true;
metadata_config.emit_bc = true;
allocator_config.emit_bc = true;
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_hir/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl DefKind {
}
}

/// The resolution of a path or export.
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
#[derive(HashStable_Generic)]
pub enum Res<Id = hir::HirId> {
Expand Down
Loading