Skip to content

Commit 4c27dff

Browse files
committed
Remove %opaque primitive.
This was used for uncurried application, but does not seem to be needed now. And for some esoteric `Sys. opaque_identity` function.
1 parent e81ed32 commit 4c27dff

13 files changed

+30
-63
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
- Build the compiler libraries/tests in uncurried mode. https://github.com/rescript-lang/rescript-compiler/pull/6864
6969
- Ignore `-uncurried` command-line flag. https://github.com/rescript-lang/rescript-compiler/pull/6885
7070
- Cleanup: remove tracking of uncurried state in parser/printer. https://github.com/rescript-lang/rescript-compiler/pull/6888
71+
- Remove `%opaque` primitive. https://github.com/rescript-lang/rescript-compiler/pull/6892
7172

7273
#### :nail_care: Polish
7374

jscomp/core/lam_convert.ml

+1-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
357357
match a with
358358
| Pbigint | Pint32 -> prim ~primitive:(Pintcomp b) ~args loc
359359
| Pint64 -> prim ~primitive:(Pint64comp b) ~args loc)
360-
| Popaque -> Ext_list.singleton_exn args
361360

362361
(* Does not exist since we compile array in js backend unlike native backend *)
363362

@@ -569,7 +568,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
569568
Lam.global_module ~dynamic_import id)
570569
| Lprim
571570
( Puncurried_apply,
572-
[ Lapply { ap_func = Lprim (Popaque, [ ap_func ], _); ap_args } ],
571+
[ Lapply { ap_func; ap_args } ],
573572
loc ) ->
574573
let ap_func = convert_aux ap_func in
575574
let ap_args = Ext_list.map ap_args convert_aux in

jscomp/ml/lambda.ml

-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ type primitive =
266266
| Pasrbint of boxed_integer
267267
| Pbintcomp of boxed_integer * comparison
268268
| Pctconst of compile_time_constant
269-
(* Inhibition of optimisation *)
270-
| Popaque
271269
| Puncurried_apply
272270
| Pcreate_extension of string
273271
and comparison =

jscomp/ml/lambda.mli

-2
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ type primitive =
233233
| Pasrbint of boxed_integer
234234
| Pbintcomp of boxed_integer * comparison
235235
| Pctconst of compile_time_constant
236-
(* Inhibition of optimisation *)
237-
| Popaque
238236
| Puncurried_apply
239237
| Pcreate_extension of string
240238
and comparison =

jscomp/ml/printlambda.ml

-2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ let primitive ppf = function
251251
| Pbintcomp(bi, Cgt) -> print_boxed_integer ">" ppf bi
252252
| Pbintcomp(bi, Cle) -> print_boxed_integer "<=" ppf bi
253253
| Pbintcomp(bi, Cge) -> print_boxed_integer ">=" ppf bi
254-
| Popaque -> fprintf ppf "opaque"
255254
| Pcreate_extension s -> fprintf ppf "extension[%s]" s
256255
let name_of_primitive = function
257256
| Puncurried_apply -> "Puncurried_apply"
@@ -342,7 +341,6 @@ let name_of_primitive = function
342341
| Plsrbint _ -> "Plsrbint"
343342
| Pasrbint _ -> "Pasrbint"
344343
| Pbintcomp _ -> "Pbintcomp"
345-
| Popaque -> "Popaque"
346344
| Pcreate_extension _ -> "Pcreate_extension"
347345

348346
let function_attribute ppf { inline; is_a_functor; return_unit } =

jscomp/ml/translcore.ml

+1-3
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ let primitives_table =
422422
("%int64_to_int32", Pcvtbint (Pint64, Pint32));
423423
("%int64_of_bigint", Pcvtbint (Pbigint, Pint64));
424424
("%int64_to_bigint", Pcvtbint (Pint64, Pbigint));
425-
("%opaque", Popaque);
426425
("%uncurried_apply", Puncurried_apply);
427426
]
428427

