Skip to content

Apply switch optimization to tagged variants. #7146

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 1 commit 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
3 changes: 1 addition & 2 deletions compiler/core/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,7 @@ let compile output_prefix =
| _ -> false
in
if
untagged
&& List.length sw_consts = 0
List.length sw_consts = 0
&& eq_default sw_num_default sw_blocks_default
then
compile_cases ~untagged ~cxt
Expand Down
3 changes: 0 additions & 3 deletions lib/es6/Intl_NumberFormat_Grouping.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import * as Type from "./Type.js";

function parseJsValue(value) {
let value$1 = Type.Classify.classify(value);
if (typeof value$1 !== "object") {
return;
}
switch (value$1.TAG) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can crash

case "Bool" :
return {
Expand Down
11 changes: 0 additions & 11 deletions lib/es6/Primitive_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ function update(shape, o, n) {
return;
}
};
if (typeof shape !== "object") {
throw {
RE_EXN_ID: "Assert_failure",
_1: [
"Primitive_module.res",
68,
9
],
Error: new Error()
};
}
if (shape.TAG === "Module") {
let comps = shape._0;
for (let i = 0, i_finish = comps.length; i < i_finish; ++i) {
Expand Down
3 changes: 0 additions & 3 deletions lib/js/Intl_NumberFormat_Grouping.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ let Type = require("./Type.js");

function parseJsValue(value) {
let value$1 = Type.Classify.classify(value);
if (typeof value$1 !== "object") {
return;
}
switch (value$1.TAG) {
case "Bool" :
return {
Expand Down
11 changes: 0 additions & 11 deletions lib/js/Primitive_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ function update(shape, o, n) {
return;
}
};
if (typeof shape !== "object") {
throw {
RE_EXN_ID: "Assert_failure",
_1: [
"Primitive_module.res",
68,
9
],
Error: new Error()
};
}
if (shape.TAG === "Module") {
let comps = shape._0;
for (let i = 0, i_finish = comps.length; i < i_finish; ++i) {
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/src/core/Core_TempTests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ let json$1 = $$JSON.Classify.classify(json);

let tmp;

if (typeof json$1 !== "object" || json$1.TAG !== "Object") {
tmp = undefined;
} else {
if (json$1.TAG === "Object") {
let value = $$JSON.Classify.classify(json$1._0["foo"]);
tmp = typeof value !== "object" || value.TAG !== "String" ? undefined : value._0;
tmp = value.TAG === "String" ? value._0 : undefined;
} else {
tmp = undefined;
}

console.log(tmp);
Expand Down
35 changes: 6 additions & 29 deletions tests/tests/src/js_json_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ let v = JSON.parse(" { \"x\" : [1, 2, 3 ] } ");

add_test("File \"js_json_test.res\", line 23, characters 11-18", () => {
let ty = Js_json.classify(v);
if (typeof ty !== "object") {
return {
TAG: "Ok",
_0: false
};
}
if (ty.TAG !== "JSONObject") {
return {
TAG: "Ok",
Expand All @@ -74,12 +68,6 @@ add_test("File \"js_json_test.res\", line 23, characters 11-18", () => {
};
}
let ty2 = Js_json.classify(v$1);
if (typeof ty2 !== "object") {
return {
TAG: "Ok",
_0: false
};
}
if (ty2.TAG !== "JSONArray") {
return {
TAG: "Ok",
Expand All @@ -88,17 +76,6 @@ add_test("File \"js_json_test.res\", line 23, characters 11-18", () => {
}
ty2._0.forEach(x => {
let ty3 = Js_json.classify(x);
if (typeof ty3 !== "object") {
throw {
RE_EXN_ID: "Assert_failure",
_1: [
"js_json_test.res",
39,
21
],
Error: new Error()
};
}
if (ty3.TAG === "JSONNumber") {
return;
}
Expand Down Expand Up @@ -169,10 +146,10 @@ let ty$2 = Js_json.classify(json$2);

let exit = 0;

if (typeof ty$2 !== "object" || ty$2.TAG !== "JSONNumber") {
exit = 1;
} else {
if (ty$2.TAG === "JSONNumber") {
eq("File \"js_json_test.res\", line 80, characters 26-33", ty$2._0, 1.23456789);
} else {
exit = 1;
}

if (exit === 1) {
Expand All @@ -188,10 +165,10 @@ let ty$3 = Js_json.classify(json$3);

let exit$1 = 0;

if (typeof ty$3 !== "object" || ty$3.TAG !== "JSONNumber") {
exit$1 = 1;
} else {
if (ty$3.TAG === "JSONNumber") {
eq("File \"js_json_test.res\", line 90, characters 26-33", ty$3._0 | 0, -1347440721);
} else {
exit$1 = 1;
}

if (exit$1 === 1) {
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/src/variant.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ function fooA1(x) {
}

function fooC(x) {
if (typeof x !== "object" || x.TAG !== "C") {
return 42;
} else {
if (x.TAG === "C") {
return x._0 + x._1 | 0;
} else {
return 42;
}
}

Expand Down