Skip to content

Commit e6925de

Browse files
committed
Quick no-wrapped-options PR for testing.
See #7430
1 parent a87e656 commit e6925de

File tree

142 files changed

+637
-753
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+637
-753
lines changed

compiler/core/j.ml

-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ and expression_desc =
147147
(* literally raw JS code
148148
*)
149149
| Array of expression list * mutable_flag
150-
| Optional_block of expression * bool
151-
(* [true] means [identity] *)
152150
| Caml_block of expression list * mutable_flag * expression * tag_info
153151
(* The third argument is [tag] , forth is [tag_info] *)
154152
(* | Caml_uninitialized_obj of expression * expression *)

compiler/core/js_analyzer.ml

-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) =
101101
the block is mutable does not mean this operation is non-pure
102102
*)
103103
Ext_list.for_all xs no_side_effect
104-
| Optional_block (x, _) -> no_side_effect x
105104
| Object (_, kvs) -> Ext_list.for_all_snd kvs no_side_effect
106105
| String_append (a, b) | Seq (a, b) -> no_side_effect a && no_side_effect b
107106
| Length (e, _) | Caml_block_tag (e, _) | Typeof e -> no_side_effect e
@@ -218,10 +217,6 @@ let rec eq_expression ({expression_desc = x0} : J.expression)
218217
match y0 with
219218
| Bool b0 -> a0 = b0
220219
| _ -> false)
221-
| Optional_block (a0, b0) -> (
222-
match y0 with
223-
| Optional_block (a1, b1) -> b0 = b1 && eq_expression a0 a1
224-
| _ -> false)
225220
| Caml_block (ls0, flag0, tag0, _) -> (
226221
match y0 with
227222
| Caml_block (ls1, flag1, tag1, _) ->

compiler/core/js_block_runtime.ml

-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
let option_id = Ident.create_persistent Primitive_modules.option
26-
2725
let curry_id = Ident.create_persistent Primitive_modules.curry
2826

2927
let check_additional_id (x : J.expression) : Ident.t option =
3028
match x.expression_desc with
31-
| Optional_block (_, false) -> Some option_id
3229
| Call (_, _, {arity = NA}) -> Some curry_id
3330
| _ -> None

compiler/core/js_dump.ml

+2-10
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ let raw_snippet_exp_simple_enough (s : string) =
148148

149149
(* e = function(x){...}(x); is good
150150
*)
151-
let rec exp_need_paren ?(arrow = false) (e : J.expression) =
151+
let exp_need_paren ?(arrow = false) (e : J.expression) =
152152
match e.expression_desc with
153153
(* | Caml_uninitialized_obj _ *)
154154
| Call ({expression_desc = Raw_js_code _}, _, _) -> true
@@ -172,8 +172,6 @@ let rec exp_need_paren ?(arrow = false) (e : J.expression) =
172172
| Await _ -> false
173173
| Spread _ -> false
174174
| Tagged_template _ -> false
175-
| Optional_block (e, true) when arrow -> exp_need_paren ~arrow e
176-
| Optional_block _ -> false
177175

178176
(** Print as underscore for unused vars, may not be
179177
needed in the future *)
@@ -867,10 +865,6 @@ and expression_desc cxt ~(level : int) f x : cxt =
867865
match el with
868866
| [] | [_] -> P.bracket_group f 1 (fun _ -> array_element_list cxt f el)
869867
| _ -> P.bracket_vgroup f 1 (fun _ -> array_element_list cxt f el))
870-
| Optional_block (e, identity) ->
871-
expression ~level cxt f
872-
(if identity then e
873-
else E.runtime_call Primitive_modules.option "some" [e])
874868
| Caml_block (el, _, _, Blk_module fields) ->
875869
expression_desc cxt ~level f
876870
(Object
@@ -1118,9 +1112,7 @@ and print_jsx cxt ?(spread_props : J.expression option)
11181112
if n = "children" then
11191113
if fnName = "jsxs" then
11201114
match e.J.expression_desc with
1121-
| J.Array (xs, _)
1122-
| J.Optional_block ({expression_desc = J.Array (xs, _)}, _) ->
1123-
Some xs
1115+
| J.Array (xs, _) -> Some xs
11241116
| _ -> Some [e]
11251117
else Some [e]
11261118
else None)

