Skip to content

Commit 688ec8c

Browse files
committed
[experiment] rustc_mir: remove #![type_length_limit] checks.
1 parent 6af1bdd commit 688ec8c

File tree

1 file changed

+1
-53
lines changed

1 file changed

+1
-53
lines changed

compiler/rustc_mir/src/monomorphize/collector.rs

+1-53
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,11 @@ use rustc_middle::mir::mono::{InstantiationMode, MonoItem};
191191
use rustc_middle::mir::visit::Visitor as MirVisitor;
192192
use rustc_middle::mir::{self, Local, Location};
193193
use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCast};
194-
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
194+
use rustc_middle::ty::subst::InternalSubsts;
195195
use rustc_middle::ty::{self, GenericParamDefKind, Instance, Ty, TyCtxt, TypeFoldable};
196196
use rustc_session::config::EntryFnType;
197197
use rustc_span::source_map::{dummy_spanned, respan, Span, Spanned, DUMMY_SP};
198198
use smallvec::SmallVec;
199-
use std::iter;
200199

201200
#[derive(PartialEq)]
202201
pub enum MonoItemCollectionMode {
@@ -375,7 +374,6 @@ fn collect_items_rec<'tcx>(
375374
// Keep track of the monomorphization recursion depth
376375
recursion_depth_reset =
377376
Some(check_recursion_limit(tcx, instance, starting_point.span, recursion_depths));
378-
check_type_length_limit(tcx, instance);
379377

380378
rustc_data_structures::stack::ensure_sufficient_stack(|| {
381379
collect_neighbours(tcx, instance, &mut neighbors);
@@ -455,56 +453,6 @@ fn check_recursion_limit<'tcx>(
455453
(def_id, recursion_depth)
456454
}
457455

458-
fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
459-
let type_length = instance
460-
.substs
461-
.iter()
462-
.flat_map(|arg| arg.walk())
463-
.filter(|arg| match arg.unpack() {
464-
GenericArgKind::Type(_) | GenericArgKind::Const(_) => true,
465-
GenericArgKind::Lifetime(_) => false,
466-
})
467-
.count();
468-
debug!(" => type length={}", type_length);
469-
470-
// Rust code can easily create exponentially-long types using only a
471-
// polynomial recursion depth. Even with the default recursion
472-
// depth, you can easily get cases that take >2^60 steps to run,
473-
// which means that rustc basically hangs.
474-
//
475-
// Bail out in these cases to avoid that bad user experience.
476-
if !tcx.sess.type_length_limit().value_within_limit(type_length) {
477-
// The instance name is already known to be too long for rustc.
478-
// Show only the first and last 32 characters to avoid blasting
479-
// the user's terminal with thousands of lines of type-name.
480-
let shrink = |s: String, before: usize, after: usize| {
481-
// An iterator of all byte positions including the end of the string.
482-
let positions = || s.char_indices().map(|(i, _)| i).chain(iter::once(s.len()));
483-
484-
let shrunk = format!(
485-
"{before}...{after}",
486-
before = &s[..positions().nth(before).unwrap_or(s.len())],
487-
after = &s[positions().rev().nth(after).unwrap_or(0)..],
488-
);
489-
490-
// Only use the shrunk version if it's really shorter.
491-
// This also avoids the case where before and after slices overlap.
492-
if shrunk.len() < s.len() { shrunk } else { s }
493-
};
494-
let msg = format!(
495-
"reached the type-length limit while instantiating `{}`",
496-
shrink(instance.to_string(), 32, 32)
497-
);
498-
let mut diag = tcx.sess.struct_span_fatal(tcx.def_span(instance.def_id()), &msg);
499-
diag.note(&format!(
500-
"consider adding a `#![type_length_limit=\"{}\"]` attribute to your crate",
501-
type_length
502-
));
503-
diag.emit();
504-
tcx.sess.abort_if_errors();
505-
}
506-
}
507-
508456
struct MirNeighborCollector<'a, 'tcx> {
509457
tcx: TyCtxt<'tcx>,
510458
body: &'a mir::Body<'tcx>,

0 commit comments

Comments
 (0)