Skip to content

Fix issue 30063 (reset codegen-units to 1 when necessary) #30208

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

Merged
merged 2 commits into from
Dec 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 46 additions & 1 deletion src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ pub enum OutputType {
DepInfo,
}

impl OutputType {
fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
match *self {
OutputType::Exe |
OutputType::DepInfo => true,
OutputType::Bitcode |
OutputType::Assembly |
OutputType::LlvmAssembly |
OutputType::Object => false,
}
}

fn shorthand(&self) -> &'static str {
match *self {
OutputType::Bitcode => "llvm-bc",
OutputType::Assembly => "asm",
OutputType::LlvmAssembly => "llvm-ir",
OutputType::Object => "obj",
OutputType::Exe => "link",
OutputType::DepInfo => "dep-info",
}
}
}

#[derive(Clone)]
pub struct Options {
// The crate config requested for the session, which may be combined
Expand Down Expand Up @@ -933,7 +957,28 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
output_types.insert(OutputType::Exe, None);
}

let cg = build_codegen_options(matches, color);
let mut cg = build_codegen_options(matches, color);

// Issue #30063: if user requests llvm-related output to one
// particular path, disable codegen-units.
if matches.opt_present("o") && cg.codegen_units != 1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd personally prefer to omit the check here for -o and always execute this logic if codegen_units != 1, that way we maintain equivalence between rustc -o foo foo.rs and rustc foo.rs (for all emit types)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay; I was trying to minimize the impact of the change over the current state of affairs, but I'm willing to concede that the principle of least surprise implies we should adopt the tack you suggest.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcrichton (okay commit 24bc2d2 should address this concern.)

let incompatible: Vec<_> = output_types.iter()
.map(|ot_path| ot_path.0)
.filter(|ot| {
!ot.is_compatible_with_codegen_units_and_single_output_file()
}).collect();
if !incompatible.is_empty() {
for ot in &incompatible {
early_warn(color, &format!("--emit={} with -o incompatible with \
-C codegen-units=N for N > 1",
ot.shorthand()));
}
early_warn(color, "resetting to default -C codegen-units=1");
cg.codegen_units = 1;
}
}

let cg = cg;

let sysroot_opt = matches.opt_str("sysroot").map(|m| PathBuf::from(&m));
let target = matches.opt_str("target").unwrap_or(
Expand Down
35 changes: 35 additions & 0 deletions src/test/run-make/issue-30063/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-include ../tools.mk

all:
rm -f $(TMPDIR)/foo-output
$(RUSTC) -C codegen-units=4 -o $(TMPDIR)/foo-output foo.rs
rm $(TMPDIR)/foo-output

rm -f $(TMPDIR)/asm-output
$(RUSTC) -C codegen-units=4 --emit=asm -o $(TMPDIR)/asm-output foo.rs
rm $(TMPDIR)/asm-output

rm -f $(TMPDIR)/bc-output
$(RUSTC) -C codegen-units=4 --emit=llvm-bc -o $(TMPDIR)/bc-output foo.rs
rm $(TMPDIR)/bc-output

rm -f $(TMPDIR)/ir-output
$(RUSTC) -C codegen-units=4 --emit=llvm-ir -o $(TMPDIR)/ir-output foo.rs
rm $(TMPDIR)/ir-output

rm -f $(TMPDIR)/link-output
$(RUSTC) -C codegen-units=4 --emit=link -o $(TMPDIR)/link-output foo.rs
rm $(TMPDIR)/link-output

rm -f $(TMPDIR)/obj-output
$(RUSTC) -C codegen-units=4 --emit=obj -o $(TMPDIR)/obj-output foo.rs
rm $(TMPDIR)/obj-output

rm -f $(TMPDIR)/dep-output
$(RUSTC) -C codegen-units=4 --emit=dep-info -o $(TMPDIR)/dep-output foo.rs
rm $(TMPDIR)/dep-output

# # (This case doesn't work yet, and may be fundamentally wrong-headed anyway.)
# rm -f $(TMPDIR)/multi-output
# $(RUSTC) -C codegen-units=4 --emit=asm,obj -o $(TMPDIR)/multi-output foo.rs
# rm $(TMPDIR)/multi-output
11 changes: 11 additions & 0 deletions src/test/run-make/issue-30063/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() { }