Skip to content

Commit 7bd81ee

Browse files
committed
Auto merge of #113673 - matthiaskrgr:rollup-zcume6k, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #113536 (avoid building proof trees in select) - #113558 (Only use max_line_length = 100 for *.rs) - #113570 (refactor proof tree formatting) - #113623 (Add jump to doc) - #113629 (Add Adt to SMIR) - #113631 (make MCP510 behavior opt-in to avoid conflicts between the CLI and target flavors) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a161ab0 + fc1cb04 commit 7bd81ee

File tree

18 files changed

+310
-137
lines changed

18 files changed

+310
-137
lines changed

.editorconfig

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ trim_trailing_whitespace = true
1111
insert_final_newline = true
1212
indent_style = space
1313
indent_size = 4
14+
15+
[*.rs]
1416
max_line_length = 100
1517

1618
[*.md]

compiler/rustc_codegen_ssa/src/back/link.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -2970,10 +2970,25 @@ fn add_lld_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
29702970
return;
29712971
}
29722972

2973+
let self_contained_linker = sess.opts.cg.link_self_contained.linker();
2974+
2975+
// FIXME: some targets default to using `lld`, but users can only override the linker on the CLI
2976+
// and cannot yet select the precise linker flavor to opt out of that. See for example issue
2977+
// #113597 for the `thumbv6m-none-eabi` target: a driver is used, and its default linker
2978+
// conflicts with the target's flavor, causing unexpected arguments being passed.
2979+
//
2980+
// Until the new `LinkerFlavor`-like CLI options are stabilized, we only adopt MCP510's behavior
2981+
// if its dedicated unstable CLI flags are used, to keep the current sub-optimal stable
2982+
// behavior.
2983+
let using_mcp510 =
2984+
self_contained_linker || sess.opts.cg.linker_flavor.is_some_and(|f| f.is_unstable());
2985+
if !using_mcp510 && !unstable_use_lld {
2986+
return;
2987+
}
2988+
29732989
// 1. Implement the "self-contained" part of this feature by adding rustc distribution
29742990
// directories to the tool's search path.
2975-
let self_contained_linker = sess.opts.cg.link_self_contained.linker() || unstable_use_lld;
2976-
if self_contained_linker {
2991+
if self_contained_linker || unstable_use_lld {
29772992
for path in sess.get_tools_search_paths(false) {
29782993
cmd.arg({
29792994
let mut arg = OsString::from("-B");

compiler/rustc_middle/src/traits/solve/inspect.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub enum GoalEvaluationKind<'tcx> {
3232
}
3333
impl Debug for GoalEvaluation<'_> {
3434
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35-
ProofTreeFormatter { f, on_newline: true }.format_goal_evaluation(self)
35+
ProofTreeFormatter::new(f).format_goal_evaluation(self)
3636
}
3737
}
3838

@@ -43,7 +43,7 @@ pub struct AddedGoalsEvaluation<'tcx> {
4343
}
4444
impl Debug for AddedGoalsEvaluation<'_> {
4545
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46-
ProofTreeFormatter { f, on_newline: true }.format_nested_goal_evaluation(self)
46+
ProofTreeFormatter::new(f).format_nested_goal_evaluation(self)
4747
}
4848
}
4949

@@ -58,7 +58,7 @@ pub struct GoalEvaluationStep<'tcx> {
5858
}
5959
impl Debug for GoalEvaluationStep<'_> {
6060
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61-
ProofTreeFormatter { f, on_newline: true }.format_evaluation_step(self)
61+
ProofTreeFormatter::new(f).format_evaluation_step(self)
6262
}
6363
}
6464

@@ -78,6 +78,6 @@ pub enum CandidateKind<'tcx> {
7878
}
7979
impl Debug for GoalCandidate<'_> {
8080
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
81-
ProofTreeFormatter { f, on_newline: true }.format_candidate(self)
81+
ProofTreeFormatter::new(f).format_candidate(self)
8282
}
8383
}

compiler/rustc_middle/src/traits/solve/inspect/format.rs

+59-53
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
use super::*;
22

33
pub(super) struct ProofTreeFormatter<'a, 'b> {
4-
pub(super) f: &'a mut (dyn Write + 'b),
5-
pub(super) on_newline: bool,
4+
f: &'a mut (dyn Write + 'b),
65
}
76

