Skip to content

Rollup of 6 pull requests #130649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
e759e0b
add guarantee about remove_dir and remove_file error kinds
lolbinarycat Aug 29, 2024
7160447
Add recursion limit to FFI safety lint
gurry Sep 20, 2024
c722641
Remove double spaces
Noratrieb Sep 20, 2024
2db62e6
compiler: factor OVERFLOWING_LITERALS impl into a file (nfc)
workingjubilee Sep 20, 2024
4e53640
Pass the current cargo to `run-make` tests
cuviper Sep 20, 2024
844edfe
compiler: reuse {un,}signed_fit in get_type_suggestion (nfc)
workingjubilee Sep 20, 2024
a9a8f79
Normalize unevaluated consts in GCE
compiler-errors Sep 21, 2024
920a973
Don't emit spurious error for pattern matched array with erroneous le…
compiler-errors Sep 21, 2024
914193c
Do not unnecessarily eval consts in codegen
compiler-errors Sep 21, 2024
d3f270b
Normalize transparent struct field type in CFI
compiler-errors Sep 20, 2024
c0d1a13
Only expect mono consts in CFI
compiler-errors Sep 21, 2024
f2290c2
Rollup merge of #129718 - lolbinarycat:remove_dir-docs, r=Noratrieb
matthiaskrgr Sep 21, 2024
28ace83
Rollup merge of #130598 - gurry:130310-improper-types-stack-overflow,…
matthiaskrgr Sep 21, 2024
4336628
Rollup merge of #130642 - cuviper:run-make-cargo, r=jieyouxu
matthiaskrgr Sep 21, 2024
ff6cd18
Rollup merge of #130644 - compiler-errors:consts-in-codegen, r=BoxyUwU
matthiaskrgr Sep 21, 2024
e6cf3bd
Rollup merge of #130645 - compiler-errors:normalize-gce-writeback, r=…
matthiaskrgr Sep 21, 2024
5770ba8
Rollup merge of #130646 - workingjubilee:literally-factorize-int-lint…
matthiaskrgr Sep 21, 2024
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
22 changes: 22 additions & 0 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,28 @@ pub enum Integer {
}

impl Integer {
pub fn int_ty_str(self) -> &'static str {
use Integer::*;
match self {
I8 => "i8",
I16 => "i16",
I32 => "i32",
I64 => "i64",
I128 => "i128",
}
}

pub fn uint_ty_str(self) -> &'static str {
use Integer::*;
match self {
I8 => "u8",
I16 => "u16",
I32 => "u32",
I64 => "u64",
I128 => "u128",
}
}

