Skip to content

Commit 6f19fa6

Browse files
flambda-backend: Fix error message regression: use manifest jkind less (#1981)
* only use manifest jkind for abstract types * add test * update comment * Use the manifest even less. --------- Co-authored-by: Richard Eisenberg <[email protected]>
1 parent 4d6adf3 commit 6f19fa6

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

testsuite/tests/typing-misc/records.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,14 @@ Line 6, characters 13-23:
300300
Error: Unbound module Coq__10
301301
Hint: Did you mean Coq__11?
302302
|}]
303+
304+
type a = unit
305+
type b = a = { a : int }
306+
[%%expect{|
307+
type a = unit
308+
Line 2, characters 0-24:
309+
2 | type b = a = { a : int }
310+
^^^^^^^^^^^^^^^^^^^^^^^^
311+
Error: This variant or record definition does not match that of type a
312+
The original is abstract, but this is a record.
313+
|}]

typing/typedecl.ml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -755,24 +755,17 @@ let transl_declaration env sdecl (id, uid) =
755755
let jkind =
756756
(* - If there's an annotation, we use that. It's checked against
757757
a kind in [update_decl_jkind] and the manifest in [check_coherence].
758-
- If there's no annotation but there is a manifest, we estimate the
759-
jkind based on the manifest here. This upper bound saves time
760-
later by avoiding expanding the manifest in jkind checks, but it
761-
would be sound to leave in `any`. We can't give a perfectly
762-
accurate jkind here because we don't have access to the
763-
manifests of mutually defined types (but we could one day consider
764-
improving it at a later point in transl_type_decl).
758+
Both of those functions update the [type_jkind] field in the
759+
[type_declaration] as appropriate.
760+
- If there's no annotation but there is a manifest, just use [any].
761+
This will get updated to the manifest's jkind in [check_coherence].
765762
- If there's no annotation and no manifest, we fill in with the
766763
default calculated above here. It will get updated in
767764
[update_decl_jkind]. See Note [Default jkinds in transl_declaration].
768765
*)
769-
(* CR layouts: Is the estimation mentioned in the second bullet above
770-
doing anything for us? Abstract types are updated by
771-
check_coherence and record/variant types are updated by
772-
update_decl_jkind. *)
773766
match jkind_annotation, man with
774767
| Some annot, _ -> annot
775-
| None, Some typ -> Ctype.estimate_type_jkind env typ
768+
| None, Some _ -> Jkind.any ~why:Initial_typedecl_env
776769
| None, None -> jkind_default
777770
in
778771
let arity = List.length params in
@@ -1777,10 +1770,10 @@ let transl_type_decl env rec_flag sdecl_list =
17771770
| Typedecl_separability.Error (loc, err) ->
17781771
raise (Error (loc, Separability err))
17791772
in
1773+
(* Check re-exportation, updating [type_jkind] from the manifest *)
1774+
let decls = List.map2 (check_abbrev new_env) sdecl_list decls in
17801775
(* Compute the final environment with variance and immediacy *)
17811776
let final_env = add_types_to_env decls env in
1782-
(* Check re-exportation *)
1783-
let decls = List.map2 (check_abbrev final_env) sdecl_list decls in
17841777
(* Keep original declaration *)
17851778
let final_decls =
17861779
List.map2

0 commit comments

Comments
 (0)