Skip to content

Commit d9a4d5e

Browse files
committed
Auto merge of #112080 - matthiaskrgr:rollup-pmpbe49, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #111558 (Move tests) - #111827 (Add build instructions for cranelift backend as part of Rust repo) - #111988 (Make `TyKind: Debug` have less verbose output) - #112022 (Check nested obligations during coercion unify in new solver) - #112057 (Suggest correct `self_ty`) - #112063 (Add a test for issue 110457/incremental ICE with closures with the same span) Failed merges: - #112068 (Move tests from `ui/discrim` dir) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 498553f + 36526cf commit d9a4d5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+385
-83
lines changed

compiler/rustc_codegen_cranelift/Readme.md

+26
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@ This will build your project with rustc_codegen_cranelift instead of the usual L
4242

4343
For additional ways to use rustc_codegen_cranelift like the JIT mode see [usage.md](docs/usage.md).
4444

45+
## Building and testing with changes in rustc code
46+
47+
This is useful when changing code in `rustc_codegen_cranelift` as part of changing [main Rust repository](https://github.com/rust-lang/rust/).
48+
This can happen, for example, when you are implementing a new compiler intrinsic.
49+
50+
Instruction below uses `$RustCheckoutDir` as substitute for any folder where you cloned Rust repository.
51+
52+
You need to do this steps to successfully compile and use the cranelift backend with your changes in rustc code:
53+
54+
1. `cd $RustCheckoutDir`
55+
2. Run `python x.py setup` and choose option for compiler (`b`).
56+
3. Build compiler and necessary tools: `python x.py build --stage=2 compiler library/std src/tools/rustdoc src/tools/rustfmt`
57+
* (Optional) You can also build cargo by adding `src/tools/cargo` to previous command.
58+
4. Copy exectutable files from `./build/host/stage2-tools/<your hostname triple>/release`
59+
to `./build/host/stage2/bin/`. Note that you would need to do this every time you rebuilt `rust` repository.
60+
5. Copy cargo from another toolchain: `cp $(rustup which cargo) .build/<your hostname triple>/stage2/bin/cargo`
61+
* Another option is to build it at step 3 and copy with other executables at step 4.
62+
6. Link your new `rustc` to toolchain: `rustup toolchain link stage2 ./build/host/stage2/`.
63+
7. (Windows only) compile y.rs: `rustc +stage2 -O y.rs`.
64+
8. You need to prefix every `./y.rs` (or `y` if you built `y.rs`) command by `rustup run stage2` to make cg_clif use your local changes in rustc.
65+
66+
* `rustup run stage2 ./y.rs prepare`
67+
* `rustup run stage2 ./y.rs build`
68+
* (Optional) run tests: `rustup run stage2 ./y.rs test`
69+
9. Now you can use your cg_clif build to compile other Rust programs, e.g. you can open any Rust crate and run commands like `$RustCheckoutDir/compiler/rustc_codegen_cranelift/dist/cargo-clif build --release`.
70+
4571
## Configuration
4672

4773
See the documentation on the `BackendConfig` struct in [config.rs](src/config.rs) for all

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ fn report_trait_method_mismatch<'tcx>(
902902
if trait_m.fn_has_self_parameter =>
903903
{
904904
let ty = trait_sig.inputs()[0];
905-
let sugg = match ExplicitSelf::determine(ty, |_| ty == impl_trait_ref.self_ty()) {
905+
let sugg = match ExplicitSelf::determine(ty, |ty| ty == impl_trait_ref.self_ty()) {
906906
ExplicitSelf::ByValue => "self".to_owned(),
907907
ExplicitSelf::ByReference(_, hir::Mutability::Not) => "&self".to_owned(),
908908
ExplicitSelf::ByReference(_, hir::Mutability::Mut) => "&mut self".to_owned(),

compiler/rustc_hir_typeck/src/coercion.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ use rustc_span::{self, BytePos, DesugaringKind, Span};
6262
use rustc_target::spec::abi::Abi;
6363
use rustc_trait_selection::infer::InferCtxtExt as _;
6464
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
65+
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
6566
use rustc_trait_selection::traits::{
6667
self, NormalizeExt, ObligationCause, ObligationCauseCode, ObligationCtxt,
6768
};
@@ -144,12 +145,28 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
144145
debug!("unify(a: {:?}, b: {:?}, use_lub: {})", a, b, self.use_lub);
145146
self.commit_if_ok(|_| {
146147
let at = self.at(&self.cause, self.fcx.param_env);
147-
if self.use_lub {
148+
149+
let res = if self.use_lub {
148150
at.lub(DefineOpaqueTypes::Yes, b, a)
149151
} else {
150152
at.sup(DefineOpaqueTypes::Yes, b, a)
151153
.map(|InferOk { value: (), obligations }| InferOk { value: a, obligations })
154+
};
155+
156+
// In the new solver, lazy norm may allow us to shallowly equate
157+
// more types, but we emit possibly impossible-to-satisfy obligations.
158+
// Filter these cases out to make sure our coercion is more accurate.
159+
if self.tcx.trait_solver_next() {
160+
if let Ok(res) = &res {
161+
for obligation in &res.obligations {
162+
if !self.predicate_may_hold(&obligation) {
163+
return Err(TypeError::Mismatch);
164+
}
165+
}
166+
}
152167
}
168+
169+
res
153170
})
154171
}
155172

compiler/rustc_middle/src/ty/context.rs

+10
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
115115
type FreeRegion = ty::FreeRegion;
116116
type RegionVid = ty::RegionVid;
117117
type PlaceholderRegion = ty::PlaceholderRegion;
118+
119+
fn ty_and_mut_to_parts(
120+
TypeAndMut { ty, mutbl }: TypeAndMut<'tcx>,
121+
) -> (Self::Ty, Self::Mutability) {
122+
(ty, mutbl)
123+
}
124+
125+
fn mutability_is_mut(mutbl: Self::Mutability) -> bool {
126+
mutbl.is_mut()
127+
}
118128
}
119129

120130
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
14961496
/// identified by both a universe, as well as a name residing within that universe. Distinct bound
14971497
/// regions/types/consts within the same universe simply have an unknown relationship to one
14981498
/// another.
1499-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
1499+
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
15001500
#[derive(HashStable, TyEncodable, TyDecodable)]
15011501
pub struct Placeholder<T> {
15021502
pub universe: UniverseIndex,

compiler/rustc_middle/src/ty/print/pretty.rs

+19-43
Original file line numberDiff line numberDiff line change
@@ -685,29 +685,30 @@ pub trait PrettyPrinter<'tcx>:
685685
}
686686
ty::FnPtr(ref bare_fn) => p!(print(bare_fn)),
687687
ty::Infer(infer_ty) => {
688-
let verbose = self.should_print_verbose();
688+
if self.should_print_verbose() {
689+
p!(write("{:?}", ty.kind()));
690+
return Ok(self);
691+
}
692+
689693
if let ty::TyVar(ty_vid) = infer_ty {
690694
if let Some(name) = self.ty_infer_name(ty_vid) {
691695
p!(write("{}", name))
692696
} else {
693-
if verbose {
694-
p!(write("{:?}", infer_ty))
695-
} else {
696-
p!(write("{}", infer_ty))
697-
}
697+
p!(write("{}", infer_ty))
698698
}
699699
} else {
700-
if verbose { p!(write("{:?}", infer_ty)) } else { p!(write("{}", infer_ty)) }
700+
p!(write("{}", infer_ty))
701701
}
702702
}
703703
ty::Error(_) => p!("{{type error}}"),
704704
ty::Param(ref param_ty) => p!(print(param_ty)),
705705
ty::Bound(debruijn, bound_ty) => match bound_ty.kind {
706-
ty::BoundTyKind::Anon => debug_bound_var(&mut self, debruijn, bound_ty.var)?,
706+
ty::BoundTyKind::Anon => {
707+
rustc_type_ir::debug_bound_var(&mut self, debruijn, bound_ty.var)?
708+
}
707709
ty::BoundTyKind::Param(_, s) => match self.should_print_verbose() {
708-
true if debruijn == ty::INNERMOST => p!(write("^{}", s)),
709-
true => p!(write("^{}_{}", debruijn.index(), s)),
710-
false => p!(write("{}", s)),
710+
true => p!(write("{:?}", ty.kind())),
711+
false => p!(write("{s}")),
711712
},
712713
},
713714
ty::Adt(def, substs) => {
@@ -740,10 +741,11 @@ pub trait PrettyPrinter<'tcx>:
740741
}
741742
}
742743
ty::Placeholder(placeholder) => match placeholder.bound.kind {
743-
ty::BoundTyKind::Anon => {
744-
debug_placeholder_var(&mut self, placeholder.universe, placeholder.bound.var)?;
745-
}
746-
ty::BoundTyKind::Param(_, name) => p!(write("{}", name)),
744+
ty::BoundTyKind::Anon => p!(write("{placeholder:?}")),
745+
ty::BoundTyKind::Param(_, name) => match self.should_print_verbose() {
746+
true => p!(write("{:?}", ty.kind())),
747+
false => p!(write("{name}")),
748+
},
747749
},
748750
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
749751
// We use verbose printing in 'NO_QUERIES' mode, to
@@ -1372,11 +1374,9 @@ pub trait PrettyPrinter<'tcx>:
13721374
}
13731375

13741376
ty::ConstKind::Bound(debruijn, bound_var) => {
1375-
debug_bound_var(&mut self, debruijn, bound_var)?
1377+
rustc_type_ir::debug_bound_var(&mut self, debruijn, bound_var)?
13761378
}
1377-
ty::ConstKind::Placeholder(placeholder) => {
1378-
debug_placeholder_var(&mut self, placeholder.universe, placeholder.bound)?;
1379-
},
1379+
ty::ConstKind::Placeholder(placeholder) => p!(write("{placeholder:?}")),
13801380
// FIXME(generic_const_exprs):
13811381
// write out some legible representation of an abstract const?
13821382
ty::ConstKind::Expr(_) => p!("{{const expr}}"),
@@ -3065,27 +3065,3 @@ pub struct OpaqueFnEntry<'tcx> {
30653065
fn_trait_ref: Option<ty::PolyTraitRef<'tcx>>,
30663066
return_ty: Option<ty::Binder<'tcx, Term<'tcx>>>,
30673067
}
3068-
3069-
pub fn debug_bound_var<T: std::fmt::Write>(
3070-
fmt: &mut T,
3071-
debruijn: ty::DebruijnIndex,
3072-
var: ty::BoundVar,
3073-
) -> Result<(), std::fmt::Error> {
3074-
if debruijn == ty::INNERMOST {
3075-
write!(fmt, "^{}", var.index())
3076-
} else {
3077-
write!(fmt, "^{}_{}", debruijn.index(), var.index())
3078-
}
3079-
}
3080-
3081-
pub fn debug_placeholder_var<T: std::fmt::Write>(
3082-
fmt: &mut T,
3083-
universe: ty::UniverseIndex,
3084-
bound: ty::BoundVar,
3085-
) -> Result<(), std::fmt::Error> {
3086-
if universe == ty::UniverseIndex::ROOT {
3087-
write!(fmt, "!{}", bound.index())
3088-
} else {
3089-
write!(fmt, "!{}_{}", universe.index(), bound.index())
3090-
}
3091-
}

