Skip to content

Remove legacy combined Import_info.t type and update all uses #2552

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

Open
wants to merge 49 commits into
base: main
Choose a base branch
from

Conversation

lukemaurer
Copy link
Contributor

@lukemaurer lukemaurer commented May 9, 2024

#1753 introduced a split API to Import_info that distinguishes between imports of interfaces (i.e., .cmi imports) and imports of implementations (i.e., .cmx imports), but it retained the old combined API to minimize the changes. This PR does the remaining work of taking away the old type, which forces every occurrence of Import_info to pick one or the other. Because very nearly every value of Import_info.t was statically one flavor of import or the other, almost everything in this PR (outside of import_info.ml) just adds either .Intf or .Impl to something.

Supersedes #1746 and #1933, which did something similar with an older version of the #1753 API.

This allows compiling an .mli as a _parameter module_ rather than a normal
compilation unit. A parameter module defines a module _type_ rather than a
module, so it cannot be referred to directly from another module. A forthcoming
PR will add the `-parameter P` option which adds the parameter module `P` as a
parameter to the current module, which then allows references to `P` in the
module. Further PRs will deal with how to actually use a module that takes
parameters.

For the moment, `-parameter` is unimplemented, so any reference to a parameter
module is an error.
To support parameterised libraries, it will help to sharpen the distinction
between `Compilation_unit.Name.t` and `Compilation_unit.t`. In particular, a
`CU.Name.t` will mean the name of a .cmi and a `CU.t` will mean the name of a
.cmo/x.

Accordingly, the `cmi_name` field in `Cmi_format` changes from `CU.t` to
`CU.Name.t`. There is never a `CU.t` for a parameter module since it has no
.cmo/x, so for these, the `CU.t` is removed from the `Cmi_format` altogether. A
non-parameter .cmi still needs it, however, since we need to store the pack
prefix for the implementation .cmo/x. (We don't support pack prefixes for
parameter modules.) Accordingly, the `cmi_kind` field now has two variants:

```
type kind =
  | Normal of { cmi_impl : CU.t }
  | Parameter
```

As it happens, all this forces through a related change in `Import_info.t` so
that we can store import info for a parameter module, which has a CRC but no
compilation unit. Since the format of import info for interfaces and
implementations is diverging, a split API is introduced to `Import_info`. (This
is the same API that ocaml-flambda#1746 adds, but here it's optional and only used in the few
places that need it.)
I've disabled the check on the output, since currently we get the wrong error
message (and the one we get is confusing). This will be much easier to fix when
PR ocaml-flambda#1764 is fixed to avoid unhelpful checks on `.mli` files that are loaded
directly rather than as part of name resolution.
Displaying the correct error message will be easier again after ocaml-flambda#1764
[Import_info.t] is now split between the intf and impl cases, which will make it
easier for a subsequent PR (which will likely supersede ocaml-flambda#1746 and ocaml-flambda#1933) to pull
apart the types and force all callers to choose.

Also added a [Consistbl]-centric API for each of [Intf] and [Impl] to make it
easy again to convert between import info and an entry in a [Consistbl].
@lukemaurer lukemaurer changed the base branch from lmaurer/cu-name-is-cmi to main May 22, 2024 14:18
@lukemaurer lukemaurer marked this pull request as ready for review May 22, 2024 14:22
@lukemaurer lukemaurer mentioned this pull request Jun 4, 2024
@lukemaurer lukemaurer force-pushed the import-info-split-v2 branch from 07d29e9 to a3e7f5b Compare June 4, 2024 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant