mirror of https://github.com/astral-sh/ruff
[ty] Experiment: make infer_expression_types/infer_definition_types non-queries
This commit is contained in:
parent
5518c84ab3
commit
c6b661f374
|
|
@ -3337,7 +3337,7 @@ impl<'db> Type<'db> {
|
|||
name: Name,
|
||||
policy: MemberLookupPolicy,
|
||||
) -> PlaceAndQualifiers<'db> {
|
||||
tracing::trace!("member_lookup_with_policy: {}.{}", self.display(db), name);
|
||||
let _span = tracing::trace_span!("member_lookup_with_policy: {}", ?name).entered();
|
||||
if name == "__class__" {
|
||||
return Place::bound(self.dunder_class(db)).into();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2816,6 +2816,8 @@ impl<'db> ClassLiteral<'db> {
|
|||
name: String,
|
||||
target_method_decorator: MethodDecorator,
|
||||
) -> PlaceAndQualifiers<'db> {
|
||||
let _span =
|
||||
tracing::trace_span!("implicit_attribute_inner", ?class_body_scope, ?name).entered();
|
||||
// If we do not see any declarations of an attribute, neither in the class body nor in
|
||||
// any method, we build a union of `Unknown` with the inferred types of all bindings of
|
||||
// that attribute. We include `Unknown` in that union to account for the fact that the
|
||||
|
|
|
|||
|
|
@ -171,7 +171,6 @@ fn scope_cycle_initial<'db>(_db: &'db dyn Db, scope: ScopeId<'db>) -> ScopeInfer
|
|||
|
||||
/// Infer all types for a [`Definition`] (including sub-expressions).
|
||||
/// Use when resolving a place use or public type of a place.
|
||||
#[salsa::tracked(returns(ref), cycle_fn=definition_cycle_recover, cycle_initial=definition_cycle_initial, heap_size=ruff_memory_usage::heap_size)]
|
||||
pub(crate) fn infer_definition_types<'db>(
|
||||
db: &'db dyn Db,
|
||||
definition: Definition<'db>,
|
||||
|
|
@ -252,7 +251,6 @@ fn deferred_cycle_initial<'db>(
|
|||
/// Use rarely; only for cases where we'd otherwise risk double-inferring an expression: RHS of an
|
||||
/// assignment, which might be unpacking/multi-target and thus part of multiple definitions, or a
|
||||
/// type narrowing guard expression (e.g. if statement test node).
|
||||
#[salsa::tracked(returns(ref), cycle_fn=expression_cycle_recover, cycle_initial=expression_cycle_initial, heap_size=ruff_memory_usage::heap_size)]
|
||||
pub(crate) fn infer_expression_types<'db>(
|
||||
db: &'db dyn Db,
|
||||
expression: Expression<'db>,
|
||||
|
|
@ -2676,7 +2674,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
fn infer_definition(&mut self, node: impl Into<DefinitionNodeKey> + std::fmt::Debug + Copy) {
|
||||
let definition = self.index.expect_single_definition(node);
|
||||
let result = infer_definition_types(self.db(), definition);
|
||||
self.extend_definition(result);
|
||||
self.extend_definition(&result);
|
||||
}
|
||||
|
||||
fn infer_function_definition_statement(&mut self, function: &ast::StmtFunctionDef) {
|
||||
|
|
@ -5142,7 +5140,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
self.check_deprecated(alias, ty.inner);
|
||||
}
|
||||
}
|
||||
self.extend_definition(inferred);
|
||||
self.extend_definition(&inferred);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5636,7 +5634,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
standalone_expression: Expression<'db>,
|
||||
) -> Type<'db> {
|
||||
let types = infer_expression_types(self.db(), standalone_expression);
|
||||
self.extend_expression(types);
|
||||
self.extend_expression(&types);
|
||||
|
||||
// Instead of calling `self.expression_type(expr)` after extending here, we get
|
||||
// the result from `types` directly because we might be in cycle recovery where
|
||||
|
|
@ -6102,7 +6100,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
if comprehension.is_first() && target.is_name_expr() {
|
||||
result.expression_type(iterable)
|
||||
} else {
|
||||
self.extend_expression_unchecked(result);
|
||||
self.extend_expression_unchecked(&result);
|
||||
result.expression_type(iterable)
|
||||
}
|
||||
};
|
||||
|
|
@ -6141,7 +6139,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
if named.target.is_name_expr() {
|
||||
let definition = self.index.expect_single_definition(named);
|
||||
let result = infer_definition_types(self.db(), definition);
|
||||
self.extend_definition(result);
|
||||
self.extend_definition(&result);
|
||||
result.binding_type(definition)
|
||||
} else {
|
||||
// For syntactically invalid targets, we still need to run type inference:
|
||||
|
|
@ -7341,6 +7339,8 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
}
|
||||
|
||||
fn infer_attribute_expression(&mut self, attribute: &ast::ExprAttribute) -> Type<'db> {
|
||||
let _span = tracing::debug_span!("infer_attribute_expression", ?attribute).entered();
|
||||
|
||||
let ast::ExprAttribute {
|
||||
value,
|
||||
attr: _,
|
||||
|
|
|
|||
Loading…
Reference in New Issue