8-
impl Write for ProofTreeFormatter<'_, '_> {
7+
/// A formatter which adds 4 spaces of indentation to its input before
8+
/// passing it on to its nested formatter.
9+
///
10+
/// We can use this for arbitrary levels of indentation by nesting it.
11+
struct Indentor<'a, 'b> {
12+
f: &'a mut (dyn Write + 'b),
13+
on_newline: bool,
14+
}
15+
16+
impl Write for Indentor<'_, '_> {
917
fn write_str(&mut self, s: &str) -> std::fmt::Result {
1018
for line in s.split_inclusive("\n") {
1119
if self.on_newline {
@@ -19,49 +27,52 @@ impl Write for ProofTreeFormatter<'_, '_> {
1927
}
2028
}
2129

22-
impl ProofTreeFormatter<'_, '_> {
23-
fn nested(&mut self) -> ProofTreeFormatter<'_, '_> {
24-
ProofTreeFormatter { f: self, on_newline: true }
30+
impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
31+
pub(super) fn new(f: &'a mut (dyn Write + 'b)) -> Self {
32+
ProofTreeFormatter { f }
2533
}
2634

27-
pub(super) fn format_goal_evaluation(&mut self, goal: &GoalEvaluation<'_>) -> std::fmt::Result {
28-
let f = &mut *self.f;
35+
fn nested<F, R>(&mut self, func: F) -> R
36+
where
37+
F: FnOnce(&mut ProofTreeFormatter<'_, '_>) -> R,
38+
{
39+
func(&mut ProofTreeFormatter { f: &mut Indentor { f: self.f, on_newline: true } })
40+
}
2941

42+
pub(super) fn format_goal_evaluation(&mut self, goal: &GoalEvaluation<'_>) -> std::fmt::Result {
3043
let goal_text = match goal.is_normalizes_to_hack {
3144
IsNormalizesToHack::Yes => "NORMALIZES-TO HACK GOAL",
3245
IsNormalizesToHack::No => "GOAL",
3346
};
3447

35-
writeln!(f, "{}: {:?}", goal_text, goal.uncanonicalized_goal,)?;
36-
writeln!(f, "CANONICALIZED: {:?}", goal.canonicalized_goal)?;
48+
writeln!(self.f, "{}: {:?}", goal_text, goal.uncanonicalized_goal)?;
49+
writeln!(self.f, "CANONICALIZED: {:?}", goal.canonicalized_goal)?;
3750

3851
match &goal.kind {
3952
GoalEvaluationKind::CacheHit(CacheHit::Global) => {
40-
writeln!(f, "GLOBAL CACHE HIT: {:?}", goal.result)
53+
writeln!(self.f, "GLOBAL CACHE HIT: {:?}", goal.result)
4154
}
4255
GoalEvaluationKind::CacheHit(CacheHit::Provisional) => {
43-
writeln!(f, "PROVISIONAL CACHE HIT: {:?}", goal.result)
56+
writeln!(self.f, "PROVISIONAL CACHE HIT: {:?}", goal.result)
4457
}
4558
GoalEvaluationKind::Uncached { revisions } => {
4659
for (n, step) in revisions.iter().enumerate() {
47-
let f = &mut *self.f;
48-
writeln!(f, "REVISION {n}: {:?}", step.result)?;
49-
let mut f = self.nested();
50-
f.format_evaluation_step(step)?;
60+
writeln!(self.f, "REVISION {n}: {:?}", step.result)?;
61+
self.nested(|this| this.format_evaluation_step(step))?;
5162
}
52-
53-
let f = &mut *self.f;
54-
writeln!(f, "RESULT: {:?}", goal.result)
63+
writeln!(self.f, "RESULT: {:?}", goal.result)
5564
}
5665
}?;
5766

5867
if goal.returned_goals.len() > 0 {
59-
let f = &mut *self.f;
60-
writeln!(f, "NESTED GOALS ADDED TO CALLER: [")?;
61-
let mut f = self.nested();
62-
for goal in goal.returned_goals.iter() {
63-
writeln!(f, "ADDED GOAL: {:?},", goal)?;
64-
}
68+
writeln!(self.f, "NESTED GOALS ADDED TO CALLER: [")?;
69+
self.nested(|this| {
70+
for goal in goal.returned_goals.iter() {
71+
writeln!(this.f, "ADDED GOAL: {:?},", goal)?;
72+
}
73+
Ok(())
74+
})?;
75+
6576
writeln!(self.f, "]")?;
6677
}
6778

@@ -72,58 +83,53 @@ impl ProofTreeFormatter<'_, '_> {
7283
&mut self,
7384
evaluation_step: &GoalEvaluationStep<'_>,
7485
) -> std::fmt::Result {
75-
let f = &mut *self.f;
76-
writeln!(f, "INSTANTIATED: {:?}", evaluation_step.instantiated_goal)?;
86+
writeln!(self.f, "INSTANTIATED: {:?}", evaluation_step.instantiated_goal)?;
7787

7888
for candidate in &evaluation_step.candidates {
79-
let mut f = self.nested();
80-
f.format_candidate(candidate)?;
89+
self.nested(|this| this.format_candidate(candidate))?;
8190
}
82-
for nested_goal_evaluation in &evaluation_step.nested_goal_evaluations {
83-
let mut f = self.nested();
84-
f.format_nested_goal_evaluation(nested_goal_evaluation)?;
91+
for nested in &evaluation_step.nested_goal_evaluations {
92+
self.nested(|this| this.format_nested_goal_evaluation(nested))?;
8593
}
8694

8795
Ok(())
8896
}
8997

9098
pub(super) fn format_candidate(&mut self, candidate: &GoalCandidate<'_>) -> std::fmt::Result {
91-
let f = &mut *self.f;
92-
9399
match &candidate.kind {
94100
CandidateKind::NormalizedSelfTyAssembly => {
95-
writeln!(f, "NORMALIZING SELF TY FOR ASSEMBLY:")
101+
writeln!(self.f, "NORMALIZING SELF TY FOR ASSEMBLY:")
96102
}
97103
CandidateKind::Candidate { name, result } => {
98-
writeln!(f, "CANDIDATE {}: {:?}", name, result)
104+
writeln!(self.f, "CANDIDATE {}: {:?}", name, result)
99105
}
100106
}?;
101107

102-
let mut f = self.nested();
103-
for candidate in &candidate.candidates {
104-
f.format_candidate(candidate)?;
105-
}
106-
for nested_evaluations in &candidate.nested_goal_evaluations {
107-
f.format_nested_goal_evaluation(nested_evaluations)?;
108-
}
109-
110-
Ok(())
108+
self.nested(|this| {
109+
for candidate in &candidate.candidates {
110+
this.format_candidate(candidate)?;
111+
}
112+
for nested in &candidate.nested_goal_evaluations {
113+
this.format_nested_goal_evaluation(nested)?;
114+
}
115+
Ok(())
116+
})
111117
}
112118

113119
pub(super) fn format_nested_goal_evaluation(
114120
&mut self,
115121
nested_goal_evaluation: &AddedGoalsEvaluation<'_>,
116122
) -> std::fmt::Result {
117-
let f = &mut *self.f;
118-
writeln!(f, "TRY_EVALUATE_ADDED_GOALS: {:?}", nested_goal_evaluation.result)?;
123+
writeln!(self.f, "TRY_EVALUATE_ADDED_GOALS: {:?}", nested_goal_evaluation.result)?;
119124

120125
for (n, revision) in nested_goal_evaluation.evaluations.iter().enumerate() {
121-
let f = &mut *self.f;
122-
writeln!(f, "REVISION {n}")?;
123-
let mut f = self.nested();
124-
for goal_evaluation in revision {
125-
f.format_goal_evaluation(goal_evaluation)?;
126-
}
126+
writeln!(self.f, "REVISION {n}")?;
127+
self.nested(|this| {
128+
for goal_evaluation in revision {
129+
this.format_goal_evaluation(goal_evaluation)?;
130+
}
131+
Ok(())
132+
})?;
127133
}
128134

129135
Ok(())

compiler/rustc_smir/src/rustc_internal/mod.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,33 @@ pub fn crate_item(did: DefId) -> stable_mir::CrateItem {
2727
with_tables(|t| t.crate_item(did))
2828
}
2929

30+
pub fn adt_def(did: DefId) -> stable_mir::ty::AdtDef {
31+
with_tables(|t| t.adt_def(did))
32+
}
33+
3034
impl<'tcx> Tables<'tcx> {
3135
pub fn item_def_id(&self, item: &stable_mir::CrateItem) -> DefId {
3236
self.def_ids[item.0]
3337
}
3438

3539
pub fn crate_item(&mut self, did: DefId) -> stable_mir::CrateItem {
40+
stable_mir::CrateItem(self.create_def_id(did))
41+
}
42+
43+
pub fn adt_def(&mut self, did: DefId) -> stable_mir::ty::AdtDef {
44+
stable_mir::ty::AdtDef(self.create_def_id(did))
45+
}
46+
47+
fn create_def_id(&mut self, did: DefId) -> stable_mir::DefId {
3648
// FIXME: this becomes inefficient when we have too many ids
3749
for (i, &d) in self.def_ids.iter().enumerate() {
3850
if d == did {
39-
return stable_mir::CrateItem(i);
51+
return i;
4052
}
4153
}
4254
let id = self.def_ids.len();
4355
self.def_ids.push(did);
44-
stable_mir::CrateItem(id)
56+
id
4557
}
4658
}
4759

compiler/rustc_smir/src/rustc_smir/mod.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
1010
use crate::rustc_internal::{self, opaque};
11-
use crate::stable_mir::ty::{FloatTy, IntTy, RigidTy, TyKind, UintTy};
11+
use crate::stable_mir::ty::{AdtSubsts, FloatTy, GenericArgKind, IntTy, RigidTy, TyKind, UintTy};
1212
use crate::stable_mir::{self, Context};
1313
use rustc_middle::mir;
1414
use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -94,7 +94,25 @@ impl<'tcx> Tables<'tcx> {
9494
ty::FloatTy::F32 => TyKind::RigidTy(RigidTy::Float(FloatTy::F32)),
9595
ty::FloatTy::F64 => TyKind::RigidTy(RigidTy::Float(FloatTy::F64)),
9696
},
97-
ty::Adt(_, _) => todo!(),
97+
ty::Adt(adt_def, substs) => TyKind::RigidTy(RigidTy::Adt(
98+
rustc_internal::adt_def(adt_def.did()),
99+
AdtSubsts(
100+
substs
101+
.iter()
102+
.map(|arg| match arg.unpack() {
103+
ty::GenericArgKind::Lifetime(region) => {
104+
GenericArgKind::Lifetime(opaque(&region))
105+
}
106+
ty::GenericArgKind::Type(ty) => {
107+
GenericArgKind::Type(self.intern_ty(ty))
108+
}
109+
ty::GenericArgKind::Const(const_) => {
110+
GenericArgKind::Const(opaque(&const_))
111+
}
112+
})
113+
.collect(),
114+
),
115+
)),
98116
ty::Foreign(_) => todo!(),
99117
ty::Str => todo!(),
100118
ty::Array(_, _) => todo!(),
@@ -149,13 +167,6 @@ pub(crate) trait Stable {
149167
fn stable(&self) -> Self::T;
150168
}
151169

152-
impl Stable for DefId {
153-
type T = stable_mir::CrateItem;
154-
fn stable(&self) -> Self::T {
155-
rustc_internal::crate_item(*self)
156-
}
157-
}
158-
159170
impl<'tcx> Stable for mir::Statement<'tcx> {
160171
type T = stable_mir::mir::Statement;
161172
fn stable(&self) -> Self::T {
@@ -190,7 +201,9 @@ impl<'tcx> Stable for mir::Rvalue<'tcx> {
190201
Ref(region, kind, place) => {
191202
stable_mir::mir::Rvalue::Ref(opaque(region), kind.stable(), place.stable())
192203
}
193-
ThreadLocalRef(def_id) => stable_mir::mir::Rvalue::ThreadLocalRef(def_id.stable()),
204+
ThreadLocalRef(def_id) => {
205+
stable_mir::mir::Rvalue::ThreadLocalRef(rustc_internal::crate_item(*def_id))
206+
}
194207
AddressOf(mutability, place) => {
195208
stable_mir::mir::Rvalue::AddressOf(mutability.stable(), place.stable())
196209
}

compiler/rustc_smir/src/stable_mir/ty.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use super::with;
1+
use super::{with, DefId};
2+
use crate::rustc_internal::Opaque;
23

34
#[derive(Copy, Clone, Debug)]
45
pub struct Ty(pub usize);
@@ -9,6 +10,9 @@ impl Ty {
910
}
1011
}
1112

13+
type Const = Opaque;
14+
type Region = Opaque;
15+
1216
#[derive(Clone, Debug)]
1317
pub enum TyKind {
1418
RigidTy(RigidTy),
@@ -21,6 +25,7 @@ pub enum RigidTy {
2125
Int(IntTy),
2226
Uint(UintTy),
2327
Float(FloatTy),
28+
Adt(AdtDef, AdtSubsts),
2429
Tuple(Vec<Ty>),
2530
}
2631

@@ -49,3 +54,18 @@ pub enum FloatTy {
4954
F32,
5055
F64,
5156
}
57+
58+
#[derive(Clone, PartialEq, Eq, Debug)]
59+
pub struct AdtDef(pub(crate) DefId);
60+
61+
#[derive(Clone, Debug)]
62+
pub struct AdtSubsts(pub Vec<GenericArgKind>);
63+
64+
#[derive(Clone, Debug)]
65+
pub enum GenericArgKind {
66+
// FIXME add proper region
67+
Lifetime(Region),
68+
Type(Ty),
69+
// FIXME add proper const
70+
Const(Const),
71+
}

0 commit comments

Comments
 (0)