Skip to content

Commit 1000fe7

Browse files
committed
Auto merge of rust-lang#125507 - compiler-errors:type-length-limit, r=<try>
Re-implement a type-size based limit r? lcnr Fixes rust-lang#125460
2 parents ada5e2c + 8d161d6 commit 1000fe7

36 files changed

+303
-237
lines changed

compiler/rustc_codegen_cranelift/src/abi/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,14 @@ pub(crate) fn codegen_terminator_call<'tcx>(
370370

371371
// Handle special calls like intrinsics and empty drop glue.
372372
let instance = if let ty::FnDef(def_id, fn_args) = *func.layout().ty.kind() {
373-
let instance =
374-
ty::Instance::expect_resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, fn_args)
375-
.polymorphize(fx.tcx);
373+
let instance = ty::Instance::expect_resolve(
374+
fx.tcx,
375+
ty::ParamEnv::reveal_all(),
376+
def_id,
377+
fn_args,
378+
Some(source_info.span),
379+
)
380+
.polymorphize(fx.tcx);
376381

377382
if is_call_from_compiler_builtins_to_upstream_monomorphization(fx.tcx, instance) {
378383
if target.is_some() {

compiler/rustc_codegen_cranelift/src/main_shim.rs

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ pub(crate) fn maybe_create_entry_wrapper(
121121
ParamEnv::reveal_all(),
122122
report.def_id,
123123
tcx.mk_args(&[GenericArg::from(main_ret_ty)]),
124+
None,
124125
)
125126
.polymorphize(tcx);
126127

@@ -146,6 +147,7 @@ pub(crate) fn maybe_create_entry_wrapper(
146147
ParamEnv::reveal_all(),
147148
start_def_id,
148149
tcx.mk_args(&[main_ret_ty.into()]),
150+
None,
149151
)
150152
.polymorphize(tcx);
151153
let start_func_id = import_function(tcx, m, start_instance);

compiler/rustc_codegen_gcc/src/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
483483
ty::ParamEnv::reveal_all(),
484484
def_id,
485485
ty::List::empty(),
486+
None,
486487
);
487488

488489
let symbol_name = tcx.symbol_name(instance).name;

compiler/rustc_codegen_llvm/src/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
566566
ty::ParamEnv::reveal_all(),
567567
def_id,
568568
ty::List::empty(),
569+
None,
569570
)),
570571
_ => {
571572
let name = name.unwrap_or("rust_eh_personality");

compiler/rustc_codegen_ssa/src/base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
468468
ty::ParamEnv::reveal_all(),
469469
start_def_id,
470470
cx.tcx().mk_args(&[main_ret_ty.into()]),
471+
None,
471472
);
472473
let start_fn = cx.get_fn_addr(start_instance);
473474

compiler/rustc_codegen_ssa/src/mir/block.rs

+1
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
843843
ty::ParamEnv::reveal_all(),
844844
def_id,
845845
args,
846+
Some(fn_span),
846847
)
847848
.polymorphize(bx.tcx()),
848849
),

compiler/rustc_const_eval/src/const_eval/machine.rs

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ impl<'tcx> CompileTimeEvalContext<'tcx> {
252252
ty::ParamEnv::reveal_all(),
253253
const_def_id,
254254
instance.args,
255+
Some(self.find_closest_untracked_caller_location()),
255256
);
256257

257258
return Ok(Some(new_instance));

compiler/rustc_const_eval/src/interpret/terminator.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -871,13 +871,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
871871
ty::ExistentialTraitRef::erase_self_ty(tcx, virtual_trait_ref);
872872
let concrete_trait_ref = existential_trait_ref.with_self_ty(tcx, dyn_ty);
873873

874-
let concrete_method = Instance::resolve_for_vtable(
874+
let concrete_method = Instance::expect_resolve_for_vtable(
875875
tcx,
876876
self.param_env,
877877
def_id,
878878
instance.args.rebase_onto(tcx, trait_def_id, concrete_trait_ref.args),
879-
)
880-
.unwrap();
879+
);
881880
assert_eq!(fn_inst, concrete_method);
882881
}
883882

compiler/rustc_middle/messages.ftl

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ middle_cannot_be_normalized =
4141
middle_conflict_types =
4242
this expression supplies two conflicting concrete types for the same opaque type
4343
44+
middle_consider_type_length_limit =
45+
consider adding a `#![type_length_limit="{$type_length}"]` attribute to your crate
46+
4447
middle_const_eval_non_int =
4548
constant evaluation of enum discriminant resulted in non-integer
4649
@@ -94,8 +97,11 @@ middle_strict_coherence_needs_negative_coherence =
9497
to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled
9598
.label = due to this attribute
9699
100+
middle_type_length_limit = reached the type-length limit while instantiating `{$shrunk}`
101+
97102
middle_unknown_layout =
98103
the type `{$ty}` has an unknown layout
99104
100105
middle_values_too_big =
101106
values of the type `{$ty}` are too big for the current architecture
107+
middle_written_to_path = the full type name has been written to '{$path}'

compiler/rustc_middle/src/error.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fmt;
2+
use std::path::PathBuf;
23

34
use rustc_errors::{codes::*, DiagArgName, DiagArgValue, DiagMessage};
45
use rustc_macros::{Diagnostic, Subdiagnostic};
@@ -149,3 +150,16 @@ pub struct ErroneousConstant {
149150

150151
/// Used by `rustc_const_eval`
151152
pub use crate::fluent_generated::middle_adjust_for_foreign_abi_error;
153+
154+
#[derive(Diagnostic)]
155+
#[diag(middle_type_length_limit)]
156+
#[help(middle_consider_type_length_limit)]
157+
pub struct TypeLengthLimit {
158+
#[primary_span]
159+
pub span: Span,
160+
pub shrunk: String,
161+
#[note(middle_written_to_path)]
162+
pub was_written: Option<()>,
163+
pub path: PathBuf,
164+
pub type_length: usize,
165+
}

compiler/rustc_middle/src/middle/limits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn provide(providers: &mut Providers) {
3030
tcx.hir().krate_attrs(),
3131
tcx.sess,
3232
sym::type_length_limit,
33-
1048576,
33+
1048576 * 2 * 2 * 2,
3434
),
3535
}
3636
}

compiler/rustc_middle/src/query/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2152,8 +2152,8 @@ rustc_queries! {
21522152
/// * `Err(ErrorGuaranteed)` when the `Instance` resolution process
21532153
/// couldn't complete due to errors elsewhere - this is distinct
21542154
/// from `Ok(None)` to avoid misleading diagnostics when an error
2155-
/// has already been/will be emitted, for the original cause
2156-
query resolve_instance(
2155+
/// has already been/will be emitted, for the original cause.
2156+
query resolve_instance_raw(
21572157
key: ty::ParamEnvAnd<'tcx, (DefId, GenericArgsRef<'tcx>)>
21582158
) -> Result<Option<ty::Instance<'tcx>>, ErrorGuaranteed> {
21592159
desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }

0 commit comments

Comments
 (0)