-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow a let
definition to introduce locally abstract types
#10237
Comments
I don't know how to reconcile |
The syntax that François suggests is consistent with the syntax for naming existential variables in GADT patterns introduced recently in #9584: I think that the feature request makes sense. |
In my mind, the type |
I'm not competent to discuss the part about typing, but if you want to inline let g () : int =
let[@local] f : type a . a foo -> a =
fun foo ->
match foo with F1 -> 0 | F2 -> true
in
f F1 This should ensure that the function is inlined by the compiler, but at a stage where types have been erased. |
In the setting of Menhir, we want to perform inlining ourselves (and not delegate it to the OCaml compiler) because it unlocks other optimizations that only Menhir can perform. Besides, it seems desirable for a programming language to guarantee that a function can always be manually inlined. |
By the way, is |
It's tersely documented in the section about built-in attributes (8.12.1 for the 4.11.1 manual) |
I think the feature and choice of syntax make sense. In principle it should be quite easy to implement using code that is very similar to the existing code for dealing with |
Thanks, the explanation makes sense. |
Syntactic type-preservation is old school :-) |
Indeed, the feature as proposed makes sense for non-recursive |
While I think that this feature makes sense, there are a few questions. |
What are these optimizations? Could you create a specialized version? |
There is work in progress on a new back-end for Menhir, with a new intermediate language where it is easier to perform optimizations such as delaying At the moment, we are taking advantage of OCaml's |
Can you work around this issue by using |
Sure, that's what Menhir has been doing for 15 years, but the point of the new project is to get rid of it (and to enable more aggressive optimizations at the same time). |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
Is |
Actually, we don't even use |
Nice! What change did you make to avoid the problem? |
The main trick is to restrict inlining: 1- we never inline a function that matches on a GADT, and 2- we never inline a function into a function that matches on a GADT. |
Did that come at a performance cost? |
(compared to this feature or using |
No, I don't think so. |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
While working on Menhir's new back-end, which produces OCaml code that uses GADTs, it has come to my attention that there seems to be currently no good way of inlining a function that performs a case analysis on a GADT, while preserving well-typedness.
Suppose I have these type and function definitions:
Suppose I want to inline
f
intog
. The following naive attempt is considered ill-typed:Florian Angeletti notes that I can write this, which is well-typed and is likely to be efficiently compiled (once types are erased,
it is an explicit beta-redex):
This is an interesting remark, but I would prefer a syntax that involves a
let
construct. Does the following proposed syntax make sense? Thelet
construct introduces the local abstract typea
in its right-hand side.The text was updated successfully, but these errors were encountered: