Skip to content

Commit 1fe3579

Browse files
committed
Auto merge of #125926 - jieyouxu:rollup-46ewsu9, r=jieyouxu
Rollup of 7 pull requests Successful merges: - #122597 (Show files produced by `--emit foo` in json artifact notifications) - #125886 (Migrate run make issue 15460) - #125893 (Handle all GVN binops in a single place.) - #125903 (rustc_span: Inline some hot functions) - #125909 (rustdoc: add a regression test for a former blanket impl synthesis ICE) - #125917 (Create `run-make` `env_var` and `env_var_os` helpers) - #125919 (Remove stray "this") r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8768db9 + b03b3ec commit 1fe3579

File tree

28 files changed

+317
-83
lines changed

28 files changed

+317
-83
lines changed

compiler/rustc_codegen_cranelift/src/driver/aot.rs

+23
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,29 @@ fn produce_final_output_artifacts(
288288
}
289289
}
290290

291+
if sess.opts.json_artifact_notifications {
292+
if codegen_results.modules.len() == 1 {
293+
codegen_results.modules[0].for_each_output(|_path, ty| {
294+
if sess.opts.output_types.contains_key(&ty) {
295+
let descr = ty.shorthand();
296+
// for single cgu file is renamed to drop cgu specific suffix
297+
// so we regenerate it the same way
298+
let path = crate_output.path(ty);
299+
sess.dcx().emit_artifact_notification(path.as_path(), descr);
300+
}
301+
});
302+
} else {
303+
for module in &codegen_results.modules {
304+
module.for_each_output(|path, ty| {
305+
if sess.opts.output_types.contains_key(&ty) {
306+
let descr = ty.shorthand();
307+
sess.dcx().emit_artifact_notification(&path, descr);
308+
}
309+
});
310+
}
311+
}
312+
}
313+
291314
// We leave the following files around by default:
292315
// - #crate#.o
293316
// - #crate#.crate.metadata.o

compiler/rustc_codegen_ssa/src/back/write.rs

+23
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,29 @@ fn produce_final_output_artifacts(
717717
}
718718
}
719719

720+
if sess.opts.json_artifact_notifications {
721+
if compiled_modules.modules.len() == 1 {
722+
compiled_modules.modules[0].for_each_output(|_path, ty| {
723+
if sess.opts.output_types.contains_key(&ty) {
724+
let descr = ty.shorthand();
725+
// for single cgu file is renamed to drop cgu specific suffix
726+
// so we regenerate it the same way
727+
let path = crate_output.path(ty);
728+
sess.dcx().emit_artifact_notification(path.as_path(), descr);
729+
}
730+
});
731+
} else {
732+
for module in &compiled_modules.modules {
733+
module.for_each_output(|path, ty| {
734+
if sess.opts.output_types.contains_key(&ty) {
735+
let descr = ty.shorthand();
736+
sess.dcx().emit_artifact_notification(&path, descr);
737+
}
738+
});
739+
}
740+
}
741+
}
742+
720743
// We leave the following files around by default:
721744
// - #crate#.o
722745
// - #crate#.crate.metadata.o

compiler/rustc_codegen_ssa/src/lib.rs

+18
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ pub struct CompiledModule {
106106
pub llvm_ir: Option<PathBuf>, // --emit=llvm-ir, llvm-bc is in bytecode
107107
}
108108

