Skip to content

Commit eba15a7

Browse files
cristianocclaude
andcommitted
Shrink the stored layout to its honest content
Review of the representation changes found derived data stored beside its source and duplicate derivations: - variant_layout collapses to the constructors array. The by-name map duplicated every case (and the names inside them), and the dispatch field was derivable; both are now computed by accessors, with the dispatch derived at its single consumer in Matching. - cstr_transparent was derivable from cstr_layout plus the unboxed attribute once descriptions carried their layout; it is a Datarepr predicate again, now environment-free. - Construction in Translcore reads the constructor's layout entry (Datarepr.constructor_case) instead of re-deriving the tag and block runtime from attributes, closing the last spot where construction and matching could derive representation independently. - Parmatch's full_match compares against the layout's length instead of looking the declaration up in the environment; the block-count folds in Translcore, Matching, and Datarepr use one Variant_runtime helper; js_dump drops a tautological num_nonconst test. - The type-equation re-exports in Ast_untagged_variants are gone: consumers reference Variant_runtime directly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YWw5GW8t4UDEWAzoqcDMkE
1 parent 58f8800 commit eba15a7

26 files changed

Lines changed: 130 additions & 218 deletions

compiler/core/j.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ and case_clause = {
244244
source_loc: Location.t option;
245245
}
246246

247-
and string_clause = Ast_untagged_variants.tag_type * case_clause
247+
and string_clause = Variant_runtime.tag_type * case_clause
248248
and int_clause = int * case_clause
249249
and label = string
250250

