Skip to content

Refactor Persistent_env to separate imports from bound names #1764

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

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
25b63ca
Refactor `Persistent_env` to separate imports from bound names
lukemaurer Aug 23, 2023
d0a1675
Merge branch 'cu-name-is-cmi' into layered-persistent_env
lukemaurer Aug 23, 2023
e2c7976
Merge branch 'cu-name-is-cmi' into layered-persistent_env
lukemaurer Aug 31, 2023
c4a43ca
Merge branch 'cu-name-is-cmi' into layered-persistent_env
lukemaurer Sep 13, 2023
68dd87f
Pass shape into `Env` callback
lukemaurer Sep 13, 2023
bc78a1d
Improve API for reading signatures from files
lukemaurer Sep 13, 2023
88b6185
Merge branch 'cu-name-is-cmi' into layered-persistent_env
lukemaurer Oct 19, 2023
52ea8fd
Revert "Disable test of error message"
lukemaurer Oct 19, 2023
a9eea0b
Fix upstream build
lukemaurer Oct 19, 2023
4b2f192
Merge branch 'cu-name-is-cmi' into layered-persistent_env
lukemaurer Nov 17, 2023
025558c
Remove warning boilerplate from new files
lukemaurer Nov 17, 2023
4c0c8b6
Update `ocaml/.depend`
lukemaurer Nov 17, 2023
e05a7f5
Code review
lukemaurer Dec 19, 2023
b3be73d
Merge branch 'cu-name-is-cmi' into layered-persistent_env
lukemaurer Dec 19, 2023
8a2b5c2
Merge branch 'cu-name-is-cmi' into layered-persistent_env
lukemaurer Apr 30, 2024
a3641bb
Compilation fixes following merge
lukemaurer Apr 30, 2024
66fb8b8
Merge branch 'cu-name-is-cmi' into layered-persistent_env
lukemaurer May 1, 2024
91b0725
Merge branch 'cu-name-is-cmi' into layered-persistent_env
lukemaurer May 1, 2024
d701be1
Code review
lukemaurer May 1, 2024
d4cacae
Re-check visibility on _either_ cache hit
lukemaurer May 1, 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
10 changes: 10 additions & 0 deletions ocaml/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -1261,35 +1261,43 @@ typing/patterns.cmi : \
parsing/asttypes.cmi
typing/persistent_env.cmo : \
utils/warnings.cmi \
typing/subst.cmi \
typing/shape.cmi \
utils/misc.cmi \
parsing/location.cmi \
utils/load_path.cmi \
utils/lazy_backtrack.cmi \
utils/import_info.cmi \
typing/ident.cmi \
utils/consistbl.cmi \
utils/compilation_unit.cmi \
file_formats/cmi_format.cmi \
utils/clflags.cmi \
typing/persistent_env.cmi
typing/persistent_env.cmx : \
utils/warnings.cmx \
typing/subst.cmx \
typing/shape.cmx \
utils/misc.cmx \
parsing/location.cmx \
utils/load_path.cmx \
utils/lazy_backtrack.cmx \
utils/import_info.cmx \
typing/ident.cmx \
utils/consistbl.cmx \
utils/compilation_unit.cmx \
file_formats/cmi_format.cmx \
utils/clflags.cmx \
typing/persistent_env.cmi
typing/persistent_env.cmi : \
typing/subst.cmi \
typing/shape.cmi \
utils/misc.cmi \
parsing/location.cmi \
utils/load_path.cmi \
utils/lazy_backtrack.cmi \
utils/import_info.cmi \
typing/ident.cmi \
utils/consistbl.cmi \
utils/compilation_unit.cmi \
file_formats/cmi_format.cmi
Expand Down Expand Up @@ -6611,6 +6619,7 @@ driver/compile_common.cmo : \
driver/compmisc.cmi \
utils/compilation_unit.cmi \
driver/compenv.cmi \
file_formats/cmi_format.cmi \
utils/clflags.cmi \
parsing/builtin_attributes.cmi \
driver/compile_common.cmi
Expand All @@ -6633,6 +6642,7 @@ driver/compile_common.cmx : \
driver/compmisc.cmx \
utils/compilation_unit.cmx \
driver/compenv.cmx \
file_formats/cmi_format.cmx \
utils/clflags.cmx \
parsing/builtin_attributes.cmx \
driver/compile_common.cmi
Expand Down
4 changes: 1 addition & 3 deletions ocaml/testsuite/tests/templates/basic/bad_param_impl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ flags = ""
module = "bad_param_impl.ml"
ocamlc_byte_exit_status = "2"
compiler_output = "bad_param_impl.output"
**** skip
reason = "error broken, will be fixed by #1764"
***** check-ocamlc.byte-output
**** check-ocamlc.byte-output
compiler_reference = "bad_param_impl.reference"
*)
4 changes: 1 addition & 3 deletions ocaml/testsuite/tests/templates/basic/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ module = "monoid.mli"
module = "bad_ref_direct.ml"
compiler_output = "bad_ref_direct.output"
ocamlc_byte_exit_status = "2"
**** skip
reason = "correct error message not yet implemented"
***** check-ocamlc.byte-output
**** check-ocamlc.byte-output
compiler_reference = "bad_ref_direct.reference"
*)
33 changes: 9 additions & 24 deletions ocaml/typing/env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ let map_summary f = function
| Env_value_unbound (s, u, r) -> Env_value_unbound (f s, u, r)
| Env_module_unbound (s, u, r) -> Env_module_unbound (f s, u, r)

