Skip to content

Commit ef58a8e

Browse files
committed
[ty] Add cycle handling to lazy_default
1 parent 7198e53 commit ef58a8e

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ regex-automata = { version = "0.4.9" }
146146
rustc-hash = { version = "2.0.0" }
147147
rustc-stable-hash = { version = "0.1.2" }
148148
# When updating salsa, make sure to also update the revision in `fuzz/Cargo.toml`
149-
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "ef9f9329be6923acd050c8dddd172e3bc93e8051", default-features = false, features = [
149+
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "8c5d8315b5dc61c3ad7c3df71c7323c3d98f3bd4", default-features = false, features = [
150150
"compact_str",
151151
"macros",
152152
"salsa_unstable",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
spark # too many iterations (in `exported_names` query), `should not be able to access instance member `spark` of type variable IndexOpsLike@astype in inferable position`
2-
steam.py # dependency graph cycle when querying TypeVarInstance < 'db >::lazy_default_(Id(2e007)), set cycle_fn/cycle_initial to fixpoint iterate.
2+
steam.py # too many iterations

crates/ty_python_semantic/src/types.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8359,7 +8359,7 @@ impl<'db> TypeVarInstance<'db> {
83598359
Some(TypeVarBoundOrConstraints::Constraints(ty))
83608360
}
83618361

8362-
#[salsa::tracked(heap_size=ruff_memory_usage::heap_size)]
8362+
#[salsa::tracked(cycle_fn=lazy_default_cycle_recover, cycle_initial=lazy_default_cycle_initial, heap_size=ruff_memory_usage::heap_size)]
83638363
fn lazy_default(self, db: &'db dyn Db) -> Option<Type<'db>> {
83648364
let definition = self.definition(db)?;
83658365
let module = parsed_module(db, definition.file(db)).load(db);
@@ -8401,6 +8401,23 @@ fn lazy_bound_cycle_initial<'db>(
84018401
None
84028402
}
84038403

8404+
#[allow(clippy::ref_option)]
8405+
fn lazy_default_cycle_recover<'db>(
8406+
_db: &'db dyn Db,
8407+
_value: &Option<Type<'db>>,
8408+
_count: u32,
8409+
_self: TypeVarInstance<'db>,
8410+
) -> salsa::CycleRecoveryAction<Option<Type<'db>>> {
8411+
salsa::CycleRecoveryAction::Iterate
8412+
}
8413+
8414+
fn lazy_default_cycle_initial<'db>(
8415+
_db: &'db dyn Db,
8416+
_self: TypeVarInstance<'db>,
8417+
) -> Option<Type<'db>> {
8418+
None
8419+
}
8420+
84048421
/// Where a type variable is bound and usable.
84058422
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, salsa::Update, get_size2::GetSize)]
84068423
pub enum BindingContext<'db> {

fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ty_python_semantic = { path = "../crates/ty_python_semantic" }
3030
ty_vendored = { path = "../crates/ty_vendored" }
3131

3232
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer", default-features = false }
33-
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "ef9f9329be6923acd050c8dddd172e3bc93e8051", default-features = false, features = [
33+
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "8c5d8315b5dc61c3ad7c3df71c7323c3d98f3bd4", default-features = false, features = [
3434
"compact_str",
3535
"macros",
3636
"salsa_unstable",

0 commit comments

Comments
 (0)