Skip to content
Open
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
121 changes: 121 additions & 0 deletions tests/compiler_tests/src/inline_twin_lib.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs";

function afterGI(p, o, f) {
f();
if (o !== undefined) {
return [
Primitive_option.valFromOption(o),
p
];
}
}

function afterGN(p, o, f) {
f();
if (o !== undefined) {
return [
Primitive_option.valFromOption(o),
p
];
}
}

function someI(x) {
return Primitive_option.some(x);
}

function someN(x) {
return Primitive_option.some(x);
}

function mapI(o, f) {
if (o !== undefined) {
return Primitive_option.some(f(Primitive_option.valFromOption(o)));
}
}

function mapN(o, f) {
if (o !== undefined) {
return Primitive_option.some(f(Primitive_option.valFromOption(o)));
}
}

function getOrI(o, d) {
if (o !== undefined) {
return Primitive_option.valFromOption(o);
} else {
return d;
}
}

function getOrN(o, d) {
if (o !== undefined) {
return Primitive_option.valFromOption(o);
} else {
return d;
}
}

function flatMapI(o, f) {
if (o !== undefined) {
return f(Primitive_option.valFromOption(o));
}
}

function flatMapN(o, f) {
if (o !== undefined) {
return f(Primitive_option.valFromOption(o));
}
}

function bothI(a, b, f) {
return [
f(a),
f(b)
];
}

function bothN(a, b, f) {
return [
f(a),
f(b)
];
}

function subI(a, b) {
return b - a | 0;
}

function subN(a, b) {
return b - a | 0;
}

function sndI(_a, b) {
return b;
}

function sndN(_a, b) {
return b;
}

export {
afterGI,
afterGN,
someI,
someN,
mapI,
mapN,
getOrI,
getOrN,
flatMapI,
flatMapN,
bothI,
bothN,
subI,
subN,
sndI,
sndN,
}
/* No side effect */
79 changes: 79 additions & 0 deletions tests/compiler_tests/src/inline_twin_lib.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Helpers for inline_twin_test.res. Each one is defined twice with the same
// body: `xI` is @inline, so other modules inline it, and `xN` is
// @inline(never), so they call it. Keep the two bodies identical, apart from
// the I or N suffix of the helpers they call. No helper may update a local
// ref: other modules would then call it instead of inlining it (warning 113).

// [f] runs before the other argument is read, and may assign the variable
// that argument was made from.
@inline
let afterGI = (p: int, o: option<'a>, f) => {
f()
switch o {
| Some(v) => Some((v, p))
| None => None
}
}

@inline(never)
let afterGN = (p: int, o: option<'a>, f) => {
f()
switch o {
| Some(v) => Some((v, p))
| None => None
}
}

@inline let someI = x => Some(x)
@inline(never) let someN = x => Some(x)

@inline
let mapI = (o, f) =>
switch o {
| Some(v) => Some(f(v))
| None => None
}

@inline(never)
let mapN = (o, f) =>
switch o {
| Some(v) => Some(f(v))
| None => None
}

@inline
let getOrI = (o, d) =>
switch o {
| Some(v) => v
| None => d
}

@inline(never)
let getOrN = (o, d) =>
switch o {
| Some(v) => v
| None => d
}

@inline
let flatMapI = (o, f) =>
switch o {
| Some(v) => f(v)
| None => None
}

@inline(never)
let flatMapN = (o, f) =>
switch o {
| Some(v) => f(v)
| None => None
}

@inline let bothI = (a, b, f) => (f(a), f(b))
@inline(never) let bothN = (a, b, f) => (f(a), f(b))

// Reads its parameters in the other order, or not at all.
@inline let subI = (a: int, b: int) => b - a
@inline(never) let subN = (a: int, b: int) => b - a
@inline let sndI = (_a, b) => b
@inline(never) let sndN = (_a, b) => b
Loading
Loading