Skip to content
Closed
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions pyrefly/lib/alt/answers_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use std::cell::RefCell;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::fmt;
use std::fmt::Debug;
use std::fmt::Display;
Expand Down Expand Up @@ -55,8 +56,10 @@ use crate::module::module_info::ModuleInfo;
use crate::solver::solver::VarRecurser;
use crate::solver::type_order::TypeOrder;
use crate::types::class::Class;
use crate::types::class::ClassDefIndex;
use crate::types::stdlib::Stdlib;
use crate::types::type_info::TypeInfo;
use crate::types::types::TParams;
use crate::types::types::Type;
use crate::types::types::Var;

Expand Down Expand Up @@ -378,6 +381,7 @@ pub struct ThreadState {
stack: CalcStack,
/// For debugging only: thread-global that allows us to control debug logging across components.
debug: RefCell<bool>,
placeholder_class_tparams: RefCell<HashMap<ClassDefIndex, Arc<TParams>>>,
}

impl ThreadState {
Expand All @@ -386,6 +390,7 @@ impl ThreadState {
cycles: Cycles::new(),
stack: CalcStack::new(),
debug: RefCell::new(false),
placeholder_class_tparams: RefCell::new(HashMap::new()),
}
}
}
Expand Down Expand Up @@ -461,6 +466,32 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
&self.thread_state.stack
}

pub fn placeholder_class_tparams(&self, class_idx: ClassDefIndex) -> Option<Arc<TParams>> {
self.thread_state
.placeholder_class_tparams
.borrow()
.get(&class_idx)
.cloned()
}

pub fn insert_placeholder_class_tparams(
&self,
class_idx: ClassDefIndex,
tparams: Arc<TParams>,
) {
self.thread_state
.placeholder_class_tparams
.borrow_mut()
.insert(class_idx, tparams);
}

pub fn remove_placeholder_class_tparams(&self, class_idx: ClassDefIndex) {
self.thread_state
.placeholder_class_tparams
.borrow_mut()
.remove(&class_idx);
}

fn cycles(&self) -> &Cycles {
&self.thread_state.cycles
}
Expand Down
7 changes: 6 additions & 1 deletion pyrefly/lib/alt/class/classdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
let precomputed_tparams = if tparams_require_binding {
None
} else {
Some(self.calculate_class_tparams_no_legacy(name, x.type_params.as_deref(), errors))
Some(self.calculate_class_tparams_no_legacy(
def_index,
name,
x.type_params.as_deref(),
errors,
))
};
Class::new(
def_index,
Expand Down
Loading