-
Notifications
You must be signed in to change notification settings - Fork 23
Lazy strengthening #119
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
Closed
rleshchinskiy
wants to merge
3
commits into
ocaml-flambda:main
from
rleshchinskiy:lazy-strengthening
Closed
Lazy strengthening #119
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
(* TEST | ||
* expect | ||
*) | ||
|
||
module type S1 = sig | ||
module type T | ||
module M : T | ||
module N : T with M | ||
end | ||
[%%expect{| | ||
module type S1 = sig module type T module M : T module N : (T with M) end | ||
|}] | ||
|
||
module type S2 = sig | ||
module type T | ||
module M : sig end | ||
module N : T with M | ||
end | ||
[%%expect{| | ||
Line 1: | ||
Error: Modules do not match: T is not included in sig end | ||
|}] | ||
|
||
module type S3 = sig | ||
module type T = sig type t end | ||
module M : T | ||
module N : T with M | ||
end | ||
[%%expect{| | ||
module type S3 = | ||
sig | ||
module type T = sig type t end | ||
module M : T | ||
module N : sig type t = M.t end | ||
end | ||
|}] | ||
|
||
module type S4 = sig | ||
module type T = sig type t end | ||
module M : T | ||
module N : T with M with type t = int | ||
end | ||
[%%expect{| | ||
Line 4, characters 13-39: | ||
4 | module N : T with M with type t = int | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Error: In this `with' constraint, the new definition of t | ||
does not match its original definition in the constrained signature: | ||
Type declarations do not match: | ||
type t = int | ||
is not included in | ||
type t = M.t | ||
The type int is not equal to the type M.t | ||
|}] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ end | |
|
||
module M : sig end | ||
module O : sig end | ||
|
||
module Nominal : sig module N : sig type t end end | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these should probably be done via the new stuff in
parsing/extensions.ml
andparsing/extensions_parsing.ml
. Maybe talk to @antalsz or @goldfirere about getting a PR to add support for module types to those first and then rebase and use it?Looking at how those files work, it looks like we'd use an encoding like:
which is maybe a little easier than the encoding here and probably works better with ppxen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes -- I'd be happy to throw that together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functor (_ : [%extension.strengthen]) -> S with module L = L
I'm not doubting you're right but I'd like to understand why this is better. I'm a bit worried that this would replace a signature with a functor type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a valid worry.
The problem with your original encoding is that ppxen don't generally look inside of extension nodes -- meaning your strengthened module types will be invisible to all ppx transformations, which could be bad.
Instead, the general-purpose extensions architecture is designed to be consulted essentially at every inspection of a parsetree type. The actual encoding I chose (in #141/#142) is
functor (_ : [%extensions.strengthen]) (_ : S) -> L
. (I decided not to usewith module L = L
to avoid duplication.) I know theL
is a module, not a module type, but the parsetree just wants aLongident.t
there, so it doesn't care about the distinction. (Though maybe this is bad, in case a ppx is looking for module identifiers? Feedback welcome, at https://github.com/ocaml-flambda/ocaml-jst/pull/142/files#r1131011021)As for your worry: we must be careful that every time we look at a module type, we check to see if it's the special form of a syntax extension. I've done this in #141. But the check that I've done it right is just "look to see if it looks right". Because we can't edit the parsetree, we can't really be sure of not making a mistake here. (Indeed, in #140, I found a few places where we might be getting this wrong for some expression extensions.)