compiler/rustc_middle/src/ty/structural_impls.rs

+52-7
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,35 @@ impl fmt::Debug for ty::FreeRegion {
8888

8989
impl<'tcx> fmt::Debug for ty::FnSig<'tcx> {
9090
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91-
write!(f, "({:?}; c_variadic: {})->{:?}", self.inputs(), self.c_variadic, self.output())
91+
let ty::FnSig { inputs_and_output: _, c_variadic, unsafety, abi } = self;
92+
93+
write!(f, "{}", unsafety.prefix_str())?;
94+
match abi {
95+
rustc_target::spec::abi::Abi::Rust => (),
96+
abi => write!(f, "extern \"{abi:?}\" ")?,
97+
};
98+
99+
write!(f, "fn(")?;
100+
let inputs = self.inputs();
101+
match inputs.len() {
102+
0 if *c_variadic => write!(f, "...)")?,
103+
0 => write!(f, ")")?,
104+
_ => {
105+
for ty in &self.inputs()[0..(self.inputs().len() - 1)] {
106+
write!(f, "{ty:?}, ")?;
107+
}
108+
write!(f, "{:?}", self.inputs().last().unwrap())?;
109+
if *c_variadic {
110+
write!(f, "...")?;
111+
}
112+
write!(f, ")")?;
113+
}
114+
}
115+
116+
match self.output().kind() {
117+
ty::Tuple(list) if list.is_empty() => Ok(()),
118+
_ => write!(f, " -> {:?}", self.output()),
119+
}
92120
}
93121
}
94122