compiler/core/js_exp_make.ml

+5-19
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,9 @@ let raw_js_code ?comment info s : t =
166166
}
167167

168168
let array ?comment mt es : t = {expression_desc = Array (es, mt); comment}
169-
let some_comment = None
169+
let optional_block e : J.expression = e
170170

171-
let optional_block e : J.expression =
172-
{expression_desc = Optional_block (e, false); comment = some_comment}
173-
174-
let optional_not_nest_block e : J.expression =
175-
{expression_desc = Optional_block (e, true); comment = None}
171+
let optional_not_nest_block e : J.expression = e
176172

177173
(** used in normal property
178174
like [e.length], no dependency introduced
@@ -599,7 +595,7 @@ let str_equal (txt0 : string) (delim0 : External_arg_spec.delim) txt1 delim1 =
599595
else None
600596
else None
601597

602-
let rec triple_equal ?comment (e0 : t) (e1 : t) : t =
598+
let triple_equal ?comment (e0 : t) (e1 : t) : t =
603599
match (e0.expression_desc, e1.expression_desc) with
604600
| ( (Null | Undefined _),
605601
(Bool _ | Number _ | Typeof _ | Fun _ | Array _ | Caml_block _) )
@@ -610,11 +606,7 @@ let rec triple_equal ?comment (e0 : t) (e1 : t) : t =
610606
when no_side_effect e0 ->
611607
false_
612608
| Number (Int {i = i0; _}), Number (Int {i = i1; _}) -> bool (i0 = i1)
613-
| Optional_block (a, _), Optional_block (b, _) -> triple_equal ?comment a b
614-
| Undefined _, Optional_block _
615-
| Optional_block _, Undefined _
616-
| Null, Undefined _
617-
| Undefined _, Null
609+
| (Null, Undefined _ | Undefined _, Null)
618610
when no_side_effect e0 && no_side_effect e1 ->
619611
false_
620612
| Null, Null | Undefined _, Undefined _ -> true_
@@ -1388,14 +1380,8 @@ let rec int_comp (cmp : Lam_compat.comparison) ?comment (e0 : t) (e1 : t) =
13881380
_ ),
13891381
Number (Int {i = 0l}) ) ->
13901382
int_comp cmp l r (* = 0 > 0 < 0 *)
1391-
| (Ceq, Optional_block _, Undefined _ | Ceq, Undefined _, Optional_block _)
1392-
when no_side_effect e0 && no_side_effect e1 ->
1393-
false_
13941383
| Ceq, _, _ -> int_equal e0 e1
1395-
| Cneq, Optional_block _, Undefined _
1396-
| Cneq, Undefined _, Optional_block _
1397-
| Cneq, Caml_block _, Number _
1398-
| Cneq, Number _, Caml_block _
1384+
| (Cneq, Caml_block _, Number _ | Cneq, Number _, Caml_block _)
13991385
when no_side_effect e0 && no_side_effect e1 ->
14001386
true_
14011387
| _ -> bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1

compiler/core/js_fold.ml

-3
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ class fold =
167167
| Array (_x0, _x1) ->
168168
let _self = list (fun _self -> _self#expression) _self _x0 in
169169
_self
170-
| Optional_block (_x0, _x1) ->
171-
let _self = _self#expression _x0 in
172-
_self
173170
| Caml_block (_x0, _x1, _x2, _x3) ->
174171
let _self = list (fun _self -> _self#expression) _self _x0 in
175172
let _self = _self#expression _x2 in

compiler/core/js_of_lam_option.ml

+3-16
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ let is_not_none (e : J.expression) : J.expression =
4646
if is_none_static desc then E.false_
4747
else
4848
match desc with
49-
| Optional_block _ -> E.true_
5049
| _ -> E.not (E.triple_equal e none)
5150

5251
(**
@@ -64,39 +63,27 @@ let is_not_none (e : J.expression) : J.expression =
6463
{!Js_ast_util.named_expression} does not help
6564
since we need an expression here, it might be a statement
6665
*)
67-
let val_from_option (arg : J.expression) =
68-
match arg.expression_desc with
69-
| Optional_block (x, _) -> x
70-
| _ -> E.runtime_call Primitive_modules.option "valFromOption" [arg]
66+
let val_from_option (arg : J.expression) = arg
7167

7268
let get_default_undefined_from_optional (arg : J.expression) : J.expression =
7369
let desc = arg.expression_desc in
7470
if is_none_static desc then E.undefined
7571
else
7672
match desc with
77-
| Optional_block (x, _) -> x (* invariant: option encoding *)
7873
| _ ->
7974
if Js_analyzer.is_okay_to_duplicate arg then
8075
(* FIXME: no need do such inlining*)
8176
E.econd (is_not_none arg) (val_from_option arg) E.undefined
82-
else E.runtime_call Primitive_modules.option "toUndefined" [arg]
77+
else arg
8378

84-
let option_unwrap (arg : J.expression) : J.expression =
85-
let desc = arg.expression_desc in
86-
if is_none_static desc then E.undefined
87-
else
88-
match desc with
89-
| Optional_block (x, _) -> E.poly_var_value_access x
90-
(* invariant: option encoding *)
91-
| _ -> E.runtime_call Primitive_modules.option "unwrapPolyVar" [arg]
79+
let option_unwrap (arg : J.expression) : J.expression = arg
9280

9381
let destruct_optional ~for_sure_none ~for_sure_some ~not_sure
9482
(arg : J.expression) =
9583
let desc = arg.expression_desc in
9684
if is_none_static desc then for_sure_none
9785
else
9886
match desc with
99-
| Optional_block (x, _) -> for_sure_some x
10087
| _ -> not_sure ()
10188

10289
let some = E.optional_block

compiler/core/js_record_fold.ml

-3
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ let expression_desc : 'a. ('a, expression_desc) fn =
173173
| Array (_x0, _x1) ->
174174
let st = list _self.expression _self st _x0 in
175175
st
176-
| Optional_block (_x0, _x1) ->
177-
let st = _self.expression _self st _x0 in
178-
st
179176
| Caml_block (_x0, _x1, _x2, _x3) ->
180177
let st = list _self.expression _self st _x0 in
181178
let st = _self.expression _self st _x2 in

compiler/core/js_record_iter.ml

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ let expression_desc : expression_desc fn =
132132
| Str _ -> ()
133133
| Raw_js_code _ -> ()
134134
| Array (_x0, _x1) -> list _self.expression _self _x0
135-
| Optional_block (_x0, _x1) -> _self.expression _self _x0
136135
| Caml_block (_x0, _x1, _x2, _x3) ->
137136
list _self.expression _self _x0;
138137
_self.expression _self _x2

compiler/core/js_record_map.ml

-3
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,6 @@ let expression_desc : expression_desc fn =
171171
| Array (_x0, _x1) ->
172172
let _x0 = list _self.expression _self _x0 in
173173
Array (_x0, _x1)
174-
| Optional_block (_x0, _x1) ->
175-
let _x0 = _self.expression _self _x0 in
176-
Optional_block (_x0, _x1)
177174
| Caml_block (_x0, _x1, _x2, _x3) ->
178175
let _x0 = list _self.expression _self _x0 in
179176
let _x2 = _self.expression _self _x2 in

compiler/core/lam_compile_primitive.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,21 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
9393
| [e] -> (
9494
match e.expression_desc with
9595
| Var _ | Undefined _ | Null -> Js_of_lam_option.null_to_opt e
96-
| _ -> E.runtime_call Primitive_modules.option "fromNull" args)
96+
| _ -> e)
9797
| _ -> assert false)
9898
| Pundefined_to_opt -> (
9999
match args with
100100
| [e] -> (
101101
match e.expression_desc with
102102
| Var _ | Undefined _ | Null -> Js_of_lam_option.undef_to_opt e
103-
| _ -> E.runtime_call Primitive_modules.option "fromUndefined" args)
103+
| _ -> e)
104104
| _ -> assert false)
105105
| Pnull_undefined_to_opt -> (
106106
match args with
107107
| [e] -> (
108108
match e.expression_desc with
109109
| Var _ | Undefined _ | Null -> Js_of_lam_option.null_undef_to_opt e
110-
| _ -> E.runtime_call Primitive_modules.option "fromNullable" args)
110+
| _ -> e)
111111
| _ -> assert false)
112112
(* Compile %import: The module argument for dynamic import is represented as a path,
113113
and the module value is expressed through wrapping it with promise.then *)

