Skip to content

Commit 6fbd649

Browse files
committed
Remove public functions for private APIs
1 parent ea2ff83 commit 6fbd649

File tree

1 file changed

+18
-107
lines changed

1 file changed

+18
-107
lines changed

compiler-core/templates/prelude.mjs

Lines changed: 18 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Values marked with @internal are not part of the public API and may change
2-
// without notice.
3-
41
export class CustomType {
52
withFields(fields) {
63
let properties = Object.keys(this).map((label) =>
@@ -27,21 +24,18 @@ export class List {
2724
return [...this];
2825
}
2926

30-
// @internal
3127
atLeastLength(desired) {
3228
let current = this;
3329
while (desired-- > 0 && current) current = current.tail;
3430
return current !== undefined;
3531
}
3632

37-
// @internal
3833
hasLength(desired) {
3934
let current = this;
4035
while (desired-- > 0 && current) current = current.tail;
4136
return desired === -1 && current instanceof Empty;
4237
}
4338

44-
// @internal
4539
countLength() {
4640
let current = this;
4741
let length = 0;
@@ -53,7 +47,6 @@ export class List {
5347
}
5448
}
5549

56-
// @internal
5750
export function prepend(element, tail) {
5851
return new NonEmpty(element, tail);
5952
}
@@ -62,7 +55,6 @@ export function toList(elements, tail) {
6255
return List.fromArray(elements, tail);
6356
}
6457

65-
// @internal
6658
class ListIterator {
6759
#current;
6860

@@ -81,15 +73,9 @@ class ListIterator {
8173
}
8274
}
8375

84-
export class Empty extends List { }
85-
86-
export function List$Empty() {
87-
return new Empty();
88-
}
89-
90-
export function List$isEmpty(value) {
91-
return value instanceof Empty;
92-
}
76+
export class Empty extends List {}
77+
export const List$Empty = () => new Empty();
78+
export const List$isEmpty = (value) => value instanceof Empty;
9379

9480
export class NonEmpty extends List {
9581
constructor(head, tail) {
@@ -98,21 +84,11 @@ export class NonEmpty extends List {
9884
this.tail = tail;
9985
}
10086
}
87+
export const List$NonEmpty = (head, tail) => new NonEmpty(head, tail);
88+
export const List$isNonEmpty = (value) => value instanceof NonEmpty;
10189

102-
export function List$NonEmpty(head, tail) {
103-
return new NonEmpty(head, tail);
104-
}
105-
106-
export function List$isNonEmpty(value) {
107-
return value instanceof NonEmpty;
108-
}
109-
110-
export function List$NonEmpty$first(value) {
111-
return value.head;
112-
}
113-
export function List$NonEmpty$rest(value) {
114-
return value.tail;
115-
}
90+
export const List$NonEmpty$first = (value) => value.head;
91+
export const List$NonEmpty$rest = (value) => value.tail;
11692

11793
/**
11894
* A bit array is a contiguous sequence of bits similar to Erlang's Binary type.
@@ -220,7 +196,6 @@ export class BitArray {
220196
return bitArrayByteAt(this.rawBuffer, this.bitOffset, index);
221197
}
222198

223-
/** @internal */
224199
equals(other) {
225200
if (this.bitSize !== other.bitSize) {
226201
return false;
@@ -329,13 +304,8 @@ export class BitArray {
329304
}
330305
}
331306

332-
export function BitArray$BitArray(buffer, bitSize, bitOffset) {
333-
return new BitArray(buffer, bitSize, bitOffset);
334-
}
335-
336-
export function BitArray$isBitArray(value) {
337-
return value instanceof BitArray;
338-
}
307+
export const BitArray$BitArray = (buffer, bitSize, bitOffset) =>
308+
new BitArray(buffer, bitSize, bitOffset);
339309

340310
/**
341311
* Returns the nth byte in the given buffer, after applying the specified bit
@@ -363,18 +333,6 @@ export class UtfCodepoint {
363333
}
364334
}
365335

366-
export function UtfCodepoint$UtfCodepoint(value) {
367-
return new UtfCodepoint(value);
368-
}
369-
370-
export function UtfCodepoint$isUtfCodepoint(value) {
371-
return value instanceof UtfCodepoint;
372-
}
373-
374-
export function UtfCodepoint$UtfCodepoint$value(value) {
375-
return value.value;
376-
}
377-
378336
const isBitArrayDeprecationMessagePrinted = {};
379337
function bitArrayPrintDeprecationWarning(name, message) {
380338
if (isBitArrayDeprecationMessagePrinted[name]) {
@@ -389,8 +347,6 @@ function bitArrayPrintDeprecationWarning(name, message) {
389347
}
390348

391349
/**
392-
* @internal
393-
*
394350
* Slices a bit array to produce a new bit array. If `end` is not supplied then
395351
* all bits from `start` onward are returned.
396352
*
@@ -599,8 +555,6 @@ export function bitArraySliceToInt(
599555
}
600556

601557
/**
602-
* @internal
603-
*
604558
* Joins the given segments into a new bit array, tightly packing them together.
605559
* Each segment must be one of the following types:
606560
*
@@ -635,7 +589,7 @@ export function toBitArray(segments) {
635589
return new BitArray(segment);
636590
}
637591

638-
return new BitArray(new Uint8Array(/** @type {number[]} */(segments)));
592+
return new BitArray(new Uint8Array(/** @type {number[]} */ (segments)));
639593
}
640594

641595
// Count the total number of bits and check if all segments are numbers, i.e.
@@ -657,7 +611,7 @@ export function toBitArray(segments) {
657611
// If all segments are numbers then pass the segments array directly to the
658612
// Uint8Array constructor
659613
if (areAllSegmentsNumbers) {
660-
return new BitArray(new Uint8Array(/** @type {number[]} */(segments)));
614+
return new BitArray(new Uint8Array(/** @type {number[]} */ (segments)));
661615
}
662616

663617
// Pack the segments into a Uint8Array
@@ -755,8 +709,6 @@ export function toBitArray(segments) {
755709
}
756710

757711
/**
758-
* @internal
759-
*
760712
* Encodes a floating point value into a `Uint8Array`. This is used to create
761713
* float segments that are part of bit array expressions.
762714
*
@@ -789,8 +741,6 @@ export function sizedFloat(value, size, isBigEndian) {
789741
}
790742

791743
/**
792-
* @internal
793-
*
794744
* Encodes an integer value into a `Uint8Array`, or a `BitArray` if the size in
795745
* bits is not a multiple of 8. This is used to create integer segments used in
796746
* bit array expressions.
@@ -1155,8 +1105,6 @@ function intFromUnalignedSliceUsingNumber(
11551105
}
11561106

11571107
/**
1158-
* @internal
1159-
*
11601108
* Reads an unaligned slice of any size as an integer. Uses the JavaScript
11611109
* `BigInt` type internally.
11621110
*
@@ -1380,8 +1328,6 @@ function bitArrayValidateRange(bitArray, start, end) {
13801328
let utf8Encoder;
13811329

13821330
/**
1383-
* @internal
1384-
*
13851331
* Returns the UTF-8 bytes for a string.
13861332
*
13871333
* @param {string} string
@@ -1393,8 +1339,6 @@ export function stringBits(string) {
13931339
}
13941340

13951341
/**
1396-
* @internal
1397-
*
13981342
* Returns the UTF-8 bytes for a single UTF codepoint.
13991343
*
14001344
* @param {UtfCodepoint} codepoint
@@ -1405,8 +1349,6 @@ export function codepointBits(codepoint) {
14051349
}
14061350

14071351
/**
1408-
* @internal
1409-
*
14101352
* Returns the UTF-16 bytes for a string.
14111353
*
14121354
* @param {string} string
@@ -1425,8 +1367,6 @@ export function stringToUtf16(string, isBigEndian) {
14251367
}
14261368

14271369
/**
1428-
* @internal
1429-
*
14301370
* Returns the UTF-16 bytes for a single UTF codepoint.
14311371
*
14321372
* @param {UtfCodepoint} codepoint
@@ -1438,8 +1378,6 @@ export function codepointToUtf16(codepoint, isBigEndian) {
14381378
}
14391379

14401380
/**
1441-
* @internal
1442-
*
14431381
* Returns the UTF-32 bytes for a string.
14441382
*
14451383
* @param {string} string
@@ -1466,8 +1404,6 @@ export function stringToUtf32(string, isBigEndian) {
14661404
}
14671405

14681406
/**
1469-
* @internal
1470-
*
14711407
* Returns the UTF-32 bytes for a single UTF codepoint.
14721408
*
14731409
* @param {UtfCodepoint} codepoint
@@ -1479,7 +1415,6 @@ export function codepointToUtf32(codepoint, isBigEndian) {
14791415
}
14801416

14811417
export class Result extends CustomType {
1482-
// @internal
14831418
static isResult(data) {
14841419
return data instanceof Result;
14851420
}
@@ -1491,47 +1426,27 @@ export class Ok extends Result {
14911426
this[0] = value;
14921427
}
14931428

1494-
// @internal
14951429
isOk() {
14961430
return true;
14971431
}
14981432
}
1499-
1500-
export function Result$Ok(value) {
1501-
return new Ok(value);
1502-
}
1503-
1504-
export function Result$isOk(value) {
1505-
return value instanceof Ok;
1506-
}
1507-
1508-
export function Result$Ok$0(value) {
1509-
return value[0];
1510-
}
1433+
export const Result$Ok = (value) => new Ok(value);
1434+
export const Result$isOk = (value) => value instanceof Ok;
1435+
export const Result$Ok$0 = (value) => value[0];
15111436

15121437
export class Error extends Result {
15131438
constructor(detail) {
15141439
super();
15151440
this[0] = detail;
15161441
}
15171442

1518-
// @internal
15191443
isOk() {
15201444
return false;
15211445
}
15221446
}
1523-
1524-
export function Result$Error(detail) {
1525-
return new Error(detail);
1526-
}
1527-
1528-
export function Result$isError(value) {
1529-
return value instanceof Error;
1530-
}
1531-
1532-
export function Result$Error$0(value) {
1533-
return value[0];
1534-
}
1447+
export const Result$Error = (detail) => new Error(detail);
1448+
export const Result$isError = (value) => value instanceof Error;
1449+
export const Result$Error$0 = (value) => value[0];
15351450

15361451
export function isEqual(x, y) {
15371452
let values = [x, y];
@@ -1557,7 +1472,7 @@ export function isEqual(x, y) {
15571472
try {
15581473
if (a.equals(b)) continue;
15591474
else return false;
1560-
} catch { }
1475+
} catch {}
15611476
}
15621477

15631478
let [keys, get] = getters(a);
@@ -1626,7 +1541,6 @@ function structurallyCompatibleObjects(a, b) {
16261541
return a.constructor === b.constructor;
16271542
}
16281543

1629-
// @internal
16301544
export function remainderInt(a, b) {
16311545
if (b === 0) {
16321546
return 0;
@@ -1635,12 +1549,10 @@ export function remainderInt(a, b) {
16351549
}
16361550
}
16371551

1638-
// @internal
16391552
export function divideInt(a, b) {
16401553
return Math.trunc(divideFloat(a, b));
16411554
}
16421555

1643-
// @internal
16441556
export function divideFloat(a, b) {
16451557
if (b === 0) {
16461558
return 0;
@@ -1649,7 +1561,6 @@ export function divideFloat(a, b) {
16491561
}
16501562
}
16511563

1652-
// @internal
16531564
export function makeError(variant, file, module, line, fn, message, extra) {
16541565
let error = new globalThis.Error(message);
16551566
error.gleam_error = variant;

0 commit comments

Comments
 (0)