Skip to content

Commit

Permalink
Merge branch 'instance-typing' (early part) into instantiate
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemaurer committed Oct 23, 2024
2 parents 9feff02 + 72d4e0e commit 6017723
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ 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".
cannot be used as an argument for parameter "Monoid".
Hint: Compile "monoid_utils.cmi" with "-as-argument-for Monoid".
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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" was expected to satisfy the parameter "Category"
but "list_monoid.cmi" was compiled to satisfy "Monoid".
Error: The module "List_monoid"
is used as an argument for the parameter "Category" but "list_monoid.cmi"
was compiled as an argument for "Monoid".
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ 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 thecurrent unit.
Hint: Compile the current unit with "-parameter Widget"
is a parameter but is not declared as such for the current unit.
Hint: Compile the current unit with "-parameter Widget".
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ 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 (-parameter "Monoid").
"Monoid" is not declared as a parameter for the current unit.
Hint: Compile the current unit with "-parameter Monoid".
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ 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 (-parameter "Monoid").
"Monoid" is not declared as a parameter for the current unit.
Hint: Compile the current unit with "-parameter Monoid".
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
File "bad_ref_indirect.ml", line 1, characters 13-32:
1 | let concat = Monoid_utils.concat
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.
1 change: 1 addition & 0 deletions ocaml/testsuite/tests/templates/basic/ref_indirect.ml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
[@@@ocaml.flambda_o3] (* normalise objinfo output *)
let concat = Monoid_utils.concat
35 changes: 19 additions & 16 deletions ocaml/typing/persistent_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type error =
| Direct_reference_from_wrong_package of
CU.t * filepath * CU.Prefix.t
| Illegal_import_of_parameter of Global_module.Name.t * filepath
| Not_compiled_as_parameter of Global_module.Name.t * filepath
| Not_compiled_as_parameter of Global_module.Name.t
| Imported_module_has_unset_parameter of
{ imported : Global_module.Name.t;
parameter : Global_module.Name.t;
Expand Down Expand Up @@ -239,7 +239,7 @@ let register_parameter ({param_imports; _} as penv) modname =
()
| Some imp ->
if not imp.imp_is_param then
raise (Error (Not_compiled_as_parameter(modname, imp.imp_filename)))
raise (Error (Not_compiled_as_parameter modname))
end;
param_imports := Param_set.add modname !param_imports

Expand Down Expand Up @@ -418,7 +418,7 @@ let remember_global { globals; _ } global ~mentioned_by =
now_mentioned_by = mentioned_by;
})

let current_unit_is0 name ~allow_args =
let current_unit_is_aux name ~allow_args =
match CU.get_current () with
| None -> false
| Some current ->
Expand All @@ -429,10 +429,10 @@ let current_unit_is0 name ~allow_args =
| None -> false

let current_unit_is name =
current_unit_is0 name ~allow_args:false
current_unit_is_aux name ~allow_args:false

let current_unit_is_instance_of name =
current_unit_is0 name ~allow_args:true
current_unit_is_aux name ~allow_args:true

(* Enforce the subset rule: we can only refer to a module if that module's
parameters are also our parameters. *)
Expand Down Expand Up @@ -712,7 +712,7 @@ let acknowledge_pers_struct penv modname pers_name val_of_pers_sig =
| true, false ->
error (Illegal_import_of_parameter(modname, filename))
| false, true ->
error (Not_compiled_as_parameter(modname, filename))
error (Not_compiled_as_parameter modname)
| true, true
| false, false -> ()
end;
Expand Down Expand Up @@ -997,17 +997,20 @@ let report_error ppf =
| Illegal_import_of_parameter(modname, filename) ->
fprintf ppf
"@[<hov>The file %a@ contains the interface of a parameter.@ \
%a is not declared as a parameter for the current unit (-parameter %a).@]"
%a is not declared as a parameter for the current unit.@]@.\
@[<hov>@{<hint>Hint@}: \
@[<hov>Compile the current unit with \
@{<inline_code>-parameter %a@}.@]@]"
(Style.as_inline_code Location.print_filename) filename
(Style.as_inline_code Global_module.Name.print) modname
(Style.as_inline_code Global_module.Name.print) modname
| Not_compiled_as_parameter(modname, _filename) ->
Global_module.Name.print modname
| Not_compiled_as_parameter modname ->
fprintf ppf
"@[<hov>The module %a@ is a parameter but is not declared as such for the\
"@[<hov>The module %a@ is a parameter but is not declared as such for the \
current unit.@]@.\
@[<hov>@{<hint>Hint@}: \
@[<hov>Compile the current unit with @{<inline_code>-parameter \
%a@}@]@]"
%a@}.@]@]"
(Style.as_inline_code Global_module.Name.print) modname
Global_module.Name.print modname
| Imported_module_has_unset_parameter
Expand All @@ -1016,11 +1019,11 @@ let report_error ppf =
"@[<hov>The module %a@ is not accessible because it takes %a@ \
as a parameter and the current unit does not.@]@.\
@[<hov>@{<hint>Hint@}: \
@[<hov>Pass `-parameter %a`@ to add %a@ as a parameter@ \
@[<hov>Pass @{<inline_code>-parameter %a@}@ to add %a@ as a parameter@ \
of the current unit.@]@]"
(Style.as_inline_code Global_module.Name.print) modname
(Style.as_inline_code Global_module.Name.print) param
(Style.as_inline_code Global_module.Name.print) param
Global_module.Name.print param
(Style.as_inline_code Global_module.Name.print) param
| Imported_module_has_no_such_parameter
{ valid_parameters; imported = modname; parameter = param; value = _; } ->
Expand Down Expand Up @@ -1049,7 +1052,7 @@ let report_error ppf =
pp_hint ()
| Not_compiled_as_argument { param; value; filename } ->
fprintf ppf
"@[<hov>The module %a@ cannot be used as an argument for parameter\
"@[<hov>The module %a@ cannot be used as an argument for parameter \
%a.@]@.\
@[<hov>@{<hint>Hint@}: Compile %a with \
@{<inline_code>-as-argument-for %a@}.@]"
Expand All @@ -1059,8 +1062,8 @@ let report_error ppf =
Global_module.Name.print param
| Argument_type_mismatch { value; filename; expected; actual; } ->
fprintf ppf
"@[<hov>The module %a@ was expected to satisfy the parameter %a@ \
but %a@ was compiled to satisfy %a.@]"
"@[<hov>The module %a@ is used as an argument for the parameter %a@ \
but %a@ was compiled as an argument for %a.@]"
(Style.as_inline_code Global_module.Name.print) value
(Style.as_inline_code Global_module.Name.print) expected
(Style.as_inline_code Location.print_filename) filename
Expand Down
2 changes: 1 addition & 1 deletion ocaml/typing/persistent_env.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type error =
| Direct_reference_from_wrong_package of
Compilation_unit.t * filepath * Compilation_unit.Prefix.t
| Illegal_import_of_parameter of Global_module.Name.t * filepath
| Not_compiled_as_parameter of Global_module.Name.t * filepath
| Not_compiled_as_parameter of Global_module.Name.t
| Imported_module_has_unset_parameter of
{ imported : Global_module.Name.t;
parameter : Global_module.Name.t;
Expand Down

0 comments on commit 6017723

Please sign in to comment.