compiler/ext/primitive_modules.ml

-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ let module_ = "Primitive_module"
4444

4545
let lazy_ = "Primitive_lazy"
4646

47-
let option = "Primitive_option"
48-
4947
let hash = "Primitive_hash"
5048

5149
let exceptions = "Primitive_exceptions"

lib/es6/Belt_Array.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11

22

33
import * as Primitive_int from "./Primitive_int.js";
4-
import * as Primitive_option from "./Primitive_option.js";
54

65
function get(arr, i) {
76
if (i >= 0 && i < arr.length) {
8-
return Primitive_option.some(arr[i]);
7+
return arr[i];
98
}
109

1110
}
@@ -297,7 +296,7 @@ function getBy(a, p) {
297296
while (r === undefined && i < l) {
298297
let v = a[i];
299298
if (p(v)) {
300-
r = Primitive_option.some(v);
299+
r = v;
301300
}
302301
i = i + 1 | 0;
303302
};
@@ -358,7 +357,7 @@ function keepMap(a, f) {
358357
let v = a[i];
359358
let v$1 = f(v);
360359
if (v$1 !== undefined) {
361-
r[j] = Primitive_option.valFromOption(v$1);
360+
r[j] = v$1;
362361
j = j + 1 | 0;
363362
}
364363

lib/es6/Belt_HashMap.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22

3-
import * as Primitive_option from "./Primitive_option.js";
43
import * as Belt_internalBuckets from "./Belt_internalBuckets.js";
54
import * as Belt_internalBucketsType from "./Belt_internalBucketsType.js";
65

@@ -138,19 +137,19 @@ function get(h, key) {
138137
}
139138
let eq = h.eq;
140139
if (eq(key, cell1.key)) {
141-
return Primitive_option.some(cell1.value);
140+
return cell1.value;
142141
}
143142
let cell2 = cell1.next;
144143
if (cell2 === undefined) {
145144
return;
146145
}
147146
if (eq(key, cell2.key)) {
148-
return Primitive_option.some(cell2.value);
147+
return cell2.value;
149148
}
150149
let cell3 = cell2.next;
151150
if (cell3 !== undefined) {
152151
if (eq(key, cell3.key)) {
153-
return Primitive_option.some(cell3.value);
152+
return cell3.value;
154153
} else {
155154
let _buckets = cell3.next;
156155
while (true) {
@@ -159,7 +158,7 @@ function get(h, key) {
159158
return;
160159
}
161160
if (eq(key, buckets.key)) {
162-
return Primitive_option.some(buckets.value);
161+
return buckets.value;
163162
}
164163
_buckets = buckets.next;
165164
continue;

lib/es6/Belt_HashMapInt.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22

33
import * as Primitive_hash from "./Primitive_hash.js";
4-
import * as Primitive_option from "./Primitive_option.js";
54
import * as Belt_internalBuckets from "./Belt_internalBuckets.js";
65
import * as Belt_internalBucketsType from "./Belt_internalBucketsType.js";
76

@@ -129,19 +128,19 @@ function get(h, key) {
129128
return;
130129
}
131130
if (key === cell1.key) {
132-
return Primitive_option.some(cell1.value);
131+
return cell1.value;
133132
}
134133
let cell2 = cell1.next;
135134
if (cell2 === undefined) {
136135
return;
137136
}
138137
if (key === cell2.key) {
139-
return Primitive_option.some(cell2.value);
138+
return cell2.value;
140139
}
141140
let cell3 = cell2.next;
142141
if (cell3 !== undefined) {
143142
if (key === cell3.key) {
144-
return Primitive_option.some(cell3.value);
143+
return cell3.value;
145144
} else {
146145
let _buckets = cell3.next;
147146
while (true) {
@@ -150,7 +149,7 @@ function get(h, key) {
150149
return;
151150
}
152151
if (key === buckets.key) {
153-
return Primitive_option.some(buckets.value);
152+
return buckets.value;
154153
}
155154
_buckets = buckets.next;
156155
continue;

0 commit comments

Comments
 (0)