Skip to content

Commit bb4672b

Browse files
borsehuss
authored andcommitted
Auto merge of rust-lang#89285 - jackh726:issue-88862, r=nikomatsakis
Don't normalize opaque types with escaping late-bound regions Fixes rust-lang#88862 Turns out, this has some really bad perf implications in large types (issue rust-lang#88862). While we technically can handle them fine, it doesn't change test output either way. For now, revert with an added benchmark. Future attempts to change this back will have to consider perf. Needs a perf run once rust-lang/rustc-perf#1033 is merged r? `@nikomatsakis`
1 parent a6c3c1b commit bb4672b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Diff for: compiler/rustc_trait_selection/src/traits/project.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,15 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
388388
// to make sure we don't forget to fold the substs regardless.
389389

390390
match *ty.kind() {
391-
ty::Opaque(def_id, substs) => {
391+
// This is really important. While we *can* handle this, this has
392+
// severe performance implications for large opaque types with
393+
// late-bound regions. See `issue-88862` benchmark.
394+
ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => {
392395
// Only normalize `impl Trait` after type-checking, usually in codegen.
393396
match self.param_env.reveal() {
394397
Reveal::UserFacing => ty.super_fold_with(self),
395398

396399
Reveal::All => {
397-
// N.b. there is an assumption here all this code can handle
398-
// escaping bound vars.
399-
400400
let recursion_limit = self.tcx().recursion_limit();
401401
if !recursion_limit.value_within_limit(self.depth) {
402402
let obligation = Obligation::with_depth(

Diff for: compiler/rustc_trait_selection/src/traits/query/normalize.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,15 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
206206

207207
// Wrap this in a closure so we don't accidentally return from the outer function
208208
let res = (|| match *ty.kind() {
209-
ty::Opaque(def_id, substs) => {
209+
// This is really important. While we *can* handle this, this has
210+
// severe performance implications for large opaque types with
211+
// late-bound regions. See `issue-88862` benchmark.
212+
ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => {
210213
// Only normalize `impl Trait` after type-checking, usually in codegen.
211214
match self.param_env.reveal() {
212215
Reveal::UserFacing => ty.super_fold_with(self),
213216

214217
Reveal::All => {
215-
// N.b. there is an assumption here all this code can handle
216-
// escaping bound vars.
217-
218218
let substs = substs.super_fold_with(self);
219219
let recursion_limit = self.tcx().recursion_limit();
220220
if !recursion_limit.value_within_limit(self.anon_depth) {

0 commit comments

Comments
 (0)