-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flambda-backend: Lazy strengthening (#1337)
This PR adds strengthening as a first-class concept to the module type language. The main motivation is faster module type checking but this also makes the language more expressive, allowing more programs to type. # New syntax Suppose we have ```ocaml module type S = sig type t end module M : S ``` The actual type of `M` is stronger than `S` - it is `sig type t = M.t end`. The new extension allows this type to be written as `S with M` (in the literature, `S/M` is often used). This effectively strengthens all types in `S` with the information that they are equal to those in `M`. # Expressivity Previously, strengthening happened by actually adding information to all types in a module type. This meant that abstract module types couldn’t be strengthened. Consider ```ocaml module F (Y : sig module type A module X : A end) = Y.X ``` We now infer the `functor (Y : …) -> (Y.A with Y.X)` for `F` where previously, we only could infer `functor (Y : …) -> Y.A`, thus losing information. See ocaml/ocaml#12204 for more details. # Efficiency The main benefit of the extension, though, is that it allows us to type check some programs much quicker. Consider the following example. ```ocaml module type S = sig type t val x : t <lots of value declarations> end module M : S = … module F (X : S) = … module N = F(M) ``` To type `N`, we have to check that the type of `M` is a subtype of `S`. With the new extension, this is simple: `M` gets the type `S with M` and `S with M < S` always holds so the check finishes very quickly. Previously, we would infer the (large) type ```ocaml sig type t = M.t val x : t … end ``` for `M` by unfolding `S` and strengthening it. When checking `F(M)`, we would then match this type against `S` which requires unfolding `S` again and then comparing the individual signature items. # Unused warnings Suppose that `x` in the above example isn’t actually used anywhere. With this PR, we will indeed issue an unused declaration warning. This wasn’t the case previously as `x` was (implicitly) used while typing `F(M)` since were unfolding `S`. --------- Co-authored-by: Roman Leshchinskiy <rleshchinskiy@janestreet.com>
- Loading branch information
1 parent
85b5c54
commit a0f8d0c
Showing
42 changed files
with
6,122 additions
and
5,304 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains 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 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 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 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 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 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 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 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.