summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWill Cohen <willcohen@users.noreply.github.com>2023-01-04 18:02:14 -0500
committerGitHub <noreply@github.com>2023-01-04 15:02:14 -0800
commitf92350d2949934c0e0ce4a27ec8b799ac2a85e45 (patch)
tree5cedc4d7a7ede518efb572b4278ffb8ef8102cb6 /src
parentfb434f95de125bbd1c3f145880d32395d86cfef2 (diff)
downloadbinaryen-f92350d2949934c0e0ce4a27ec8b799ac2a85e45.tar.gz
binaryen-f92350d2949934c0e0ce4a27ec8b799ac2a85e45.tar.bz2
binaryen-f92350d2949934c0e0ce4a27ec8b799ac2a85e45.zip
wasm2js: Stop emitting nan and infinity (#5391)
As noted in #4739, legacy language emitting nan and infinity exists, with the observation that it can be removed once asm.js is no longer used and global NaN is available. This commit removes that asm.js-specific code accordingly.
Diffstat (limited to 'src')
-rw-r--r--src/emscripten-optimizer/simple_ast.h20
-rw-r--r--src/tools/wasm2js.cpp7
-rw-r--r--src/wasm2js.h9
3 files changed, 6 insertions, 30 deletions
diff --git a/src/emscripten-optimizer/simple_ast.h b/src/emscripten-optimizer/simple_ast.h
index eb43209cc..e4c886dd8 100644
--- a/src/emscripten-optimizer/simple_ast.h
+++ b/src/emscripten-optimizer/simple_ast.h
@@ -919,25 +919,17 @@ struct JSPrinter {
void printName(Ref node) { emit(node->getCString()); }
static char* numToString(double d, bool finalize = true) {
- // If this number is NaN or infinite then things are a bit tricky. In JS we
- // want to eventually use `NaN` and/or `Infinity`, but neither of those
- // identifiers are valid in asm.js. Instead we have to explicitly import
- // `NaN` and `Infinity` from the global environment, and those names are
- // bound locally in an asm function as `nan` and `infinity`.
- //
- // TODO: the JS names of `NaN` and `Infinity` should be used once literal
- // asm.js code isn't generated any more
if (std::isnan(d)) {
if (std::signbit(d)) {
- return (char*)"-nan";
+ return (char*)"-NaN";
} else {
- return (char*)"nan";
+ return (char*)"NaN";
}
} else if (!std::isfinite(d)) {
if (std::signbit(d)) {
- return (char*)"-infinity";
+ return (char*)"-Infinity";
} else {
- return (char*)"infinity";
+ return (char*)"Infinity";
}
}
bool neg = d < 0;
@@ -1193,10 +1185,10 @@ struct JSPrinter {
ensure(1); // we temporarily append a 0
char* curr = buffer + last; // ensure might invalidate
buffer[used] = 0;
- if (strstr(curr, "infinity")) {
+ if (strstr(curr, "Infinity")) {
return;
}
- if (strstr(curr, "nan")) {
+ if (strstr(curr, "NaN")) {
return;
}
if (strchr(curr, '.')) {
diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp
index a6430fe12..79eee56a0 100644
--- a/src/tools/wasm2js.cpp
+++ b/src/tools/wasm2js.cpp
@@ -788,13 +788,6 @@ void AssertionEmitter::fixCalls(Ref asmjs, Name asmModule) {
}
void AssertionEmitter::emit() {
- // TODO: nan and infinity shouldn't be needed once literal asm.js code isn't
- // generated
- out << R"(
- var nan = NaN;
- var infinity = Infinity;
- )";
-
// When equating floating point values in spec tests we want to use bitwise
// equality like wasm does. Unfortunately though NaN makes this tricky. JS
// implementations like Spidermonkey and JSC will canonicalize NaN loads from
diff --git a/src/wasm2js.h b/src/wasm2js.h
index db394c36c..25931db85 100644
--- a/src/wasm2js.h
+++ b/src/wasm2js.h
@@ -577,15 +577,6 @@ void Wasm2JSBuilder::addBasics(Ref ast, Module* wasm) {
addMath(MATH_CEIL, CEIL);
addMath(MATH_TRUNC, TRUNC);
addMath(MATH_SQRT, SQRT);
- // TODO: this shouldn't be needed once we stop generating literal asm.js code
- // NaN and Infinity variables
- Ref nanVar = ValueBuilder::makeVar();
- ast->push_back(nanVar);
- ValueBuilder::appendToVar(nanVar, "nan", ValueBuilder::makeName("NaN"));
- Ref infinityVar = ValueBuilder::makeVar();
- ast->push_back(infinityVar);
- ValueBuilder::appendToVar(
- infinityVar, "infinity", ValueBuilder::makeName("Infinity"));
}
static bool needsQuoting(Name name) {