Skip to content

Use Compilation_unit.t instead of Ident.t for globals #871

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 82 commits into from
Nov 28, 2022

Conversation

lukemaurer
Copy link
Contributor

This PR adds a requirement to use -for-pack when compiling an .mli. In return, we will now always be able to determine the fully-qualified name of a compilation unit during compilation, rather than having to fix up identifiers when assembling a pack. Because of this, it makes more sense to use Compilation_unit.t instead of Ident.t whenever an identifier is known to be global. Currently this is done in the type checker and in Lambda - in particular, the Pgetglobal and Psetglobal primitives now operate on Compilation_unit.t rather than Ident.t. (There is a new primitive, Pgetpredef, for getting predefined values, since these have no representation as Compilation_unit.ts.) This simplifies a number of things, not least asmpackager.ml and bytepackager.ml, which no longer have to do any rewriting (and export_info_for_pack.ml is gone entirely).

lukemaurer and others added 30 commits July 26, 2022 09:13
b7ec31d47 Don't check the names of unprefixed compilation units
4da7b7519 Fix compilation
f012913f3 Code review
204fdff1c Fix compilation on Power
e7ebe5b11 Code review
b3f462cae Temporarily allow `.cinaps` as the name of a compilation unit
01a9585d1 Fix `opttoploop.ml` compilation
2864c3463 Replace `Compilenv.make_symbol` in all archs
96d2760cd Simpler symbols
67b25c1 Merge flambda-backend changes
b2cab95 flambda-backend: Merge ocaml-jst
a6d6e0e flambda-backend: Merge ocaml-jst
88a4f63 flambda-backend: Use Pmakearray for immutable arrays (oxcaml#699)
eeaa44b flambda-backend: Install an ocamldoc binary (oxcaml#695)
48d322b flambda-backend: Ensure that GC is not invoked from bounds check failures (oxcaml#681)
4370fa1 flambda-backend: Review changes of term directory (oxcaml#602)
65a4566 flambda-backend: Add code coverage using bisect_ppx (oxcaml#352)
63ab65f flambda-backend: Bugfix for primitive inclusion (oxcaml#662)
7e3e0c8 flambda-backend: Fix inclusion checks for primitives (oxcaml#661)
96c68f9 flambda-backend: Speed up linking by changing cmxa format (oxcaml#607)
1829150 flambda-backend: Bugfix for Translmod.all_idents (oxcaml#659)

git-subtree-dir: ocaml
git-subtree-split: b7ec31d4701dd0d3c63b9fa241dac6b983ef84f5
These fixes were intended to be done before the move to
`flambda-backend` but got dropped somehow.
Instead of a `getglobal` primitive taking an `Ident.t`, Lambda
now has a `getglobal` taking a `Compilation_unit.t` and a
separate `getpredef` taking a predef `Ident.t`. (It would be
sensible to define a new type `Predef.t` or something.)

In order to generate the full `Compilation_unit.t` when producing
Lambda, we need to know the pack prefix of each global used in the
source file. In particular, it means we need the pack prefix in the
`.cmi` format. This suffices even with `-no-alias-deps` (that is,
when we might be missing the relevant `.cmi`), since a module that's
merely aliased never produces a `getglobal` operation.

In return, packing no longer requires fiddling with the `Ident.t`s in
the code of the component modules - they are created correctly to
begin with.

These changes don't reach much into the bytecode compiler or the
middle ends: the `Compilation_unit.t` gets translated into an
`Ident.t` or `Symbol.t`, respectively, on the way in. Many fiddly
details at the driver level are affected, however, since we've been
treating `modname` and `Ident.t` as interchangeable.

Finally, I've removed the `Misc.modname` type (which was simply an
alias to `string`) in favor of `Compilation_unit.t` or
`Compilation_unit.Name.t`, as applicable. (Indeed, making the
difference explicit is a significant improvement.)
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.

This is a great change which has cleaned up a lot of code.
Approving everything except:

  • the typing/ directory
  • the comment on Compilation_unit.can_access_by_name (although I suggest renaming this function to make its semantics clearer)
  • the add_used_primitive / get_units_with_used_primitives logic in Translprim.
    @lukemaurer please liaise with @lpw25 for these final parts of review, as discussed.

@mshinwell mshinwell marked this pull request as ready for review November 9, 2022 15:29
Copy link
Collaborator

@lpw25 lpw25 left a comment

Choose a reason for hiding this comment

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

Approving the parts Mark didn't

@mshinwell mshinwell merged commit 4783162 into oxcaml:main Nov 28, 2022
mshinwell added a commit to mshinwell/oxcaml that referenced this pull request Dec 13, 2022
06c189a flambda-backend: Make stack allocation the default (oxcaml#1013)
98debd5 flambda-backend: Initial support for value slots not of value kind (oxcaml#946)
deb1714 flambda-backend: Add is_last flag to closinfo words (oxcaml#938)
d07fce1 flambda-backend: Disable poll insertion in Configure (oxcaml#967)
0f1ce0e flambda-backend: Regenerate ocaml/configure autoconf 2.69 (instead of 2.71) (oxcaml#1012)
27132d8 flambda-backend: Fix for spurious typing error related to expanding through functor arguments (oxcaml#997)
724fb68 flambda-backend: Use `Compilation_unit.t` instead of `Ident.t` for globals (oxcaml#871)
396d5b8 flambda-backend: Add a test for frametable setup in natdynlinked libraries (oxcaml#983)
b73ab12 flambda-backend: Fix invocation of `caml_shared_startup` in native dynlink (oxcaml#980)
7c7d75a flambda-backend: Fix split_default_wrapper which did not trigger anymore with flambda2 (oxcaml#970)
8fb75bd flambda-backend: Port ocaml/ocaml#11727 and ocaml/ocaml#11732 (oxcaml#965)
fdb7987 flambda-backend: Fix include functor issue after 4.14 merge. (oxcaml#948)
9745cdb flambda-backend: Print -dprofile/-dtimings output to stdout like 4.12 (oxcaml#943)
5f51f21 flambda-backend: Merge pull request oxcaml#932 from mshinwell/4.14-upgrade
841687d flambda-backend: Run make alldepend in ocaml/ (oxcaml#936)
72a7658 flambda-backend: Remove reformatting changes only in dynlink/dune (preserving PR889 and adjusting to minimise diff)
6d758cd flambda-backend: Revert whitespace changes in dune files, to match upstream
c86bf6e flambda-backend: Remove duplicate tests for polling
971dbeb flambda-backend: Testsuite fixes
32f8356 flambda-backend: Topeval fix for symbols patch
befea01 flambda-backend: Compilation fixes / rectify merge faults
a84543f flambda-backend: Merge ocaml-jst
8e65056 flambda-backend: Merge ocaml-jst
4d70045 flambda-backend: Remove filename from system frametable (amd64) (oxcaml#920)
5e57b7d flambda-backend: Bugfix for runtime frame_descr logic for C frames (oxcaml#918)
6423d5e flambda-backend: Merge pull request oxcaml#914 from mshinwell/merge-ocaml-jst-2022-10-24
ead605c flambda-backend: Add a missing Extract_exception (oxcaml#916)
c8f1481 flambda-backend: Resolve conflicts and add specialise/specialised attributes to Builtin_attributes
cf4d0d3 flambda-backend: Merge fixes (#21)
c2f742f flambda-backend: Re-enable some tests for Flambda2 (oxcaml#881)
3d38d13 flambda-backend: Long frames in frametable (oxcaml#797)
85aec7b flambda-backend: Add loop attribute to Builtin_attributes
c0f16e3 flambda-backend: Compilation fixes
90dea23 flambda-backend: Merge flambda-backend/main
5acc6ea flambda-backend: Fixes after merge
e501946 flambda-backend: Merge ocaml-jst
115083b flambda-backend: Merge ocaml-jst
9943b2e flambda-backend: Revert "Revert "Transform tail-recursive functions into recursive continuations (oxcaml#893)"" (oxcaml#909)
ce339f1 flambda-backend: Fix alloc modes and call kinds for overapplications (oxcaml#902)
e6a317c flambda-backend: Revert "Transform tail-recursive functions into recursive continuations (oxcaml#893)"
853c488 flambda-backend: Transform tail-recursive functions into recursive continuations (oxcaml#893)
5a977e4 flambda-backend: Fix missing End_region primitives on switch arms (oxcaml#898)
7fa7f9d flambda-backend: Add missing dependencies to Dune files (oxcaml#889)
3cd36f0 flambda-backend: Have Lambda `Pgetglobal` and `Psetglobal` take `Compilation_unit.t` (oxcaml#896)
7565915 flambda-backend: [@poll error] attribute (oxcaml#745)
9eb9448 flambda-backend: Backport the main safepoints PRs (oxcaml#740)
689bdda flambda-backend: Add strict mode for ocamldep (oxcaml#892)

git-subtree-dir: ocaml
git-subtree-split: 06c189a
mshinwell added a commit to mshinwell/oxcaml that referenced this pull request Dec 13, 2022
06c189a flambda-backend: Make stack allocation the default (oxcaml#1013)
98debd5 flambda-backend: Initial support for value slots not of value kind (oxcaml#946)
deb1714 flambda-backend: Add is_last flag to closinfo words (oxcaml#938)
d07fce1 flambda-backend: Disable poll insertion in Configure (oxcaml#967)
0f1ce0e flambda-backend: Regenerate ocaml/configure autoconf 2.69 (instead of 2.71) (oxcaml#1012)
27132d8 flambda-backend: Fix for spurious typing error related to expanding through functor arguments (oxcaml#997)
724fb68 flambda-backend: Use `Compilation_unit.t` instead of `Ident.t` for globals (oxcaml#871)
396d5b8 flambda-backend: Add a test for frametable setup in natdynlinked libraries (oxcaml#983)
b73ab12 flambda-backend: Fix invocation of `caml_shared_startup` in native dynlink (oxcaml#980)
7c7d75a flambda-backend: Fix split_default_wrapper which did not trigger anymore with flambda2 (oxcaml#970)
8fb75bd flambda-backend: Port ocaml/ocaml#11727 and ocaml/ocaml#11732 (oxcaml#965)
fdb7987 flambda-backend: Fix include functor issue after 4.14 merge. (oxcaml#948)
9745cdb flambda-backend: Print -dprofile/-dtimings output to stdout like 4.12 (oxcaml#943)
5f51f21 flambda-backend: Merge pull request oxcaml#932 from mshinwell/4.14-upgrade
841687d flambda-backend: Run make alldepend in ocaml/ (oxcaml#936)
72a7658 flambda-backend: Remove reformatting changes only in dynlink/dune (preserving PR889 and adjusting to minimise diff)
6d758cd flambda-backend: Revert whitespace changes in dune files, to match upstream
c86bf6e flambda-backend: Remove duplicate tests for polling
971dbeb flambda-backend: Testsuite fixes
32f8356 flambda-backend: Topeval fix for symbols patch
befea01 flambda-backend: Compilation fixes / rectify merge faults
a84543f flambda-backend: Merge ocaml-jst
8e65056 flambda-backend: Merge ocaml-jst
4d70045 flambda-backend: Remove filename from system frametable (amd64) (oxcaml#920)
5e57b7d flambda-backend: Bugfix for runtime frame_descr logic for C frames (oxcaml#918)
6423d5e flambda-backend: Merge pull request oxcaml#914 from mshinwell/merge-ocaml-jst-2022-10-24
ead605c flambda-backend: Add a missing Extract_exception (oxcaml#916)
c8f1481 flambda-backend: Resolve conflicts and add specialise/specialised attributes to Builtin_attributes
cf4d0d3 flambda-backend: Merge fixes (#21)
c2f742f flambda-backend: Re-enable some tests for Flambda2 (oxcaml#881)
3d38d13 flambda-backend: Long frames in frametable (oxcaml#797)
85aec7b flambda-backend: Add loop attribute to Builtin_attributes
c0f16e3 flambda-backend: Compilation fixes
90dea23 flambda-backend: Merge flambda-backend/main
5acc6ea flambda-backend: Fixes after merge
e501946 flambda-backend: Merge ocaml-jst
115083b flambda-backend: Merge ocaml-jst
9943b2e flambda-backend: Revert "Revert "Transform tail-recursive functions into recursive continuations (oxcaml#893)"" (oxcaml#909)
ce339f1 flambda-backend: Fix alloc modes and call kinds for overapplications (oxcaml#902)
e6a317c flambda-backend: Revert "Transform tail-recursive functions into recursive continuations (oxcaml#893)"
853c488 flambda-backend: Transform tail-recursive functions into recursive continuations (oxcaml#893)
5a977e4 flambda-backend: Fix missing End_region primitives on switch arms (oxcaml#898)
7fa7f9d flambda-backend: Add missing dependencies to Dune files (oxcaml#889)
3cd36f0 flambda-backend: Have Lambda `Pgetglobal` and `Psetglobal` take `Compilation_unit.t` (oxcaml#896)
7565915 flambda-backend: [@poll error] attribute (oxcaml#745)
9eb9448 flambda-backend: Backport the main safepoints PRs (oxcaml#740)
689bdda flambda-backend: Add strict mode for ocamldep (oxcaml#892)

git-subtree-dir: ocaml
git-subtree-split: 06c189a
mshinwell added a commit to mshinwell/oxcaml that referenced this pull request Dec 28, 2022
b11eea1 flambda-backend: Introduce Import_info (oxcaml#1036)
bc5b135 flambda-backend: Fix `ocamlobjinfo` on flambda2 .cmx files (oxcaml#1029)
c8babbd flambda-backend: Compilation_unit optimisations (oxcaml#1035)
e8d3e22 flambda-backend: Use 4.14.0 opam switch for building (includes upgrading ocamlformat to 0.24.1) (oxcaml#1030)
eb14a86 flambda-backend: Port PR81 from ocaml-jst (oxcaml#1024)
131bc12 flambda-backend: Merge ocaml-jst 2022-12-13 (oxcaml#1022)
06c189a flambda-backend: Make stack allocation the default (oxcaml#1013)
98debd5 flambda-backend: Initial support for value slots not of value kind (oxcaml#946)
deb1714 flambda-backend: Add is_last flag to closinfo words (oxcaml#938)
d07fce1 flambda-backend: Disable poll insertion in Configure (oxcaml#967)
0f1ce0e flambda-backend: Regenerate ocaml/configure autoconf 2.69 (instead of 2.71) (oxcaml#1012)
27132d8 flambda-backend: Fix for spurious typing error related to expanding through functor arguments (oxcaml#997)
724fb68 flambda-backend: Use `Compilation_unit.t` instead of `Ident.t` for globals (oxcaml#871)
396d5b8 flambda-backend: Add a test for frametable setup in natdynlinked libraries (oxcaml#983)
b73ab12 flambda-backend: Fix invocation of `caml_shared_startup` in native dynlink (oxcaml#980)
7c7d75a flambda-backend: Fix split_default_wrapper which did not trigger anymore with flambda2 (oxcaml#970)
8fb75bd flambda-backend: Port ocaml/ocaml#11727 and ocaml/ocaml#11732 (oxcaml#965)
fdb7987 flambda-backend: Fix include functor issue after 4.14 merge. (oxcaml#948)
9745cdb flambda-backend: Print -dprofile/-dtimings output to stdout like 4.12 (oxcaml#943)
5f51f21 flambda-backend: Merge pull request oxcaml#932 from mshinwell/4.14-upgrade
841687d flambda-backend: Run make alldepend in ocaml/ (oxcaml#936)
72a7658 flambda-backend: Remove reformatting changes only in dynlink/dune (preserving PR889 and adjusting to minimise diff)
6d758cd flambda-backend: Revert whitespace changes in dune files, to match upstream
c86bf6e flambda-backend: Remove duplicate tests for polling
971dbeb flambda-backend: Testsuite fixes
32f8356 flambda-backend: Topeval fix for symbols patch
befea01 flambda-backend: Compilation fixes / rectify merge faults
a84543f flambda-backend: Merge ocaml-jst
8e65056 flambda-backend: Merge ocaml-jst
4d70045 flambda-backend: Remove filename from system frametable (amd64) (oxcaml#920)
5e57b7d flambda-backend: Bugfix for runtime frame_descr logic for C frames (oxcaml#918)
6423d5e flambda-backend: Merge pull request oxcaml#914 from mshinwell/merge-ocaml-jst-2022-10-24
ead605c flambda-backend: Add a missing Extract_exception (oxcaml#916)
c8f1481 flambda-backend: Resolve conflicts and add specialise/specialised attributes to Builtin_attributes
cf4d0d3 flambda-backend: Merge fixes (#21)
c2f742f flambda-backend: Re-enable some tests for Flambda2 (oxcaml#881)
3d38d13 flambda-backend: Long frames in frametable (oxcaml#797)
85aec7b flambda-backend: Add loop attribute to Builtin_attributes
c0f16e3 flambda-backend: Compilation fixes
90dea23 flambda-backend: Merge flambda-backend/main
5acc6ea flambda-backend: Fixes after merge
e501946 flambda-backend: Merge ocaml-jst
115083b flambda-backend: Merge ocaml-jst
9943b2e flambda-backend: Revert "Revert "Transform tail-recursive functions into recursive continuations (oxcaml#893)"" (oxcaml#909)
ce339f1 flambda-backend: Fix alloc modes and call kinds for overapplications (oxcaml#902)
e6a317c flambda-backend: Revert "Transform tail-recursive functions into recursive continuations (oxcaml#893)"
853c488 flambda-backend: Transform tail-recursive functions into recursive continuations (oxcaml#893)
5a977e4 flambda-backend: Fix missing End_region primitives on switch arms (oxcaml#898)
7fa7f9d flambda-backend: Add missing dependencies to Dune files (oxcaml#889)
3cd36f0 flambda-backend: Have Lambda `Pgetglobal` and `Psetglobal` take `Compilation_unit.t` (oxcaml#896)
7565915 flambda-backend: [@poll error] attribute (oxcaml#745)
9eb9448 flambda-backend: Backport the main safepoints PRs (oxcaml#740)
689bdda flambda-backend: Add strict mode for ocamldep (oxcaml#892)

git-subtree-dir: ocaml
git-subtree-split: b11eea1
@lthls lthls mentioned this pull request Jan 10, 2023
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 to upstream PR should be sent to upstream OCaml
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants