Skip to content

Commit 3b38264

Browse files
committed
Auto merge of rust-lang#133818 - matthiaskrgr:rollup-iav1wq7, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#132937 (a release operation synchronizes with an acquire operation) - rust-lang#133681 (improve TagEncoding::Niche docs, sanity check, and UB checks) - rust-lang#133726 (Add `core::arch::breakpoint` and test) - rust-lang#133768 (Remove `generic_associated_types_extended` feature gate) - rust-lang#133811 ([AIX] change AIX default codemodel=large) - rust-lang#133812 (Update wasm-component-ld to 0.5.11) - rust-lang#133813 (compiletest: explain that UI tests are expected not to compile by default) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c44b3d5 + cd56913 commit 3b38264

Some content is hidden

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

51 files changed

+566
-240
lines changed

Cargo.lock

+11-2
Original file line numberDiff line numberDiff line change
@@ -5803,17 +5803,20 @@ checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d"
58035803

58045804
[[package]]
58055805
name = "wasm-component-ld"
5806-
version = "0.5.10"
5806+
version = "0.5.11"
58075807
source = "registry+https://github.com/rust-lang/crates.io-index"
5808-
checksum = "4d4aa6bd7fbe7cffbed29fe3e236fda74419def1bdef6f80f989ec51137edf44"
5808+
checksum = "a2b05c3820968b335f10e703218459e4fd2cc91fdfc8f7936a993f1aacaa0938"
58095809
dependencies = [
58105810
"anyhow",
58115811
"clap",
58125812
"lexopt",
5813+
"libc",
58135814
"tempfile",
58145815
"wasi-preview1-component-adapter-provider",
58155816
"wasmparser 0.219.1",
58165817
"wat",
5818+
"windows-sys 0.59.0",
5819+
"winsplit",
58175820
"wit-component",
58185821
"wit-parser",
58195822
]
@@ -6185,6 +6188,12 @@ dependencies = [
61856188
"memchr",
61866189
]
61876190

6191+
[[package]]
6192+
name = "winsplit"
6193+
version = "0.1.0"
6194+
source = "registry+https://github.com/rust-lang/crates.io-index"
6195+
checksum = "3ab703352da6a72f35c39a533526393725640575bb211f61987a2748323ad956"
6196+
61886197
[[package]]
61896198
name = "wit-component"
61906199
version = "0.219.1"

compiler/rustc_abi/src/lib.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,15 @@ impl Scalar {
12151215
Scalar::Union { .. } => true,
12161216
}
12171217
}
1218+
1219+
/// Returns `true` if this is a signed integer scalar
1220+
#[inline]
1221+
pub fn is_signed(&self) -> bool {
1222+
match self.primitive() {
1223+
Primitive::Int(_, signed) => signed,
1224+
_ => false,
1225+
}
1226+
}
12181227
}
12191228

12201229
// NOTE: This struct is generic over the FieldIdx for rust-analyzer usage.
@@ -1401,10 +1410,7 @@ impl BackendRepr {
14011410
#[inline]
14021411
pub fn is_signed(&self) -> bool {
14031412
match self {
1404-
BackendRepr::Scalar(scal) => match scal.primitive() {
1405-
Primitive::Int(_, signed) => signed,
1406-
_ => false,
1407-
},
1413+
BackendRepr::Scalar(scal) => scal.is_signed(),
14081414
_ => panic!("`is_signed` on non-scalar ABI {self:?}"),
14091415
}
14101416
}
@@ -1499,7 +1505,11 @@ impl BackendRepr {
14991505
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
15001506
pub enum Variants<FieldIdx: Idx, VariantIdx: Idx> {
15011507
/// Single enum variants, structs/tuples, unions, and all non-ADTs.
1502-
Single { index: VariantIdx },
1508+
Single {
1509+
/// Always 0 for non-enums/generators.
1510+
/// For enums without a variant, this is an invalid index!
1511+
index: VariantIdx,
1512+
},
15031513

15041514
/// Enum-likes with more than one variant: each variant comes with
15051515
/// a *discriminant* (usually the same as the variant index but the user can
@@ -1528,14 +1538,22 @@ pub enum TagEncoding<VariantIdx: Idx> {
15281538
/// The variant `untagged_variant` contains a niche at an arbitrary
15291539
/// offset (field `tag_field` of the enum), which for a variant with
15301540
/// discriminant `d` is set to
1531-
/// `(d - niche_variants.start).wrapping_add(niche_start)`.
1541+
/// `(d - niche_variants.start).wrapping_add(niche_start)`
1542+
/// (this is wrapping arithmetic using the type of the niche field).
15321543
///
15331544
/// For example, `Option<(usize, &T)>` is represented such that
15341545
/// `None` has a null pointer for the second tuple field, and
15351546
/// `Some` is the identity function (with a non-null reference).
1547+
///
1548+
/// Other variants that are not `untagged_variant` and that are outside the `niche_variants`
1549+
/// range cannot be represented; they must be uninhabited.
15361550
Niche {
15371551
untagged_variant: VariantIdx,
1552+
/// This range *may* contain `untagged_variant`; that is then just a "dead value" and
1553+
/// not used to encode anything.
15381554
niche_variants: RangeInclusive<VariantIdx>,
1555+
/// This is inbounds of the type of the niche field
1556+
/// (not sign-extended, i.e., all bits beyond the niche field size are 0).
15391557
niche_start: u128,
15401558
},
15411559
}

compiler/rustc_const_eval/src/const_eval/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use rustc_abi::VariantIdx;
44
use rustc_middle::query::{Key, TyCtxtAt};
5+
use rustc_middle::ty::layout::LayoutOf;
56
use rustc_middle::ty::{self, Ty, TyCtxt};
67
use rustc_middle::{bug, mir};
78
use tracing::instrument;
@@ -85,5 +86,6 @@ pub fn tag_for_variant_provider<'tcx>(
8586
crate::const_eval::DummyMachine,
8687
);
8788

88-
ecx.tag_for_variant(ty, variant_index).unwrap().map(|(tag, _tag_field)| tag)
89+
let layout = ecx.layout_of(ty).unwrap();
90+
ecx.tag_for_variant(layout, variant_index).unwrap().map(|(tag, _tag_field)| tag)
8991
}

compiler/rustc_const_eval/src/interpret/discriminant.rs

+25-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Functions for reading and writing discriminants of multi-variant layouts (enums and coroutines).
22
33
use rustc_abi::{self as abi, TagEncoding, VariantIdx, Variants};
4-
use rustc_middle::ty::layout::{LayoutOf, PrimitiveExt};
4+
use rustc_middle::ty::layout::{LayoutOf, PrimitiveExt, TyAndLayout};
55
use rustc_middle::ty::{self, CoroutineArgsExt, ScalarInt, Ty};
66
use rustc_middle::{mir, span_bug};
77
use tracing::{instrument, trace};
@@ -21,17 +21,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
2121
variant_index: VariantIdx,
2222
dest: &impl Writeable<'tcx, M::Provenance>,
2323
) -> InterpResult<'tcx> {
24-
// Layout computation excludes uninhabited variants from consideration
25-
// therefore there's no way to represent those variants in the given layout.
26-
// Essentially, uninhabited variants do not have a tag that corresponds to their
27-
// discriminant, so we cannot do anything here.
28-
// When evaluating we will always error before even getting here, but ConstProp 'executes'
29-
// dead code, so we cannot ICE here.
30-
if dest.layout().for_variant(self, variant_index).is_uninhabited() {
31-
throw_ub!(UninhabitedEnumVariantWritten(variant_index))
32-
}
33-
34-
match self.tag_for_variant(dest.layout().ty, variant_index)? {
24+
match self.tag_for_variant(dest.layout(), variant_index)? {
3525
Some((tag, tag_field)) => {
3626
// No need to validate that the discriminant here because the
3727
// `TyAndLayout::for_variant()` call earlier already checks the
@@ -80,7 +70,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
8070
if ty.is_enum() {
8171
// Hilariously, `Single` is used even for 0-variant enums.
8272
// (See https://github.com/rust-lang/rust/issues/89765).
83-
if matches!(ty.kind(), ty::Adt(def, ..) if def.variants().is_empty()) {
73+
if ty.ty_adt_def().unwrap().variants().is_empty() {
8474
throw_ub!(UninhabitedEnumVariantRead(index))
8575
}
8676
// For consistency with `write_discriminant`, and to make sure that
@@ -188,6 +178,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
188178
let variants =
189179
ty.ty_adt_def().expect("tagged layout for non adt").variants();
190180
assert!(variant_index < variants.next_index());
181+
if variant_index == untagged_variant {
182+
// The untagged variant can be in the niche range, but even then it
183+
// is not a valid encoding.
184+
throw_ub!(InvalidTag(Scalar::from_uint(tag_bits, tag_layout.size)))
185+
}
191186
variant_index
192187
} else {
193188
untagged_variant
@@ -236,10 +231,18 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
236231
/// given field index.
237232
pub(crate) fn tag_for_variant(
238233
&self,
239-
ty: Ty<'tcx>,
234+
layout: TyAndLayout<'tcx>,
240235
variant_index: VariantIdx,
241236
) -> InterpResult<'tcx, Option<(ScalarInt, usize)>> {
242-
match self.layout_of(ty)?.variants {
237+
// Layout computation excludes uninhabited variants from consideration.
238+
// Therefore, there's no way to represent those variants in the given layout.
239+
// Essentially, uninhabited variants do not have a tag that corresponds to their
240+
// discriminant, so we have to bail out here.
241+
if layout.for_variant(self, variant_index).is_uninhabited() {
242+
throw_ub!(UninhabitedEnumVariantWritten(variant_index))
243+
}
244+
245+
match layout.variants {
243246
abi::Variants::Single { .. } => {
244247
// The tag of a `Single` enum is like the tag of the niched
245248
// variant: there's no tag as the discriminant is encoded
@@ -260,7 +263,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
260263
// raw discriminants for enums are isize or bigger during
261264
// their computation, but the in-memory tag is the smallest possible
262265
// representation
263-
let discr = self.discriminant_for_variant(ty, variant_index)?;
266+
let discr = self.discriminant_for_variant(layout.ty, variant_index)?;
264267
let discr_size = discr.layout.size;
265268
let discr_val = discr.to_scalar().to_bits(discr_size)?;
266269
let tag_size = tag_layout.size(self);
@@ -286,11 +289,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
286289
..
287290
} => {
288291
assert!(variant_index != untagged_variant);
292+
// We checked that this variant is inhabited, so it must be in the niche range.
293+
assert!(
294+
niche_variants.contains(&variant_index),
295+
"invalid variant index for this enum"
296+
);
289297
let variants_start = niche_variants.start().as_u32();
290-
let variant_index_relative = variant_index
291-
.as_u32()
292-
.checked_sub(variants_start)
293-
.expect("overflow computing relative variant idx");
298+
let variant_index_relative = variant_index.as_u32().strict_sub(variants_start);
294299
// We need to use machine arithmetic when taking into account `niche_start`:
295300
// tag_val = variant_index_relative + niche_start_val
296301
let tag_layout = self.layout_of(tag_layout.primitive().to_int_ty(*self.tcx))?;

compiler/rustc_const_eval/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![feature(never_type)]
1111
#![feature(rustdoc_internals)]
1212
#![feature(slice_ptr_get)]
13+
#![feature(strict_overflow_ops)]
1314
#![feature(trait_alias)]
1415
#![feature(try_blocks)]
1516
#![feature(unqualified_local_imports)]

compiler/rustc_error_codes/src/error_codes/E0622.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ Erroneous code example:
77
#![allow(internal_features)]
88
99
extern "rust-intrinsic" {
10-
pub static breakpoint: fn(); // error: intrinsic must be a function
10+
pub static atomic_singlethreadfence_seqcst: fn();
11+
// error: intrinsic must be a function
1112
}
1213
13-
fn main() { unsafe { breakpoint(); } }
14+
fn main() { unsafe { atomic_singlethreadfence_seqcst(); } }
1415
```
1516

1617
An intrinsic is a function available for use in a given programming language
@@ -22,8 +23,8 @@ error, just declare a function. Example:
2223
#![allow(internal_features)]
2324
2425
extern "rust-intrinsic" {
25-
pub fn breakpoint(); // ok!
26+
pub fn atomic_singlethreadfence_seqcst(); // ok!
2627
}
2728
28-
fn main() { unsafe { breakpoint(); } }
29+
fn main() { unsafe { atomic_singlethreadfence_seqcst(); } }
2930
```

compiler/rustc_feature/src/removed.rs

+7
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ declare_features! (
119119
(removed, generator_clone, "1.65.0", Some(95360), Some("renamed to `coroutine_clone`")),
120120
/// Allows defining generators.
121121
(removed, generators, "1.21.0", Some(43122), Some("renamed to `coroutines`")),
122+
/// An extension to the `generic_associated_types` feature, allowing incomplete features.
123+
(removed, generic_associated_types_extended, "CURRENT_RUSTC_VERSION", Some(95451),
124+
Some(
125+
"feature needs overhaul and reimplementation pending \
126+
better implied higher-ranked implied bounds support"
127+
)
128+
),
122129
/// Allows `impl Trait` in bindings (`let`, `const`, `static`).
123130
(removed, impl_trait_in_bindings, "1.55.0", Some(63065),
124131
Some("the implementation was not maintainable, the feature may get reintroduced once the current refactorings are done")),

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,6 @@ declare_features! (
499499
(unstable, gen_blocks, "1.75.0", Some(117078)),
500500
/// Infer generic args for both consts and types.
501501
(unstable, generic_arg_infer, "1.55.0", Some(85077)),
502-
/// An extension to the `generic_associated_types` feature, allowing incomplete features.
503-
(incomplete, generic_associated_types_extended, "1.61.0", Some(95451)),
504502
/// Allows non-trivial generic constants which have to have wfness manually propagated to callers
505503
(incomplete, generic_const_exprs, "1.56.0", Some(76560)),
506504
/// Allows generic parameters and where-clauses on free & associated const items.

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -
8787
| sym::assert_inhabited
8888
| sym::assert_zero_valid
8989
| sym::assert_mem_uninitialized_valid
90+
| sym::breakpoint
9091
| sym::size_of
9192
| sym::min_align_of
9293
| sym::needs_drop

compiler/rustc_middle/src/query/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,8 @@ rustc_queries! {
10811081
}
10821082

10831083
/// Computes the tag (if any) for a given type and variant.
1084+
/// `None` means that the variant doesn't need a tag (because it is niched).
1085+
/// Will panic for uninhabited variants.
10841086
query tag_for_variant(
10851087
key: (Ty<'tcx>, abi::VariantIdx)
10861088
) -> Option<ty::ScalarInt> {

compiler/rustc_target/src/spec/base/aix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::spec::{Cc, CodeModel, LinkOutputKind, LinkerFlavor, TargetOptions, cr
44
pub(crate) fn opts() -> TargetOptions {
55
TargetOptions {
66
abi: "vec-extabi".into(),
7-
code_model: Some(CodeModel::Small),
7+
code_model: Some(CodeModel::Large),
88
cpu: "pwr7".into(),
99
os: "aix".into(),
1010
vendor: "ibm".into(),

compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,7 @@ pub fn dyn_compatibility_violations_for_assoc_item(
328328
.collect(),
329329
// Associated types can only be dyn-compatible if they have `Self: Sized` bounds.
330330
ty::AssocKind::Type => {
331-
if !tcx.features().generic_associated_types_extended()
332-
&& !tcx.generics_of(item.def_id).is_own_empty()
333-
&& !item.is_impl_trait_in_trait()
334-
{
331+
if !tcx.generics_of(item.def_id).is_own_empty() && !item.is_impl_trait_in_trait() {
335332
vec![DynCompatibilityViolation::GAT(item.name, item.ident(tcx).span)]
336333
} else {
337334
// We will permit associated types if they are explicitly mentioned in the trait object.

compiler/rustc_trait_selection/src/traits/project.rs

+1-25
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::traits::select::OverflowError;
1414
use rustc_middle::traits::{BuiltinImplSource, ImplSource, ImplSourceUserDefinedData};
1515
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
1616
use rustc_middle::ty::fold::TypeFoldable;
17-
use rustc_middle::ty::visit::{MaxUniverse, TypeVisitable, TypeVisitableExt};
17+
use rustc_middle::ty::visit::TypeVisitableExt;
1818
use rustc_middle::ty::{self, Term, Ty, TyCtxt, TypingMode, Upcast};
1919
use rustc_middle::{bug, span_bug};
2020
use rustc_span::symbol::sym;
@@ -179,35 +179,11 @@ pub(super) fn poly_project_and_unify_term<'cx, 'tcx>(
179179
) -> ProjectAndUnifyResult<'tcx> {
180180
let infcx = selcx.infcx;
181181
let r = infcx.commit_if_ok(|_snapshot| {
182-
let old_universe = infcx.universe();
183182
let placeholder_predicate = infcx.enter_forall_and_leak_universe(obligation.predicate);
184-
let new_universe = infcx.universe();
185183

186184
let placeholder_obligation = obligation.with(infcx.tcx, placeholder_predicate);
187185
match project_and_unify_term(selcx, &placeholder_obligation) {
188186
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => Err(e),
189-
ProjectAndUnifyResult::Holds(obligations)
190-
if old_universe != new_universe
191-
&& selcx.tcx().features().generic_associated_types_extended() =>
192-
{
193-
// If the `generic_associated_types_extended` feature is active, then we ignore any
194-
// obligations references lifetimes from any universe greater than or equal to the
195-
// universe just created. Otherwise, we can end up with something like `for<'a> I: 'a`,
196-
// which isn't quite what we want. Ideally, we want either an implied
197-
// `for<'a where I: 'a> I: 'a` or we want to "lazily" check these hold when we
198-
// instantiate concrete regions. There is design work to be done here; until then,
199-
// however, this allows experimenting potential GAT features without running into
200-
// well-formedness issues.
201-
let new_obligations = obligations
202-
.into_iter()
203-
.filter(|obligation| {
204-
let mut visitor = MaxUniverse::new();
205-
obligation.predicate.visit_with(&mut visitor);
206-
visitor.max_universe() < new_universe
207-
})
208-
.collect();
209-
Ok(ProjectAndUnifyResult::Holds(new_obligations))
210-
}
211187
other => Ok(other),
212188
}
213189
});

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
626626
for assoc_type in assoc_types {
627627
let defs: &ty::Generics = tcx.generics_of(assoc_type);
628628

629-
if !defs.own_params.is_empty() && !tcx.features().generic_associated_types_extended() {
629+
if !defs.own_params.is_empty() {
630630
tcx.dcx().span_delayed_bug(
631631
obligation.cause.span,
632632
"GATs in trait object shouldn't have been considered",

0 commit comments

Comments
 (0)