Skip to content
Closed
Changes from all commits
Commits
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
39 changes: 29 additions & 10 deletions crates/ty_python_semantic/src/types/infer/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5035,6 +5035,35 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
infer_argument_ty: &mut dyn FnMut(&mut Self, ArgExpr<'db, '_>) -> Type<'db>,
bindings: &mut Bindings<'db>,
call_expression_tcx: TypeContext<'db>,
) -> Result<(), CallErrorKind> {
// Cache expressions inferred across speculative inference attempts.
//
// This is important to avoid exponential blowup for deeply nested generic calls,
// as inner expressions are repeatedly inferred with the same type context.
let teardown = self.setup_expression_cache();

let result = self.infer_and_check_argument_types_impl(
ast_arguments,
argument_types,
infer_argument_ty,
bindings,
call_expression_tcx,
);

if teardown {
self.teardown_expression_cache();
}

result
}

fn infer_and_check_argument_types_impl(
&mut self,
ast_arguments: ArgumentsIter<'_>,
argument_types: &mut CallArguments<'_, 'db>,
infer_argument_ty: &mut dyn FnMut(&mut Self, ArgExpr<'db, '_>) -> Type<'db>,
bindings: &mut Bindings<'db>,
call_expression_tcx: TypeContext<'db>,
) -> Result<(), CallErrorKind> {
let db = self.db();
let constraints = ConstraintSetBuilder::new();
Expand Down Expand Up @@ -5356,12 +5385,6 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {

let mut seen = FxHashSet::default();

// Cache expressions inferred across speculative inference attempts.
//
// This is important to avoid exponential blowup for deeply nested generic calls,
// as inner expressions are repeatedly inferred with the same type context.
let teardown = self.setup_expression_cache();

for (parameter, parameter_tcx) in parameter_types {
if !seen.insert(parameter.annotated_type()) {
continue;
Expand All @@ -5376,10 +5399,6 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
);
argument_types.insert(parameter.annotated_type(), inferred_ty);
}

if teardown {
self.teardown_expression_cache();
}
}
}
}
Expand Down
Loading