Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent eta expansion in rty checking #970

Merged
merged 1 commit into from
Jan 27, 2025
Merged
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
2 changes: 1 addition & 1 deletion crates/flux-infer/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ impl<'a, E: LocEnv> Sub<'a, E> {
let vars = a
.vars()
.iter()
.map(|kind| infcx.define_vars(kind.expect_sort()))
.map(|kind| Expr::fvar(infcx.define_var(kind.expect_sort())))
.collect_vec();
let body_a = a.apply(&vars);
let body_b = b.apply(&vars);
Expand Down
3 changes: 2 additions & 1 deletion crates/flux-infer/src/refine_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ pub struct Unpacker<'a, 'b> {

impl HoisterDelegate for Unpacker<'_, '_> {
fn hoist_exists(&mut self, ty_ctor: &TyCtor) -> Ty {
let ty = ty_ctor.replace_bound_refts_with(|sort, _, _| self.cursor.define_vars(sort));
let ty =
ty_ctor.replace_bound_refts_with(|sort, _, _| Expr::fvar(self.cursor.define_var(sort)));
if let AssumeInvariants::Yes { check_overflow } = self.assume_invariants {
self.cursor.assume_invariants(&ty, check_overflow);
}
Expand Down
8 changes: 4 additions & 4 deletions crates/flux-refineck/src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fn check_fn_subtyping(
let tcx = infcx.genv.tcx();

let super_sig = super_sig
.replace_bound_vars(|_| rty::ReErased, |sort, _| infcx.define_vars(sort))
.replace_bound_vars(|_| rty::ReErased, |sort, _| Expr::fvar(infcx.define_var(sort)))
.normalize_projections(&mut infcx)?;

// 1. Unpack `T_g` input types
Expand Down Expand Up @@ -275,7 +275,7 @@ fn check_fn_subtyping(

let output = infcx
.fully_resolve_evars(&output)
.replace_bound_refts_with(|sort, _, _| infcx.define_vars(sort));
.replace_bound_refts_with(|sort, _, _| Expr::fvar(infcx.define_var(sort)));

// 4. OUTPUT subtyping (f_out <: g_out)
infcx.ensure_resolved_evars(|infcx| {
Expand Down Expand Up @@ -422,7 +422,7 @@ impl<'ck, 'genv, 'tcx, M: Mode> Checker<'ck, 'genv, 'tcx, M> {
let body = genv.mir(def_id).with_span(span)?;

let fn_sig = poly_sig
.replace_bound_vars(|_| rty::ReErased, |sort, _| infcx.define_vars(sort))
.replace_bound_vars(|_| rty::ReErased, |sort, _| Expr::fvar(infcx.define_var(sort)))
.normalize_projections(&mut infcx)
.with_span(span)?;

Expand Down Expand Up @@ -804,7 +804,7 @@ impl<'ck, 'genv, 'tcx, M: Mode> Checker<'ck, 'genv, 'tcx, M> {

let output = infcx
.fully_resolve_evars(&fn_sig.output)
.replace_bound_refts_with(|sort, _, _| infcx.define_vars(sort));
.replace_bound_refts_with(|sort, _, _| Expr::fvar(infcx.define_var(sort)));

env.assume_ensures(infcx, &output.ensures);
fold_local_ptrs(infcx, env, span).with_span(span)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/flux-refineck/src/type_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ impl BasicBlockEnv {
) -> TypeEnv<'a> {
let data = self
.data
.replace_bound_refts_with(|sort, _, _| infcx.define_vars(sort));
.replace_bound_refts_with(|sort, _, _| Expr::fvar(infcx.define_var(sort)));
for constr in &data.constrs {
infcx.assume_pred(constr);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/flux-refineck/src/type_env/place_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ fn downcast_enum(
.variant_sig(adt.did(), variant_idx)?
.expect("enums cannot be opaque")
.instantiate(tcx, args, &[])
.replace_bound_refts_with(|sort, _, _| infcx.define_vars(sort))
.replace_bound_refts_with(|sort, _, _| Expr::fvar(infcx.define_var(sort)))
.normalize_projections(infcx)?;

// FIXME(nilehmann) We could assert idx1 == variant_def.idx directly, but for aggregate sorts there
Expand Down
Loading