Skip to content

Commit ed806ba

Browse files
committed
Infer string annotations in the same definition query
This is the second attempt for string annotation which infers the string annotation types in the same definition query. This has the added advantage of avoiding to go through two salsa queries. It does this by maintaining a state on the builder and utilizes that to make certain decisions throughout the inference process.
1 parent 6217f48 commit ed806ba

File tree

3 files changed

+185
-269
lines changed

3 files changed

+185
-269
lines changed

crates/red_knot_python_semantic/src/types.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,13 @@ pub(crate) fn global_symbol<'db>(db: &'db dyn Db, file: File, name: &str) -> Sym
181181
/// Infer the type of a binding.
182182
pub(crate) fn binding_ty<'db>(db: &'db dyn Db, definition: Definition<'db>) -> Type<'db> {
183183
let inference = infer_definition_types(db, definition);
184-
if inference.is_eagerly_deferred(definition) {
185-
infer_deferred_types(db, definition).binding_ty(definition)
186-
} else {
187-
inference.binding_ty(definition)
188-
}
184+
inference.binding_ty(definition)
189185
}
190186

191187
/// Infer the type of a declaration.
192188
fn declaration_ty<'db>(db: &'db dyn Db, definition: Definition<'db>) -> Type<'db> {
193189
let inference = infer_definition_types(db, definition);
194-
if inference.is_eagerly_deferred(definition) {
195-
infer_deferred_types(db, definition).declaration_ty(definition)
196-
} else {
197-
inference.declaration_ty(definition)
198-
}
190+
inference.declaration_ty(definition)
199191
}
200192

201193
/// Infer the type of a (possibly deferred) sub-expression of a [`Definition`].
@@ -2229,21 +2221,6 @@ impl<'db> IterationOutcome<'db> {
22292221
}
22302222
}
22312223

2232-
#[derive(Debug)]
2233-
enum MaybeDeferred<'db> {
2234-
Type(Type<'db>),
2235-
Deferred,
2236-
}
2237-
2238-
impl<'db> MaybeDeferred<'db> {
2239-
fn expect_type(self) -> Type<'db> {
2240-
match self {
2241-
MaybeDeferred::Type(ty) => ty,
2242-
MaybeDeferred::Deferred => panic!("expected a type, but got a deferred annotation"),
2243-
}
2244-
}
2245-
}
2246-
22472224
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
22482225
pub enum Truthiness {
22492226
/// For an object `x`, `bool(x)` will always return `True`

0 commit comments

Comments
 (0)