Skip to content

Commit cda76d2

Browse files
committed
Represent disequality as != and !==.
1 parent 3286c4d commit cda76d2

File tree

15 files changed

+51
-33
lines changed

15 files changed

+51
-33
lines changed

compiler/ml/ast_mapper_from0.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ module E = struct
319319
| ( Pexp_ident ({txt = Longident.Lident "^"} as lid),
320320
[(Nolabel, _); (Nolabel, _)] ) ->
321321
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "++"}}
322+
| ( Pexp_ident ({txt = Longident.Lident "<>"} as lid),
323+
[(Nolabel, _); (Nolabel, _)] ) ->
324+
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!="}}
325+
| ( Pexp_ident ({txt = Longident.Lident "!="} as lid),
326+
[(Nolabel, _); (Nolabel, _)] ) ->
327+
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!=="}}
322328
| _ -> e
323329
in
324330
let process_partial_app_attribute attrs =

compiler/ml/ast_mapper_to0.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ module E = struct
330330
| ( Pexp_ident ({txt = Longident.Lident "++"} as lid),
331331
[(Nolabel, _); (Nolabel, _)] ) ->
332332
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "^"}}
333+
| ( Pexp_ident ({txt = Longident.Lident "!="} as lid),
334+
[(Nolabel, _); (Nolabel, _)] ) ->
335+
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "<>"}}
336+
| ( Pexp_ident ({txt = Longident.Lident "!=="} as lid),
337+
[(Nolabel, _); (Nolabel, _)] ) ->
338+
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!="}}
333339
| _ -> e
334340
in
335341
let attrs =

compiler/syntax/src/res_core.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,7 @@ let build_longident words =
391391

392392
let make_infix_operator (p : Parser.t) token start_pos end_pos =
393393
let stringified_token =
394-
if token = Token.BangEqual then "<>"
395-
else if token = Token.BangEqualEqual then "!="
396-
else if token = Token.Equal then (
394+
if token = Token.Equal then (
397395
(* TODO: could have a totally different meaning like x->fooSet(y)*)
398396
Parser.err ~start_pos ~end_pos p
399397
(Diagnostics.message "Did you mean `==` here?");

compiler/syntax/src/res_parsetree_viewer.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ let is_binary_expression expr =
321321

322322
let is_equality_operator operator =
323323
match operator with
324-
| "=" | "==" | "<>" | "!=" -> true
324+
| "=" | "==" | "!=" | "!==" -> true
325325
| _ -> false
326326

327327
let is_rhs_binary_operator operator =

compiler/syntax/src/res_printer.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3666,8 +3666,6 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
36663666
match operator with
36673667
| "=" -> "=="
36683668
| "==" -> "==="
3669-
| "<>" -> "!="
3670-
| "!=" -> "!=="
36713669
| txt -> txt
36723670
in
36733671
let spacing_before_operator =

runtime/Pervasives.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ external mod: ('a, 'a) => 'a = "%mod"
5656
/* Note: Later comparisons will be converted to unified operations too */
5757

5858
external \"=": ('a, 'a) => bool = "%equal"
59-
external \"<>": ('a, 'a) => bool = "%notequal"
59+
external \"!=": ('a, 'a) => bool = "%notequal"
6060
external \"<": ('a, 'a) => bool = "%lessthan"
6161
external \">": ('a, 'a) => bool = "%greaterthan"
6262
external \"<=": ('a, 'a) => bool = "%lessequal"
@@ -65,7 +65,7 @@ external compare: ('a, 'a) => int = "%compare"
6565
external min: ('a, 'a) => 'a = "%min"
6666
external max: ('a, 'a) => 'a = "%max"
6767
external \"==": ('a, 'a) => bool = "%eq"
68-
external \"!=": ('a, 'a) => bool = "%noteq"
68+
external \"!==": ('a, 'a) => bool = "%noteq"
6969

7070
/* Boolean operations */
7171

runtime/Pervasives_mini.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ external mod: (int, int) => int = "%modint"
3535
/* Note: Later comparisons will be converted to unified operations too */
3636

3737
external \"=": ('a, 'a) => bool = "%equal"
38-
external \"<>": ('a, 'a) => bool = "%notequal"
38+
external \"!=": ('a, 'a) => bool = "%notequal"
3939
external \"<": ('a, 'a) => bool = "%lessthan"
4040
external \">": ('a, 'a) => bool = "%greaterthan"
4141
external \"<=": ('a, 'a) => bool = "%lessequal"
@@ -44,7 +44,7 @@ external compare: ('a, 'a) => int = "%compare"
4444
external min: ('a, 'a) => 'a = "%min"
4545
external max: ('a, 'a) => 'a = "%max"
4646
external \"==": ('a, 'a) => bool = "%eq"
47-
external \"!=": ('a, 'a) => bool = "%noteq"
47+
external \"!==": ('a, 'a) => bool = "%noteq"
4848

4949
/* Boolean operations */
5050

tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
;;if (color == Black) && ((sibling == None) || (parent == None)) then ()
22
;;if
3-
((color == Black) && (color != Red)) &&
3+
((color == Black) && ((!==) color Red)) &&
44
((sibling == None) || (parent == None))
55
then ()
66
;;match (color == Black) && ((sibling == None) || (parent == None)) with
77
| _ -> ()
8-
;;match ((color == Black) && (color != Red)) &&
8+
;;match ((color == Black) && ((!==) color Red)) &&
99
((sibling == None) || (parent == None))
1010
with
1111
| _ -> ()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;;a -> (f b)
22
;;{js|string1|js} ++ {js|string2|js}
3-
;;a <> b
43
;;a != b
4+
;;(!==) a b
55
;;a = b
66
;;a == b

tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let rec _addLoop [arity:2]rbt currentNode =
1919
else
2020
if
2121
(((let uncle = uncleOf currentNode in
22-
(uncle != None) && ((uncle -> castNotOption).color == Red)))
22+
((!==) uncle None) && ((uncle -> castNotOption).color == Red)))
2323
[@res.braces ])
2424
then
2525
((currentNode.parent -> castNotOption).color <- Black;
@@ -67,7 +67,7 @@ let removeNode [arity:2]rbt node =
6767
| Some successorParent ->
6868
let sibling = siblingOf successor in
6969
(if
70-
(sibling != None) &&
70+
((!==) sibling None) &&
7171
((sibling -> castNotOption).color == Red)
7272
then
7373
(successorParent.color <- Red;
@@ -89,7 +89,7 @@ let removeNode [arity:2]rbt node =
8989
((siblingNN.right -> castNotOption).color ==
9090
Black))))
9191
then
92-
(if sibling != None then siblingNN.color <- Red;
92+
(if (!==) sibling None then siblingNN.color <- Red;
9393
successorRef.contents <- successorParent)
9494
else
9595
if
@@ -104,12 +104,12 @@ let removeNode [arity:2]rbt node =
104104
((siblingNN.right -> castNotOption).color ==
105105
Black))))
106106
then
107-
(if sibling != None then siblingNN.color <- Red;
107+
(if (!==) sibling None then siblingNN.color <- Red;
108108
successorParent.color <- Black;
109109
break.contents <- true)
110110
else
111111
if
112-
(sibling != None) &&
112+
((!==) sibling None) &&
113113
((sibling -> castNotOption).color == Black)
114114
then
115115
(let sibling = sibling -> castNotOption in
@@ -118,7 +118,7 @@ let removeNode [arity:2]rbt node =
118118
((sibling.right == None) ||
119119
((sibling.right -> castNotOption).color ==
120120
Black)))
121-
&& (sibling.left != None))
121+
&& ((!==) sibling.left None))
122122
&&
123123
((sibling.left -> castNotOption).color == Red)
124124
then
@@ -131,7 +131,7 @@ let removeNode [arity:2]rbt node =
131131
((sibling.left == None) ||
132132
((sibling.left -> castNotOption).color ==
133133
Black)))
134-
&& (sibling.right != None))
134+
&& ((!==) sibling.right None))
135135
&&
136136
((sibling.right -> castNotOption).color == Red)
137137
then

tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ include
120120
;;{js||js}
121121
;;{js|BS:6.0.1\x84\x95\xa6\xbe\0\0\0\x13\0\0\0\x07\0\0\0\x14\0\0\0\x13\xb0\xa0\xa0A\x91@@A\x98\xa0'compare@|js}
122122
end
123-
let has [arity:2]rbt value = (_findNode rbt (rootGet rbt) value) != None
123+
let has [arity:2]rbt value =
124+
(!==) (_findNode rbt (rootGet rbt) value) None
124125
let rec minNode [arity:1]node = [%rescript.exprhole ]
125126
let findMin [arity:1]rbt = [%rescript.exprhole ]
126127
let removeNode [arity:2]rbt node =
@@ -173,7 +174,7 @@ include
173174
| Some successorParent ->
174175
let sibling = siblingOf successor in
175176
(if
176-
(sibling != None) &&
177+
((!==) sibling None) &&
177178
((colorGet (castNotOption sibling)) == Red)
178179
then
179180
(colorSet successorParent Red;
@@ -197,7 +198,7 @@ include
197198
(castNotOption (rightGet siblingNN)))
198199
== Black))))
199200
then
200-
(if sibling != None then colorSet siblingNN Red;
201+
(if (!==) sibling None then colorSet siblingNN Red;
201202
successorRef.contents <- successorParent)
202203
else
203204
if
@@ -214,12 +215,12 @@ include
214215
(castNotOption (rightGet siblingNN)))
215216
== Black))))
216217
then
217-
(if sibling != None then colorSet siblingNN Red;
218+
(if (!==) sibling None then colorSet siblingNN Red;
218219
colorSet successorParent Black;
219220
break.contents <- true)
220221
else
221222
if
222-
(sibling != None) &&
223+
((!==) sibling None) &&
223224
((colorGet (castNotOption sibling)) == Black)
224225
then
225226
(let sibling = castNotOption sibling in
@@ -229,7 +230,7 @@ include
229230
((colorGet
230231
(castNotOption (rightGet sibling)))
231232
== Black)))
232-
&& ((leftGet sibling) != None))
233+
&& ((!==) (leftGet sibling) None))
233234
&&
234235
((colorGet (castNotOption (leftGet sibling)))
235236
== Red)
@@ -245,7 +246,7 @@ include
245246
((colorGet
246247
(castNotOption (leftGet sibling)))
247248
== Black)))
248-
&& ((rightGet sibling) != None))
249+
&& ((!==) (rightGet sibling) None))
249250
&&
250251
((colorGet
251252
(castNotOption (rightGet sibling)))
@@ -313,14 +314,14 @@ include
313314
then sumGet n
314315
else
315316
if
316-
(lhs != None) &&
317+
((!==) lhs None) &&
317318
((Js.Internal.fn_run2 (compareGet rbt) (valueGet n)
318319
(castNotOption lhs))
319320
< 0)
320321
then heightOfInterval rbt (rightGet n) lhs rhs
321322
else
322323
if
323-
(rhs != None) &&
324+
((!==) rhs None) &&
324325
((Js.Internal.fn_run2 (compareGet rbt) (valueGet n)
325326
(castNotOption rhs))
326327
> 0)
@@ -407,7 +408,7 @@ include
407408
| None -> ()
408409
| Some node ->
409410
(if inclusive then Js.Internal.fn_run1 callback node;
410-
if firstNode != lastNode
411+
if (!==) firstNode lastNode
411412
then
412413
(if not inclusive then Js.Internal.fn_run1 callback node;
413414
iterate ~inclusive:((inclusive)[@res.namedArgLoc ])
@@ -421,7 +422,7 @@ include
421422
| Some node ->
422423
let y = match y with | None -> getY node | Some y -> y in
423424
(if inclusive then Js.Internal.fn_run2 callback node y;
424-
if firstNode != lastNode
425+
if (!==) firstNode lastNode
425426
then
426427
(if not inclusive then Js.Internal.fn_run2 callback node y;
427428
iterateWithY ~y:((y +. (heightGet node))[@res.namedArgLoc ])

tests/tests/src/bigint_test.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let generic_compare = Pervasives.compare
77
let bigint_equal = (x: bigint, y) => x == y
88
let generic_equal = \"="
99
let bigint_notequal = (x: bigint, y) => x != y
10-
let generic_notequal = \"<>"
10+
let generic_notequal = \"!="
1111
let bigint_lessthan = (x: bigint, y) => x < y
1212
let generic_lessthan = \"<"
1313
let bigint_greaterthan = (x: bigint, y) => x > y

tests/tests/src/float_test.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let generic_compare = Pervasives.compare
1414
let float_equal = (x: float, y) => x == y
1515
let generic_equal = \"="
1616
let float_notequal = (x: float, y) => x != y
17-
let generic_notequal = \"<>"
17+
let generic_notequal = \"!="
1818
let float_lessthan = (x: float, y) => x < y
1919
let generic_lessthan = \"<"
2020
let float_greaterthan = (x: float, y) => x > y

tests/tools_tests/ppx/TestPpx.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ module Pipe = {
5252
}
5353

5454
let concat = "a" ++ "b"
55+
56+
let neq = 3 != 3
57+
let neq2 = 3 !== 3

tests/tools_tests/src/expected/TestPpx.res.jsout

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ let b = "B";
7878

7979
let vv = 10;
8080

81+
let neq = false;
82+
83+
let neq2 = false;
84+
8185
exports.a = a;
8286
exports.b = b;
8387
exports.M = M;
@@ -92,4 +96,6 @@ exports.add = add;
9296
exports.partial_add = partial_add;
9397
exports.Pipe = Pipe;
9498
exports.concat = concat;
99+
exports.neq = neq;
100+
exports.neq2 = neq2;
95101
/* Not a pure module */

0 commit comments

Comments
 (0)