Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0d0aaa1
Some arena macro tweaks.
nnethercote Apr 20, 2026
cdefdd0
Fix a metadata table name.
nnethercote Apr 22, 2026
3b5dd18
Fix some comments.
nnethercote Apr 24, 2026
a07a3b1
windows/time: avoid being too close to 0
RalfJung May 5, 2026
3c83d3a
llvm: Use correct type for splat mask
maurer May 5, 2026
803c7ba
Some fold/visit tweaks.
nnethercote Apr 24, 2026
4fe8268
Refactor `Type::size` field to `TypeId::size` method for `type_info`
SpriteOvO May 6, 2026
814fc17
Deny warnings in rustc crates on stable
jdonszelmann Apr 29, 2026
0afe083
Avoid some global `node_id_to_def_id` lookups in import resolution
oli-obk May 5, 2026
191cda5
Avoid using `id` followed by `local_def_id` if we can just call `def_…
oli-obk May 5, 2026
400240a
Avoid hitting the global node_id_to_def_id table for unused macros
oli-obk May 5, 2026
a082567
Follow-up cleanups reusing the now-available `LocalDefId`s
oli-obk May 5, 2026
b8e547a
fix warnings in rustc_type_ir
jdonszelmann Apr 29, 2026
3f7bf60
Add Trusty OS to the generic error implementation.
chaos2007 May 6, 2026
7ccd895
add passing test that should fail
lqd May 6, 2026
325b013
prevent directives from having multiple revisions
lqd May 6, 2026
ccd70c1
move coercion tests out of ui/issues into its folder
danieljofficial May 6, 2026
c5cf608
add issue links and bless
danieljofficial May 6, 2026
ff25d8a
Use special DefIds for aliases
ChayimFriedman2 Apr 9, 2026
aadf600
Document wasi-sdk minimum versions for WASI targets
alexcrichton May 6, 2026
f7649e7
Rename and move `downcast` to `project_downcast_named` for `InterpCx`
SpriteOvO May 6, 2026
ac468d5
Rollup merge of #156173 - oli-obk:fewer-global-lookups, r=petrochenkov
jhpratt May 7, 2026
746ea54
Rollup merge of #156177 - RalfJung:windows-time-epoch, r=ChrisDenton
jhpratt May 7, 2026
70c1afd
Rollup merge of #155961 - jdonszelmann:deny-warnings-stable, r=mejrs
jhpratt May 7, 2026
b320b56
Rollup merge of #155981 - ChayimFriedman2:alias-def-id, r=lcnr
jhpratt May 7, 2026
2bc8e5e
Rollup merge of #156130 - nnethercote:fold-visit-tweaks, r=WaffleLapkin
jhpratt May 7, 2026
2aadc4a
Rollup merge of #156131 - nnethercote:rm-unnecessary-decode, r=Zalathar
jhpratt May 7, 2026
e6fac7e
Rollup merge of #156202 - maurer:splat, r=nikic
jhpratt May 7, 2026
44ce9e7
Rollup merge of #156223 - SpriteOvO:type-info-refactor-size, r=oli-obk
jhpratt May 7, 2026
99e0e37
Rollup merge of #156227 - chaos2007:main, r=jhpratt,randomPoison
jhpratt May 7, 2026
6fa435d
Rollup merge of #156237 - lqd:compiletest-revisions, r=wesleywiser,ji…
jhpratt May 7, 2026
3d841c1
Rollup merge of #156241 - danieljofficial:move-tests-coercion, r=Kivooeo
jhpratt May 7, 2026
f84a2cd
Rollup merge of #156258 - alexcrichton:update-some-docs, r=jieyouxu
jhpratt May 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
}

if name == sym::simd_splat {
let (_out_len, out_ty) = require_simd!(ret_ty, SimdReturn);
let (out_len, out_ty) = require_simd!(ret_ty, SimdReturn);

require!(
args[0].layout.ty == out_ty,
Expand All @@ -2105,7 +2105,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>(

// `shufflevector <N x elem> v0, <N x elem> poison, <N x i32> zeroinitializer`
// The masks is all zeros, so this splats lane 0 (which has our element in it).
let splat = bx.shuffle_vector(v0, poison_vec, bx.const_null(llret_ty));
let mask_ty = bx.type_vector(bx.type_i32(), out_len);
let splat = bx.shuffle_vector(v0, poison_vec, bx.const_null(mask_ty));

return Ok(splat);
}
Expand Down
21 changes: 19 additions & 2 deletions compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::{Borrow, Cow};
use std::hash::Hash;
use std::{fmt, mem};

use rustc_abi::{Align, FIRST_VARIANT, Size};
use rustc_abi::{Align, FIRST_VARIANT, FieldIdx, Size};
use rustc_ast::Mutability;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, IndexEntry};
use rustc_hir::def_id::{DefId, LocalDefId};
Expand All @@ -11,7 +11,7 @@ use rustc_middle::mir::AssertMessage;
use rustc_middle::mir::interpret::ReportedErrorInfo;
use rustc_middle::query::TyCtxtAt;
use rustc_middle::ty::layout::{HasTypingEnv, TyAndLayout, ValidityRequirement};
use rustc_middle::ty::{self, FieldInfo, Ty, TyCtxt};
use rustc_middle::ty::{self, FieldInfo, ScalarInt, Ty, TyCtxt};
use rustc_middle::{bug, mir, span_bug};
use rustc_span::{Span, Symbol, sym};
use rustc_target::callconv::FnAbi;
Expand Down Expand Up @@ -605,6 +605,23 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
ecx.write_type_info(ty, dest)?;
}

sym::size_of_type_id => {
let ty = ecx.read_type_id(&args[0])?;
let layout = ecx.layout_of(ty)?;
let variant_index = if layout.is_sized() {
let (variant, variant_place) = ecx.project_downcast_named(dest, sym::Some)?;
let size_field_place = ecx.project_field(&variant_place, FieldIdx::ZERO)?;
ecx.write_scalar(
ScalarInt::try_from_target_usize(layout.size.bytes(), ecx.tcx.tcx).unwrap(),
&size_field_place,
)?;
variant
} else {
ecx.project_downcast_named(dest, sym::None)?.0
};
ecx.write_discriminant(variant_index, dest)?;
}

sym::field_offset => {
let frt_ty = instance.args.type_at(0);
ensure_monomorphic_enough(ecx.tcx.tcx, frt_ty)?;
Expand Down
77 changes: 24 additions & 53 deletions compiler/rustc_const_eval/src/const_eval/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod adt;

use std::borrow::Cow;

use rustc_abi::{ExternAbi, FieldIdx, VariantIdx};
use rustc_abi::{ExternAbi, FieldIdx};
use rustc_ast::Mutability;
use rustc_hir::LangItem;
use rustc_middle::span_bug;
Expand All @@ -12,27 +12,11 @@ use rustc_span::{Symbol, sym};

use crate::const_eval::CompileTimeMachine;
use crate::interpret::{
CtfeProvenance, Immediate, InterpCx, InterpResult, MPlaceTy, MemoryKind, Projectable, Scalar,
Writeable, interp_ok,
CtfeProvenance, Immediate, InterpCx, InterpResult, MPlaceTy, MemoryKind, Scalar, Writeable,
interp_ok,
};

impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
/// Equivalent to `project_downcast`, but identifies the variant by name instead of index.
fn downcast<'a>(
&self,
place: &(impl Writeable<'tcx, CtfeProvenance> + 'a),
name: Symbol,
) -> InterpResult<'tcx, (VariantIdx, impl Writeable<'tcx, CtfeProvenance> + 'a)> {
let variants = place.layout().ty.ty_adt_def().unwrap().variants();
let variant_idx = variants
.iter_enumerated()
.find(|(_idx, var)| var.name == name)
.unwrap_or_else(|| panic!("got {name} but expected one of {variants:#?}"))
.0;

interp_ok((variant_idx, self.project_downcast(place, variant_idx)?))
}

// A general method to write an array to a static slice place.
fn allocate_fill_and_write_slice_ptr(
&mut self,
Expand Down Expand Up @@ -83,7 +67,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
let variant_index = match ty.kind() {
ty::Tuple(fields) => {
let (variant, variant_place) =
self.downcast(&field_dest, sym::Tuple)?;
self.project_downcast_named(&field_dest, sym::Tuple)?;
// project to the single tuple variant field of `type_info::Tuple` struct type
let tuple_place = self.project_field(&variant_place, FieldIdx::ZERO)?;
assert_eq!(
Expand All @@ -102,7 +86,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
}
ty::Array(ty, len) => {
let (variant, variant_place) =
self.downcast(&field_dest, sym::Array)?;
self.project_downcast_named(&field_dest, sym::Array)?;
let array_place = self.project_field(&variant_place, FieldIdx::ZERO)?;

self.write_array_type_info(array_place, *ty, *len)?;
Expand All @@ -111,7 +95,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
}
ty::Slice(ty) => {
let (variant, variant_place) =
self.downcast(&field_dest, sym::Slice)?;
self.project_downcast_named(&field_dest, sym::Slice)?;
let slice_place = self.project_field(&variant_place, FieldIdx::ZERO)?;

self.write_slice_type_info(slice_place, *ty)?;
Expand All @@ -123,16 +107,17 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
}
ty::Bool => {
let (variant, _variant_place) =
self.downcast(&field_dest, sym::Bool)?;
self.project_downcast_named(&field_dest, sym::Bool)?;
variant
}
ty::Char => {
let (variant, _variant_place) =
self.downcast(&field_dest, sym::Char)?;
self.project_downcast_named(&field_dest, sym::Char)?;
variant
}
ty::Int(int_ty) => {
let (variant, variant_place) = self.downcast(&field_dest, sym::Int)?;
let (variant, variant_place) =
self.project_downcast_named(&field_dest, sym::Int)?;
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
self.write_int_type_info(
place,
Expand All @@ -142,7 +127,8 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
variant
}
ty::Uint(uint_ty) => {
let (variant, variant_place) = self.downcast(&field_dest, sym::Int)?;
let (variant, variant_place) =
self.project_downcast_named(&field_dest, sym::Int)?;
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
self.write_int_type_info(
place,
Expand All @@ -153,18 +139,19 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
}
ty::Float(float_ty) => {
let (variant, variant_place) =
self.downcast(&field_dest, sym::Float)?;
self.project_downcast_named(&field_dest, sym::Float)?;
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
self.write_float_type_info(place, float_ty.bit_width())?;
variant
}
ty::Str => {
let (variant, _variant_place) = self.downcast(&field_dest, sym::Str)?;
let (variant, _variant_place) =
self.project_downcast_named(&field_dest, sym::Str)?;
variant
}
ty::Ref(_, ty, mutability) => {
let (variant, variant_place) =
self.downcast(&field_dest, sym::Reference)?;
self.project_downcast_named(&field_dest, sym::Reference)?;
let reference_place =
self.project_field(&variant_place, FieldIdx::ZERO)?;
self.write_reference_type_info(reference_place, *ty, *mutability)?;
Expand All @@ -173,7 +160,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
}
ty::RawPtr(ty, mutability) => {
let (variant, variant_place) =
self.downcast(&field_dest, sym::Pointer)?;
self.project_downcast_named(&field_dest, sym::Pointer)?;
let pointer_place =
self.project_field(&variant_place, FieldIdx::ZERO)?;

Expand All @@ -183,14 +170,14 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
}
ty::Dynamic(predicates, region) => {
let (variant, variant_place) =
self.downcast(&field_dest, sym::DynTrait)?;
self.project_downcast_named(&field_dest, sym::DynTrait)?;
let dyn_place = self.project_field(&variant_place, FieldIdx::ZERO)?;
self.write_dyn_trait_type_info(dyn_place, *predicates, *region)?;
variant
}
ty::FnPtr(sig, fn_header) => {
let (variant, variant_place) =
self.downcast(&field_dest, sym::FnPtr)?;
self.project_downcast_named(&field_dest, sym::FnPtr)?;
let fn_ptr_place =
self.project_field(&variant_place, FieldIdx::ZERO)?;

Expand All @@ -214,27 +201,10 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
| ty::Bound(..)
| ty::Placeholder(_)
| ty::Infer(..)
| ty::Error(_) => self.downcast(&field_dest, sym::Other)?.0,
| ty::Error(_) => self.project_downcast_named(&field_dest, sym::Other)?.0,
};
self.write_discriminant(variant_index, &field_dest)?
}
sym::size => {
let layout = self.layout_of(ty)?;
let variant_index = if layout.is_sized() {
let (variant, variant_place) = self.downcast(&field_dest, sym::Some)?;
let size_field_place =
self.project_field(&variant_place, FieldIdx::ZERO)?;
self.write_scalar(
ScalarInt::try_from_target_usize(layout.size.bytes(), self.tcx.tcx)
.unwrap(),
&size_field_place,
)?;
variant
} else {
self.downcast(&field_dest, sym::None)?.0
};
self.write_discriminant(variant_index, &field_dest)?;
}
other => span_bug!(self.tcx.span, "unknown `Type` field {other}"),
}
}
Expand Down Expand Up @@ -433,16 +403,17 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
sym::abi => match fn_sig_kind.abi() {
ExternAbi::C { .. } => {
let (rust_variant, _rust_place) =
self.downcast(&field_place, sym::ExternC)?;
self.project_downcast_named(&field_place, sym::ExternC)?;
self.write_discriminant(rust_variant, &field_place)?;
}
ExternAbi::Rust => {
let (rust_variant, _rust_place) =
self.downcast(&field_place, sym::ExternRust)?;
self.project_downcast_named(&field_place, sym::ExternRust)?;
self.write_discriminant(rust_variant, &field_place)?;
}
other_abi => {
let (variant, variant_place) = self.downcast(&field_place, sym::Named)?;
let (variant, variant_place) =
self.project_downcast_named(&field_place, sym::Named)?;
let str_place = self.allocate_str_dedup(other_abi.as_str())?;
let str_ref = self.mplace_to_imm_ptr(&str_place, None)?;
let payload = self.project_field(&variant_place, FieldIdx::ZERO)?;
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_const_eval/src/const_eval/type_info/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
let (adt_ty, adt_def) = adt;
let variant_idx = match adt_def.adt_kind() {
AdtKind::Struct => {
let (variant, variant_place) = self.downcast(place, sym::Struct)?;
let (variant, variant_place) = self.project_downcast_named(place, sym::Struct)?;
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
self.write_struct_type_info(
place,
Expand All @@ -32,7 +32,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
variant
}
AdtKind::Union => {
let (variant, variant_place) = self.downcast(place, sym::Union)?;
let (variant, variant_place) = self.project_downcast_named(place, sym::Union)?;
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
self.write_union_type_info(
place,
Expand All @@ -42,7 +42,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
variant
}
AdtKind::Enum => {
let (variant, variant_place) = self.downcast(place, sym::Enum)?;
let (variant, variant_place) = self.project_downcast_named(place, sym::Enum)?;
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
self.write_enum_type_info(place, adt, generics)?;
variant
Expand Down Expand Up @@ -219,13 +219,13 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
_region: Region<'tcx>,
place: MPlaceTy<'tcx>,
) -> InterpResult<'tcx> {
let (variant_idx, _) = self.downcast(&place, sym::Lifetime)?;
let (variant_idx, _) = self.project_downcast_named(&place, sym::Lifetime)?;
self.write_discriminant(variant_idx, &place)?;
interp_ok(())
}

fn write_generic_type(&mut self, ty: Ty<'tcx>, place: MPlaceTy<'tcx>) -> InterpResult<'tcx> {
let (variant_idx, variant_place) = self.downcast(&place, sym::Type)?;
let (variant_idx, variant_place) = self.project_downcast_named(&place, sym::Type)?;
let generic_type_place = self.project_field(&variant_place, FieldIdx::ZERO)?;

for (field_idx, field_def) in generic_type_place
Expand All @@ -251,7 +251,7 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
fn write_generic_const(&mut self, c: Const<'tcx>, place: MPlaceTy<'tcx>) -> InterpResult<'tcx> {
let ConstKind::Value(c) = c.kind() else { bug!("expected a computed const, got {c:?}") };

let (variant_idx, variant_place) = self.downcast(&place, sym::Const)?;
let (variant_idx, variant_place) = self.project_downcast_named(&place, sym::Const)?;
let const_place = self.project_field(&variant_place, FieldIdx::ZERO)?;

for (field_idx, field_def) in const_place
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_const_eval/src/interpret/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use rustc_abi::{self as abi, FieldIdx, Size, VariantIdx};
use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::TyAndLayout;
use rustc_middle::{bug, mir, span_bug, ty};
use rustc_span::Symbol;
use tracing::{debug, instrument};

use super::{
Expand Down Expand Up @@ -227,6 +228,22 @@ where
base.offset(Size::ZERO, layout, self)
}

/// Equivalent to `project_downcast`, but identifies the variant by name instead of index.
pub fn project_downcast_named<P: Projectable<'tcx, M::Provenance>>(
&self,
base: &P,
name: Symbol,
) -> InterpResult<'tcx, (VariantIdx, P)> {
let variants = base.layout().ty.ty_adt_def().unwrap().variants();
let variant_idx = variants
.iter_enumerated()
.find(|(_idx, var)| var.name == name)
.unwrap_or_else(|| panic!("got {name} but expected one of {variants:#?}"))
.0;

interp_ok((variant_idx, self.project_downcast(base, variant_idx)?))
}

/// Compute the offset and field layout for accessing the given index.
pub fn project_index<P: Projectable<'tcx, M::Provenance>>(
&self,
Expand Down
Loading
Loading