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

Incorrect erasure of function types #3366

Open
gebner opened this issue Jul 19, 2024 · 0 comments
Open

Incorrect erasure of function types #3366

gebner opened this issue Jul 19, 2024 · 0 comments

Comments

@gebner
Copy link
Contributor

gebner commented Jul 19, 2024

(Following up on the discussion we just had.)

F* treats function types with an erasable codomain as erasable themselves. For example, Type -> Type is erasable. If such a function type is hidden behind an interface, then F* will replace values of that function type by () which is incompatible with polymorphism. (In the same file, values of that type are erased to fun _ -> () which is fine.)

//==> FunErasureHelper.fsti <==
module FunErasureHelper

[@@must_erase_for_extraction]
val t : Type u#1

val x : t

val f : t * nat -> nat

//==> FunErasureHelper.fst <==
module FunErasureHelper

let t = Type0 -> Type0

let x = list

let generic_apply #a #b (f: (a -> b) * nat) (x: a) : b * nat =
  (f._1 x, f._2)

let f (x: t * nat) =
  (generic_apply x nat)._2

//==> FunErasure.fst <==
module FunErasure
open FunErasureHelper

let _ = f (x, 42) // <- crash

The last definition will crash, because x is incorrectly erased to (), and generic_apply then treats it as a function and calls it.

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

No branches or pull requests

1 participant