compiler/core/js_dump.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
970970
| Caml_block (el, _, ((Blk_extension | Blk_record_ext _) as ext)) ->
971971
expression_desc cxt ~level f (exn_block_as_obj ~stack:false el ext)
972972
| Caml_block (el, _, Blk_record_inlined p) ->
973-
let {Ast_untagged_variants.tag; tag_name; untagged} = p.runtime in
973+
let {Variant_runtime.tag; tag_name; untagged} = p.runtime in
974974
let objs =
975975
let tails =
976976
Ext_list.combine_array p.fields el (fun (i, opt) -> (Js_op.Lit i, opt))
@@ -994,7 +994,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
994994
expression_desc cxt ~level f (Object (None, objs))
995995
| Caml_block (el, _, Blk_constructor p) ->
996996
let not_is_cons = p.name <> Literals.cons in
997-
let {Ast_untagged_variants.tag; tag_name; untagged} = p.runtime in
997+
let {Variant_runtime.tag; tag_name; untagged} = p.runtime in
998998
let tag_type = tag.tag_type in
999999
let tag_name = Option.value tag_name ~default:L.tag in
10001000
let objs =
@@ -1010,7 +1010,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
10101010
[(name_symbol, E.str p.name)]
10111011
else [])
10121012
in
1013-
if untagged || (not_is_cons = false && p.num_nonconst = 1) then tails
1013+
if untagged || not_is_cons = false then tails
10141014
else
10151015
( Js_op.Lit tag_name,
10161016
(* TAG:xx *)
@@ -1689,7 +1689,7 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
16891689
let cxt = P.paren_group f 1 (fun _ -> expression ~level:0 cxt f e) in
16901690
P.space f;
16911691
P.brace_vgroup f 1 (fun _ ->
1692-
let pp_as_value f (tag_type : Ast_untagged_variants.tag_type) =
1692+
let pp_as_value f (tag_type : Variant_runtime.tag_type) =
16931693
let e = E.tag_type tag_type in
16941694
ignore @@ expression_desc cxt ~level:0 f e.expression_desc
16951695
in

compiler/core/js_exp_make.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ let rec float_equal ?comment (e0 : t) (e1 : t) : t =
13581358
let int_equal = float_equal
13591359

13601360
let tag_type = function
1361-
| Ast_untagged_variants.String s -> str s ~delim:DStarJ
1361+
| Variant_runtime.String s -> str s ~delim:DStarJ
13621362
| Int i -> small_int i
13631363
| Float f -> float f
13641364
| BigInt i ->
@@ -1374,7 +1374,7 @@ let tag_type = function
13741374
| Untagged FunctionType -> str "function"
13751375
| Untagged StringType -> str "string"
13761376
| Untagged (InstanceType i) ->
1377-
str (Ast_untagged_variants.Instance.to_string i) ~delim:DNoQuotes
1377+
str (Variant_runtime.Instance.to_string i) ~delim:DNoQuotes
13781378
| Untagged ObjectType -> str "object"
13791379
| Untagged UnknownType ->
13801380
(* TODO: this should not happen *)
@@ -1395,7 +1395,7 @@ let rec emit_check (check : t Ast_untagged_variants.Dynamic_checks.t) =
13951395
| TypeOf x -> typeof (emit_check x)
13961396
| IsInstanceOf (Array, x) -> is_array (emit_check x)
13971397
| IsInstanceOf (instance, x) ->
1398-
let instance_name = Ast_untagged_variants.Instance.to_string instance in
1398+
let instance_name = Variant_runtime.Instance.to_string instance in
13991399
instanceof (emit_check x) (str instance_name ~delim:DNoQuotes)
14001400
| Not x -> not (emit_check x)
14011401
| Expr x -> x

compiler/core/js_exp_make.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ val extension_assign : t -> int32 -> string -> t -> t
165165

166166
val assign : ?comment:string -> t -> t -> t
167167

168-
val tag_type : Ast_untagged_variants.tag_type -> t
168+
val tag_type : Variant_runtime.tag_type -> t
169169

170170
val emit_check : t Ast_untagged_variants.Dynamic_checks.t -> t
171171

@@ -187,8 +187,8 @@ val is_type_number : ?comment:string -> t -> t
187187
val is_int_tag : ?has_null_undefined_other:bool * bool * bool -> t -> t
188188

189189
val is_a_literal_case :
190-
literal_cases:Ast_untagged_variants.tag_type list ->
191-
block_cases:Ast_untagged_variants.block_type list ->
190+
literal_cases:Variant_runtime.tag_type list ->
191+
block_cases:Variant_runtime.block_type list ->
192192
t ->
193193
t
194194

compiler/core/js_of_lam_variant.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ let eval (arg : J.expression) (dispatches : (string * string) list) : E.t =
4040
[
4141
S.string_switch arg
4242
(Ext_list.map dispatches (fun (s, r) ->
43-
( Ast_untagged_variants.String s,
43+
( Variant_runtime.String s,
4444
J.
4545
{
4646
switch_body = [S.return_stmt (E.str r)];
@@ -81,7 +81,7 @@ let eval_as_event (arg : J.expression)
8181
S.string_switch
8282
(E.poly_var_tag_access arg)
8383
(Ext_list.map dispatches (fun (s, r) ->
84-
( Ast_untagged_variants.String s,
84+
( Variant_runtime.String s,
8585
J.
8686
{
8787
switch_body = [S.return_stmt (E.str r)];
@@ -110,7 +110,7 @@ let eval_as_int (arg : J.expression) (dispatches : (string * int) list) : E.t =
110110
[
111111
S.string_switch arg
112112
(Ext_list.map dispatches (fun (s, r) ->
113-
( Ast_untagged_variants.String s,
113+
( Variant_runtime.String s,
114114
J.
115115
{
116116
switch_body = [S.return_stmt (E.int (Int32.of_int r))];

compiler/core/js_stmt_make.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ let int_switch ?(comment : string option)
142142
let string_switch ?(comment : string option)
143143
?(declaration : (J.property * Ident.t) option) ?(default : J.block option)
144144
(e : J.expression)
145-
(clauses : (Ast_untagged_variants.tag_type * J.case_clause) list) : t =
145+
(clauses : (Variant_runtime.tag_type * J.case_clause) list) : t =
146146
match e.expression_desc with
147147
| Str {txt} -> (
148148
let continuation =

compiler/core/js_stmt_make.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ val string_switch :
7373
?declaration:Lam_compat.let_kind * Ident.t ->
7474
?default:J.block ->
7575
J.expression ->
76-
(Ast_untagged_variants.tag_type * J.case_clause) list ->
76+
(Variant_runtime.tag_type * J.case_clause) list ->
7777
t
7878

7979
val declare_variable :

compiler/core/lam.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ let switch lam (lam_switch : lambda_switch) : t =
295295
match key with
296296
| Lambda.Switch_int ordinal when ordinal = i -> Some action
297297
| Switch_constructor
298-
(Constant {tag_type = Some (Ast_untagged_variants.Int value)})
298+
(Constant {tag_type = Some (Variant_runtime.Int value)})
299299
when comment = None && value = i ->
300300
Some action
301301
| Switch_int _ | Switch_constructor _ -> None)

compiler/core/lam_compile.ml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ let dispatch_info = function
218218
| Lambda.Switch_direct -> (Js_dump_lit.tag, [], [], (false, false, false))
219219
| Switch_variant
220220
{
221-
Ast_untagged_variants.tag_name;
221+
Variant_runtime.tag_name;
222222
block_types;
223223
literal_tags;
224224
has_null;
@@ -690,7 +690,7 @@ let compile output_prefix =
690690
List.fold_right
691691
(fun (key, lam) acc ->
692692
match (tag_of_switch_key key, acc) with
693-
| Some {Ast_untagged_variants.tag_type = Some t}, Some string_table ->
693+
| Some {Variant_runtime.tag_type = Some t}, Some string_table ->
694694
Some ((t, lam) :: string_table)
695695
| Some {name; tag_type = None}, Some string_table ->
696696
Some ((String name, lam) :: string_table)
@@ -786,9 +786,7 @@ let compile output_prefix =
786786
&& List.length sw_consts = 0
787787
&& eq_default sw_num_default sw_blocks_default
788788
then
789-
let has_null_case =
790-
List.mem Ast_untagged_variants.Null literal_cases
791-
in
789+
let has_null_case = List.mem Variant_runtime.Null literal_cases in
792790
compile_cases ~untagged ~cxt
793791
~switch_exp:(if untagged then e else E.tag ~name:tag_name e)
794792
~block_cases ~has_null_case ~default:sw_blocks_default sw_blocks
@@ -838,7 +836,7 @@ let compile output_prefix =
838836
~switch_exp ~default
839837
and compile_untagged_cases ~cxt ~switch_exp ~default ~block_cases
840838
~has_null_case cases =
841-
let mk_eq (i : Ast_untagged_variants.tag_type option) x j y =
839+
let mk_eq (i : Variant_runtime.tag_type option) x j y =
842840
let check =
843841
match (i, j) with
844842
| Some tag_type, _ ->
@@ -852,7 +850,7 @@ let compile output_prefix =
852850
E.emit_check check
853851
in
854852
let tag_is_not_typeof = function
855-
| Ast_untagged_variants.Untagged (InstanceType _) -> true
853+
| Variant_runtime.Untagged (InstanceType _) -> true
856854
| _ -> false
857855
in
858856
let clause_is_not_typeof (tag, _) = tag_is_not_typeof tag in
@@ -863,21 +861,21 @@ let compile output_prefix =
863861
let has_object_typeof =
864862
List.exists
865863
(function
866-
| Ast_untagged_variants.Untagged ObjectType, _ -> true
864+
| Variant_runtime.Untagged ObjectType, _ -> true
867865
| _ -> false)
868866
typeof_clauses
869867
in
870868
let clauses_have_array_case =
871869
List.exists
872870
(function
873-
| Ast_untagged_variants.Untagged (InstanceType Array), _ -> true
871+
| Variant_runtime.Untagged (InstanceType Array), _ -> true
874872
| _ -> false)
875873
not_typeof_clauses
876874
in
877875
let type_has_array_case =
878876
List.exists
879877
(function
880-
| Ast_untagged_variants.InstanceType Array -> true
878+
| Variant_runtime.InstanceType Array -> true
881879
| _ -> false)
882880
block_cases
883881
in
@@ -890,7 +888,7 @@ let compile output_prefix =
890888
in
891889
let rec build_if_chain remaining_clauses =
892890
match remaining_clauses with
893-
| ( Ast_untagged_variants.Untagged (InstanceType instance_type),
891+
| ( Variant_runtime.Untagged (InstanceType instance_type),
894892
{J.switch_body} )
895893
:: rest ->
896894
S.if_
@@ -930,7 +928,7 @@ let compile output_prefix =
930928
The [gen] can be elimiated when number of [cases] is less than 3
931929
*)
932930
let cases =
933-
cases |> List.map (fun (s, l) -> (Ast_untagged_variants.String s, l))
931+
cases |> List.map (fun (s, l) -> (Variant_runtime.String s, l))
934932
in
935933
match
936934
compile_lambda {lambda_cxt with continuation = NeedValue Not_tail} l

compiler/core/lam_constant_convert.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let rec convert_constant (const : Lambda.structured_constant) : Lam_constant.t =
4242
| Pt_module_alias -> Const_module_alias
4343
| Pt_shape_none -> Lam_constant.lam_none
4444
| Pt_assertfalse -> Const_int {i = 0l; comment = Pt_assertfalse}
45-
| Pt_constructor {tag_type = Some (Ast_untagged_variants.Int v)} ->
45+
| Pt_constructor {tag_type = Some (Variant_runtime.Int v)} ->
4646
(* A constructor represented as a number is a genuine number at
4747
runtime; folding relies on it being an ordinary int constant *)
4848
Const_int {i = Int32.of_int v; comment = None}

0 commit comments

Comments
 (0)