@@ -216,20 +244,37 @@ impl<'tcx> fmt::Debug for ty::ConstKind<'tcx> {
216244
match self {
217245
Param(param) => write!(f, "{param:?}"),
218246
Infer(var) => write!(f, "{var:?}"),
219-
Bound(debruijn, var) => ty::print::debug_bound_var(f, *debruijn, *var),
220-
Placeholder(placeholder) => {
221-
ty::print::debug_placeholder_var(f, placeholder.universe, placeholder.bound)
222-
}
247+
Bound(debruijn, var) => rustc_type_ir::debug_bound_var(f, *debruijn, *var),
248+
Placeholder(placeholder) => write!(f, "{placeholder:?}"),
223249
Unevaluated(uv) => {
224250
f.debug_tuple("Unevaluated").field(&uv.substs).field(&uv.def).finish()
225251
}
226252
Value(valtree) => write!(f, "{valtree:?}"),
227-
Error(_) => write!(f, "[const error]"),
253+
Error(_) => write!(f, "{{const error}}"),
228254
Expr(expr) => write!(f, "{expr:?}"),
229255
}
230256
}
231257
}
232258

259+
impl fmt::Debug for ty::BoundTy {
260+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
261+
match self.kind {
262+
ty::BoundTyKind::Anon => write!(f, "{:?}", self.var),
263+
ty::BoundTyKind::Param(_, sym) => write!(f, "{sym:?}"),
264+
}
265+
}
266+
}
267+
268+
impl<T: fmt::Debug> fmt::Debug for ty::Placeholder<T> {
269+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
270+
if self.universe == ty::UniverseIndex::ROOT {
271+
write!(f, "!{:?}", self.bound)
272+
} else {
273+
write!(f, "!{}_{:?}", self.universe.index(), self.bound)
274+
}
275+
}
276+
}
277+
233278
///////////////////////////////////////////////////////////////////////////
234279
// Atomic structs
235280
//
@@ -294,6 +339,7 @@ TrivialTypeTraversalAndLiftImpls! {
294339
crate::ty::AliasRelationDirection,
295340
crate::ty::Placeholder<crate::ty::BoundRegion>,
296341
crate::ty::Placeholder<crate::ty::BoundTy>,
342+
crate::ty::Placeholder<ty::BoundVar>,
297343
crate::ty::ClosureKind,
298344
crate::ty::FreeRegion,
299345
crate::ty::InferTy,
@@ -310,7 +356,6 @@ TrivialTypeTraversalAndLiftImpls! {
310356
interpret::Scalar,
311357
rustc_target::abi::Size,
312358
ty::BoundVar,
313-
ty::Placeholder<ty::BoundVar>,
314359
}
315360

316361
TrivialTypeTraversalAndLiftImpls! {

compiler/rustc_middle/src/ty/sty.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1511,10 +1511,11 @@ impl Atom for RegionVid {
15111511

15121512
rustc_index::newtype_index! {
15131513
#[derive(HashStable)]
1514+
#[debug_format = "{}"]
15141515
pub struct BoundVar {}
15151516
}
15161517

1517-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
1518+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
15181519
#[derive(HashStable)]
15191520
pub struct BoundTy {
15201521
pub var: BoundVar,

compiler/rustc_type_ir/src/lib.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub trait Interner: Sized {
5252
type PolyFnSig: Clone + Debug + Hash + Ord;
5353
type ListBinderExistentialPredicate: Clone + Debug + Hash + Ord;
5454
type BinderListTy: Clone + Debug + Hash + Ord;
55-
type ListTy: Clone + Debug + Hash + Ord;
55+
type ListTy: Clone + Debug + Hash + Ord + IntoIterator<Item = Self::Ty>;
5656
type AliasTy: Clone + Debug + Hash + Ord;
5757
type ParamTy: Clone + Debug + Hash + Ord;
5858
type BoundTy: Clone + Debug + Hash + Ord;
@@ -67,6 +67,9 @@ pub trait Interner: Sized {
6767
type FreeRegion: Clone + Debug + Hash + Ord;
6868
type RegionVid: Clone + Debug + Hash + Ord;
6969
type PlaceholderRegion: Clone + Debug + Hash + Ord;
70+
71+
fn ty_and_mut_to_parts(ty_and_mut: Self::TypeAndMut) -> (Self::Ty, Self::Mutability);
72+
fn mutability_is_mut(mutbl: Self::Mutability) -> bool;
7073
}
7174

7275
/// Imagine you have a function `F: FnOnce(&[T]) -> R`, plus an iterator `iter`
@@ -390,7 +393,19 @@ impl DebruijnIndex {
390393
}
391394
}
392395

393-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
396+
pub fn debug_bound_var<T: std::fmt::Write>(
397+
fmt: &mut T,
398+
debruijn: DebruijnIndex,
399+
var: impl std::fmt::Debug,
400+
) -> Result<(), std::fmt::Error> {
401+
if debruijn == INNERMOST {
402+
write!(fmt, "^{:?}", var)
403+
} else {
404+
write!(fmt, "^{}_{:?}", debruijn.index(), var)
405+
}
406+
}
407+
408+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
394409
#[derive(Encodable, Decodable, HashStable_Generic)]
395410
pub enum IntTy {
396411
Isize,
@@ -448,7 +463,7 @@ impl IntTy {
448463
}
449464
}
450465

451-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Debug)]
466+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
452467
#[derive(Encodable, Decodable, HashStable_Generic)]
453468
pub enum UintTy {
454469
Usize,
@@ -506,7 +521,7 @@ impl UintTy {
506521
}
507522
}
508523

509-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
524+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
510525
#[derive(Encodable, Decodable, HashStable_Generic)]
511526
pub enum FloatTy {
512527
F32,

0 commit comments

Comments
 (0)