Skip to content

Commit 092019a

Browse files
committed
Fix Obj.magic, String.length etc. appearing in JS output
1 parent 05d7afa commit 092019a

Some content is hidden

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

41 files changed

+144
-280
lines changed

lib/es6/js_exn.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import * as Primitive_option from "./primitive_option.js";
55
let $$Error = "JsError";
66

77
function asJsExn(exn) {
8-
let t = exn;
9-
if (t.RE_EXN_ID === $$Error) {
10-
return Primitive_option.some(t._1);
8+
if (exn.RE_EXN_ID === $$Error) {
9+
return Primitive_option.some(exn._1);
1110
}
1211

1312
}

lib/es6/obj.js

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1 @@
1-
2-
3-
4-
function magic(prim) {
5-
return prim;
6-
}
7-
8-
function repr(prim) {
9-
return prim;
10-
}
11-
12-
function obj(prim) {
13-
return prim;
14-
}
15-
16-
function tag(prim) {
17-
return prim.TAG;
18-
}
19-
20-
function size(prim) {
21-
return prim.length | 0;
22-
}
23-
24-
function field(prim0, prim1) {
25-
return prim0[prim1];
26-
}
27-
28-
function set_field(prim0, prim1, prim2) {
29-
prim0[prim1] = prim2;
30-
}
31-
32-
function dup(prim) {
33-
return {...prim};
34-
}
35-
36-
function update_dummy(prim0, prim1) {
37-
Object.assign(prim0, prim1);
38-
}
39-
40-
export {
41-
magic,
42-
repr,
43-
obj,
44-
tag,
45-
size,
46-
field,
47-
set_field,
48-
dup,
49-
update_dummy,
50-
}
51-
/* No side effect */
1+
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

lib/es6/string.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ function concat(sep, xs) {
1717
return $$Array.of_list(xs).join(sep);
1818
}
1919

20-
function length(prim) {
21-
return prim.length;
22-
}
23-
24-
function get(prim0, prim1) {
25-
return prim0.codePointAt(prim1);
26-
}
27-
28-
function unsafe_get(prim0, prim1) {
29-
return prim0.codePointAt(prim1);
30-
}
31-
3220
function bos(str) {
3321
return $$Array.map(str => str.codePointAt(0), Array.from(str));
3422
}
@@ -306,8 +294,6 @@ function split_on_char(sep, s) {
306294
}
307295

308296
export {
309-
length,
310-
get,
311297
make,
312298
init,
313299
sub,
@@ -333,6 +319,5 @@ export {
333319
capitalize_ascii,
334320
uncapitalize_ascii,
335321
split_on_char,
336-
unsafe_get,
337322
}
338323
/* No side effect */

lib/js/js_exn.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ let Primitive_option = require("./primitive_option.js");
55
let $$Error = "JsError";
66

77
function asJsExn(exn) {
8-
let t = exn;
9-
if (t.RE_EXN_ID === $$Error) {
10-
return Primitive_option.some(t._1);
8+
if (exn.RE_EXN_ID === $$Error) {
9+
return Primitive_option.some(exn._1);
1110
}
1211

1312
}

lib/js/obj.js

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1 @@
1-
'use strict';
2-
3-
4-
function magic(prim) {
5-
return prim;
6-
}
7-
8-
function repr(prim) {
9-
return prim;
10-
}
11-
12-
function obj(prim) {
13-
return prim;
14-
}
15-
16-
function tag(prim) {
17-
return prim.TAG;
18-
}
19-
20-
function size(prim) {
21-
return prim.length | 0;
22-
}
23-
24-
function field(prim0, prim1) {
25-
return prim0[prim1];
26-
}
27-
28-
function set_field(prim0, prim1, prim2) {
29-
prim0[prim1] = prim2;
30-
}
31-
32-
function dup(prim) {
33-
return {...prim};
34-
}
35-
36-
function update_dummy(prim0, prim1) {
37-
Object.assign(prim0, prim1);
38-
}
39-
40-
exports.magic = magic;
41-
exports.repr = repr;
42-
exports.obj = obj;
43-
exports.tag = tag;
44-
exports.size = size;
45-
exports.field = field;
46-
exports.set_field = set_field;
47-
exports.dup = dup;
48-
exports.update_dummy = update_dummy;
49-
/* No side effect */
1+
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

lib/js/string.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ function concat(sep, xs) {
1717
return $$Array.of_list(xs).join(sep);
1818
}
1919

20-
function length(prim) {
21-
return prim.length;
22-
}
23-
24-
function get(prim0, prim1) {
25-
return prim0.codePointAt(prim1);
26-
}
27-
28-
function unsafe_get(prim0, prim1) {
29-
return prim0.codePointAt(prim1);
30-
}
31-
3220
function bos(str) {
3321
return $$Array.map(str => str.codePointAt(0), Array.from(str));
3422
}
@@ -305,8 +293,6 @@ function split_on_char(sep, s) {
305293
};
306294
}
307295

308-
exports.length = length;
309-
exports.get = get;
310296
exports.make = make;
311297
exports.init = init;
312298
exports.sub = sub;
@@ -332,5 +318,4 @@ exports.lowercase_ascii = lowercase_ascii;
332318
exports.capitalize_ascii = capitalize_ascii;
333319
exports.uncapitalize_ascii = uncapitalize_ascii;
334320
exports.split_on_char = split_on_char;
335-
exports.unsafe_get = unsafe_get;
336321
/* No side effect */

runtime/char.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let chr = unsafe_chr
1414

1515
external bytes_create: int => array<char> = "Array"
1616

17-
let bytes_unsafe_set = Primitive_array_extern.setUnsafe
17+
external bytes_unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set"
1818

1919
@scope("String") @variadic
2020
external unsafe_to_string: array<char> => string = "fromCodePoint"

runtime/obj.res

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44

55
type t = Primitive_object_extern.t
66

7-
let magic = Primitive_object_extern.magic
7+
external magic: 'a => 'b = "%identity"
88

99
@deprecated("Do not use directly. This will be removed in v13")
10-
let repr = Primitive_object_extern.repr
10+
external repr: 'a => t = "%identity"
1111

1212
@deprecated("Do not use directly. This will be removed in v13")
13-
let obj = Primitive_object_extern.obj
13+
external obj: t => 'a = "%identity"
1414

1515
@deprecated("Do not use directly. This will be removed in v13")
16-
let tag = Primitive_object_extern.tag
16+
external tag: t => int = "%obj_tag"
1717

1818
@deprecated("Do not use directly. This will be removed in v13")
19-
let size = Primitive_object_extern.size
19+
external size: t => int = "%obj_size"
2020

2121
@deprecated("Do not use directly. This will be removed in v13")
22-
let field = Primitive_object_extern.getField
22+
external getField: (t, 'a) => t = "%obj_get_field"
2323

2424
@deprecated("Do not use directly. This will be removed in v13")
25-
let set_field = Primitive_object_extern.setField
25+
external setField: (t, 'a, t) => unit = "%obj_set_field"
2626

2727
@deprecated("Do not use directly. This will be removed in v13")
28-
let dup = Primitive_object_extern.dup
28+
external dup: t => t = "%obj_dup"
2929

30-
@deprecated("Do not use directly. This will be removed in v13")
31-
let update_dummy = Primitive_object_extern.updateDummy
30+
@deprecated("Do not use directly. This will be removed in v13") @scope("Object")
31+
external updateDummy: (t, t) => unit = "assign"

runtime/primitive_object.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ module Js = Primitive_js_extern
2727

2828
type t = Primitive_object_extern.t
2929

30+
// Note: this only works as intended as long as the runtime is compiled
31+
// with -bs-cross-module-opt.
3032
let repr = Primitive_object_extern.repr
3133
let magic = Primitive_object_extern.magic
3234
let tag = Primitive_object_extern.tag

runtime/string.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ module B = {
3030

3131
let concat = (sep: string, xs: list<string>) => xs->Array.of_list->join(sep)
3232

33-
let length = Primitive_string_extern.length
33+
external length: string => int = "%string_length"
3434

35-
let get = Primitive_string_extern.getCharUnsafe
35+
@send external get: (string, int) => char = "codePointAt"
3636

37-
let unsafe_get = Primitive_string_extern.getCharUnsafe
37+
@send external unsafe_get: (string, int) => char = "codePointAt"
3838

3939
@scope("Array") external bos: string => array<string> = "from"
4040
let bos = str => B.map(str => str->unsafe_get(0), str->bos)

runtime/string.resi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77
/** Return the length (number of characters) of the given string. */
88
@deprecated("Use Core instead. This will be removed in v13")
9-
let length: string => int
9+
external length: string => int = "%string_length"
1010

1111
/** [String.get s n] returns the character at index [n] in string [s].
1212
You can also write [s.[n]] instead of [String.get s n].
1313
1414
Raise [Invalid_argument] if [n] not a valid index in [s]. */
1515
@deprecated("Use Core instead. This will be removed in v13")
16-
let get: (string, int) => char
16+
@send
17+
external get: (string, int) => char = "codePointAt"
1718

1819
/** [String.make n c] returns a fresh string of length [n],
1920
filled with the character [c]. */
@@ -245,5 +246,5 @@ external equal: (t, t) => bool = "%equal"
245246
let split_on_char: (char, string) => list<string>
246247

247248
/* The following is for system use only. Do not call directly. */
248-
@deprecated("Use Core instead. This will be removed in v13")
249-
let unsafe_get: (string, int) => char
249+
@deprecated("Use Core instead. This will be removed in v13") @send
250+
external unsafe_get: (string, int) => char = "codePointAt"

tests/tests/src/UntaggedVariants.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tests/src/alias_test.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tests/src/chn_test.js

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tests/src/equal_exception_test.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tests/src/exception_raise_test.js

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)