type address =
type address = Persistent_env.address =
| Aunit of Compilation_unit.t
| Alocal of Ident.t
| Adot of address * int
Expand Down Expand Up @@ -970,34 +970,24 @@ let components_of_module ~alerts ~uid env ps path addr mty shape =
}
}

let read_sign_of_cmi { Persistent_env.Persistent_signature.cmi; _ } =
let name =
match cmi.cmi_kind with
| Normal { cmi_impl } -> cmi_impl
| Parameter -> Misc.fatal_error "Unsupported import of parameter module"
in
let sign = cmi.cmi_sign in
let flags = cmi.cmi_flags in
let id = Ident.create_persistent (Compilation_unit.name_as_string name) in
let read_sign_of_cmi sign name uid ~shape ~address:addr ~flags =
let id = Ident.create_persistent (Compilation_unit.Name.to_string name) in
let path = Pident id in
let alerts =
List.fold_left (fun acc -> function Alerts s -> s | _ -> acc)
Misc.Stdlib.String.Map.empty
flags
in
let sign = Subst.Lazy.signature Make_local Subst.identity sign in
let md =
{ Subst.Lazy.md_type = Mty_signature sign;
md_loc = Location.none;
md_attributes = [];
md_uid = Uid.of_compilation_unit_id name;
md_uid = uid;
}
in
let mda_address = Lazy_backtrack.create_forced (Aunit name) in
let mda_address = Lazy_backtrack.create_forced addr in
let mda_declaration = md in
let mda_shape =
Shape.for_persistent_unit (name |> Compilation_unit.full_path_as_string)
in
let mda_shape = shape in
let mda_components =
let mty = md.md_type in
components_of_module ~alerts ~uid:md.md_uid
Expand Down Expand Up @@ -1033,7 +1023,7 @@ let check_pers_mod ~loc name =
Persistent_env.check !persistent_env read_sign_of_cmi ~loc name

let crc_of_unit name =
Persistent_env.crc_of_unit !persistent_env read_sign_of_cmi name
Persistent_env.crc_of_unit !persistent_env name

let is_imported_opaque modname =
Persistent_env.is_imported_opaque !persistent_env modname
Expand Down Expand Up @@ -2659,13 +2649,8 @@ let open_signature

(* Read a signature from a file *)
let read_signature modname filename ~add_binding =
let mda =
read_pers_mod modname filename ~add_binding
in
let md = Subst.Lazy.force_module_decl mda.mda_declaration in
match md.md_type with
| Mty_signature sg -> sg
| Mty_ident _ | Mty_functor _ | Mty_alias _ | Mty_strengthen _ -> assert false
let mty = read_pers_mod modname filename ~add_binding in
Subst.Lazy.force_signature mty

let is_identchar_latin1 = function
| 'A'..'Z' | 'a'..'z' | '_' | '\192'..'\214' | '\216'..'\246'
Expand Down
Loading