Skip to content

Commit 0a51f1d

Browse files
committed
Auto merge of rust-lang#116902 - matthiaskrgr:rollup-8binpfx, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#116493 (Bump `COINDUCTIVE_OVERLAP_IN_COHERENCE` to deny + warn in deps) - rust-lang#116837 (Avoid having `rustc_smir` depend on `rustc_interface` or `rustc_driver`) - rust-lang#116883 (Change my name in mailmap) - rust-lang#116896 (Only check in a single place if a pass is enabled.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents cc705b8 + 64e0e6b commit 0a51f1d

File tree

12 files changed

+158
-88
lines changed

12 files changed

+158
-88
lines changed

.mailmap

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Benoît Cortier <benoit.cortier@fried-world.eu>
7474
Bheesham Persaud <bheesham123@hotmail.com> Bheesham Persaud <bheesham.persaud@live.ca>
7575
Björn Steinbrink <bsteinbr@gmail.com> <B.Steinbrink@gmx.de>
7676
blake2-ppc <ulrik.sverdrup@gmail.com> <blake2-ppc>
77+
blyxyas <blyxyas@gmail.com> Alejandra González <blyxyas@gmail.com>
7778
boolean_coercion <booleancoercion@gmail.com>
7879
Boris Egorov <jightuse@gmail.com> <egorov@linux.com>
7980
bors <bors@rust-lang.org> bors[bot] <26634292+bors[bot]@users.noreply.github.com>

Cargo.lock

-2
Original file line numberDiff line numberDiff line change
@@ -4482,9 +4482,7 @@ name = "rustc_smir"
44824482
version = "0.0.0"
44834483
dependencies = [
44844484
"rustc_data_structures",
4485-
"rustc_driver",
44864485
"rustc_hir",
4487-
"rustc_interface",
44884486
"rustc_middle",
44894487
"rustc_span",
44904488
"rustc_target",

compiler/rustc_lint_defs/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4449,11 +4449,11 @@ declare_lint! {
44494449
/// on itself), the blanket impl is not considered to hold for `u8`. This will
44504450
/// change in a future release.
44514451
pub COINDUCTIVE_OVERLAP_IN_COHERENCE,
4452-
Warn,
4452+
Deny,
44534453
"impls that are not considered to overlap may be considered to \
44544454
overlap in the future",
44554455
@future_incompatible = FutureIncompatibleInfo {
4456-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
4456+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
44574457
reference: "issue #114040 <https://github.com/rust-lang/rust/issues/114040>",
44584458
};
44594459
}

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
383383
let is_fn_like = tcx.def_kind(def).is_fn_like();
384384
if is_fn_like {
385385
// Do not compute the mir call graph without said call graph actually being used.
386-
if inline::Inline.is_enabled(&tcx.sess) {
386+
if pm::should_run_pass(tcx, &inline::Inline) {
387387
tcx.ensure_with_value().mir_inliner_callees(ty::InstanceDef::Item(def.to_def_id()));
388388
}
389389
}

compiler/rustc_mir_transform/src/pass_manager.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,25 @@ pub fn run_passes<'tcx>(
8383
run_passes_inner(tcx, body, passes, phase_change, true);
8484
}
8585

86+
pub fn should_run_pass<'tcx, P>(tcx: TyCtxt<'tcx>, pass: &P) -> bool
87+
where
88+
P: MirPass<'tcx> + ?Sized,
89+
{
90+
let name = pass.name();
91+
92+
let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
93+
let overridden =
94+
overridden_passes.iter().rev().find(|(s, _)| s == &*name).map(|(_name, polarity)| {
95+
trace!(
96+
pass = %name,
97+
"{} as requested by flag",
98+
if *polarity { "Running" } else { "Not running" },
99+
);
100+
*polarity
101+
});
102+
overridden.unwrap_or_else(|| pass.is_enabled(&tcx.sess))
103+
}
104+
86105
fn run_passes_inner<'tcx>(
87106
tcx: TyCtxt<'tcx>,
88107
body: &mut Body<'tcx>,
@@ -100,19 +119,9 @@ fn run_passes_inner<'tcx>(
100119
for pass in passes {
101120
let name = pass.name();
102121

103-
let overridden = overridden_passes.iter().rev().find(|(s, _)| s == &*name).map(
104-
|(_name, polarity)| {
105-
trace!(
106-
pass = %name,
107-
"{} as requested by flag",
108-
if *polarity { "Running" } else { "Not running" },
109-
);
110-
*polarity
111-
},
112-
);
113-
if !overridden.unwrap_or_else(|| pass.is_enabled(&tcx.sess)) {
122+
if !should_run_pass(tcx, *pass) {
114123
continue;
115-
}
124+
};
116125

117126
let dump_enabled = pass.is_mir_dump_enabled();
118127

compiler/rustc_smir/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
rustc_data_structures = { path = "../rustc_data_structures" }
8-
rustc_driver = { path = "../rustc_driver" }
98
rustc_hir = { path = "../rustc_hir" }
10-
rustc_interface = { path = "../rustc_interface" }
119
rustc_middle = { path = "../rustc_middle" }
1210
rustc_span = { path = "../rustc_span" }
1311
rustc_target = { path = "../rustc_target" }

compiler/rustc_smir/src/rustc_internal/mod.rs

+72-58
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@
33
//! For that, we define APIs that will temporarily be public to 3P that exposes rustc internal APIs
44
//! until stable MIR is complete.
55
6-
use crate::rustc_internal;
76
use crate::rustc_smir::Tables;
87
use rustc_data_structures::fx;
98
use rustc_data_structures::fx::FxIndexMap;
10-
use rustc_driver::{Callbacks, Compilation, RunCompiler};
11-
use rustc_interface::{interface, Queries};
129
use rustc_middle::mir::interpret::AllocId;
1310
use rustc_middle::ty;
1411
use rustc_middle::ty::TyCtxt;
1512
use rustc_span::def_id::{CrateNum, DefId};
1613
use rustc_span::Span;
1714
use stable_mir::ty::IndexedVal;
18-
use stable_mir::CompilerError;
1915
use std::fmt::Debug;
2016
use std::hash::Hash;
21-
use std::ops::{ControlFlow, Index};
17+
use std::ops::Index;
2218

2319
impl<'tcx> Index<stable_mir::DefId> for Tables<'tcx> {
2420
type Output = DefId;
@@ -141,63 +137,81 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
141137
);
142138
}
143139

