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

Split Import_info.t into Import_info.{Intf,Impl}.t #1746

Conversation

lukemaurer
Copy link
Contributor

@lukemaurer lukemaurer commented Aug 15, 2023

Depends on #1933.

This improves clarity, since every Import.t is statically either an interface import or an implementation import and they don't support quite the same operations. In particular, every implementation import (being an import of a .cmo/x file) must have a fully-specified compilation unit, whereas an interface import might only have a name (with unknown pack prefix).

Produced by reverting commit 4bd7544 from the 'instance-typing' branch.

This improves clarity, since every `Import.t` is statically either an interface
import or an implementation import and they don't support quite the same
operations. In particular, every implementation import (being an import of a
.cmo/x file) must have a fully-specified compilation unit, whereas in
implementation import might only have a name (with unknown pack prefix).

Produced by reverting commit 4bd7544 from the
'instance-typing' branch.
@mshinwell mshinwell added the parameterized-libs PRs needed for parameterized libraries label Aug 16, 2023
lukemaurer added a commit to lukemaurer/flambda-backend that referenced this pull request Aug 16, 2023
To support parameterised libraries, it will help to sharpen the distinction
between `CU.Name.t` and `CU.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.)
lukemaurer added a commit to lukemaurer/flambda-backend that referenced this pull request Aug 16, 2023
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.)
@lpw25 lpw25 removed the parameterized-libs PRs needed for parameterized libraries label Oct 5, 2023
@mshinwell mshinwell added the parameterized-libs PRs needed for parameterized libraries label Oct 13, 2023
@mshinwell
Copy link
Collaborator

I'll review this

Copy link
Collaborator

@mshinwell mshinwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would have been easier split into two PRs, and maybe that could still be done. The first could have all of the renames (adding .Impl or .Intf) and just two duplicate copies of the original Import_info module. Then the second PR could change the semantics of the two modules.

@@ -12,7 +12,7 @@
(* *)
(**************************************************************************)

module CU = Compilation_unit
module CU := Compilation_unit

(* CR mshinwell: maybe there should be a phantom type allowing to distinguish
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CR should be split and the first part removed (please change to CR xclerc:), since it's done (in a different way) by this patch.

| Other of CU.Name.t * (CU.t * Digest.t) option
module Intf = struct
type t =
| Normal of CU.Name.t * Digest.t (* Unpacked, so compilation unit = name *)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this comment apply for all three cases? If so maybe clarify

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding comments to the other two

match crc_with_unit with
| None -> Other (cu_name, None)
| Some (cu, crc) ->
(* For the moment be conservative and only use the [Normal] constructor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems out of date now, but maybe there should still be a comment here about the decision based on the pack prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating the comment.


let create_normal cu ~crc =
match crc with Some crc -> Normal (cu, crc) | None -> Normal_no_crc cu
let impl t =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify why the semantics of this was changed from that of the old cu function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because an Import_info.Impl.t always has a full compilation unit, whereas it's normal for an Import_info.Intf.t not to have one.

@lukemaurer
Copy link
Contributor Author

I think this would have been easier split into two PRs, and maybe that could still be done. The first could have all of the renames (adding .Impl or .Intf) and just two duplicate copies of the original Import_info module. Then the second PR could change the semantics of the two modules.

I can split this off easily enough. I've pushed some review changes in the meantime.

lukemaurer added a commit to lukemaurer/flambda-backend that referenced this pull request Oct 16, 2023
PR ocaml-flambda#1746 will change the APIs and implementations to reflect the differences in
the datatypes. (Currently, the major difference is that an `Impl.t` always has a
full compilation unit, but parameterised libraries will add more differences.)
lukemaurer added a commit to lukemaurer/flambda-backend that referenced this pull request Oct 16, 2023
@lukemaurer lukemaurer marked this pull request as draft October 16, 2023 13:04
@lukemaurer
Copy link
Contributor Author

I think this would have been easier split into two PRs, and maybe that could still be done. The first could have all of the renames (adding .Impl or .Intf) and just two duplicate copies of the original Import_info module. Then the second PR could change the semantics of the two modules.

I can split this off easily enough. I've pushed some review changes in the meantime.

Done: #1933 just copies and pastes Intf to Impl, so it's now easier to see the differences here. I've marked this one as a draft since I'll need to rebase it once #1933 is in.

@lukemaurer lukemaurer changed the base branch from main to lmaurer/import-info-split-copy December 5, 2023 22:56
lukemaurer added a commit to lukemaurer/flambda-backend that referenced this pull request Apr 30, 2024
[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
Copy link
Contributor Author

Superseded by #2552.

@lukemaurer lukemaurer closed this May 9, 2024
lpw25 pushed a commit that referenced this pull request May 15, 2024
…1753)

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 #1746 adds, but here it's optional and only used in the few
places that need it.)
lukemaurer added a commit to lukemaurer/flambda-backend that referenced this pull request Oct 23, 2024
…o for parameters (ocaml-flambda#1753)

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.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parameterized-libs PRs needed for parameterized libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants