Skip to content

Forward useful improvements within blocked PRs #964

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

Merged
merged 3 commits into from
Nov 18, 2019
Merged
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: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ jobs:
npm run build
- name: Test distribution files
run: npm test
- name: Reconfigure for release
run: npm run release
- name: Set up version
run: |
VERSION=$(node -e "console.log(require('./package.json').version)")
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules/
out/
raw/
.history
*.backup
137 changes: 123 additions & 14 deletions cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,34 +600,143 @@ exports.main = function main(argv, options, callback) {
module.setShrinkLevel(shrinkLevel);
module.setDebugInfo(args.debug);

var runPasses = [];
const runPasses = [];
if (args.runPasses) {
if (typeof args.runPasses === "string") {
args.runPasses = args.runPasses.split(",");
}
if (args.runPasses.length) {
args.runPasses.forEach(pass => {
if (runPasses.indexOf(pass) < 0)
if (runPasses.indexOf(pass = pass.trim()) < 0)
runPasses.push(pass);
});
}
}

// Optimize the module if requested
if (optimizeLevel > 0 || shrinkLevel > 0) {
stats.optimizeCount++;
stats.optimizeTime += measure(() => {
module.optimize();
});
function doOptimize() {
const hasARC = args.runtime == "half" || args.runtime == "full";
const passes = [];
function add(pass) { passes.push(pass); }

// Optimize the module if requested
if (optimizeLevel > 0 || shrinkLevel > 0) {
// Binaryen's default passes with Post-AssemblyScript passes added.
// see: Binaryen/src/pass.cpp

// PassRunner::addDefaultGlobalOptimizationPrePasses
add("duplicate-function-elimination");

// PassRunner::addDefaultFunctionOptimizationPasses
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
add("ssa-nomerge");
}
if (optimizeLevel >= 4) {
add("flatten");
add("local-cse");
}
// if (hasARC) { // differs
// if (optimizeLevel < 4) {
// add("flatten");
// }
// add("post-assemblyscript");
// }
add("dce");
add("remove-unused-brs");
add("remove-unused-names");
add("optimize-instructions");
if (optimizeLevel >= 2 || shrinkLevel >= 2) {
add("pick-load-signs");
}
if (optimizeLevel >= 3 || shrinkLevel >= 2) {
add("precompute-propagate");
} else {
add("precompute");
}
if (optimizeLevel >= 2 || shrinkLevel >= 2) {
add("code-pushing");
}
add("simplify-locals-nostructure");
add("vacuum");
add("reorder-locals");
add("remove-unused-brs");
if (optimizeLevel >= 3 || shrinkLevel >= 2) {
add("merge-locals");
}
add("coalesce-locals");
add("simplify-locals");
add("vacuum");
add("reorder-locals");
add("coalesce-locals");
add("reorder-locals");
add("vacuum");
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
add("code-folding");
}
add("merge-blocks");
add("remove-unused-brs");
add("remove-unused-names");
add("merge-blocks");
if (optimizeLevel >= 3 || shrinkLevel >= 2) {
add("precompute-propagate");
} else {
add("precompute");
}
add("optimize-instructions");
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
add("rse");
}
// if (hasARC) { // differs
// add("post-assemblyscript-finalize");
// }
add("vacuum");

// PassRunner::addDefaultGlobalOptimizationPostPasses
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
add("dae-optimizing");
}
if (optimizeLevel >= 2 || shrinkLevel >= 2) {
add("inlining-optimizing");
}
add("duplicate-function-elimination");
add("duplicate-import-elimination");
if (optimizeLevel >= 2 || shrinkLevel >= 2) {
add("simplify-globals-optimizing");
} else {
add("simplify-globals");
}
add("remove-unused-module-elements");
add("memory-packing");
add("directize");
add("inlining-optimizing"); // differs
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
add("generate-stack-ir");
add("optimize-stack-ir");
}
}

// Append additional passes if requested and execute
module.runPasses(passes.concat(runPasses));
}

// Run additional passes if requested
if (runPasses.length) {
stats.optimizeTime += measure(() => {
stats.optimizeCount++;
stats.optimizeTime += measure(() => {
module.runPasses(runPasses.map(pass => pass.trim()));
});
}
doOptimize();
if (args.converge) {
let last = module.toBinary();
do {
stats.optimizeCount++;
doOptimize();
let next = module.toBinary();
if (next.output.length >= last.output.length) {
if (next.output.length > last.output.length) {
stderr.write("Last converge was suboptimial." + EOL);
}
break;
}
last = next;
} while (true);
}
});

// Prepare output
if (!args.noEmit) {
Expand Down
5 changes: 5 additions & 0 deletions cli/asc.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"description": "How much to focus on shrinking code size. [0-2, s=1, z=2]",
"type": "i"
},
"converge": {
"description": "Re-optimizes until no further improvements can be made.",
"type": "b",
"default": false
},
"validate": {
"description": "Validates the module using Binaryen. Exits if invalid.",
"type": "b",
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"url": "https://github.com/AssemblyScript/assemblyscript/issues"
},
"dependencies": {
"binaryen": "89.0.0-nightly.20191113",
"binaryen": "89.0.0-nightly.20191116",
"long": "^4.0.0",
"source-map-support": "^0.5.16",
"ts-node": "^6.2.0",
Expand Down Expand Up @@ -63,7 +63,8 @@
"make": "npm run clean && npm test && npm run build && npm test",
"all": "npm run check && npm run make",
"docs": "typedoc --tsconfig tsconfig-docs.json --mode modules --name \"AssemblyScript Compiler API\" --out ./docs/api --ignoreCompilerErrors --excludeNotExported --excludePrivate --excludeExternals --exclude **/std/** --includeDeclarations --readme src/README.md",
"release": "node scripts/release"
"prepublishOnly": "node scripts/prepublish",
"postpublish": "node scripts/postpublish"
},
"releaseFiles": [
"lib/rtrace/index.d.ts",
Expand Down
5 changes: 5 additions & 0 deletions scripts/postpublish-files.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"package.json",
"index.js",
"index.d.ts"
]
22 changes: 22 additions & 0 deletions scripts/postpublish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Reconfigures the repository after publishing

const fs = require("fs");
const path = require("path");
const devFiles = require("./postpublish-files.json");

console.log("Restoring development files ...");

devFiles.forEach(originalName => {
const backupName = originalName + ".backup";
const backupPath = path.join(__dirname, "..", backupName);
if (!fs.existsSync(backupPath)) {
console.log("- " + backupName + " does not exist");
} else {
console.log("- " + backupName + " -> " + originalName);
fs.copyFileSync(
backupPath,
path.join(__dirname, "..", originalName)
);
fs.unlinkSync(backupPath);
}
});
19 changes: 18 additions & 1 deletion scripts/release.js → scripts/prepublish.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
// Reconfigures the repository before publishing a release
// Reconfigures the repository before publishing

const fs = require("fs");
const path = require("path");
const pkg = require("../package.json");
const devFiles = require("./postpublish-files.json");

if (!pkg.releaseFiles) {
console.log("Package has already been updated");
return;
}

console.log("Backing up development files ...");

devFiles.forEach(originalName => {
const backupName = originalName + ".backup";
console.log("- " + originalName + " -> " + backupName);
fs.copyFileSync(
path.join(__dirname, "..", originalName),
path.join(__dirname, "..", backupName)
);
});

console.log("Updating package.json ...");

Expand Down
3 changes: 2 additions & 1 deletion src/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ export function compileCall(
case TypeKind.USIZE: { value = "usize"; break; }
case TypeKind.V128: { value = "v128"; break; }
case TypeKind.ANYREF: { value = "anyref"; break; }
case TypeKind.EXNREF: { value = "exnref"; break; }
default: assert(false);
case TypeKind.VOID: { value = "void"; break; }
}
Expand Down Expand Up @@ -4788,7 +4789,7 @@ export function compileAbort(
// essentially ignoring the message GC-wise. Doesn't matter anyway on a crash.
messageArg = compiler.compileExpression(message, stringInstance.type, Constraints.CONV_IMPLICIT | Constraints.WILL_RETAIN);
} else {
messageArg = stringInstance.type.toNativeZero(module);
messageArg = compiler.makeZero(stringInstance.type);
}

var filenameArg = compiler.ensureStaticString(reportNode.range.source.normalizedPath);
Expand Down
1 change: 1 addition & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export namespace CommonSymbols {
export const Uint64Array = "Uint64Array";
export const Float32Array = "Float32Array";
export const Float64Array = "Float64Array";
export const Error = "Error";
// runtime
export const abort = "abort";
export const pow = "pow";
Expand Down
Loading