144-
pub struct StableMir<B = (), C = ()>
145-
where
146-
B: Send,
147-
C: Send,
148-
{
149-
args: Vec<String>,
150-
callback: fn(TyCtxt<'_>) -> ControlFlow<B, C>,
151-
result: Option<ControlFlow<B, C>>,
152-
}
140+
#[macro_export]
141+
macro_rules! run {
142+
($args:expr, $callback:expr) => {
143+
run!($args, tcx, $callback)
144+
};
145+
($args:expr, $tcx:ident, $callback:expr) => {{
146+
use rustc_driver::{Callbacks, Compilation, RunCompiler};
147+
use rustc_interface::{interface, Queries};
148+
use stable_mir::CompilerError;
149+
use std::ops::ControlFlow;
150+
151+
pub struct StableMir<B = (), C = ()>
152+
where
153+
B: Send,
154+
C: Send,
155+
{
156+
args: Vec<String>,
157+
callback: fn(TyCtxt<'_>) -> ControlFlow<B, C>,
158+
result: Option<ControlFlow<B, C>>,
159+
}
153160

154-
impl<B, C> StableMir<B, C>
155-
where
156-
B: Send,
157-
C: Send,
158-
{
159-
/// Creates a new `StableMir` instance, with given test_function and arguments.
160-
pub fn new(args: Vec<String>, callback: fn(TyCtxt<'_>) -> ControlFlow<B, C>) -> Self {
161-
StableMir { args, callback, result: None }
162-
}
163-
164-
/// Runs the compiler against given target and tests it with `test_function`
165-
pub fn run(&mut self) -> Result<C, CompilerError<B>> {
166-
let compiler_result =
167-
rustc_driver::catch_fatal_errors(|| RunCompiler::new(&self.args.clone(), self).run());
168-
match (compiler_result, self.result.take()) {
169-
(Ok(Ok(())), Some(ControlFlow::Continue(value))) => Ok(value),
170-
(Ok(Ok(())), Some(ControlFlow::Break(value))) => Err(CompilerError::Interrupted(value)),
171-
(Ok(Ok(_)), None) => Err(CompilerError::Skipped),
172-
(Ok(Err(_)), _) => Err(CompilerError::CompilationFailed),
173-
(Err(_), _) => Err(CompilerError::ICE),
161+
impl<B, C> StableMir<B, C>
162+
where
163+
B: Send,
164+
C: Send,
165+
{
166+
/// Creates a new `StableMir` instance, with given test_function and arguments.
167+
pub fn new(args: Vec<String>, callback: fn(TyCtxt<'_>) -> ControlFlow<B, C>) -> Self {
168+
StableMir { args, callback, result: None }
169+
}
170+
171+
/// Runs the compiler against given target and tests it with `test_function`
172+
pub fn run(&mut self) -> Result<C, CompilerError<B>> {
173+
let compiler_result = rustc_driver::catch_fatal_errors(|| {
174+
RunCompiler::new(&self.args.clone(), self).run()
175+
});
176+
match (compiler_result, self.result.take()) {
177+
(Ok(Ok(())), Some(ControlFlow::Continue(value))) => Ok(value),
178+
(Ok(Ok(())), Some(ControlFlow::Break(value))) => {
179+
Err(CompilerError::Interrupted(value))
180+
}
181+
(Ok(Ok(_)), None) => Err(CompilerError::Skipped),
182+
(Ok(Err(_)), _) => Err(CompilerError::CompilationFailed),
183+
(Err(_), _) => Err(CompilerError::ICE),
184+
}
185+
}
174186
}
175-
}
176-
}
177187

178-
impl<B, C> Callbacks for StableMir<B, C>
179-
where
180-
B: Send,
181-
C: Send,
182-
{
183-
/// Called after analysis. Return value instructs the compiler whether to
184-
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
185-
fn after_analysis<'tcx>(
186-
&mut self,
187-
_compiler: &interface::Compiler,
188-
queries: &'tcx Queries<'tcx>,
189-
) -> Compilation {
190-
queries.global_ctxt().unwrap().enter(|tcx| {
191-
rustc_internal::run(tcx, || {
192-
self.result = Some((self.callback)(tcx));
193-
});
194-
if self.result.as_ref().is_some_and(|val| val.is_continue()) {
195-
Compilation::Continue
196-
} else {
197-
Compilation::Stop
188+
impl<B, C> Callbacks for StableMir<B, C>
189+
where
190+
B: Send,
191+
C: Send,
192+
{
193+
/// Called after analysis. Return value instructs the compiler whether to
194+
/// continue the compilation afterwards (defaults to `Compilation::Continue`)
195+
fn after_analysis<'tcx>(
196+
&mut self,
197+
_compiler: &interface::Compiler,
198+
queries: &'tcx Queries<'tcx>,
199+
) -> Compilation {
200+
queries.global_ctxt().unwrap().enter(|tcx| {
201+
rustc_internal::run(tcx, || {
202+
self.result = Some((self.callback)(tcx));
203+
});
204+
if self.result.as_ref().is_some_and(|val| val.is_continue()) {
205+
Compilation::Continue
206+
} else {
207+
Compilation::Stop
208+
}
209+
})
198210
}
199-
})
200-
}
211+
}
212+
213+
StableMir::new($args, |$tcx| $callback).run()
214+
}};
201215
}
202216

203217
/// Simmilar to rustc's `FxIndexMap`, `IndexMap` with extra

tests/mir-opt/inline/unit_test.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Check that `-Zmir-enable-passes=+Inline` does not ICE because of stolen MIR.
2+
// unit-test: Inline
3+
// skip-filecheck
4+
#![crate_type = "lib"]
5+
6+
// Randomize `def_path_hash` by defining them under a module with different names
7+
macro_rules! emit {
8+
($($m:ident)*) => {$(
9+
pub mod $m {
10+
pub fn main() {
11+
let func = || 123u8;
12+
func();
13+
}
14+
}
15+
)*};
16+
}
17+
18+
// Increase the chance of triggering the bug
19+
emit!(m00 m01 m02 m03 m04 m05 m06 m07 m08 m09 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19);

tests/ui-fulldeps/stable-mir/compilation-result.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
#![feature(assert_matches)]
1111

1212
extern crate rustc_middle;
13+
#[macro_use]
1314
extern crate rustc_smir;
15+
extern crate rustc_driver;
16+
extern crate rustc_interface;
1417
extern crate stable_mir;
1518

1619
use rustc_middle::ty::TyCtxt;
1720
use rustc_smir::rustc_internal;
1821
use std::io::Write;
19-
use std::ops::ControlFlow;
2022

2123
/// This test will generate and analyze a dummy crate using the stable mir.
2224
/// For that, it will first write the dummy crate into a file.
@@ -33,28 +35,26 @@ fn main() {
3335
}
3436

3537
fn test_continue(args: Vec<String>) {
36-
let continue_fn = |_: TyCtxt| ControlFlow::Continue::<(), bool>(true);
37-
let result = rustc_internal::StableMir::new(args, continue_fn).run();
38+
let result = run!(args, ControlFlow::Continue::<(), bool>(true));
3839
assert_eq!(result, Ok(true));
3940
}
4041

4142
fn test_break(args: Vec<String>) {
42-
let continue_fn = |_: TyCtxt| ControlFlow::Break::<bool, i32>(false);
43-
let result = rustc_internal::StableMir::new(args, continue_fn).run();
43+
let result = run!(args, ControlFlow::Break::<bool, i32>(false));
4444
assert_eq!(result, Err(stable_mir::CompilerError::Interrupted(false)));
4545
}
4646

47+
#[allow(unreachable_code)]
4748
fn test_skipped(mut args: Vec<String>) {
4849
args.push("--version".to_string());
49-
let unreach_fn = |_: TyCtxt| -> ControlFlow<()> { unreachable!() };
50-
let result = rustc_internal::StableMir::new(args, unreach_fn).run();
50+
let result = run!(args, unreachable!() as ControlFlow<()>);
5151
assert_eq!(result, Err(stable_mir::CompilerError::Skipped));
5252
}
5353

54+
#[allow(unreachable_code)]
5455
fn test_failed(mut args: Vec<String>) {
5556
args.push("--cfg=broken".to_string());
56-
let unreach_fn = |_: TyCtxt| -> ControlFlow<()> { unreachable!() };
57-
let result = rustc_internal::StableMir::new(args, unreach_fn).run();
57+
let result = run!(args, unreachable!() as ControlFlow<()>);
5858
assert_eq!(result, Err(stable_mir::CompilerError::CompilationFailed));
5959
}
6060

tests/ui-fulldeps/stable-mir/crate-info.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
extern crate rustc_hir;
1414
extern crate rustc_middle;
15+
#[macro_use]
1516
extern crate rustc_smir;
17+
extern crate rustc_driver;
18+
extern crate rustc_interface;
1619
extern crate stable_mir;
1720

1821
use rustc_hir::def::DefKind;
@@ -185,7 +188,7 @@ fn main() {
185188
CRATE_NAME.to_string(),
186189
path.to_string(),
187190
];
188-
rustc_internal::StableMir::new(args, test_stable_mir).run().unwrap();
191+
run!(args, tcx, test_stable_mir(tcx)).unwrap();
189192
}
190193

191194
fn generate_input(path: &str) -> std::io::Result<()> {

tests/ui-fulldeps/stable-mir/instance.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
#![feature(control_flow_enum)]
1212

1313
extern crate rustc_middle;
14+
#[macro_use]
1415
extern crate rustc_smir;
1516
extern crate stable_mir;
17+
extern crate rustc_driver;
18+
extern crate rustc_interface;
1619

1720
use rustc_middle::ty::TyCtxt;
1821

@@ -61,7 +64,7 @@ fn main() {
6164
CRATE_NAME.to_string(),
6265
path.to_string(),
6366
];
64-
rustc_internal::StableMir::new(args, test_stable_mir).run().unwrap();
67+
run!(args, tcx, test_stable_mir(tcx)).unwrap();
6568
}
6669

6770
fn generate_input(path: &str) -> std::io::Result<()> {

tests/ui/coherence/warn-when-cycle-is-error-in-coherence.stderr

+25
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,28 @@ LL | #![deny(coinductive_overlap_in_coherence)]
2424

2525
error: aborting due to previous error
2626

27+
Future incompatibility report: Future breakage diagnostic:
28+
error: implementations of `PartialEq<Interval<_>>` for `Interval<_>` will conflict in the future
29+
--> $DIR/warn-when-cycle-is-error-in-coherence.rs:13:1
30+
|
31+
LL | #[derive(PartialEq, Default)]
32+
| --------- the second impl is here
33+
...
34+
LL | / impl<T, Q> PartialEq<Q> for Interval<T>
35+
LL | |
36+
LL | |
37+
LL | | where
38+
LL | | T: Borrow<Q>,
39+
LL | | Q: ?Sized + PartialOrd,
40+
| |___________________________^ the first impl is here
41+
|
42+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
43+
= note: for more information, see issue #114040 <https://github.com/rust-lang/rust/issues/114040>
44+
= note: impls that are not considered to overlap may be considered to overlap in the future
45+
= note: `Interval<_>: PartialOrd` may be considered to hold in future releases, causing the impls to overlap
46+
note: the lint level is defined here
47+
--> $DIR/warn-when-cycle-is-error-in-coherence.rs:1:9
48+
|
49+
LL | #![deny(coinductive_overlap_in_coherence)]
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
51+

0 commit comments

Comments
 (0)