#[inline]
pub fn size(self) -> Size {
use Integer::*;
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,10 @@ fn codegen_stmt<'tcx>(
}
Rvalue::Repeat(ref operand, times) => {
let operand = codegen_operand(fx, operand);
let times =
fx.monomorphize(times).eval_target_usize(fx.tcx, ParamEnv::reveal_all());
let times = fx
.monomorphize(times)
.try_to_target_usize(fx.tcx)
.expect("expected monomorphic const in codegen");
if operand.layout().size.bytes() == 0 {
// Do nothing for ZST's
} else if fx.clif_type(operand.layout().ty) == Some(types::I8) {
Expand Down Expand Up @@ -944,7 +946,10 @@ fn codegen_stmt<'tcx>(
fn codegen_array_len<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, place: CPlace<'tcx>) -> Value {
match *place.layout().ty.kind() {
ty::Array(_elem_ty, len) => {
let len = fx.monomorphize(len).eval_target_usize(fx.tcx, ParamEnv::reveal_all()) as i64;
let len = fx
.monomorphize(len)
.try_to_target_usize(fx.tcx)
.expect("expected monomorphic const in codegen") as i64;
fx.bcx.ins().iconst(fx.pointer_type, len)
}
ty::Slice(_elem_ty) => place.to_ptr_unsized().1,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/debuginfo/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl DebugContext {
type_dbg,
ty,
*elem_ty,
len.eval_target_usize(tcx, ty::ParamEnv::reveal_all()),
len.try_to_target_usize(tcx).expect("expected monomorphic const in codegen"),
),
// ty::Slice(_) | ty::Str
// ty::Dynamic
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(

let idx = generic_args[2]
.expect_const()
.eval(fx.tcx, ty::ParamEnv::reveal_all(), span)
.unwrap()
.1
.try_to_valtree()
.expect("expected monomorphic const in codegen")
.unwrap_branch();

assert_eq!(x.layout(), y.layout());
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_cranelift/src/unsize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ pub(crate) fn unsized_info<'tcx>(
let (source, target) =
fx.tcx.struct_lockstep_tails_for_codegen(source, target, ParamEnv::reveal_all());
match (&source.kind(), &target.kind()) {
(&ty::Array(_, len), &ty::Slice(_)) => fx
.bcx
.ins()
.iconst(fx.pointer_type, len.eval_target_usize(fx.tcx, ParamEnv::reveal_all()) as i64),
(&ty::Array(_, len), &ty::Slice(_)) => fx.bcx.ins().iconst(
fx.pointer_type,
len.try_to_target_usize(fx.tcx).expect("expected monomorphic const in codegen") as i64,
),
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
if src_dyn_kind == target_dyn_kind =>
{
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ fn build_fixed_size_array_di_node<'ll, 'tcx>(

let (size, align) = cx.size_and_align_of(array_type);

let upper_bound = len.eval_target_usize(cx.tcx, ty::ParamEnv::reveal_all()) as c_longlong;
let upper_bound = len
.try_to_target_usize(cx.tcx)
.expect("expected monomorphic const in codegen") as c_longlong;

let subrange =
unsafe { Some(llvm::LLVMRustDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound)) };
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let (source, target) =
cx.tcx().struct_lockstep_tails_for_codegen(source, target, bx.param_env());
match (source.kind(), target.kind()) {
(&ty::Array(_, len), &ty::Slice(_)) => {
cx.const_usize(len.eval_target_usize(cx.tcx(), ty::ParamEnv::reveal_all()))
}
(&ty::Array(_, len), &ty::Slice(_)) => cx.const_usize(
len.try_to_target_usize(cx.tcx()).expect("expected monomorphic const in codegen"),
),
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
if src_dyn_kind == target_dyn_kind =>
{
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ fn push_debuginfo_type_name<'tcx>(
_ => write!(
output,
",{}>",
len.eval_target_usize(tcx, ty::ParamEnv::reveal_all())
len.try_to_target_usize(tcx)
.expect("expected monomorphic const in codegen")
)
.unwrap(),
}
Expand All @@ -200,7 +201,8 @@ fn push_debuginfo_type_name<'tcx>(
_ => write!(
output,
"; {}]",
len.eval_target_usize(tcx, ty::ParamEnv::reveal_all())
len.try_to_target_usize(tcx)
.expect("expected monomorphic const in codegen")
)
.unwrap(),
}
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

let count = self
.monomorphize(count)
.eval_target_usize(bx.cx().tcx(), ty::ParamEnv::reveal_all());
.try_to_target_usize(bx.tcx())
.expect("expected monomorphic const in codegen");

bx.write_operand_repeatedly(cg_elem, count, dest);
}
Expand Down Expand Up @@ -803,7 +804,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
if let Some(index) = place.as_local() {
if let LocalRef::Operand(op) = self.locals[index] {
if let ty::Array(_, n) = op.layout.ty.kind() {
let n = n.eval_target_usize(bx.cx().tcx(), ty::ParamEnv::reveal_all());
let n = n
.try_to_target_usize(bx.tcx())
.expect("expected monomorphic const in codegen");
return bx.cx().const_usize(n);
}
}
Expand Down
13 changes: 1 addition & 12 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::pat_util::EnumerateAndAdjustIterator;
use rustc_hir::{self as hir, BindingMode, ByRef, HirId, LangItem, Mutability, Pat, PatKind};
use rustc_infer::infer;
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
use rustc_middle::{bug, span_bug};
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
Expand Down Expand Up @@ -2413,17 +2412,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
len: ty::Const<'tcx>,
min_len: u64,
) -> (Option<Ty<'tcx>>, Ty<'tcx>) {
let len = match len.eval(self.tcx, self.param_env, span) {
Ok((_, val)) => val
.try_to_scalar()
.and_then(|scalar| scalar.try_to_scalar_int().ok())
.map(|int| int.to_target_usize(self.tcx)),
Err(ErrorHandled::Reported(..)) => {
let guar = self.error_scrutinee_unfixed_length(span);
return (Some(Ty::new_error(self.tcx, guar)), arr_ty);
}
Err(ErrorHandled::TooGeneric(..)) => None,
};
let len = len.try_eval_target_usize(self.tcx, self.param_env);

let guar = if let Some(len) = len {
// Now we know the length...
Expand Down
37 changes: 33 additions & 4 deletions compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
// We must deeply normalize in the new solver, since later lints
// expect that types that show up in the typeck are fully
// normalized.
let value = if self.should_normalize {
let mut value = if self.should_normalize {
let body_id = tcx.hir().body_owner_def_id(self.body.id());
let cause = ObligationCause::misc(self.span.to_span(tcx), body_id);
let at = self.fcx.at(&cause, self.fcx.param_env);
Expand All @@ -818,12 +818,27 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
value
};

// Bail if there are any non-region infer.
if value.has_non_region_infer() {
let guar = self.report_error(value);
new_err(tcx, guar)
} else {
tcx.fold_regions(value, |_, _| tcx.lifetimes.re_erased)
value = new_err(tcx, guar);
}

// Erase the regions from the ty, since it's not really meaningful what
// these region values are; there's not a trivial correspondence between
// regions in the HIR and MIR, so when we turn the body into MIR, there's
// no reason to keep regions around. They will be repopulated during MIR
// borrowck, and specifically region constraints will be populated during
// MIR typeck which is run on the new body.
value = tcx.fold_regions(value, |_, _| tcx.lifetimes.re_erased);

// Normalize consts in writeback, because GCE doesn't normalize eagerly.
if tcx.features().generic_const_exprs {
value =
value.fold_with(&mut EagerlyNormalizeConsts { tcx, param_env: self.fcx.param_env });
}

value
}
}

Expand Down Expand Up @@ -858,3 +873,17 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
predicate
}
}

struct EagerlyNormalizeConsts<'tcx> {
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
}
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EagerlyNormalizeConsts<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}

fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
self.tcx.try_normalize_erasing_regions(self.param_env, ct).unwrap_or(ct)
}
}
2 changes: 2 additions & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ lint_improper_ctypes_opaque = opaque types have no C equivalent
lint_improper_ctypes_pat_help = consider using the base type instead

lint_improper_ctypes_pat_reason = pattern types have no C equivalent

lint_improper_ctypes_recursion_limit_reached = type is infinitely recursive
lint_improper_ctypes_slice_help = consider using a raw pointer instead

lint_improper_ctypes_slice_reason = slices have no C equivalent
Expand Down
Loading
Loading