Skip to content
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

Use CU.Name.t for name of .cmi; support import info for parameters #1753

Merged
merged 40 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
80a2978
Add `-as-parameter` option
lukemaurer Aug 16, 2023
65d7cbd
Use `CU.Name.t` for name of .cmi; support import info for parameters
lukemaurer Aug 16, 2023
cf8f9e1
Missed a few changes
lukemaurer Aug 21, 2023
ef2c16b
Add checks for misuse of `-as-parameter`
lukemaurer Aug 30, 2023
546e73a
Raise error on combination of `-as-parameter` and `-for-pack`
lukemaurer Aug 30, 2023
7f03329
Add test for check for compiling `.ml` of parameter `.mli`
lukemaurer Aug 30, 2023
431d6bb
Add test of check for `-as-parameter` on implementation
lukemaurer Aug 30, 2023
3d952f6
Implement `register_parameter_import` and `is_registered_parameter_im…
lukemaurer Aug 31, 2023
73835a0
Code review
lukemaurer Aug 31, 2023
f95b877
Merge branch 'as-parameter' into cu-name-is-cmi
lukemaurer Aug 31, 2023
cd5ff12
Fix missing change to use of `Env.read_signature`
lukemaurer Sep 13, 2023
c24e14f
Code review
lukemaurer Sep 29, 2023
4336e64
Merge remote-tracking branch 'upstream/main' into as-parameter
lukemaurer Sep 29, 2023
8b52f69
Fix error message and re-enable test
lukemaurer Oct 19, 2023
c1ebcbe
Merge branch 'as-parameter' into cu-name-is-cmi
lukemaurer Oct 19, 2023
2dda1ca
Fix compilation following merge
lukemaurer Oct 19, 2023
a3b7a31
Update bootstrap compiler
lukemaurer Oct 19, 2023
fa251ce
Fix upstream build
lukemaurer Oct 19, 2023
6f86fb9
Disable test of error message
lukemaurer Oct 19, 2023
294ad42
Merge remote-tracking branch 'upstream/main' into as-parameter
lukemaurer Nov 16, 2023
5518617
Merge remote-tracking branch 'upstream/main' into as-parameter
lukemaurer Nov 16, 2023
77e4338
Merge branch 'as-parameter' into cu-name-is-cmi
lukemaurer Nov 17, 2023
23adeca
Merge branch 'as-parameter' into cu-name-is-cmi
lukemaurer Nov 17, 2023
9234fcd
Bootstrap
lukemaurer Nov 17, 2023
4dd61bb
Merge remote-tracking branch 'upstream/main' into as-parameter
lukemaurer Dec 5, 2023
c67a202
Merge remote-tracking branch 'upstream/main' into as-parameter
lukemaurer Dec 8, 2023
398cc90
Bring in squashed merge of 'as-parameter' branch
lukemaurer Dec 12, 2023
9db2c13
Merge branch 'unsquash/as-parameter' into cu-name-is-cmi
lukemaurer Dec 12, 2023
bf51bd8
Merge remote-tracking branch 'upstream/main' into cu-name-is-cmi
lukemaurer Dec 12, 2023
28654cc
Merge remote-tracking branch 'upstream/main' into unsquash/as-parameter
lukemaurer Dec 12, 2023
f1e32a9
Merge branch 'unsquash/as-parameter' into cu-name-is-cmi
lukemaurer Dec 12, 2023
3cb1126
Code review
lukemaurer Dec 18, 2023
ccd7064
Overhaul `Import_info` implementation and new API
lukemaurer Apr 30, 2024
c6f988b
Code review
lukemaurer Apr 30, 2024
91c2329
Bootstrap
lukemaurer Apr 30, 2024
7e760a1
Copy changes from `asmlink.ml` to `asmlink.ml`
lukemaurer May 1, 2024
014a2d3
Rename a few things for consistency and update comments
lukemaurer May 1, 2024
447c2dd
Merge remote-tracking branch 'upstream/main' into cu-name-is-cmi
lukemaurer May 1, 2024
efd3020
Merge remote-tracking branch 'upstream/main' into cu-name-is-cmi
lukemaurer May 9, 2024
2adb8bd
Rename a few things for code review
lukemaurer May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add checks for misuse of -as-parameter
  • Loading branch information
lukemaurer committed Aug 30, 2023
commit ef2c16b7545b837f9b8899b3aa00fbd7ba60fcca
3 changes: 3 additions & 0 deletions ocaml/typing/env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,9 @@ let is_imported_opaque modname =
let register_import_as_opaque modname =
Persistent_env.register_import_as_opaque !persistent_env modname

let is_parameter_unit modname =
Persistent_env.is_parameter_unit !persistent_env modname

let reset_declaration_caches () =
Types.Uid.Tbl.clear !value_declarations;
Types.Uid.Tbl.clear !type_declarations;
Expand Down
4 changes: 4 additions & 0 deletions ocaml/typing/env.mli
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ val is_imported_opaque: Compilation_unit.Name.t -> bool
(* [register_import_as_opaque md] registers [md] as an opaque imported module *)
val register_import_as_opaque: Compilation_unit.Name.t -> unit

(* [is_parameter_unit md] returns true if [md] was compiled with
-as-parameter *)
val is_parameter_unit: Compilation_unit.Name.t -> bool

(* Summaries -- compact representation of an environment, to be
exported in debugging information. *)

Expand Down
3 changes: 3 additions & 0 deletions ocaml/typing/persistent_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ let is_imported {imported_units; _} s =
let is_imported_opaque {imported_opaque_units; _} s =
CU.Name.Set.mem s !imported_opaque_units

let is_parameter_unit penv s =
is_registered_parameter_import penv s

let make_cmi penv modname kind sign alerts =
let flags =
List.concat [
Expand Down
4 changes: 4 additions & 0 deletions ocaml/typing/persistent_env.mli
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ val is_imported_opaque : 'a t -> Compilation_unit.Name.t -> bool
opaque module *)
val register_import_as_opaque : 'a t -> Compilation_unit.Name.t -> unit

(* [is_parameter_unit penv md] checks if [md] has been imported in [penv] and
was compiled as a parameter *)
val is_parameter_unit : 'a t -> Compilation_unit.Name.t -> bool

val make_cmi : 'a t
-> Compilation_unit.t
-> Cmi_format.kind
Expand Down
19 changes: 19 additions & 0 deletions ocaml/typing/typemod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ type error =
| Unpackable_local_modtype_subst of Path.t
| With_cannot_remove_packed_modtype of Path.t * module_type
| Toplevel_nonvalue of string * sort
| Cannot_implement_parameter of filepath
| Cannot_compile_implementation_as_parameter

exception Error of Location.t * Env.t * error
exception Error_forward of Location.error
Expand Down Expand Up @@ -3214,6 +3216,9 @@ let gen_annot outputprefix sourcefile annots =
~sourcefile:(Some sourcefile) ~use_summaries:false annots

let type_implementation sourcefile outputprefix modulename initial_env ast =
let error e =
raise (Error (Location.in_file sourcefile, initial_env, e))
in
Cmt_format.clear ();
Misc.try_finally (fun () ->
Typecore.reset_delayed_checks ();
Expand Down Expand Up @@ -3246,6 +3251,8 @@ let type_implementation sourcefile outputprefix modulename initial_env ast =
signature = simple_sg
} (* result is ignored by Compile.implementation *)
end else begin
if !Clflags.as_parameter then
error Cannot_compile_implementation_as_parameter;
let sourceintf =
Filename.remove_extension sourcefile ^ !Config.interface_suffix in
if Sys.file_exists sourceintf then begin
Expand All @@ -3258,6 +3265,8 @@ let type_implementation sourcefile outputprefix modulename initial_env ast =
Interface_not_compiled sourceintf)) in
let dclsig =
Env.read_signature modulename intf_file ~add_binding:false in
if Env.is_parameter_unit (Compilation_unit.name modulename) then
error (Cannot_implement_parameter intf_file);
let coercion, shape =
Profile.record_call "check_sig" (fun () ->
Includemod.compunit initial_env ~mark:Mark_positive
Expand All @@ -3282,6 +3291,8 @@ let type_implementation sourcefile outputprefix modulename initial_env ast =
signature = dclsig
}
end else begin
if !Clflags.as_parameter then
error Cannot_compile_implementation_as_parameter;
Location.prerr_warning (Location.in_file sourcefile)
Warnings.Missing_mli;
let coercion, shape =
Expand Down Expand Up @@ -3634,6 +3645,14 @@ let report_error ~loc _env = function
Location.errorf ~loc
"@[Top-level module bindings must have layout value, but@ \
%s has layout@ %a.@]" id Sort.format sort
| Cannot_implement_parameter path ->
Location.errorf ~loc
"@[Interface %s@ found for this unit is flagged as a parameter.@ \
It cannot be implemented directly. Use -as-argument-for instead.@]"
path
| Cannot_compile_implementation_as_parameter ->
Location.errorf ~loc
"Cannot compile an implementation with -as-parameter."

let report_error env ~loc err =
Printtyp.wrap_printing_env ~error:true env
Expand Down
2 changes: 2 additions & 0 deletions ocaml/typing/typemod.mli
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ type error =
| Unpackable_local_modtype_subst of Path.t
| With_cannot_remove_packed_modtype of Path.t * module_type
| Toplevel_nonvalue of string * sort
| Cannot_implement_parameter of Misc.filepath
| Cannot_compile_implementation_as_parameter

exception Error of Location.t * Env.t * error
exception Error_forward of Location.error
Expand Down