Skip to content

Commit d0e0512

Browse files
authored
flambda-backend: Print jkind on locally abstract type (#2115)
Print layout on locally abstract type
1 parent 9248fea commit d0e0512

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

typing/ctype.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ let get_new_abstract_name env s =
13221322
let index = Misc.find_first_mono check in
13231323
name index
13241324

1325-
let new_local_type ?(loc = Location.none) ?manifest_and_scope jkind =
1325+
let new_local_type ?(loc = Location.none) ?manifest_and_scope jkind ~jkind_annot =
13261326
let manifest, expansion_scope =
13271327
match manifest_and_scope with
13281328
None -> None, Btype.lowest_level
@@ -1333,7 +1333,7 @@ let new_local_type ?(loc = Location.none) ?manifest_and_scope jkind =
13331333
type_arity = 0;
13341334
type_kind = Type_abstract Abstract_def;
13351335
type_jkind = jkind;
1336-
type_jkind_annotation = None;
1336+
type_jkind_annotation = jkind_annot;
13371337
type_private = Public;
13381338
type_manifest = manifest;
13391339
type_variance = [];
@@ -1371,7 +1371,7 @@ let instance_constructor existential_treatment cstr =
13711371
(* Existential row variable *)
13721372
| _ -> assert false
13731373
in
1374-
let decl = new_local_type jkind in
1374+
let decl = new_local_type jkind ~jkind_annot:None in
13751375
let name = existential_name cstr existential in
13761376
let (id, new_env) =
13771377
Env.enter_type (get_new_abstract_name !env name) decl !env
@@ -2613,7 +2613,7 @@ let reify env t =
26132613
let fresh_constr_scope = get_gadt_equations_level () in
26142614
let create_fresh_constr lev name jkind =
26152615
let name = match name with Some s -> "$'"^s | _ -> "$" in
2616-
let decl = new_local_type jkind in
2616+
let decl = new_local_type jkind ~jkind_annot:None in
26172617
let (id, new_env) =
26182618
Env.enter_type (get_new_abstract_name !env name) decl !env
26192619
~scope:fresh_constr_scope in
@@ -2975,7 +2975,8 @@ let jkind_of_abstract_type_declaration env p =
29752975
which guards the case of unify3 that reaches this function. Would be
29762976
nice to eliminate the duplication, but is seems tricky to do so without
29772977
complicating unify3. *)
2978-
(Env.find_type p env).type_jkind
2978+
let typ = Env.find_type p env in
2979+
typ.type_jkind, typ.type_jkind_annotation
29792980
with
29802981
Not_found -> assert false
29812982

@@ -3015,10 +3016,13 @@ let add_gadt_equation env source destination =
30153016
(* Recording the actual jkind here is required, not just for efficiency.
30163017
When we check the jkind later, we may not be able to see the local
30173018
equation because of its scope. *)
3018-
let jkind = jkind_of_abstract_type_declaration !env source in
3019+
let jkind, jkind_annot =
3020+
jkind_of_abstract_type_declaration !env source
3021+
in
30193022
add_jkind_equation ~reason:(Gadt_equation source) env destination jkind;
30203023
let decl =
30213024
new_local_type ~manifest_and_scope:(destination, expansion_scope) jkind
3025+
~jkind_annot
30223026
in
30233027
env := Env.add_local_type source decl !env;
30243028
cleanup_abbrev ()

typing/ctype.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ val instance_list: type_expr list -> type_expr list
176176
(* Take an instance of a list of type schemes *)
177177
val new_local_type:
178178
?loc:Location.t -> ?manifest_and_scope:(type_expr * int) ->
179-
Jkind.t -> type_declaration
179+
Jkind.t -> jkind_annot:Jkind.annotation option -> type_declaration
180180
val existential_name: constructor_description -> type_expr -> string
181181

182182
type existential_treatment =

typing/typecore.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,7 @@ let solve_constructor_annotation tps env name_list sty ty_args ty_ex =
13891389
annotations on explicitly quantified vars in gadt constructors.
13901390
See: https://github.com/ocaml/ocaml/pull/9584/ *)
13911391
let decl = new_local_type ~loc:name.loc
1392+
~jkind_annot:None
13921393
(Jkind.value ~why:Existential_type_variable) in
13931394
let (id, new_env) =
13941395
Env.enter_type ~scope:expansion_scope name.txt decl !env in
@@ -7647,7 +7648,7 @@ and type_newtype ~loc ~env ~expected_mode ~rue ~attributes
76477648
(* Use [with_local_level] just for scoping *)
76487649
let body, ety = with_local_level begin fun () ->
76497650
(* Create a fake abstract type declaration for name. *)
7650-
let decl = new_local_type ~loc jkind in
7651+
let decl = new_local_type ~loc jkind ~jkind_annot in
76517652
let scope = create_scope () in
76527653
let (id, new_env) = Env.enter_type ~scope name decl env in
76537654

0 commit comments

Comments
 (0)