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

Fixing mistaken erasure of effectful type applications #3518

Merged
merged 6 commits into from
Oct 3, 2024
Merged

Conversation

nikswamy
Copy link
Collaborator

@nikswamy nikswamy commented Oct 3, 2024

Fixes issue #3473

An effectful polymorphic function f at type a:Type -> Dv t was typed in the ML extraction as unit -> t.

This fix types it now as unit -Impure-> t, ensuring that an application f a is extracted as f () with effect Impure and so is ineligible for erasure, even if t is an erasable type.

@nikswamy
Copy link
Collaborator Author

nikswamy commented Oct 3, 2024

I have a check-world green with this: https://github.com/FStarLang/FStar/actions/runs/11153756864

val push_unit (ts : mltyscheme) : mltyscheme
val pop_unit (ts : mltyscheme) : mltyscheme
val push_unit (eff:e_tag) (ts : mltyscheme) : mltyscheme
val pop_unit (ts : mltyscheme) : e_tag & mltyscheme
Copy link
Collaborator Author

@nikswamy nikswamy Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

push_unit is called when replacing the type arguments of a function with a unit.

pop_unit is the converse, eliminating a polymorphic function with a type application where the type argument is extracted as unit.

We now record the effect of type application as an e_tag, i.e., Pure, Erasable, Impure

| None -> bs, U.comp_result c
| Some (bs, b, rest) -> bs, U.arrow (b::rest) c in

| None -> bs, etag_of_comp c, U.comp_result c
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

record the effect of the type instantiation

fun ctr ->
let n = FStar_HyperStack_ST.op_Bang ctr in
FStar_HyperStack_ST.testify ()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interestingly, this was being dropped previously (testify: ((heap -> Type) -> ST unit))

let recall : 'p . unit -> unit = fun uu___ -> FStar_ST.gst_recall ()
let witness : 'p . unit -> unit = fun uu___ -> FStar_ST.gst_witness ()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these are really noops, but they are effectful type applications in F* and should not have been dropped

@nikswamy nikswamy merged commit e56786f into master Oct 3, 2024
3 checks passed
@nikswamy nikswamy deleted the nik_3473 branch October 3, 2024 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant