···294294- #14198 Constraints on module unpacking are not ghost
295295 (Thomas Refis, review by Nicolás Ojeda Bär)
296296297297+- #14260: Refactor Lambda.structured_constant to avoid duplicate
298298+ representations for string constants
299299+ (Vincent Laviron, review by Nicolás Ojeda Bär and Gabriel Scherer)
300300+297301### Build system:
298302299303- #13810: Support build of cross compilers to native freestanding targets
+5-5
bytecomp/bytegen.ml
···570570 let getmethod, args' =
571571 if kind = Self then (Kgetmethod, met::obj::args) else
572572 match met with
573573- Lconst(Const_base(Const_int n)) -> (Kgetpubmet n, obj::args)
573573+ Lconst(Const_int n) -> (Kgetpubmet n, obj::args)
574574 | _ -> (Kgetdynmet, met::obj::args)
575575 in
576576 if is_tailcall cont then
···667667 end
668668 | Lprim(Praise k, [arg], _) ->
669669 comp_expr stack_info env arg sz (Kraise k :: discard_dead_code cont)
670670- | Lprim(Paddint, [arg; Lconst(Const_base(Const_int n))], _)
670670+ | Lprim(Paddint, [arg; Lconst(Const_int n)], _)
671671 when is_immed n ->
672672 comp_expr stack_info env arg sz (Koffsetint n :: cont)
673673- | Lprim(Psubint, [arg; Lconst(Const_base(Const_int n))], _)
673673+ | Lprim(Psubint, [arg; Lconst(Const_int n)], _)
674674 when is_immed (-n) ->
675675 comp_expr stack_info env arg sz (Koffsetint (-n) :: cont)
676676 | Lprim (Poffsetint n, [arg], _)
677677 when not (is_immed n) ->
678678 comp_expr stack_info env arg sz
679679 (Kpush::
680680- Kconst (Const_base (Const_int n))::
680680+ Kconst (Const_int n)::
681681 Kaddint::cont)
682682 | Lprim(Pmakearray (kind, _), args, loc) ->
683683 let cont = add_pseudo_event loc !compunit_name cont in
···10431043 let code = comp_expr stack_info env exp sz cont in
10441044 let used_safe = !(stack_info.max_stack_used) + Config.stack_safety_margin in
10451045 if used_safe > Config.stack_threshold then
10461046- Kconst(Const_base(Const_int used_safe)) ::
10461046+ Kconst(Const_int used_safe) ::
10471047 Kccall("caml_ensure_stack_capacity", 1) ::
10481048 code
10491049 else
+6-7
bytecomp/emitcode.ml
···17171818open Config
1919open Misc
2020-open Asttypes
2120open Lambda
2221open Instruct
2322open Opcodes
···8382exception AsInt
84838584let const_as_int = function
8686- | Const_base(Const_int i) -> i
8787- | Const_base(Const_char c) -> Char.code c
8585+ | Const_int i -> i
8686+ | Const_char c -> Char.code c
8887 | _ -> raise AsInt
89889089let is_immed i = immed_min <= i && i <= immed_max
···260259 | Ksetglobal q -> out opSETGLOBAL; slot_for_setglobal q
261260 | Kconst sc ->
262261 begin match sc with
263263- Const_base(Const_int i) when is_immed i ->
262262+ Const_int i when is_immed i ->
264263 if i >= 0 && i <= 3
265264 then out (opCONST0 + i)
266265 else (out opCONSTINT; out_int i)
267267- | Const_base(Const_char c) ->
266266+ | Const_char c ->
268267 out opCONSTINT; out_int (Char.code c)
269268 | Const_block(t, []) ->
270269 if t = 0 then out opATOM0 else (out opATOM; out_int t)
···392391 out opPUSHGETGLOBAL; slot_for_getglobal id; emit c
393392 | Kpush :: Kconst sc :: c ->
394393 begin match sc with
395395- Const_base(Const_int i) when is_immed i ->
394394+ Const_int i when is_immed i ->
396395 if i >= 0 && i <= 3
397396 then out (opPUSHCONST0 + i)
398397 else (out opPUSHCONSTINT; out_int i)
399399- | Const_base(Const_char c) ->
398398+ | Const_char c ->
400399 out opPUSHCONSTINT; out_int(Char.code c)
401400 | Const_block(t, []) ->
402401 if t = 0 then out opPUSHATOM0 else (out opPUSHATOM; out_int t)
+8-9
bytecomp/symtable.ml
···205205(* Translate structured constants *)
206206207207let rec transl_const = function
208208- Const_base(Const_int i) -> Obj.repr i
209209- | Const_base(Const_char c) -> Obj.repr c
210210- | Const_base(Const_string (s, _, _)) -> Obj.repr s
211211- | Const_base(Const_float f) -> Obj.repr (float_of_string f)
212212- | Const_base(Const_int32 i) -> Obj.repr i
213213- | Const_base(Const_int64 i) -> Obj.repr i
214214- | Const_base(Const_nativeint i) -> Obj.repr i
208208+ Const_int i -> Obj.repr i
209209+ | Const_char c -> Obj.repr c
210210+ | Const_float f -> Obj.repr (float_of_string f)
211211+ | Const_int32 i -> Obj.repr i
212212+ | Const_int64 i -> Obj.repr i
213213+ | Const_nativeint i -> Obj.repr i
215214 | Const_immstring s -> Obj.repr s
216215 | Const_block(tag, fields) ->
217216 let block = Obj.new_block tag (List.length fields) in
···238237 let c = slot_for_setglobal global in
239238 let cst = Const_block
240239 (Obj.object_tag,
241241- [Const_base(Const_string (name, Location.none,None));
242242- Const_base(Const_int (-i-1))
240240+ [Const_immstring name;
241241+ Const_int (-i-1)
243242 ])
244243 in
245244 literal_table := (c, transl_const cst) :: !literal_table)
+17-4
lambda/lambda.ml
···215215216216217217type structured_constant =
218218- Const_base of constant
218218+ Const_int of int
219219+ | Const_char of char
220220+ | Const_float of string
221221+ | Const_int32 of int32
222222+ | Const_int64 of int64
223223+ | Const_nativeint of nativeint
219224 | Const_block of int * structured_constant list
220225 | Const_float_array of string list
221226 | Const_immstring of string
···369374 required_globals : Ident.Set.t;
370375 code : lambda }
371376372372-let const_int n = Const_base (Const_int n)
377377+let const_int n = Const_int n
373378374379let const_unit = const_int 0
375380376381let dummy_constant = Lconst (const_int (0xBBBB / 2))
382382+383383+let lambda_of_const (c : Asttypes.constant) =
384384+ match c with
385385+ | Const_int n -> Lconst (Const_int n)
386386+ | Const_char c -> Lconst (Const_char c)
387387+ | Const_float f -> Lconst (Const_float f)
388388+ | Const_int32 n -> Lconst (Const_int32 n)
389389+ | Const_int64 n -> Lconst (Const_int64 n)
390390+ | Const_nativeint n -> Lconst (Const_nativeint n)
391391+ | Const_string (s, _, _) -> Lconst (Const_immstring s)
377392378393let max_arity () =
379394 if !Clflags.native_code then 126 else max_int
···434449 try Ident.find_same id env
435450 with Not_found -> e
436451 end
437437- | Lconst (Const_base (Const_string (s, _, _))) ->
438438- Lconst (Const_base (Const_string (s, Location.none, None)))
439452 | Lconst _ -> e
440453 | Lapply ap ->
441454 Lapply {ap with ap_func = tr_rec env ap.ap_func;
+8-1
lambda/lambda.mli
···214214val equal_boxed_integer : boxed_integer -> boxed_integer -> bool
215215216216type structured_constant =
217217- Const_base of constant
217217+ Const_int of int
218218+ | Const_char of char
219219+ | Const_float of string
220220+ | Const_int32 of int32
221221+ | Const_int64 of int64
222222+ | Const_nativeint of nativeint
218223 | Const_block of int * structured_constant list
219224 | Const_float_array of string list
220225 | Const_immstring of string
···385390val const_unit: structured_constant
386391val const_int : int -> structured_constant
387392val lambda_unit: lambda
393393+394394+val lambda_of_const : Asttypes.constant -> lambda
388395389396(** [dummy_constant] produces a plecholder value with a recognizable
390397 bit pattern (currently 0xBBBB in its tagged form) *)
+15-15
lambda/matching.ml
···21792179 let varg = Lvar idarg in
21802180 let tag = Ident.create_local "tag" in
21812181 let test_tag t =
21822182- Lprim(Pintcomp Ceq, [Lvar tag; Lconst(Const_base(Const_int t))], loc)
21822182+ Lprim(Pintcomp Ceq, [Lvar tag; Lconst(Const_int t)], loc)
21832183 in
2184218421852185 Llet
···22442244 { ap_tailcall = Default_tailcall;
22452245 ap_loc = loc;
22462246 ap_func = Lazy.force code_force_lazy;
22472247- ap_args = [ Lconst (Const_base (Const_int 0)); arg ];
22472247+ ap_args = [ Lconst (Const_int 0); arg ];
22482248 ap_inlined = Never_inline;
22492249 ap_specialised = Default_specialise
22502250 }
···23932393 let arg =
23942394 Lprim
23952395 (Parrayrefu kind,
23962396- [ arg; Lconst (Const_base (Const_int pos)) ], loc)
23962396+ [ arg; Lconst (Const_int pos) ], loc)
23972397 in
23982398 {
23992399 arg;
···24762476 let xs, y0, ys = split (k - 2) xs in
24772477 (x0 :: xs, y0, ys)
2478247824792479-let zero_lam = Lconst (Const_base (Const_int 0))
24792479+let zero_lam = Lconst (Const_int 0)
2480248024812481let tree_way_test loc arg lt eq gt =
24822482 Lifthenelse
···25752575 | [] -> fail
25762576 | (c, act) :: rem ->
25772577 Lifthenelse
25782578- ( Lprim (tst, [ arg; Lconst (Const_base c) ], loc),
25782578+ ( Lprim (tst, [ arg; lambda_of_const c ], loc),
25792579 do_tests_fail loc fail tst arg rem,
25802580 act )
25812581···25842584 | [ (_, act) ] -> act
25852585 | (c, act) :: rem ->
25862586 Lifthenelse
25872587- ( Lprim (tst, [ arg; Lconst (Const_base c) ], loc),
25872587+ ( Lprim (tst, [ arg; lambda_of_const c ], loc),
25882588 do_tests_nofail loc tst arg rem,
25892589 act )
25902590···26052605 rev_split_at (List.length const_lambda_list / 2) const_lambda_list
26062606 in
26072607 Lifthenelse
26082608- ( Lprim (lt_tst, [ arg; Lconst (Const_base (fst (List.hd list2))) ], loc),
26082608+ ( Lprim (lt_tst, [ arg; lambda_of_const (fst (List.hd list2)) ], loc),
26092609 make_test_sequence list1,
26102610 make_test_sequence list2 )
26112611 in
···26482648 in
26492649 bind Alias newvar arg (body newarg)
2650265026512651- let make_const i = Lconst (Const_base (Const_int i))
26512651+ let make_const i = Lconst (Const_int i)
2652265226532653 let make_isout h arg = Lprim (Pisout, [ h; arg ], Loc_unknown)
26542654···26572657 let make_is_nonzero arg =
26582658 if !Clflags.native_code then
26592659 Lprim (Pintcomp Cne,
26602660- [arg; Lconst (Const_base (Const_int 0))],
26602660+ [arg; Lconst (Const_int 0)],
26612661 Loc_unknown)
26622662 else
26632663 arg
···31053105 (const_lambda_list, total, _pats) =
31063106 let fail, local_jumps = mk_failaction_neg partial ctx def in
31073107 let lambda1 =
31083108- match cst with
31083108+ match (cst : Asttypes.constant) with
31093109 | Const_int _ ->
31103110 let int_lambda_list =
31113111 List.map
31123112 (function
31133113- | Const_int n, l -> (n, l)
31133113+ | Asttypes.Const_int n, l -> (n, l)
31143114 | _ -> assert false)
31153115 const_lambda_list
31163116 in
···31193119 let int_lambda_list =
31203120 List.map
31213121 (function
31223122- | Const_char c, l -> (Char.code c, l)
31223122+ | Asttypes.Const_char c, l -> (Char.code c, l)
31233123 | _ -> assert false)
31243124 const_lambda_list
31253125 in
···40104010 Lconst
40114011 (Const_block
40124012 ( 0,
40134013- [ Const_base (Const_string (fname, loc, None));
40144014- Const_base (Const_int line);
40154015- Const_base (Const_int char)
40134013+ [ Const_immstring fname;
40144014+ Const_int line;
40154015+ Const_int char
40164016 ] ))
40174017 ],
40184018 sloc )
+7-8
lambda/printlambda.ml
···212122222323let rec struct_const ppf = function
2424- | Const_base(Const_int n) -> fprintf ppf "%i" n
2525- | Const_base(Const_char c) -> fprintf ppf "%C" c
2626- | Const_base(Const_string (s, _, _)) -> fprintf ppf "%S" s
2727- | Const_immstring s -> fprintf ppf "#%S" s
2828- | Const_base(Const_float f) -> fprintf ppf "%s" f
2929- | Const_base(Const_int32 n) -> fprintf ppf "%lil" n
3030- | Const_base(Const_int64 n) -> fprintf ppf "%LiL" n
3131- | Const_base(Const_nativeint n) -> fprintf ppf "%nin" n
2424+ | Const_int n -> fprintf ppf "%i" n
2525+ | Const_char c -> fprintf ppf "%C" c
2626+ | Const_immstring s -> fprintf ppf "%S" s
2727+ | Const_float f -> fprintf ppf "%s" f
2828+ | Const_int32 n -> fprintf ppf "%lil" n
2929+ | Const_int64 n -> fprintf ppf "%LiL" n
3030+ | Const_nativeint n -> fprintf ppf "%nin" n
3231 | Const_block(tag, []) ->
3332 fprintf ppf "[%i]" tag
3433 | Const_block(tag, sc1::scl) ->
···131131 let k_with_placeholder =
132132 apply { constr with flag = Mutable } tmc_placeholder in
133133 let placeholder_pos = List.length constr.before in
134134- let placeholder_pos_lam = Lconst (Const_base (Const_int placeholder_pos)) in
134134+ let placeholder_pos_lam = Lconst (Const_int placeholder_pos) in
135135 let block_var = Ident.create_local "block" in
136136 Llet (Strict, Pgenval, block_var, k_with_placeholder,
137137 body {
+8-8
lambda/translcore.ml
···6969 match ext.ext_kind with
7070 Text_decl _ ->
7171 Lprim (Pmakeblock (Obj.object_tag, Immutable, None),
7272- [Lconst (Const_base (Const_string (name, ext.ext_loc, None)));
7272+ [Lconst (Const_immstring name);
7373 Lprim (prim_fresh_oo_id, [Lconst (const_int 0)], loc)],
7474 loc)
7575 | Text_rebind(path, _lid) ->
···8484 | _ -> raise Not_constant
85858686let extract_float = function
8787- Const_base(Const_float f) -> f
8787+ Const_float f -> f
8888 | _ -> fatal_error "Translcore.extract_float"
89899090(* Insertion of debugging events *)
···122122 (Lprim(Pmakeblock(0, Immutable, None),
123123 [slot;
124124 Lconst(Const_block(0,
125125- [Const_base(Const_string (fname, exp.exp_loc, None));
126126- Const_base(Const_int line);
127127- Const_base(Const_int char)]))], loc))], loc)
125125+ [Const_immstring fname;
126126+ Const_int line;
127127+ Const_int char]))], loc))], loc)
128128129129(* In cases where we're careful to preserve syntactic arity, we disable
130130 the arity fusion attempted by simplif.ml *)
···209209 transl_ident (of_location ~scopes e.exp_loc)
210210 e.exp_env e.exp_type path desc
211211 | Texp_constant cst ->
212212- Lconst(Const_base cst)
212212+ Lambda.lambda_of_const cst
213213 | Texp_let(rec_flag, pat_expr_list, body) ->
214214 transl_let ~scopes rec_flag pat_expr_list
215215 (event_before ~scopes body (transl_exp ~scopes body))
···10821082 "Translcore.transl_atomic_loc: atomic field in unboxed record"
10831083 | Record_extension _ -> 1
10841084 in
10851085- let lbl = Lconst (Const_base (Const_int (lbl.lbl_pos + offset))) in
10851085+ let lbl = Lconst (Const_int (lbl.lbl_pos + offset)) in
10861086 (arg, lbl)
1087108710881088and transl_match ~scopes e arg pat_expr_list partial =
···12451245 (lfunction ~kind:Curried ~params:[param, Pgenval] ~return:Pgenval
12461246 ~attr:default_function_attribute ~loc:Loc_unknown
12471247 ~body,
12481248- Lconst(Const_base(Const_int 0)))
12481248+ Lconst(Const_int 0))
12491249 in
12501250 let alloc_stack =
12511251 Lprim(prim_alloc_stack, [val_fun; exn_fun; eff_fun], Loc_unknown)
···148148 String.equal prim.prim_name other_prim.prim_name
149149 in
150150 let int_arg = match args with
151151- | [Lconst (Const_base (Const_int n))] -> Some n
151151+ | [Lconst (Const_int n)] -> Some n
152152 | _ -> None
153153 in
154154 if same_as alloc_prim then
+6-8
middle_end/closure/closure.ml
···905905 Uconst_ref (name, Some cst)
906906 in
907907 let rec transl = function
908908- | Const_base(Const_int n) -> Uconst_int n
909909- | Const_base(Const_char c) -> Uconst_int (Char.code c)
908908+ | Const_int n -> Uconst_int n
909909+ | Const_char c -> Uconst_int (Char.code c)
910910 | Const_block (tag, fields) ->
911911 str (Uconst_block (tag, List.map transl fields))
912912 | Const_float_array sl ->
···914914 str (Uconst_float_array (List.map float_of_string sl))
915915 | Const_immstring s ->
916916 str (Uconst_string s)
917917- | Const_base (Const_string (s, _, _)) ->
918918- str (Uconst_string s)
919919- | Const_base(Const_float x) -> str (Uconst_float (float_of_string x))
920920- | Const_base(Const_int32 x) -> str (Uconst_int32 x)
921921- | Const_base(Const_int64 x) -> str (Uconst_int64 x)
922922- | Const_base(Const_nativeint x) -> str (Uconst_nativeint x)
917917+ | Const_float x -> str (Uconst_float (float_of_string x))
918918+ | Const_int32 x -> str (Uconst_int32 x)
919919+ | Const_int64 x -> str (Uconst_int64 x)
920920+ | Const_nativeint x -> str (Uconst_nativeint x)
923921 in
924922 make_const (transl cst)
925923 | Lfunction funct ->
+7-13
middle_end/flambda/closure_conversion.ml
···109109let rec declare_const t (const : Lambda.structured_constant)
110110 : Flambda.constant_defining_value_block_field * Internal_variable_names.t =
111111 match const with
112112- | Const_base (Const_int c) -> (Const (Int c), Names.const_int)
113113- | Const_base (Const_char c) -> (Const (Char c), Names.const_char)
114114- | Const_base (Const_string (s, _, _)) ->
115115- let const, name =
116116- (Flambda.Allocated_const (Immutable_string s),
117117- Names.const_immstring)
118118- in
119119- register_const t const name
120120- | Const_base (Const_float c) ->
112112+ | Const_int c -> (Const (Int c), Names.const_int)
113113+ | Const_char c -> (Const (Char c), Names.const_char)
114114+ | Const_float c ->
121115 register_const t
122116 (Allocated_const (Float (float_of_string c)))
123117 Names.const_float
124124- | Const_base (Const_int32 c) ->
118118+ | Const_int32 c ->
125119 register_const t (Allocated_const (Int32 c))
126120 Names.const_int32
127127- | Const_base (Const_int64 c) ->
121121+ | Const_int64 c ->
128122 register_const t (Allocated_const (Int64 c))
129123 Names.const_int64
130130- | Const_base (Const_nativeint c) ->
124124+ | Const_nativeint c ->
131125 register_const t (Allocated_const (Nativeint c)) Names.const_nativeint
132126 | Const_immstring c ->
133127 register_const t (Allocated_const (Immutable_string c))
···158152 Lambda.const_int 0
159153160154let lambda_const_int i : Lambda.structured_constant =
161161- Const_base (Const_int i)
155155+ Lambda.const_int i
162156163157let rec close t env (lam : Lambda.lambda) : Flambda.t =
164158 match lam with