Skip to content

Bring in core #6761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jscomp/ext/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let bs_only = ref true
let unsafe_empty_array = ref false

type uncurried = Legacy | Uncurried | Swap
let uncurried = ref Legacy
let uncurried = ref Uncurried

and cmi_magic_number = "Caml1999I022"

Expand Down
152 changes: 76 additions & 76 deletions jscomp/others/js_array.res

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions jscomp/others/js_promise.res
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ type error
*/

@new
external make: ((@uncurry ~resolve: (. 'a) => unit, ~reject: (. exn) => unit) => unit) => promise<
'a,
> = "Promise"
external make: ((~resolve: 'a => unit, ~reject: exn => unit) => unit) => promise<'a> = "Promise"

/* `make (fun resolve reject -> .. )` */
@val @scope("Promise") external resolve: 'a => promise<'a> = "resolve"
Expand Down Expand Up @@ -83,10 +81,10 @@ external all6: (

@val @scope("Promise") external race: array<promise<'a>> => promise<'a> = "race"

@bs.send.pipe(: promise<'a>) external then_: (@uncurry ('a => promise<'b>)) => promise<'b> = "then"
@bs.send.pipe(: promise<'a>) external then_: ('a => promise<'b>) => promise<'b> = "then"

@bs.send.pipe(: promise<'a>)
external catch: (@uncurry (error => promise<'a>)) => promise<'a> = "catch"
external catch: (error => promise<'a>) => promise<'a> = "catch"
/* ` p|> catch handler`
Note in JS the returned promise type is actually runtime dependent,
if promise is rejected, it will pick the `handler` otherwise the original promise,
Expand Down
4 changes: 1 addition & 3 deletions jscomp/others/js_promise2.res
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ let catch: (promise<'a>, error => promise<'a>) => promise<'a> = %raw(`
`)

@new
external make: ((@uncurry ~resolve: (. 'a) => unit, ~reject: (. exn) => unit) => unit) => promise<
'a,
> = "Promise"
external make: ((~resolve: 'a => unit, ~reject: exn => unit) => unit) => promise<'a> = "Promise"

@val @scope("Promise") external resolve: 'a => promise<'a> = "resolve"
@val @scope("Promise") external reject: exn => promise<'a> = "reject"
Expand Down
14 changes: 7 additions & 7 deletions jscomp/others/js_string.res
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Js.String.concat("bell", "cow") == "cowbell"
*/
external concat: t => t = "concat"

@bs.send.pipe(: t)
@send.pipe(: t)
@variadic
/**
`concat(arr, original)` returns a new `string` consisting of each item of an
Expand Down Expand Up @@ -410,8 +410,8 @@ Js.String.localeCompare("cat", "CAT") > 0.0
*/
external localeCompare: t => float = "localeCompare"

@bs.send.pipe(: t)
@return({null_to_opt: null_to_opt})
@send.pipe(: t)
@return(nullable)
/**
`match(regexp, str)` matches a `string` against the given `regexp`. If there is
no match, it returns `None`. For regular expressions without the g modifier, if
Expand Down Expand Up @@ -540,7 +540,7 @@ let matchFn = (matchPart, _offset, _wholeString) => Js.String.toUpperCase(matchP
Js.String.unsafeReplaceBy0(re, matchFn, str) == "bEAUtIfUl vOwEls"
```
*/
external unsafeReplaceBy0: (Js_re.t, @uncurry (t, int, t) => t) => t = "replace"
external unsafeReplaceBy0: (Js_re.t, (t, int, t) => t) => t = "replace"

@bs.send.pipe(: t)
/**
Expand All @@ -565,7 +565,7 @@ let matchFn = (_match, part1, _offset, _wholeString) => {
Js.String.unsafeReplaceBy1(re, matchFn, str) == "Jony is 41"
```
*/
external unsafeReplaceBy1: (Js_re.t, @uncurry (t, t, int, t) => t) => t = "replace"
external unsafeReplaceBy1: (Js_re.t, (t, t, int, t) => t) => t = "replace"

@bs.send.pipe(: t)
/**
Expand Down Expand Up @@ -593,7 +593,7 @@ let matchFn = (_match, p1, p2, _offset, _wholeString) => {
Js.String.unsafeReplaceBy2(re, matchFn, str) == "42"
```
*/
external unsafeReplaceBy2: (Js_re.t, @uncurry (t, t, t, int, t) => t) => t = "replace"
external unsafeReplaceBy2: (Js_re.t, (t, t, t, int, t) => t) => t = "replace"

@bs.send.pipe(: t)
/**
Expand All @@ -606,7 +606,7 @@ matched.
See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
on MDN.
*/
external unsafeReplaceBy3: (Js_re.t, @uncurry (t, t, t, t, int, t) => t) => t = "replace"
external unsafeReplaceBy3: (Js_re.t, (t, t, t, t, int, t) => t) => t = "replace"

@bs.send.pipe(: t)
/**
Expand Down
4 changes: 2 additions & 2 deletions jscomp/runtime/caml_obj.res
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ and aux_obj_compare = (a: Obj.t, b: Obj.t) => {
}
}

let do_key_a = do_key((a, b, min_key_rhs))
let do_key_b = do_key((b, a, min_key_lhs))
let do_key_a = do_key((a, b, min_key_rhs), ...)
let do_key_b = do_key((b, a, min_key_lhs), ...)
O.for_in(a, do_key_a)
O.for_in(b, do_key_b)
let res = switch (min_key_lhs.contents, min_key_rhs.contents) {
Expand Down
68 changes: 34 additions & 34 deletions jscomp/runtime/curry.res
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ external apply8: (
%%private(
let curry_1 = (o, a0, arity) =>
switch arity {
| 1 => apply1(Obj.magic(o), a0)
| 2 => apply2(Obj.magic(o), a0)
| 3 => apply3(Obj.magic(o), a0)
| 4 => apply4(Obj.magic(o), a0)
| 5 => apply5(Obj.magic(o), a0)
| 6 => apply6(Obj.magic(o), a0)
| 7 => apply7(Obj.magic(o), a0)
| 1 => Obj.magic(apply1)(Obj.magic(o), a0)
| 2 => Obj.magic(apply2)(Obj.magic(o), a0)
| 3 => Obj.magic(apply3)(Obj.magic(o), a0)
| 4 => Obj.magic(apply4)(Obj.magic(o), a0)
| 5 => Obj.magic(apply5)(Obj.magic(o), a0)
| 6 => Obj.magic(apply6)(Obj.magic(o), a0)
| 7 => Obj.magic(apply7)(Obj.magic(o), a0)
| _ => Obj.magic(app(o, [a0]))
}
)
Expand Down Expand Up @@ -122,13 +122,13 @@ let __1 = o => {
%%private(
let curry_2 = (o, a0, a1, arity) =>
switch arity {
| 1 => app(apply1(Obj.magic(o), a0), [a1])
| 2 => apply2(Obj.magic(o), a0, a1)
| 3 => apply3(Obj.magic(o), a0, a1)
| 4 => apply4(Obj.magic(o), a0, a1)
| 5 => apply5(Obj.magic(o), a0, a1)
| 6 => apply6(Obj.magic(o), a0, a1)
| 7 => apply7(Obj.magic(o), a0, a1)
| 1 => Obj.magic(app)(apply1(Obj.magic(o), a0), [a1])
| 2 => Obj.magic(apply2)(Obj.magic(o), a0, a1)
| 3 => Obj.magic(apply3)(Obj.magic(o), a0, a1)
| 4 => Obj.magic(apply4)(Obj.magic(o), a0, a1)
| 5 => Obj.magic(apply5)(Obj.magic(o), a0, a1)
| 6 => Obj.magic(apply6)(Obj.magic(o), a0, a1)
| 7 => Obj.magic(apply7)(Obj.magic(o), a0, a1)
| _ => Obj.magic(app(o, [a0, a1]))
}
)
Expand All @@ -139,7 +139,7 @@ let _2 = (o, a0, a1) => {
if arity == 2 {
apply2(o, a0, a1)
} else {
curry_2(o, a0, a1, arity)
Obj.magic(curry_2)(o, a0, a1, arity)
}
}

Expand All @@ -159,10 +159,10 @@ let __2 = o => {
| 1 => app(apply1(Obj.magic(o), a0), [a1, a2])
| 2 => app(apply2(Obj.magic(o), a0, a1), [a2])
| 3 => apply3(Obj.magic(o), a0, a1, a2)
| 4 => apply4(Obj.magic(o), a0, a1, a2)
| 5 => apply5(Obj.magic(o), a0, a1, a2)
| 6 => apply6(Obj.magic(o), a0, a1, a2)
| 7 => apply7(Obj.magic(o), a0, a1, a2)
| 4 => Obj.magic(apply4)(Obj.magic(o), a0, a1, a2)
| 5 => Obj.magic(apply5)(Obj.magic(o), a0, a1, a2)
| 6 => Obj.magic(apply6)(Obj.magic(o), a0, a1, a2)
| 7 => Obj.magic(apply7)(Obj.magic(o), a0, a1, a2)
| _ => Obj.magic(app(o, [a0, a1, a2]))
}
)
Expand All @@ -173,7 +173,7 @@ let _3 = (o, a0, a1, a2) => {
if arity == 3 {
apply3(o, a0, a1, a2)
} else {
curry_3(o, a0, a1, a2, arity)
Obj.magic(curry_3)(o, a0, a1, a2, arity)
}
}

Expand All @@ -194,9 +194,9 @@ let __3 = o => {
| 2 => app(apply2(Obj.magic(o), a0, a1), [a2, a3])
| 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3])
| 4 => apply4(Obj.magic(o), a0, a1, a2, a3)
| 5 => apply5(Obj.magic(o), a0, a1, a2, a3)
| 6 => apply6(Obj.magic(o), a0, a1, a2, a3)
| 7 => apply7(Obj.magic(o), a0, a1, a2, a3)
| 5 => Obj.magic(apply5)(Obj.magic(o), a0, a1, a2, a3)
| 6 => Obj.magic(apply6)(Obj.magic(o), a0, a1, a2, a3)
| 7 => Obj.magic(apply7)(Obj.magic(o), a0, a1, a2, a3)
| _ => Obj.magic(app(o, [a0, a1, a2, a3]))
}
)
Expand All @@ -207,7 +207,7 @@ let _4 = (o, a0, a1, a2, a3) => {
if arity == 4 {
apply4(o, a0, a1, a2, a3)
} else {
curry_4(o, a0, a1, a2, a3, arity)
Obj.magic(curry_4)(o, a0, a1, a2, a3, arity)
}
}

Expand All @@ -228,9 +228,9 @@ let __4 = o => {
| 2 => app(apply2(Obj.magic(o), a0, a1), [a2, a3, a4])
| 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3, a4])
| 4 => app(apply4(Obj.magic(o), a0, a1, a2, a3), [a4])
| 5 => apply5(Obj.magic(o), a0, a1, a2, a3, a4)
| 6 => apply6(Obj.magic(o), a0, a1, a2, a3, a4)
| 7 => apply7(Obj.magic(o), a0, a1, a2, a3, a4)
| 5 => Obj.magic(apply5)(Obj.magic(o), a0, a1, a2, a3, a4)
| 6 => Obj.magic(apply6)(Obj.magic(o), a0, a1, a2, a3, a4)
| 7 => Obj.magic(apply7)(Obj.magic(o), a0, a1, a2, a3, a4)
| _ => Obj.magic(app(o, [a0, a1, a2, a3, a4]))
}
)
Expand All @@ -241,7 +241,7 @@ let _5 = (o, a0, a1, a2, a3, a4) => {
if arity == 5 {
apply5(o, a0, a1, a2, a3, a4)
} else {
curry_5(o, a0, a1, a2, a3, a4, arity)
Obj.magic(curry_5)(o, a0, a1, a2, a3, a4, arity)
}
}

Expand All @@ -263,8 +263,8 @@ let __5 = o => {
| 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3, a4, a5])
| 4 => app(apply4(Obj.magic(o), a0, a1, a2, a3), [a4, a5])
| 5 => app(apply5(Obj.magic(o), a0, a1, a2, a3, a4), [a5])
| 6 => apply6(Obj.magic(o), a0, a1, a2, a3, a4, a5)
| 7 => apply7(Obj.magic(o), a0, a1, a2, a3, a4, a5)
| 6 => Obj.magic(apply6)(Obj.magic(o), a0, a1, a2, a3, a4, a5)
| 7 => Obj.magic(apply7)(Obj.magic(o), a0, a1, a2, a3, a4, a5)
| _ => Obj.magic(app(o, [a0, a1, a2, a3, a4, a5]))
}
)
Expand All @@ -275,7 +275,7 @@ let _6 = (o, a0, a1, a2, a3, a4, a5) => {
if arity == 6 {
apply6(o, a0, a1, a2, a3, a4, a5)
} else {
curry_6(o, a0, a1, a2, a3, a4, a5, arity)
Obj.magic(curry_6)(o, a0, a1, a2, a3, a4, a5, arity)
}
}

Expand All @@ -298,7 +298,7 @@ let __6 = o => {
| 4 => app(apply4(Obj.magic(o), a0, a1, a2, a3), [a4, a5, a6])
| 5 => app(apply5(Obj.magic(o), a0, a1, a2, a3, a4), [a5, a6])
| 6 => app(apply6(Obj.magic(o), a0, a1, a2, a3, a4, a5), [a6])
| 7 => apply7(Obj.magic(o), a0, a1, a2, a3, a4, a5, a6)
| 7 => Obj.magic(apply7)(Obj.magic(o), a0, a1, a2, a3, a4, a5, a6)
| _ => Obj.magic(app(o, [a0, a1, a2, a3, a4, a5, a6]))
}
)
Expand All @@ -309,7 +309,7 @@ let _7 = (o, a0, a1, a2, a3, a4, a5, a6) => {
if arity == 7 {
apply7(o, a0, a1, a2, a3, a4, a5, a6)
} else {
curry_7(o, a0, a1, a2, a3, a4, a5, a6, arity)
Obj.magic(curry_7)(o, a0, a1, a2, a3, a4, a5, a6, arity)
}
}

Expand Down Expand Up @@ -343,7 +343,7 @@ let _8 = (o, a0, a1, a2, a3, a4, a5, a6, a7) => {
if arity == 8 {
apply8(o, a0, a1, a2, a3, a4, a5, a6, a7)
} else {
curry_8(o, a0, a1, a2, a3, a4, a5, a6, a7, arity)
Obj.magic(curry_8)(o, a0, a1, a2, a3, a4, a5, a6, a7, arity)
}
}

Expand Down
7 changes: 7 additions & 0 deletions jscomp/stdlib-406/ArrayBuffer.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type t = Js.TypedArray2.ArrayBuffer.t

@new external make: int => t = "ArrayBuffer"
@get external byteLength: t => int = "byteLength"

@send external slice: (t, ~start: int, ~end: int) => t = "slice"
@send external sliceToEnd: (t, ~start: int) => t = "slice"
18 changes: 18 additions & 0 deletions jscomp/stdlib-406/AsyncIterator.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type t<'a>

type value<'a> = {
done: bool,
value: option<'a>,
}

@send external next: t<'a> => promise<value<'a>> = "next"

let forEach = async (iterator, f) => {
let iteratorDone = ref(false)

while !iteratorDone.contents {
let {done, value} = await iterator->next
f(value)
iteratorDone := done
}
}
80 changes: 80 additions & 0 deletions jscomp/stdlib-406/AsyncIterator.resi
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/***
Bindings to async iterators, a way to do async iteration in JavaScript.

See [async iterator protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols) on MDN.*/

/**
The type representing an async iterator.
*/
type t<'a>

type value<'a> = {
/**
Whether there are more values to iterate on before the iterator is done.
*/
done: bool,
/**
The value of this iteration, if any.
*/
value: option<'a>,
}

/**
`next(asyncIterator)`

Returns the next value of the iterator, if any.

See [async iterator protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols) on MDN.

## Examples
- A simple example, getting the next value:
```rescript
@val external asyncIterator: AsyncIterator.t<int> = "someAsyncIterator"
let {AsyncIterator.done, value} = await asyncIterator->AsyncIterator.next
```

- Complete example, including looping over all values:
```rescript
// Let's pretend we get an async iterator returning ints from somewhere.
@val external asyncIterator: AsyncIterator.t<int> = "someAsyncIterator"


let processMyAsyncIterator = async () => {
// ReScript doesn't have `for ... of` loops, but it's easy to mimic using a while loop.
let break = ref(false)

while !break.contents {
// Await the next iterator value
let {value, done} = await asyncIterator->AsyncIterator.next

// Exit the while loop if the iterator says it's done
break := done

// This will log the (int) value of the current async iteration, if a value was returned.
Console.log(value)
}
}
```
*/
@send
external next: t<'a> => promise<value<'a>> = "next"

/**
`forEach(iterator, fn)` consumes all values in the async iterator and runs the callback `fn` for each value.

See [iterator protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) on MDN.

## Examples
```rescript
// Let's pretend we get an async iterator returning ints from somewhere.
@val external asyncIterator: AsyncIterator.t<int> = "someAsyncIterator"

await asyncIterator->AsyncIterator.forEach(value =>
switch value {
| Some(value) if value > 10 => Console.log("More than 10!")
| _ => ()
}
)
```
*/
let forEach: (t<'a>, option<'a> => unit) => promise<unit>
Loading
Loading