109+
impl CompiledModule {
110+
/// Call `emit` function with every artifact type currently compiled
111+
pub fn for_each_output(&self, mut emit: impl FnMut(&Path, OutputType)) {
112+
if let Some(path) = self.object.as_deref() {
113+
emit(path, OutputType::Object);
114+
}
115+
if let Some(path) = self.bytecode.as_deref() {
116+
emit(path, OutputType::Bitcode);
117+
}
118+
if let Some(path) = self.llvm_ir.as_deref() {
119+
emit(path, OutputType::LlvmAssembly);
120+
}
121+
if let Some(path) = self.assembly.as_deref() {
122+
emit(path, OutputType::Assembly);
123+
}
124+
}
125+
}
126+
109127
pub struct CachedModuleCodegen {
110128
pub name: String,
111129
pub source: WorkProduct,

compiler/rustc_mir_transform/src/dump_mir.rs

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ pub fn emit_mir(tcx: TyCtxt<'_>) -> io::Result<()> {
2828
OutFileName::Real(path) => {
2929
let mut f = io::BufWriter::new(File::create(&path)?);
3030
write_mir_pretty(tcx, None, &mut f)?;
31+
if tcx.sess.opts.json_artifact_notifications {
32+
tcx.dcx().emit_artifact_notification(&path, "mir");
33+
}
3134
}
3235
}
3336
Ok(())

compiler/rustc_mir_transform/src/gvn.rs

+40-30
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ enum Value<'tcx> {
223223
NullaryOp(NullOp<'tcx>, Ty<'tcx>),
224224
UnaryOp(UnOp, VnIndex),
225225
BinaryOp(BinOp, VnIndex, VnIndex),
226-
CheckedBinaryOp(BinOp, VnIndex, VnIndex), // FIXME get rid of this, work like MIR instead
227226
Cast {
228227
kind: CastKind,
229228
value: VnIndex,
@@ -508,17 +507,6 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
508507
let val = self.ecx.binary_op(bin_op, &lhs, &rhs).ok()?;
509508
val.into()
510509
}
511-
CheckedBinaryOp(bin_op, lhs, rhs) => {
512-
let lhs = self.evaluated[lhs].as_ref()?;
513-
let lhs = self.ecx.read_immediate(lhs).ok()?;
514-
let rhs = self.evaluated[rhs].as_ref()?;
515-
let rhs = self.ecx.read_immediate(rhs).ok()?;
516-
let val = self
517-
.ecx
518-
.binary_op(bin_op.wrapping_to_overflowing().unwrap(), &lhs, &rhs)
519-
.ok()?;
520-
val.into()
521-
}
522510
Cast { kind, value, from: _, to } => match kind {
523511
CastKind::IntToInt | CastKind::IntToFloat => {
524512
let value = self.evaluated[value].as_ref()?;
@@ -829,17 +817,10 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
829817
let lhs = lhs?;
830818
let rhs = rhs?;
831819

832-
if let Some(op) = op.overflowing_to_wrapping() {
833-
if let Some(value) = self.simplify_binary(op, true, ty, lhs, rhs) {
834-
return Some(value);
835-
}
836-
Value::CheckedBinaryOp(op, lhs, rhs)
837-
} else {
838-
if let Some(value) = self.simplify_binary(op, false, ty, lhs, rhs) {
839-
return Some(value);
840-
}
841-
Value::BinaryOp(op, lhs, rhs)
820+
if let Some(value) = self.simplify_binary(op, ty, lhs, rhs) {
821+
return Some(value);
842822
}
823+
Value::BinaryOp(op, lhs, rhs)
843824
}
844825
Rvalue::UnaryOp(op, ref mut arg) => {
845826
let arg = self.simplify_operand(arg, location)?;
@@ -970,7 +951,6 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
970951
fn simplify_binary(
971952
&mut self,
972953
op: BinOp,
973-
checked: bool,
974954
lhs_ty: Ty<'tcx>,
975955
lhs: VnIndex,
976956
rhs: VnIndex,
@@ -999,22 +979,39 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
999979
use Either::{Left, Right};
1000980
let a = as_bits(lhs).map_or(Right(lhs), Left);
1001981
let b = as_bits(rhs).map_or(Right(rhs), Left);
982+
1002983
let result = match (op, a, b) {
1003984
// Neutral elements.
1004-
(BinOp::Add | BinOp::BitOr | BinOp::BitXor, Left(0), Right(p))
985+
(
986+
BinOp::Add
987+
| BinOp::AddWithOverflow
988+
| BinOp::AddUnchecked
989+
| BinOp::BitOr
990+
| BinOp::BitXor,
991+
Left(0),
992+
Right(p),
993+
)
1005994
| (
1006995
BinOp::Add
996+
| BinOp::AddWithOverflow
997+
| BinOp::AddUnchecked
1007998
| BinOp::BitOr
1008999
| BinOp::BitXor
10091000
| BinOp::Sub
1001+
| BinOp::SubWithOverflow
1002+
| BinOp::SubUnchecked
10101003
| BinOp::Offset
10111004
| BinOp::Shl
10121005
| BinOp::Shr,
10131006
Right(p),
10141007
Left(0),
10151008
)
1016-
| (BinOp::Mul, Left(1), Right(p))
1017-
| (BinOp::Mul | BinOp::Div, Right(p), Left(1)) => p,
1009+
| (BinOp::Mul | BinOp::MulWithOverflow | BinOp::MulUnchecked, Left(1), Right(p))
1010+
| (
1011+
BinOp::Mul | BinOp::MulWithOverflow | BinOp::MulUnchecked | BinOp::Div,
1012+
Right(p),
1013+
Left(1),
1014+
) => p,
10181015
// Attempt to simplify `x & ALL_ONES` to `x`, with `ALL_ONES` depending on type size.
10191016
(BinOp::BitAnd, Right(p), Left(ones)) | (BinOp::BitAnd, Left(ones), Right(p))
10201017
if ones == layout.size.truncate(u128::MAX)
@@ -1023,10 +1020,21 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
10231020
p
10241021
}
10251022
// Absorbing elements.
1026-
(BinOp::Mul | BinOp::BitAnd, _, Left(0))
1023+
(
1024+
BinOp::Mul | BinOp::MulWithOverflow | BinOp::MulUnchecked | BinOp::BitAnd,
1025+
_,
1026+
Left(0),
1027+
)
10271028
| (BinOp::Rem, _, Left(1))
10281029
| (
1029-
BinOp::Mul | BinOp::Div | BinOp::Rem | BinOp::BitAnd | BinOp::Shl | BinOp::Shr,
1030+
BinOp::Mul
1031+
| BinOp::MulWithOverflow
1032+
| BinOp::MulUnchecked
1033+
| BinOp::Div
1034+
| BinOp::Rem
1035+
| BinOp::BitAnd
1036+
| BinOp::Shl
1037+
| BinOp::Shr,
10301038
Left(0),
10311039
_,
10321040
) => self.insert_scalar(Scalar::from_uint(0u128, layout.size), lhs_ty),
@@ -1038,7 +1046,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
10381046
self.insert_scalar(Scalar::from_uint(ones, layout.size), lhs_ty)
10391047
}
10401048
// Sub/Xor with itself.
1041-
(BinOp::Sub | BinOp::BitXor, a, b) if a == b => {
1049+
(BinOp::Sub | BinOp::SubWithOverflow | BinOp::SubUnchecked | BinOp::BitXor, a, b)
1050+
if a == b =>
1051+
{
10421052
self.insert_scalar(Scalar::from_uint(0u128, layout.size), lhs_ty)
10431053
}
10441054
// Comparison:
@@ -1052,7 +1062,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
10521062
_ => return None,
10531063
};
10541064

1055-
if checked {
1065+
if op.is_overflowing() {
10561066
let false_val = self.insert_bool(false);
10571067
Some(self.insert_tuple(vec![result, false_val]))
10581068
} else {

compiler/rustc_span/src/span_encoding.rs

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ impl Span {
216216

217217
// Returns either syntactic context, if it can be retrieved without taking the interner lock,
218218
// or an index into the interner if it cannot.
219+
#[inline]
219220
fn inline_ctxt(self) -> Result<SyntaxContext, usize> {
220221
Ok(if self.len_with_tag_or_marker != BASE_LEN_INTERNED_MARKER {
221222
if self.len_with_tag_or_marker & PARENT_TAG == 0 {

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,7 @@ impl fmt::Display for IdentPrinter {
22132213
pub struct MacroRulesNormalizedIdent(Ident);
22142214

22152215
impl MacroRulesNormalizedIdent {
2216+
#[inline]
22162217
pub fn new(ident: Ident) -> Self {
22172218
Self(ident.normalize_to_macro_rules())
22182219
}

library/std/src/sys/pal/unix/fs.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1910,8 +1910,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
19101910
// The code below ensures that `FreeOnDrop` is never a null pointer
19111911
unsafe {
19121912
// `copyfile_state_free` returns -1 if the `to` or `from` files
1913-
// cannot be closed. However, this is not considered this an
1914-
// error.
1913+
// cannot be closed. However, this is not considered an error.
19151914
libc::copyfile_state_free(self.0);
19161915
}
19171916
}

src/doc/rustc/src/json.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ Diagnostics have the following format:
217217
Artifact notifications are emitted when the [`--json=artifacts`
218218
flag][option-json] is used. They indicate that a file artifact has been saved
219219
to disk. More information about emit kinds may be found in the [`--emit`
220-
flag][option-emit] documentation.
220+
flag][option-emit] documentation. Notifications can contain more than one file
221+
for each type, for example when using multiple codegen units.
221222

222223
```javascript
223224
{
@@ -229,6 +230,11 @@ flag][option-emit] documentation.
229230
- "link": The generated crate as specified by the crate-type.
230231
- "dep-info": The `.d` file with dependency information in a Makefile-like syntax.
231232
- "metadata": The Rust `.rmeta` file containing metadata about the crate.
233+
- "asm": The `.s` file with generated assembly
234+
- "llvm-ir": The `.ll` file with generated textual LLVM IR
235+
- "llvm-bc": The `.bc` file with generated LLVM bitcode
236+
- "mir": The `.mir` file with rustc's mid-level intermediate representation.
237+
- "obj": The `.o` file with generated native object code
232238
*/
233239
"emit": "link"
234240
}

src/tools/compiletest/src/runtest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3655,6 +3655,7 @@ impl<'test> TestCx<'test> {
36553655
cmd.env("IS_MSVC", "1")
36563656
.env("IS_WINDOWS", "1")
36573657
.env("MSVC_LIB", format!("'{}' -nologo", lib.display()))
3658+
.env("MSVC_LIB_PATH", format!("{}", lib.display()))
36583659
// Note: we diverge from legacy run_make and don't lump `CC` the compiler and
36593660
// default flags together.
36603661
.env("CC_DEFAULT_FLAGS", &cflags)

src/tools/run-make-support/src/cc.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use std::env;
21
use std::path::Path;
32
use std::process::Command;
43

5-
use crate::{bin_name, cygpath_windows, handle_failed_output, is_msvc, is_windows, tmp_dir, uname};
4+
use crate::{
5+
bin_name, cygpath_windows, env_var, handle_failed_output, is_msvc, is_windows, tmp_dir, uname,
6+
};
67

78
/// Construct a new platform-specific C compiler invocation.
89
///
@@ -27,11 +28,11 @@ impl Cc {
2728
/// WARNING: This means that what flags are accepted by the underlying C compile is
2829
/// platform- AND compiler-specific. Consult the relevant docs for `gcc`, `clang` and `mvsc`.
2930
pub fn new() -> Self {
30-
let compiler = env::var("CC").unwrap();
31+
let compiler = env_var("CC");
3132

3233
let mut cmd = Command::new(compiler);
3334

34-
let default_cflags = env::var("CC_DEFAULT_FLAGS").unwrap();
35+
let default_cflags = env_var("CC_DEFAULT_FLAGS");
3536
for flag in default_cflags.split(char::is_whitespace) {
3637
cmd.arg(flag);
3738
}

src/tools/run-make-support/src/clang.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use std::env;
21
use std::path::Path;
32
use std::process::Command;
43

5-
use crate::{bin_name, handle_failed_output, tmp_dir};
4+
use crate::{bin_name, env_var, handle_failed_output, tmp_dir};
65

76
/// Construct a new `clang` invocation. `clang` is not always available for all targets.
87
pub fn clang() -> Clang {
@@ -20,8 +19,7 @@ crate::impl_common_helpers!(Clang);
2019
impl Clang {
2120
/// Construct a new `clang` invocation. `clang` is not always available for all targets.
2221
pub fn new() -> Self {
23-
let clang =
24-
env::var("CLANG").expect("`CLANG` not specified, but this is required to find `clang`");
22+
let clang = env_var("CLANG");
2523
let cmd = Command::new(clang);
2624
Self { cmd }
2725
}

0 commit comments

Comments
 (0)