forked from ocaml-flambda/flambda-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Typing for parameterised libraries (ocaml-flambda#1726)
Typechecking of references to parameterised libraries, with or without arguments. Currently such references can't actually be compiled to working code because we don't have the `-instantiate` pass, but this contains all the typechecking logic to make sure that, for instance, a module `A` can't refer to a parameterised module `B` unless `A` takes all the parameters that `B` does (the subset rule) or the reference includes an argument for each missing parameter.
- Loading branch information
1 parent
9a7cc9f
commit 9768a53
Showing
66 changed files
with
1,514 additions
and
175 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,6 +199,7 @@ | |
mode | ||
jkind_types | ||
jkind_intf | ||
signature_with_global_bindings | ||
typedtree | ||
printtyped | ||
ctype | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
File "main.ml", line 1: | ||
File "main.ml", line 28, characters 11-30: | ||
28 | module _ = Use_member_directly | ||
^^^^^^^^^^^^^^^^^^^ | ||
Error: The file subdir/use_member_directly.cmi | ||
is imported both as "Pack.Member" and as "Member". |
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
2 changes: 2 additions & 0 deletions
2
testsuite/tests/templates/basic/bad_instance_arg_name_not_found.ml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Monoid_utils_of_banana = | ||
Monoid_utils(Banana)(List_monoid) [@jane.non_erasable.instances] |
5 changes: 5 additions & 0 deletions
5
testsuite/tests/templates/basic/bad_instance_arg_name_not_found.reference
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
File "bad_instance_arg_name_not_found.ml", line 2, characters 2-35: | ||
2 | Monoid_utils(Banana)(List_monoid) [@jane.non_erasable.instances] | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Error: The module "Monoid_utils" has no parameter "Banana". | ||
Hint: Parameters for "Monoid_utils": "Monoid" |
2 changes: 2 additions & 0 deletions
2
testsuite/tests/templates/basic/bad_instance_arg_value_not_arg.ml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Monoid_utils_of_int = | ||
Monoid_utils(Monoid)(Monoid_utils(Monoid)(List_monoid)) [@jane.non_erasable.instances] |
6 changes: 6 additions & 0 deletions
6
testsuite/tests/templates/basic/bad_instance_arg_value_not_arg.reference
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
File "bad_instance_arg_value_not_arg.ml", line 2, characters 2-57: | ||
2 | Monoid_utils(Monoid)(Monoid_utils(Monoid)(List_monoid)) [@jane.non_erasable.instances] | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Error: The module "Monoid_utils[Monoid:List_monoid]" | ||
cannot be used as an argument for parameter "Monoid". | ||
Hint: Compile "monoid_utils.cmi" with "-as-argument-for Monoid". |
2 changes: 2 additions & 0 deletions
2
testsuite/tests/templates/basic/bad_instance_arg_value_not_found.ml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Monoid_utils_of_int = | ||
Monoid_utils(Monoid)(Banana) [@jane.non_erasable.instances] |
4 changes: 4 additions & 0 deletions
4
testsuite/tests/templates/basic/bad_instance_arg_value_not_found.reference
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
File "bad_instance_arg_value_not_found.ml", line 2, characters 2-30: | ||
2 | Monoid_utils(Monoid)(Banana) [@jane.non_erasable.instances] | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Error: Unbound module "Banana" in instance "Monoid_utils[Monoid:Banana]" |
2 changes: 2 additions & 0 deletions
2
testsuite/tests/templates/basic/bad_instance_arg_value_wrong_type.ml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Category_utils_of_list_monoid = | ||
Category_utils(Category)(List_monoid) [@jane.non_erasable.instances] |
7 changes: 7 additions & 0 deletions
7
testsuite/tests/templates/basic/bad_instance_arg_value_wrong_type.reference
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
File "bad_instance_arg_value_wrong_type.ml", line 2, characters 2-39: | ||
2 | Category_utils(Category)(List_monoid) [@jane.non_erasable.instances] | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Error: The module "List_monoid" | ||
is used as an argument for the parameter "Category" but "List_monoid" | ||
is an argument for "Monoid". | ||
Hint: "list_monoid.cmi" was compiled with "-as-argument-for Category". |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let (f @ portable) () = | ||
let module Monoid_utils_of_list_monoid = | ||
Monoid_utils(Monoid)(List_monoid) [@jane.non_erasable.instances] | ||
in | ||
() |
4 changes: 4 additions & 0 deletions
4
testsuite/tests/templates/basic/bad_instance_wrong_mode.reference
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
File "bad_instance_wrong_mode.ml", line 3, characters 4-37: | ||
3 | Monoid_utils(Monoid)(List_monoid) [@jane.non_erasable.instances] | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Error: Modules are nonportable, so cannot be used inside a function that is portable. |
9 changes: 6 additions & 3 deletions
9
testsuite/tests/templates/basic/bad_param_not_param.reference
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
File "bad_param_not_param.mli", line 1: | ||
Error: The module "Widget" is specified as a parameter, but "widget.cmi" | ||
was not compiled with -as-parameter. | ||
File "bad_param_not_param.mli", line 19, characters 17-25: | ||
19 | val frobnicate : Widget.t -> Widget.t | ||
^^^^^^^^ | ||
Error: The module "Widget" | ||
is a parameter but is not declared as such for the current unit. | ||
Hint: Compile the current unit with "-parameter Widget". |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
File "bad_ref_direct.ml", line 1: | ||
Error: The file "monoid.cmi" contains the interface of a parameter. | ||
"Monoid" is not declared as a parameter for the current unit (-parameter "Monoid"). | ||
File "bad_ref_direct.ml", line 3, characters 12-21: | ||
3 | let empty = Monoid.id | ||
^^^^^^^^^ | ||
Error: The file "monoid.cmi" contains the interface of a parameter. "Monoid" | ||
is not declared as a parameter for the current unit. | ||
Hint: Compile the current unit with "-parameter Monoid". |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(* [Monoid] is not a parameter of this, but it _is_ imported because it's used | ||
as a parameter *) | ||
|
||
module Monoid_utils_of_semigroup = | ||
Monoid_utils(Monoid)(Monoid_of_semigroup) [@jane.non_erasable.instances] | ||
|
||
let empty = Monoid.empty |
6 changes: 6 additions & 0 deletions
6
testsuite/tests/templates/basic/bad_ref_direct_imported.reference
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
File "bad_ref_direct_imported.ml", line 7, characters 12-24: | ||
7 | let empty = Monoid.empty | ||
^^^^^^^^^^^^ | ||
Error: The file "monoid.cmi" contains the interface of a parameter. "Monoid" | ||
is not declared as a parameter for the current unit. | ||
Hint: Compile the current unit with "-parameter Monoid". |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
File "bad_ref_indirect.ml", line 1: | ||
File "bad_ref_indirect.ml", line 2, characters 13-32: | ||
2 | let concat = Monoid_utils.concat | ||
^^^^^^^^^^^^^^^^^^^ | ||
Error: The module "Monoid_utils" is not accessible because it takes "Monoid" | ||
as a parameter and the current unit does not. | ||
Hint: Pass `-parameter "Monoid"` to add "Monoid" as a parameter | ||
Hint: Pass "-parameter Monoid" to add "Monoid" as a parameter | ||
of the current unit. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include Category_intf.S |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include Category_intf.S |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include Category |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include Category_intf.S with type ('a, 'b) t = ('a, 'b) Category.t |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module type S = sig | ||
type ('a, 'b) t | ||
|
||
val id : ('a, 'a) t | ||
val compose : first:('a, 'b) t -> second:('b, 'c) t -> ('a, 'c) t | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type ('a, 'b) t = Monoid.t | ||
|
||
let id = Monoid.empty | ||
let compose ~first ~second = Monoid.append first second | ||
|
||
let as_unit t = t |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
type ('a, 'b) t = Monoid.t | ||
|
||
val id : ('a, 'a) t | ||
val compose : first:('a, 'b) t -> second:('b, 'c) t -> ('a, 'c) t | ||
|
||
(* Demonstrate that we can have extra functions beyond what's required by the | ||
.mli for the parameter type *) | ||
val as_unit : (_, _) t -> (unit, unit) t |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let rec concat : type a b. (a, b) Chain.t -> (a, b) Category.t = | ||
fun chain -> | ||
match chain with | ||
| [] -> Category.id | ||
| a_to_b :: b_to_c -> Category.compose ~first:a_to_b ~second:(concat b_to_c) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
val concat : ('a, 'b) Chain.t -> ('a, 'b) Category.t |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type (_, _) t = | ||
| [] : ('a, 'a) t | ||
| (::) : ('a, 'b) Category.t * ('b, 'c) t -> ('a, 'c) t |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type (_, _) t = | ||
| [] : ('a, 'a) t | ||
| (::) : ('a, 'b) Category.t * ('b, 'c) t -> ('a, 'c) t |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Chain_of_semigroup = | ||
Chain(Category)(Category_of_monoid(Monoid)(Monoid_of_semigroup)) | ||
[@jane.non_erasable.instances] | ||
|
||
module Chain_of_lists = | ||
Chain(Category)(Category_of_monoid(Monoid)(List_monoid)) | ||
[@jane.non_erasable.instances] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Category_of_semigroup_and_lists = | ||
Product_category | ||
(Category)(Category_of_monoid(Monoid)(Monoid_of_semigroup)) | ||
(Category_b)(Category_b_of_category | ||
(Category)(Category_of_monoid(Monoid)(List_monoid))) | ||
[@jane.non_erasable.instances] | ||
|
||
module Chain_of_semigroup_and_lists = | ||
Chain | ||
(Category) | ||
(Product_category | ||
(Category)(Category_of_monoid(Monoid)(Monoid_of_semigroup)) | ||
(Category_b)(Category_b_of_category | ||
(Category)(Category_of_monoid(Monoid)(List_monoid)))) | ||
[@jane.non_erasable.instances] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type t |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
type t = List_element.t list | ||
|
||
let empty = [] | ||
let append = List.append |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
type t = List_element.t list | ||
|
||
val empty : t | ||
val append : t -> t -> t |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Monoid_utils_of_semigroup = | ||
Monoid_utils(Monoid)(Monoid_of_semigroup) [@jane.non_erasable.instances] | ||
|
||
module Category_utils_of_semigroup = | ||
Category_utils(Category)(Category_of_monoid(Monoid)(Monoid_of_semigroup)) | ||
[@jane.non_erasable.instances] | ||
|
||
module Category_utils_of_list = | ||
Category_utils(Category)(Category_of_monoid(Monoid)(List_monoid)) | ||
[@jane.non_erasable.instances] | ||
|
||
module Category_of_list_monoid = | ||
Category_of_monoid(Monoid)(List_monoid) | ||
[@jane.non_erasable.instances] | ||
|
||
let concat_semi : Monoid_utils_of_semigroup.ts -> Monoid_of_semigroup.t = | ||
Monoid_utils_of_semigroup.concat | ||
|
||
let concat_chain_semi = Category_utils_of_semigroup.concat | ||
|
||
let append3_semi a b c = Category_utils_of_semigroup.concat [ a; b; c ] | ||
|
||
let concat_lists = List.concat | ||
|
||
let concat_chain_lists = Category_utils_of_list.concat | ||
|
||
let append3_lists a b c = concat_chain_lists [ a; b; c ] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
open Import | ||
|
||
val append3_semi | ||
: Semigroup.t option | ||
-> Semigroup.t option | ||
-> Semigroup.t option | ||
-> Semigroup.t option | ||
|
||
val concat_semi : Semigroup.t option list -> Monoid_of_semigroup.t | ||
|
||
val concat_chain_semi | ||
: (unit, unit) Chain_of_semigroup.t -> Monoid_of_semigroup.t | ||
|
||
val append3_lists | ||
: List_monoid.t -> List_monoid.t -> List_monoid.t -> List_monoid.t | ||
|
||
val concat_lists : List_monoid.t list -> List_element.t list | ||
|
||
val concat_chain_lists : (_, _) Chain_of_lists.t -> List_element.t list |
Oops, something went wrong.