@@ -1101,8 +1100,7 @@ and transl_apply ?(inlined = Default_inline) ?(uncurried_partial_application=Non
11011100
let extra_ids = Array.init extra_arity (fun _ -> Ident.create "extra") |> Array.to_list in
11021101
let extra_args = Ext_list.map extra_ids (fun id -> Lvar id) in
11031102
let ap_args = args @ extra_args in
1104-
let lam_opaque = Lprim (Popaque, [lam], loc) in
1105-
let l0 = Lapply { ap_func = lam_opaque; ap_args; ap_inlined = inlined; ap_loc = loc } in
1103+
let l0 = Lapply { ap_func = lam; ap_args; ap_inlined = inlined; ap_loc = loc } in
11061104
let l1 = Lprim (Puncurried_apply, [l0], loc) in
11071105
Lfunction
11081106
{

jscomp/ml/typecore.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg=Rejected) env sexp ty
21782178
| _ -> false in
21792179

21802180
if fully_applied && not is_primitive then
2181-
rue (apply_internal "opaqueFullApply" (mk_apply (apply_internal "opaque" funct) args))
2181+
rue (apply_internal "opaqueFullApply" (mk_apply funct args))
21822182
else
21832183
rue (mk_apply funct args)
21842184
| Pexp_match(sarg, caselist) ->

jscomp/others/js.res

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ module Internal = {
8282

8383
/* Use opaque instead of [._n] to prevent some optimizations happening */
8484
external run: ((. unit) => 'a) => 'a = "#run"
85-
external opaque: 'a => 'a = "%opaque"
8685
}
8786

8887
/**

jscomp/runtime/js.res

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ module Internal = {
8282

8383
/* Use opaque instead of [._n] to prevent some optimizations happening */
8484
external run: ((. unit) => 'a) => 'a = "#run"
85-
external opaque: 'a => 'a = "%opaque"
8685
}
8786

8887
/**

jscomp/stdlib-406/sys.res

-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,3 @@ let runtime_warnings_enabled: unit => bool = _ => false
125125
/* The version string is found in file ../VERSION */
126126

127127
let ocaml_version = "4.06.2+BS"
128-
129-
/* Optimization */
130-
131-
external opaque_identity: 'a => 'a = "%opaque"

jscomp/stdlib-406/sys.resi

-19
Original file line numberDiff line numberDiff line change
@@ -302,22 +302,3 @@ let enable_runtime_warnings: bool => unit
302302

303303
@since 4.03.0 */
304304
let runtime_warnings_enabled: unit => bool
305-
306-
/* {1 Optimization} */
307-
308-
/** For the purposes of optimization, [opaque_identity] behaves like an
309-
unknown (and thus possibly side-effecting) function.
310-
311-
At runtime, [opaque_identity] disappears altogether.
312-
313-
A typical use of this function is to prevent pure computations from being
314-
optimized away in benchmarking loops. For example:
315-
{[
316-
for _round = 1 to 100_000 do
317-
ignore (Sys.opaque_identity (my_pure_computation ()))
318-
done
319-
]}
320-
321-
@since 4.03.0
322-
*/
323-
external opaque_identity: 'a => 'a = "%opaque"

lib/es6/belt_internalBuckets.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@
33
import * as Belt_Array from "./belt_Array.js";
44
import * as Caml_option from "./caml_option.js";
55

6-
function copyBucket(c) {
7-
if (c === undefined) {
8-
return c;
9-
}
10-
let head = {
11-
key: c.key,
12-
value: c.value,
13-
next: undefined
14-
};
15-
copyAuxCont(c.next, head);
16-
return head;
17-
}
18-
196
function copyAuxCont(_c, _prec) {
207
while(true) {
218
let prec = _prec;
@@ -35,6 +22,19 @@ function copyAuxCont(_c, _prec) {
3522
};
3623
}
3724

25+
function copyBucket(c) {
26+
if (c === undefined) {
27+
return c;
28+
}
29+
let head = {
30+
key: c.key,
31+
value: c.value,
32+
next: undefined
33+
};
34+
copyAuxCont(c.next, head);
35+
return head;
36+
}
37+
3838
function copyBuckets(buckets) {
3939
let len = buckets.length;
4040
let newBuckets = new Array(len);

lib/js/belt_internalBuckets.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@
33
let Belt_Array = require("./belt_Array.js");
44
let Caml_option = require("./caml_option.js");
55

6-
function copyBucket(c) {
7-
if (c === undefined) {
8-
return c;
9-
}
10-
let head = {
11-
key: c.key,
12-
value: c.value,
13-
next: undefined
14-
};
15-
copyAuxCont(c.next, head);
16-
return head;
17-
}
18-
196
function copyAuxCont(_c, _prec) {
207
while(true) {
218
let prec = _prec;
@@ -35,6 +22,19 @@ function copyAuxCont(_c, _prec) {
3522
};
3623
}
3724

25+
function copyBucket(c) {
26+
if (c === undefined) {
27+
return c;
28+
}
29+
let head = {
30+
key: c.key,
31+
value: c.value,
32+
next: undefined
33+
};
34+
copyAuxCont(c.next, head);
35+
return head;
36+
}
37+
3838
function copyBuckets(buckets) {
3939
let len = buckets.length;
4040
let newBuckets = new Array(len);

0 commit comments

Comments
 (0)