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

Ensure that types from packed modules are always generalised #11732

Merged
merged 2 commits into from
Nov 17, 2022

Conversation

stedolan
Copy link
Contributor

The type system ensures that in the right-hand side of a type definition type t = foo, the type foo is always generalised.

This invariant is violated in one case, when the right-hand side comes not from the module language but from a with constraint on a first class module (e.g. (module T with type t = foo)). In this case, types with level below generic_level could end up in declarations.

In older versions of OCaml, I think this still occurred but mostly was ignored. When OCaml 4.13 (specifically, #10277) introduced stricter level and scope checking, this issue began to cause some code to spuriously fail to typecheck. Under OCaml 4.14 and later, the second example in the attached test yields the following nonsensical error message:

Error: Signature mismatch:
       Modules do not match:
         sig type t = foo end
       is not included in
         sig type t = int end
       Type declarations do not match:
         type t = foo
       is not included in
         type t = int
       The type foo = int is not equal to the type int

where foo is simultaneously equal to and not equal to int.

The fix is to ensure that the type is at generic_level before adding it to the environment, by calling Ctype.correct_levels.

@stedolan stedolan changed the title Package type levels Ensure that types from packed modules are always generalised Nov 16, 2022
@stedolan stedolan force-pushed the package-type-levels branch from 0852bd2 to 6a9689e Compare November 16, 2022 14:51
Copy link
Contributor

@garrigue garrigue left a comment

Choose a reason for hiding this comment

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

Well spotted. The fix is correct.
In this case the types are given explicitly somewhere, so there is no question of principality on those parameters.

@Octachron
Copy link
Member

The fix looks worthwhile to backport to 4.14 (and 5.0), any objections @garrigue ?

@stedolan stedolan force-pushed the package-type-levels branch from 6a9689e to 2266947 Compare November 17, 2022 13:17
stedolan added a commit to stedolan/flambda-backend that referenced this pull request Nov 17, 2022
@stedolan stedolan merged commit bf4a8ef into ocaml:trunk Nov 17, 2022
stedolan added a commit to stedolan/flambda-backend that referenced this pull request Nov 17, 2022
@garrigue
Copy link
Contributor

No problem with backporting. This is clearly a simple bug fix.

lpw25 pushed a commit to ocaml-flambda/flambda-backend that referenced this pull request Nov 18, 2022
Octachron pushed a commit that referenced this pull request Nov 23, 2022
Octachron pushed a commit that referenced this pull request Nov 23, 2022
@Octachron
Copy link
Member

Cherry picked on 5.0 (as aecdd88) and 4.14 (as bc510ed). I have cherry-picked #11340 to 4.14 along the way to avoid a conflict since this change seemed worthy of a backport to 4.14 too.

mshinwell pushed a commit to ocaml-flambda/ocaml-jst that referenced this pull request Dec 13, 2022
mshinwell added a commit to mshinwell/flambda-backend that referenced this pull request Dec 13, 2022
06c189a flambda-backend: Make stack allocation the default (ocaml-flambda#1013)
98debd5 flambda-backend: Initial support for value slots not of value kind (ocaml-flambda#946)
deb1714 flambda-backend: Add is_last flag to closinfo words (ocaml-flambda#938)
d07fce1 flambda-backend: Disable poll insertion in Configure (ocaml-flambda#967)
0f1ce0e flambda-backend: Regenerate ocaml/configure autoconf 2.69 (instead of 2.71) (ocaml-flambda#1012)
27132d8 flambda-backend: Fix for spurious typing error related to expanding through functor arguments (ocaml-flambda#997)
724fb68 flambda-backend: Use `Compilation_unit.t` instead of `Ident.t` for globals (ocaml-flambda#871)
396d5b8 flambda-backend: Add a test for frametable setup in natdynlinked libraries (ocaml-flambda#983)
b73ab12 flambda-backend: Fix invocation of `caml_shared_startup` in native dynlink (ocaml-flambda#980)
7c7d75a flambda-backend: Fix split_default_wrapper which did not trigger anymore with flambda2 (ocaml-flambda#970)
8fb75bd flambda-backend: Port ocaml/ocaml#11727 and ocaml/ocaml#11732 (ocaml-flambda#965)
fdb7987 flambda-backend: Fix include functor issue after 4.14 merge. (ocaml-flambda#948)
9745cdb flambda-backend: Print -dprofile/-dtimings output to stdout like 4.12 (ocaml-flambda#943)
5f51f21 flambda-backend: Merge pull request ocaml-flambda#932 from mshinwell/4.14-upgrade
841687d flambda-backend: Run make alldepend in ocaml/ (ocaml-flambda#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) (ocaml-flambda#920)
5e57b7d flambda-backend: Bugfix for runtime frame_descr logic for C frames (ocaml-flambda#918)
6423d5e flambda-backend: Merge pull request ocaml-flambda#914 from mshinwell/merge-ocaml-jst-2022-10-24
ead605c flambda-backend: Add a missing Extract_exception (ocaml-flambda#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 (ocaml-flambda#881)
3d38d13 flambda-backend: Long frames in frametable (ocaml-flambda#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 (ocaml-flambda#893)"" (ocaml-flambda#909)
ce339f1 flambda-backend: Fix alloc modes and call kinds for overapplications (ocaml-flambda#902)
e6a317c flambda-backend: Revert "Transform tail-recursive functions into recursive continuations (ocaml-flambda#893)"
853c488 flambda-backend: Transform tail-recursive functions into recursive continuations (ocaml-flambda#893)
5a977e4 flambda-backend: Fix missing End_region primitives on switch arms (ocaml-flambda#898)
7fa7f9d flambda-backend: Add missing dependencies to Dune files (ocaml-flambda#889)
3cd36f0 flambda-backend: Have Lambda `Pgetglobal` and `Psetglobal` take `Compilation_unit.t` (ocaml-flambda#896)
7565915 flambda-backend: [@poll error] attribute (ocaml-flambda#745)
9eb9448 flambda-backend: Backport the main safepoints PRs (ocaml-flambda#740)
689bdda flambda-backend: Add strict mode for ocamldep (ocaml-flambda#892)

git-subtree-dir: ocaml
git-subtree-split: 06c189a
mshinwell added a commit to mshinwell/flambda-backend that referenced this pull request Dec 13, 2022
06c189a flambda-backend: Make stack allocation the default (ocaml-flambda#1013)
98debd5 flambda-backend: Initial support for value slots not of value kind (ocaml-flambda#946)
deb1714 flambda-backend: Add is_last flag to closinfo words (ocaml-flambda#938)
d07fce1 flambda-backend: Disable poll insertion in Configure (ocaml-flambda#967)
0f1ce0e flambda-backend: Regenerate ocaml/configure autoconf 2.69 (instead of 2.71) (ocaml-flambda#1012)
27132d8 flambda-backend: Fix for spurious typing error related to expanding through functor arguments (ocaml-flambda#997)
724fb68 flambda-backend: Use `Compilation_unit.t` instead of `Ident.t` for globals (ocaml-flambda#871)
396d5b8 flambda-backend: Add a test for frametable setup in natdynlinked libraries (ocaml-flambda#983)
b73ab12 flambda-backend: Fix invocation of `caml_shared_startup` in native dynlink (ocaml-flambda#980)
7c7d75a flambda-backend: Fix split_default_wrapper which did not trigger anymore with flambda2 (ocaml-flambda#970)
8fb75bd flambda-backend: Port ocaml/ocaml#11727 and ocaml/ocaml#11732 (ocaml-flambda#965)
fdb7987 flambda-backend: Fix include functor issue after 4.14 merge. (ocaml-flambda#948)
9745cdb flambda-backend: Print -dprofile/-dtimings output to stdout like 4.12 (ocaml-flambda#943)
5f51f21 flambda-backend: Merge pull request ocaml-flambda#932 from mshinwell/4.14-upgrade
841687d flambda-backend: Run make alldepend in ocaml/ (ocaml-flambda#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) (ocaml-flambda#920)
5e57b7d flambda-backend: Bugfix for runtime frame_descr logic for C frames (ocaml-flambda#918)
6423d5e flambda-backend: Merge pull request ocaml-flambda#914 from mshinwell/merge-ocaml-jst-2022-10-24
ead605c flambda-backend: Add a missing Extract_exception (ocaml-flambda#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 (ocaml-flambda#881)
3d38d13 flambda-backend: Long frames in frametable (ocaml-flambda#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 (ocaml-flambda#893)"" (ocaml-flambda#909)
ce339f1 flambda-backend: Fix alloc modes and call kinds for overapplications (ocaml-flambda#902)
e6a317c flambda-backend: Revert "Transform tail-recursive functions into recursive continuations (ocaml-flambda#893)"
853c488 flambda-backend: Transform tail-recursive functions into recursive continuations (ocaml-flambda#893)
5a977e4 flambda-backend: Fix missing End_region primitives on switch arms (ocaml-flambda#898)
7fa7f9d flambda-backend: Add missing dependencies to Dune files (ocaml-flambda#889)
3cd36f0 flambda-backend: Have Lambda `Pgetglobal` and `Psetglobal` take `Compilation_unit.t` (ocaml-flambda#896)
7565915 flambda-backend: [@poll error] attribute (ocaml-flambda#745)
9eb9448 flambda-backend: Backport the main safepoints PRs (ocaml-flambda#740)
689bdda flambda-backend: Add strict mode for ocamldep (ocaml-flambda#892)

git-subtree-dir: ocaml
git-subtree-split: 06c189a
mshinwell added a commit to mshinwell/flambda-backend that referenced this pull request Dec 28, 2022
b11eea1 flambda-backend: Introduce Import_info (ocaml-flambda#1036)
bc5b135 flambda-backend: Fix `ocamlobjinfo` on flambda2 .cmx files (ocaml-flambda#1029)
c8babbd flambda-backend: Compilation_unit optimisations (ocaml-flambda#1035)
e8d3e22 flambda-backend: Use 4.14.0 opam switch for building (includes upgrading ocamlformat to 0.24.1) (ocaml-flambda#1030)
eb14a86 flambda-backend: Port PR81 from ocaml-jst (ocaml-flambda#1024)
131bc12 flambda-backend: Merge ocaml-jst 2022-12-13 (ocaml-flambda#1022)
06c189a flambda-backend: Make stack allocation the default (ocaml-flambda#1013)
98debd5 flambda-backend: Initial support for value slots not of value kind (ocaml-flambda#946)
deb1714 flambda-backend: Add is_last flag to closinfo words (ocaml-flambda#938)
d07fce1 flambda-backend: Disable poll insertion in Configure (ocaml-flambda#967)
0f1ce0e flambda-backend: Regenerate ocaml/configure autoconf 2.69 (instead of 2.71) (ocaml-flambda#1012)
27132d8 flambda-backend: Fix for spurious typing error related to expanding through functor arguments (ocaml-flambda#997)
724fb68 flambda-backend: Use `Compilation_unit.t` instead of `Ident.t` for globals (ocaml-flambda#871)
396d5b8 flambda-backend: Add a test for frametable setup in natdynlinked libraries (ocaml-flambda#983)
b73ab12 flambda-backend: Fix invocation of `caml_shared_startup` in native dynlink (ocaml-flambda#980)
7c7d75a flambda-backend: Fix split_default_wrapper which did not trigger anymore with flambda2 (ocaml-flambda#970)
8fb75bd flambda-backend: Port ocaml/ocaml#11727 and ocaml/ocaml#11732 (ocaml-flambda#965)
fdb7987 flambda-backend: Fix include functor issue after 4.14 merge. (ocaml-flambda#948)
9745cdb flambda-backend: Print -dprofile/-dtimings output to stdout like 4.12 (ocaml-flambda#943)
5f51f21 flambda-backend: Merge pull request ocaml-flambda#932 from mshinwell/4.14-upgrade
841687d flambda-backend: Run make alldepend in ocaml/ (ocaml-flambda#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) (ocaml-flambda#920)
5e57b7d flambda-backend: Bugfix for runtime frame_descr logic for C frames (ocaml-flambda#918)
6423d5e flambda-backend: Merge pull request ocaml-flambda#914 from mshinwell/merge-ocaml-jst-2022-10-24
ead605c flambda-backend: Add a missing Extract_exception (ocaml-flambda#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 (ocaml-flambda#881)
3d38d13 flambda-backend: Long frames in frametable (ocaml-flambda#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 (ocaml-flambda#893)"" (ocaml-flambda#909)
ce339f1 flambda-backend: Fix alloc modes and call kinds for overapplications (ocaml-flambda#902)
e6a317c flambda-backend: Revert "Transform tail-recursive functions into recursive continuations (ocaml-flambda#893)"
853c488 flambda-backend: Transform tail-recursive functions into recursive continuations (ocaml-flambda#893)
5a977e4 flambda-backend: Fix missing End_region primitives on switch arms (ocaml-flambda#898)
7fa7f9d flambda-backend: Add missing dependencies to Dune files (ocaml-flambda#889)
3cd36f0 flambda-backend: Have Lambda `Pgetglobal` and `Psetglobal` take `Compilation_unit.t` (ocaml-flambda#896)
7565915 flambda-backend: [@poll error] attribute (ocaml-flambda#745)
9eb9448 flambda-backend: Backport the main safepoints PRs (ocaml-flambda#740)
689bdda flambda-backend: Add strict mode for ocamldep (ocaml-flambda#892)

git-subtree-dir: ocaml
git-subtree-split: b11eea1
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Mar 21, 2023
a09392d Set Menhir version back to 20210419 again (ocaml#89)
cc63992 Merge pull request ocaml#88 from mshinwell/flambda-backend-changes-2022-12-27
3e49df3 HACKING.jst.adoc
1866676 Merge flambda-backend changes
e012992 Merge pull request ocaml#87 from mshinwell/merge-4.14.1
ac5c7c8 Merge tag '4.14.1' into main
3da21bc add a useful debug printer
83b7c72 Document the debug_printers script
98896e0 Remove a tiny code stutter I came across
99cb5d9 release 4.14.1
b49060f last commit before tagging 4.14.1
fae9aef Add documentation
708e5a9 Add tests
c609eee Bootstrap
7f922d0 Polymorphic parameters
51aeb04 Keep generalized structure from patterns when typing let
4b68bb3 Add test of princiaplity from polymorphic type constraints
82c7afe fix wong raise
aca252f x86: Force result of Icomp to be in a register (ocaml#11808)
985725b Add dynlink_compilerlibs.mli to .gitignore (ocaml#79)
2b1fa24 Regenerate parser (ocaml#80)
1bb6c79 Merge pull request ocaml#78 from mshinwell/flambda-backend-patches-2022-12-13
9029581 Update otherlibs/dynlink/Makefile
3e4f1b9 Revert toplevel/native/dune to ocaml-jst version
6061e4c Regenerate configure using autoconf 2.71
888d4b1 Back out patch which disables alloc-check in ocaml-jst
a6d5796 Fix dynlink build
3e46daf Update .depend files
a5c547e Bootstrap
a6a9031 Merge flambda-backend changes
0ac7fdd temp fix for linker error (ocaml#77)
1018602 Remove references to 32-bit Cygwin (ocaml#11797)
e2d0d9e Enable individual testing with Makefile.jst (ocaml#76)
f10cbf6 increment version number after tagging 4.14.1~rc1
11c5ab7 release 4.14.1~rc1
e4c3920 last commit before tagging 4.14.1~rc1
9e598ca Merge pull request ocaml#11793 from dra27/then-than
2a7e501 Use a more relaxed mode for unification in Ctype.subst (ocaml#11771) (ocaml#73)
7b35ef7 Statically initialize `caml_global_data` with a valid value (ocaml#11788)
cbd791a Allow immediates to cross modes (ocaml#58)
85a0817 Merge pull request ocaml#11534 from gasche/follow-synonyms-in-show-module-type
699f43c Changes
e54e9bc fix the 'stuttering' issue in #show
d9799d3 test comments
fec3b23 follow synonyms when #show-ing module types
06a1ad7 regression tests for ocaml#11533 (still failing)
549d757 Run "misplaced attributes" check when compiling mlis (ocaml#72)
b2b74bf Fix bug in `Mtype.strengthen_lazy` causing spurious typing errors (ocaml#11776)
a6c0e75 Ensure that Ctype.nongen always calls remove_mode_variables (ocaml#70)
6c50831 array elements are global (ocaml#67)
bc510ed Ensure that types from packed modules are always generalised (ocaml#11732)
4d47036 Fix ocaml#10768
8788ff6 Add/move some documentation
9891a36 Propagate location information to `local_` in expressions
988306d Add support for `global_` and `nonlocal_` constructor arguments (ocaml#50)
6729eb8 Missing CAMLparam in win32's Unix.stat (ocaml#11737)
e7dd740 Add debug_printers.ml (ocaml#63)
65f2896 more entries in gitignore (ocaml#62)
a9a84d0 Move `global_flag` to `Asttypes` (ocaml#60)
fac5896 Minor attribute fixes from flambda-backend
75f402e Note about make install and Makefile.jst (ocaml#56)
fb5b1e4 Remove the -force-tmc flag (ocaml#11661)
bd87a61 ocamlmklib: use `ar rcs` instead of `ar rc` (ocaml#11670)
83762af Merge pull request ocaml#11622 from Octachron/fix_recursive_types_in_constructor_mismatch
ca48730 Merge pull request ocaml#11609 from Octachron/pr11194_unbound_and_printing_context

git-subtree-dir: ocaml
git-subtree-split: a09392d
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.

3 participants