Skip to content

Commit a2e4f30

Browse files
?
1 parent 471d809 commit a2e4f30

2 files changed

Lines changed: 4 additions & 70 deletions

File tree

pyrefly/lib/solver/solver.rs

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const VAR_LEAK: &str = "Internal error: a variable has leaked from one module to
7777
/// due to large enums (Type) and lock guards.
7878
const INITIAL_GAS: Gas = Gas::new(200);
7979

80-
#[derive(Clone, Debug)]
80+
#[derive(Debug)]
8181
enum Variable {
8282
/// A "partial type" (terminology borrowed from mypy) for an empty container.
8383
///
@@ -182,7 +182,7 @@ struct Variables(SmallMap<Var, RefCell<VariableNode>>);
182182
/// can implement path compression. We use a separate Cell instead of using
183183
/// the RefCell around the node, because we might find that two vars point
184184
/// to the same root, which would cause us to borrow_mut twice and panic.
185-
#[derive(Clone, Debug)]
185+
#[derive(Debug)]
186186
enum VariableNode {
187187
Goto(Cell<Var>),
188188
Root(Variable, usize),
@@ -198,20 +198,6 @@ impl Display for VariableNode {
198198
}
199199

200200
impl Variables {
201-
fn snapshot(&self) -> SmallMap<Var, VariableNode> {
202-
self.0
203-
.iter()
204-
.map(|(var, node)| (*var, node.borrow().clone()))
205-
.collect()
206-
}
207-
208-
fn restore(&mut self, snapshot: SmallMap<Var, VariableNode>) {
209-
self.0 = snapshot
210-
.into_iter()
211-
.map(|(var, node)| (var, RefCell::new(node)))
212-
.collect();
213-
}
214-
215201
fn get<'a>(&'a self, x: Var) -> Ref<'a, Variable> {
216202
let root = self.get_root(x);
217203
let variable = self.get_node(root).borrow();
@@ -334,12 +320,6 @@ pub struct Solver {
334320
pub strict_callable_subtyping: bool,
335321
}
336322

337-
#[derive(Clone)]
338-
pub(crate) struct SolverSnapshot {
339-
variables: SmallMap<Var, VariableNode>,
340-
instantiation_errors: SmallMap<Var, TypeVarSpecializationError>,
341-
}
342-
343323
impl Display for Solver {
344324
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
345325
for (x, y) in self.variables.lock().iter() {
@@ -374,18 +354,6 @@ impl Solver {
374354
self.variables.lock().recurse(var, recurser)
375355
}
376356

377-
pub(crate) fn snapshot(&self) -> SolverSnapshot {
378-
SolverSnapshot {
379-
variables: self.variables.lock().snapshot(),
380-
instantiation_errors: self.instantiation_errors.read().clone(),
381-
}
382-
}
383-
384-
pub(crate) fn restore(&self, snapshot: SolverSnapshot) {
385-
self.variables.lock().restore(snapshot.variables);
386-
*self.instantiation_errors.write() = snapshot.instantiation_errors;
387-
}
388-
389357
/// Force all non-recursive Vars in `vars`.
390358
/// TODO: deduplicate Variable-to-gradual-type logic with `force_var`.
391359
pub fn pin_placeholder_type(&self, var: Var, pin_partial_types: bool) -> Option<PinError> {

pyrefly/lib/solver/subset.rs

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ use pyrefly_util::owner::Owner;
3535
use ruff_python_ast::name::Name;
3636
use ruff_text_size::TextRange;
3737
use starlark_map::small_map::SmallMap;
38-
use starlark_map::small_set::SmallSet;
3938

4039
use crate::alt::answers::LookupAnswer;
4140
use crate::alt::callable::CallArg;
4241
use crate::alt::expr::TypeOrExpr;
4342
use crate::solver::solver::OpenTypedDictSubsetError;
44-
use crate::solver::solver::SolverSnapshot;
4543
use crate::solver::solver::Subset;
4644
use crate::solver::solver::SubsetCacheEntry;
4745
use crate::solver::solver::SubsetError;
@@ -51,7 +49,6 @@ use crate::types::callable::Param;
5149
use crate::types::callable::ParamList;
5250
use crate::types::callable::Params;
5351
use crate::types::callable::Required;
54-
use crate::types::class::Class;
5552
use crate::types::class::ClassType;
5653
use crate::types::quantified::QuantifiedKind;
5754
use crate::types::simplify::unions;
@@ -131,37 +128,6 @@ fn any<T>(
131128
}
132129

133130
impl<'a, Ans: LookupAnswer> Subset<'a, Ans> {
134-
fn try_with_rollback<T>(
135-
&mut self,
136-
f: impl FnOnce(&mut Self) -> Result<T, SubsetError>,
137-
) -> Result<T, SubsetError> {
138-
let solver = self.solver.snapshot();
139-
let subset_cache = self.subset_cache.clone();
140-
let class_protocol_assumptions = self.class_protocol_assumptions.clone();
141-
match f(self) {
142-
Ok(result) => Ok(result),
143-
Err(err) => {
144-
self.restore_after_failed_tentative_check(
145-
solver,
146-
subset_cache,
147-
class_protocol_assumptions,
148-
);
149-
Err(err)
150-
}
151-
}
152-
}
153-
154-
fn restore_after_failed_tentative_check(
155-
&mut self,
156-
solver: SolverSnapshot,
157-
subset_cache: SmallMap<(Type, Type), SubsetCacheEntry>,
158-
class_protocol_assumptions: SmallSet<(Class, Class)>,
159-
) {
160-
self.solver.restore(solver);
161-
self.subset_cache = subset_cache;
162-
self.class_protocol_assumptions = class_protocol_assumptions;
163-
}
164-
165131
/// Can a function with l_args be called as a function with u_args?
166132
fn is_subset_param_list(
167133
&mut self,
@@ -1104,7 +1070,7 @@ impl<'a, Ans: LookupAnswer> Subset<'a, Ans> {
11041070

11051071
fn is_subset_overload(&mut self, overload: &Overload, want: &Type) -> Result<(), SubsetError> {
11061072
if any(overload.signatures.iter(), |l| {
1107-
self.try_with_rollback(|this| this.is_subset_eq(&l.as_type(), want))
1073+
self.is_subset_eq(&l.as_type(), want)
11081074
})
11091075
.is_ok()
11101076
{
@@ -1156,7 +1122,7 @@ impl<'a, Ans: LookupAnswer> Subset<'a, Ans> {
11561122
ret.clone(),
11571123
)));
11581124
any(overload.signatures.iter(), |l| {
1159-
self.try_with_rollback(|this| this.is_subset_eq(&l.as_type(), &callable))
1125+
self.is_subset_eq(&l.as_type(), &callable)
11601126
})
11611127
})
11621128
.is_ok()

0 commit comments

Comments
 (0)