Skip to content

Commit 40dc64b

Browse files
rchen152meta-codesync[bot]
authored andcommitted
Add option to expand unfinished quantified
Summary: Adds `expand_unfinished_quantified` parameter to `Solver::expand_with_limit` that will control whether we expand Quantified variables to their lower bounds. The parameter doesn't do anything yet, but this diff shows where we intend to expand: * in `expand_dimension`, which is currently relying on eager pinning to get answers for vars when they are expanded * in `for_display`, which should expand to eliminate `_` in error messages For #105. Reviewed By: yangdanny97 Differential Revision: D96547435 fbshipit-source-id: 9e8ba75b7619cb0cf615cc81ddd6fc5ffe00d49a
1 parent 7eb55d9 commit 40dc64b

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

pyrefly/lib/solver/solver.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl Solver {
429429
/// Finish the type returned from a function call. This entails expanding solved variables and
430430
/// erasing unsolved variables without defaults from unions.
431431
pub fn finish_function_return(&self, mut t: Type) -> Type {
432-
self.expand_with_limit(&mut t, TYPE_LIMIT, &VarRecurser::new());
432+
self.expand_with_limit(&mut t, TYPE_LIMIT, &VarRecurser::new(), false);
433433
self.erase_unsolved_variables(&mut t);
434434
self.simplify_mut(&mut t);
435435
t
@@ -447,14 +447,21 @@ impl Solver {
447447

448448
/// Like `expand`, but when you have a `&mut`.
449449
pub fn expand_vars_mut(&self, t: &mut Type) {
450-
self.expand_with_limit(t, TYPE_LIMIT, &VarRecurser::new());
450+
self.expand_with_limit(t, TYPE_LIMIT, &VarRecurser::new(), false);
451451
// After we substitute bound variables, we may be able to simplify some types
452452
self.simplify_mut(t);
453453
}
454454

455455
/// Expand, but if the resulting type will be greater than limit levels deep, return an `Any`.
456456
/// Avoids producing things that stack overflow later in the process.
457-
fn expand_with_limit(&self, t: &mut Type, limit: usize, recurser: &VarRecurser) {
457+
#[expect(clippy::only_used_in_recursion)]
458+
fn expand_with_limit(
459+
&self,
460+
t: &mut Type,
461+
limit: usize,
462+
recurser: &VarRecurser,
463+
expand_unfinished_quantified: bool,
464+
) {
458465
if limit == 0 {
459466
// TODO: Should probably add an error here, and use any_error,
460467
// but don't have any good location information to hand.
@@ -468,22 +475,29 @@ impl Solver {
468475
*t = ty.clone();
469476
drop(variable);
470477
drop(lock);
471-
self.expand_with_limit(t, limit - 1, recurser);
478+
self.expand_with_limit(
479+
t,
480+
limit - 1,
481+
recurser,
482+
expand_unfinished_quantified,
483+
);
472484
}
473485
_ => {}
474486
}
475487
} else {
476488
*t = self.heap.mk_any_implicit();
477489
}
478490
} else {
479-
t.recurse_mut(&mut |t| self.expand_with_limit(t, limit - 1, recurser));
491+
t.recurse_mut(&mut |t| {
492+
self.expand_with_limit(t, limit - 1, recurser, expand_unfinished_quantified)
493+
});
480494
}
481495
}
482496

483497
/// Public wrapper to expand a dimension type by resolving bound Vars.
484498
/// Used by subset checking to expand Vars before comparing dimension expressions.
485499
pub fn expand_dimension(&self, dim_ty: &mut Type) {
486-
self.expand_with_limit(dim_ty, TYPE_LIMIT, &VarRecurser::new());
500+
self.expand_with_limit(dim_ty, TYPE_LIMIT, &VarRecurser::new(), true);
487501
}
488502

489503
/// Given a `Var`, ensures that the solver has an answer for it (or inserts Any if not already),
@@ -1066,7 +1080,7 @@ impl Solver {
10661080
}
10671081

10681082
pub fn for_display(&self, mut t: Type) -> Type {
1069-
self.expand_with_limit(&mut t, TYPE_LIMIT, &VarRecurser::new());
1083+
self.expand_with_limit(&mut t, TYPE_LIMIT, &VarRecurser::new(), true);
10701084
self.simplify_mut(&mut t);
10711085
t.deterministic_printing()
10721086
}

0 commit comments

Comments
 (0)