From fb277d558189481b698722b71a19f859d60d68de Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Sat, 8 Aug 2020 14:46:53 -0400 Subject: [PATCH 1/9] revert blocked change to publish.yml --- .github/workflows/publish.yml | 67 ++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e4fcbf64ba..36c5d41ad5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,19 +1,29 @@ name: Publish on: - schedule: - - cron: '0 0 * * *' + push: + branches: + - master jobs: - release: - name: Packages - if: github.repository == 'AssemblyScript/assemblyscript' + publish: + name: "Packages" + if: github.repository == 'DuncanUszkay1/assemblyscript' runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 with: - ref: master + ref: release - uses: dcodeIO/setup-node-nvm@master with: node-version: current + - name: Merge master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" + git fetch origin + git merge origin/master - name: Install dependencies run: npm ci - name: Build distribution files @@ -22,18 +32,41 @@ jobs: npm run build - name: Test distribution files run: npm test - - name: Make semantic release + - name: Set up version + run: | + VERSION=$(node -e "console.log(require('./package.json').version)") + git add --force dist/* + if git rev-parse v$VERSION >/dev/null 2>&1; then + VERSION=$VERSION-nightly.$(date "+%Y%m%d") + if git rev-parse v$VERSION >/dev/null 2>&1; then + echo "Nightly $VERSION does already exist." + exit 1 + fi + echo ::set-env name=CHANNEL::nightly + echo "Committing nightly ($VERSION) ..." + git commit -m "Nightly v$VERSION" + npm version $VERSION --no-git-tag-version --force + else + echo ::set-env name=CHANNEL::latest + echo "Committing release ($VERSION) ..." + git commit --allow-empty -m "Release v$VERSION" + fi + echo ::set-env name=VERSION::$VERSION + cd lib/loader + npm version $VERSION --no-git-tag-version --force + cd ../.. + - name: Create tag and push distribution files + run: | + git tag v$VERSION + git push origin release + git push origin v$VERSION + - name: Publish to npm env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - # On success, semantic-release will update the version and publish, - # triggering the postversion script that'll update the loader's version - # as well. If nothing was published, the version will still be '0.0.0'. + NPM_REGISTRY: "registry.npmjs.org" + NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: | - node node_modules/semantic-release/bin/semantic-release.js --unstable + npm config set "//${NPM_REGISTRY}/:_authToken=${NPM_AUTH_TOKEN}" + npm publish --tag $CHANNEL cd lib/loader - if [ $(node -pe "require('./package.json').version") != "0.0.0" ]; then - npm config set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" - npm publish --access public - fi + npm publish --tag $CHANNEL --access public cd ../.. From a02d214172ddd5c742c98b6f0ae1b7fad5d91a9a Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Sat, 8 Aug 2020 14:47:22 -0400 Subject: [PATCH 2/9] revert blocked change to test.yml --- .github/workflows/test.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 60f636a26a..49597efacf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -68,8 +68,6 @@ jobs: exit 1 fi npm test - - name: Test browser build - run: node tests/browser-asc test-windows: name: "Compiler (Windows, node current)" runs-on: windows-latest @@ -89,8 +87,6 @@ jobs: run: npm run build - name: Test distribution run: npm test - - name: Test browser build - run: node tests/browser-asc test-macos: name: "Compiler (MacOS, node current)" runs-on: macos-latest @@ -110,8 +106,6 @@ jobs: run: npm run build - name: Test distribution run: npm test - - name: Test browser build - run: node tests/browser-asc test-features: name: "Features" runs-on: ubuntu-latest @@ -121,7 +115,8 @@ jobs: - uses: dcodeIO/setup-node-nvm@master with: node-mirror: https://nodejs.org/download/v8-canary/ - node-version: "15.0.0-v8-canary202007077c53168ead" + # FIXME: newer node-v8 builds are currently broken + node-version: "14.0.0-v8-canary201911242015a12d82" - name: Install dependencies run: npm ci --no-audit - name: Clean distribution files From 3559b5a365345e597e31851079d09bfbf86b9b6e Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Sat, 5 Sep 2020 21:39:10 -0400 Subject: [PATCH 3/9] Rename indexArg to functionInstance --- src/builtins.ts | 8 ++++---- src/compiler.ts | 43 ++++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/builtins.ts b/src/builtins.ts index 8c2feadc5c..ad568a1724 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -2898,7 +2898,7 @@ function builtin_call_indirect(ctx: BuiltinContext): ExpressionRef { } else { returnType = ctx.contextualType; } - var indexArg = compiler.compileExpression(operands[0], Type.u32, Constraints.CONV_IMPLICIT); + var functionInstance = compiler.compileExpression(operands[0], Type.u32, Constraints.CONV_IMPLICIT); var numOperands = operands.length - 1; var operandExprs = new Array(numOperands); var nativeParamTypes = new Array(numOperands); @@ -2907,7 +2907,7 @@ function builtin_call_indirect(ctx: BuiltinContext): ExpressionRef { nativeParamTypes[i] = compiler.currentType.toNativeType(); } compiler.currentType = returnType; - return module.call_indirect(indexArg, operandExprs, createType(nativeParamTypes), returnType.toNativeType()); + return module.call_indirect(functionInstance, operandExprs, createType(nativeParamTypes), returnType.toNativeType()); } builtins.set(BuiltinNames.call_indirect, builtin_call_indirect); @@ -2997,7 +2997,7 @@ function builtin_function_call(ctx: BuiltinContext): ExpressionRef { compiler.currentType = returnType; return compiler.module.unreachable(); } - var indexArg = compiler.compileExpression(assert(ctx.thisOperand), ftype, Constraints.CONV_IMPLICIT); + var functionInstance = compiler.compileExpression(assert(ctx.thisOperand), ftype, Constraints.CONV_IMPLICIT); var thisOperand = assert(ctx.operands.shift()); var thisType = signature.thisType; var thisArg: usize = 0; @@ -3010,7 +3010,7 @@ function builtin_function_call(ctx: BuiltinContext): ExpressionRef { ); return compiler.module.unreachable(); } - return compiler.compileCallIndirect(signature, indexArg, ctx.operands, ctx.reportNode, thisArg, ctx.contextualType == Type.void); + return compiler.compileCallIndirect(signature, functionInstance, ctx.operands, ctx.reportNode, thisArg, ctx.contextualType == Type.void); } function_builtins.set("call", builtin_function_call); diff --git a/src/compiler.ts b/src/compiler.ts index e63e08361c..3afc432054 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -6668,7 +6668,7 @@ export class Compiler extends DiagnosticEmitter { var thisExpression = this.resolver.currentThisExpression; var signature: Signature | null; - var indexArg: ExpressionRef; + var functionInstance: ExpressionRef; switch (target.kind) { // direct call: concrete function @@ -6708,9 +6708,9 @@ export class Compiler extends DiagnosticEmitter { signature = local.type.signatureReference; if (signature) { if (local.is(CommonFlags.INLINED)) { - indexArg = module.i32(i64_low(local.constantIntegerValue)); + functionInstance = module.i32(i64_low(local.constantIntegerValue)); } else { - indexArg = module.local_get(local.index, NativeType.I32); + functionInstance = module.local_get(local.index, NativeType.I32); } break; } @@ -6724,7 +6724,7 @@ export class Compiler extends DiagnosticEmitter { let global = target; signature = global.type.signatureReference; if (signature) { - indexArg = module.global_get(global.internalName, global.type.toNativeType()); + functionInstance = module.global_get(global.internalName, global.type.toNativeType()); break; } this.error( @@ -6740,7 +6740,7 @@ export class Compiler extends DiagnosticEmitter { if (signature) { let fieldParent = fieldInstance.parent; assert(fieldParent.kind == ElementKind.CLASS); - indexArg = module.load(4, false, + functionInstance = module.load(4, false, this.compileExpression( assert(thisExpression), (fieldParent).type, @@ -6775,7 +6775,7 @@ export class Compiler extends DiagnosticEmitter { Constraints.CONV_IMPLICIT | Constraints.IS_THIS ); } - indexArg = this.compileCallDirect(getterInstance, [], expression.expression, thisArg); + functionInstance = this.compileCallDirect(getterInstance, [], expression.expression, thisArg); signature = this.currentType.signatureReference; if (!signature) { this.error( @@ -6792,7 +6792,7 @@ export class Compiler extends DiagnosticEmitter { if (typeArguments !== null && typeArguments.length > 0) { let ftype = typeArguments[0]; signature = ftype.getSignature(); - indexArg = this.compileExpression(expression.expression, ftype, Constraints.CONV_IMPLICIT); + functionInstance = this.compileExpression(expression.expression, ftype, Constraints.CONV_IMPLICIT); break; } // fall-through @@ -6817,7 +6817,7 @@ export class Compiler extends DiagnosticEmitter { } return this.compileCallIndirect( assert(signature), // FIXME: bootstrap can't see this yet - indexArg, + functionInstance, expression.args, expression, 0, @@ -7973,7 +7973,7 @@ export class Compiler extends DiagnosticEmitter { /** Compiles an indirect call using an index argument and a signature. */ compileCallIndirect( signature: Signature, - indexArg: ExpressionRef, + functionInstance: ExpressionRef, argumentExpressions: Expression[], reportNode: Node, thisArg: ExpressionRef = 0, @@ -8004,13 +8004,13 @@ export class Compiler extends DiagnosticEmitter { ); } assert(index == numArgumentsInclThis); - return this.makeCallIndirect(signature, indexArg, reportNode, operands, immediatelyDropped); + return this.makeCallIndirect(signature, functionInstance, reportNode, operands, immediatelyDropped); } - /** Creates an indirect call to the function at `indexArg` in the function table. */ + /** Creates an indirect call to the function at `functionInstance` in the function table. */ makeCallIndirect( signature: Signature, - indexArg: ExpressionRef, + functionInstance: ExpressionRef, reportNode: Node, operands: ExpressionRef[] | null = null, immediatelyDropped: bool = false, @@ -8044,7 +8044,7 @@ export class Compiler extends DiagnosticEmitter { } if (this.options.isWasm64) { - indexArg = module.unary(UnaryOp.WrapI64, indexArg); + functionInstance = module.unary(UnaryOp.WrapI64, functionInstance); } // We might be calling a varargs stub here, even if all operands have been @@ -8052,27 +8052,27 @@ export class Compiler extends DiagnosticEmitter { // into the index argument, which becomes executed last after any operands. this.ensureArgumentsLength(); var nativeSizeType = this.options.nativeSizeType; - if (getSideEffects(indexArg) & SideEffects.WritesGlobal) { + if (getSideEffects(functionInstance) & SideEffects.WritesGlobal) { let flow = this.currentFlow; - let temp = flow.getTempLocal(this.options.usizeType, findUsedLocals(indexArg)); - indexArg = module.block(null, [ - module.local_set(temp.index, indexArg), + let temp = flow.getTempLocal(this.options.usizeType, findUsedLocals(functionInstance)); + functionInstance = module.block(null, [ + module.local_set(temp.index, functionInstance), module.global_set(BuiltinNames.argumentsLength, module.i32(numArguments)), module.local_get(temp.index, nativeSizeType) ], nativeSizeType); flow.freeTempLocal(temp); } else { // simplify - indexArg = module.block(null, [ + functionInstance = module.block(null, [ module.global_set(BuiltinNames.argumentsLength, module.i32(numArguments)), - indexArg + functionInstance ], nativeSizeType); } var expr = module.call_indirect( nativeSizeType == NativeType.I64 ? module.unary(UnaryOp.WrapI64, - module.load(8, false, indexArg, NativeType.I64) + module.load(8, false, functionInstance, NativeType.I64) ) - : module.load(4, false, indexArg, NativeType.I32), + : module.load(4, false, functionInstance, NativeType.I32), operands, signature.nativeParams, signature.nativeResults @@ -8148,6 +8148,7 @@ export class Compiler extends DiagnosticEmitter { contextualSignature: Signature | null, constraints: Constraints ): ExpressionRef { + console.log("compiling function expression"); var declaration = expression.declaration.clone(); // generic contexts can have multiple assert(!declaration.typeParameters); // function expression cannot be generic var flow = this.currentFlow; From 387e7d79e334baa6e6ea61724936c3ec4a9f5c90 Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Sat, 5 Sep 2020 21:43:31 -0400 Subject: [PATCH 4/9] Remove local publication changes so that we can merge this upstream --- .github/workflows/publish.yml | 67 +++++++++-------------------------- .github/workflows/test.yml | 9 +++-- 2 files changed, 24 insertions(+), 52 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 36c5d41ad5..e4fcbf64ba 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,29 +1,19 @@ name: Publish on: - push: - branches: - - master + schedule: + - cron: '0 0 * * *' jobs: - publish: - name: "Packages" - if: github.repository == 'DuncanUszkay1/assemblyscript' + release: + name: Packages + if: github.repository == 'AssemblyScript/assemblyscript' runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 with: - ref: release + ref: master - uses: dcodeIO/setup-node-nvm@master with: node-version: current - - name: Merge master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - git config user.name "GitHub Actions" - git config user.email "actions@github.com" - git remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" - git fetch origin - git merge origin/master - name: Install dependencies run: npm ci - name: Build distribution files @@ -32,41 +22,18 @@ jobs: npm run build - name: Test distribution files run: npm test - - name: Set up version - run: | - VERSION=$(node -e "console.log(require('./package.json').version)") - git add --force dist/* - if git rev-parse v$VERSION >/dev/null 2>&1; then - VERSION=$VERSION-nightly.$(date "+%Y%m%d") - if git rev-parse v$VERSION >/dev/null 2>&1; then - echo "Nightly $VERSION does already exist." - exit 1 - fi - echo ::set-env name=CHANNEL::nightly - echo "Committing nightly ($VERSION) ..." - git commit -m "Nightly v$VERSION" - npm version $VERSION --no-git-tag-version --force - else - echo ::set-env name=CHANNEL::latest - echo "Committing release ($VERSION) ..." - git commit --allow-empty -m "Release v$VERSION" - fi - echo ::set-env name=VERSION::$VERSION - cd lib/loader - npm version $VERSION --no-git-tag-version --force - cd ../.. - - name: Create tag and push distribution files - run: | - git tag v$VERSION - git push origin release - git push origin v$VERSION - - name: Publish to npm + - name: Make semantic release env: - NPM_REGISTRY: "registry.npmjs.org" - NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + # On success, semantic-release will update the version and publish, + # triggering the postversion script that'll update the loader's version + # as well. If nothing was published, the version will still be '0.0.0'. run: | - npm config set "//${NPM_REGISTRY}/:_authToken=${NPM_AUTH_TOKEN}" - npm publish --tag $CHANNEL + node node_modules/semantic-release/bin/semantic-release.js --unstable cd lib/loader - npm publish --tag $CHANNEL --access public + if [ $(node -pe "require('./package.json').version") != "0.0.0" ]; then + npm config set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" + npm publish --access public + fi cd ../.. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 49597efacf..60f636a26a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -68,6 +68,8 @@ jobs: exit 1 fi npm test + - name: Test browser build + run: node tests/browser-asc test-windows: name: "Compiler (Windows, node current)" runs-on: windows-latest @@ -87,6 +89,8 @@ jobs: run: npm run build - name: Test distribution run: npm test + - name: Test browser build + run: node tests/browser-asc test-macos: name: "Compiler (MacOS, node current)" runs-on: macos-latest @@ -106,6 +110,8 @@ jobs: run: npm run build - name: Test distribution run: npm test + - name: Test browser build + run: node tests/browser-asc test-features: name: "Features" runs-on: ubuntu-latest @@ -115,8 +121,7 @@ jobs: - uses: dcodeIO/setup-node-nvm@master with: node-mirror: https://nodejs.org/download/v8-canary/ - # FIXME: newer node-v8 builds are currently broken - node-version: "14.0.0-v8-canary201911242015a12d82" + node-version: "15.0.0-v8-canary202007077c53168ead" - name: Install dependencies run: npm ci --no-audit - name: Clean distribution files From d9dac28741eb0ee174edc7c772090f99ebdc6ca7 Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Sun, 6 Sep 2020 09:48:21 -0400 Subject: [PATCH 5/9] Revert changes to call indirect builtin, rename functionInstance to functionPointer --- src/builtins.ts | 4 ++-- src/compiler.ts | 54 ++++++++++++++++++++++++------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/builtins.ts b/src/builtins.ts index ad568a1724..182cb235d0 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -2898,7 +2898,7 @@ function builtin_call_indirect(ctx: BuiltinContext): ExpressionRef { } else { returnType = ctx.contextualType; } - var functionInstance = compiler.compileExpression(operands[0], Type.u32, Constraints.CONV_IMPLICIT); + var indexArg = compiler.compileExpression(operands[0], Type.u32, Constraints.CONV_IMPLICIT); var numOperands = operands.length - 1; var operandExprs = new Array(numOperands); var nativeParamTypes = new Array(numOperands); @@ -2907,7 +2907,7 @@ function builtin_call_indirect(ctx: BuiltinContext): ExpressionRef { nativeParamTypes[i] = compiler.currentType.toNativeType(); } compiler.currentType = returnType; - return module.call_indirect(functionInstance, operandExprs, createType(nativeParamTypes), returnType.toNativeType()); + return module.call_indirect(indexArg, operandExprs, createType(nativeParamTypes), returnType.toNativeType()); } builtins.set(BuiltinNames.call_indirect, builtin_call_indirect); diff --git a/src/compiler.ts b/src/compiler.ts index 3afc432054..5456a0a280 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -6668,7 +6668,7 @@ export class Compiler extends DiagnosticEmitter { var thisExpression = this.resolver.currentThisExpression; var signature: Signature | null; - var functionInstance: ExpressionRef; + var functionPointer: ExpressionRef; switch (target.kind) { // direct call: concrete function @@ -6678,23 +6678,23 @@ export class Compiler extends DiagnosticEmitter { // builtins handle present respectively omitted type arguments on their own return this.compileCallExpressionBuiltin(functionPrototype, expression, contextualType); } - let functionInstance = this.resolver.maybeInferCall(expression, functionPrototype, flow); - if (!functionInstance) return this.module.unreachable(); - target = functionInstance; + let functionPointer = this.resolver.maybeInferCall(expression, functionPrototype, flow); + if (!functionPointer) return this.module.unreachable(); + target = functionPointer; // fall-through } case ElementKind.FUNCTION: { - let functionInstance = target; + let functionPointer = target; let thisArg: ExpressionRef = 0; - if (functionInstance.is(CommonFlags.INSTANCE)) { + if (functionPointer.is(CommonFlags.INSTANCE)) { thisArg = this.compileExpression( assert(thisExpression), - assert(functionInstance.signature.thisType), + assert(functionPointer.signature.thisType), Constraints.CONV_IMPLICIT | Constraints.IS_THIS ); } return this.compileCallDirect( - functionInstance, + functionPointer, expression.args, expression, thisArg, @@ -6708,9 +6708,9 @@ export class Compiler extends DiagnosticEmitter { signature = local.type.signatureReference; if (signature) { if (local.is(CommonFlags.INLINED)) { - functionInstance = module.i32(i64_low(local.constantIntegerValue)); + functionPointer = module.i32(i64_low(local.constantIntegerValue)); } else { - functionInstance = module.local_get(local.index, NativeType.I32); + functionPointer = module.local_get(local.index, NativeType.I32); } break; } @@ -6724,7 +6724,7 @@ export class Compiler extends DiagnosticEmitter { let global = target; signature = global.type.signatureReference; if (signature) { - functionInstance = module.global_get(global.internalName, global.type.toNativeType()); + functionPointer = module.global_get(global.internalName, global.type.toNativeType()); break; } this.error( @@ -6740,7 +6740,7 @@ export class Compiler extends DiagnosticEmitter { if (signature) { let fieldParent = fieldInstance.parent; assert(fieldParent.kind == ElementKind.CLASS); - functionInstance = module.load(4, false, + functionPointer = module.load(4, false, this.compileExpression( assert(thisExpression), (fieldParent).type, @@ -6775,7 +6775,7 @@ export class Compiler extends DiagnosticEmitter { Constraints.CONV_IMPLICIT | Constraints.IS_THIS ); } - functionInstance = this.compileCallDirect(getterInstance, [], expression.expression, thisArg); + functionPointer = this.compileCallDirect(getterInstance, [], expression.expression, thisArg); signature = this.currentType.signatureReference; if (!signature) { this.error( @@ -6792,7 +6792,7 @@ export class Compiler extends DiagnosticEmitter { if (typeArguments !== null && typeArguments.length > 0) { let ftype = typeArguments[0]; signature = ftype.getSignature(); - functionInstance = this.compileExpression(expression.expression, ftype, Constraints.CONV_IMPLICIT); + functionPointer = this.compileExpression(expression.expression, ftype, Constraints.CONV_IMPLICIT); break; } // fall-through @@ -6817,7 +6817,7 @@ export class Compiler extends DiagnosticEmitter { } return this.compileCallIndirect( assert(signature), // FIXME: bootstrap can't see this yet - functionInstance, + functionPointer, expression.args, expression, 0, @@ -7973,7 +7973,7 @@ export class Compiler extends DiagnosticEmitter { /** Compiles an indirect call using an index argument and a signature. */ compileCallIndirect( signature: Signature, - functionInstance: ExpressionRef, + functionPointer: ExpressionRef, argumentExpressions: Expression[], reportNode: Node, thisArg: ExpressionRef = 0, @@ -8004,13 +8004,13 @@ export class Compiler extends DiagnosticEmitter { ); } assert(index == numArgumentsInclThis); - return this.makeCallIndirect(signature, functionInstance, reportNode, operands, immediatelyDropped); + return this.makeCallIndirect(signature, functionPointer, reportNode, operands, immediatelyDropped); } /** Creates an indirect call to the function at `functionInstance` in the function table. */ makeCallIndirect( signature: Signature, - functionInstance: ExpressionRef, + functionPointer: ExpressionRef, reportNode: Node, operands: ExpressionRef[] | null = null, immediatelyDropped: bool = false, @@ -8044,7 +8044,7 @@ export class Compiler extends DiagnosticEmitter { } if (this.options.isWasm64) { - functionInstance = module.unary(UnaryOp.WrapI64, functionInstance); + functionPointer = module.unary(UnaryOp.WrapI64, functionPointer); } // We might be calling a varargs stub here, even if all operands have been @@ -8052,27 +8052,27 @@ export class Compiler extends DiagnosticEmitter { // into the index argument, which becomes executed last after any operands. this.ensureArgumentsLength(); var nativeSizeType = this.options.nativeSizeType; - if (getSideEffects(functionInstance) & SideEffects.WritesGlobal) { + if (getSideEffects(functionPointer) & SideEffects.WritesGlobal) { let flow = this.currentFlow; - let temp = flow.getTempLocal(this.options.usizeType, findUsedLocals(functionInstance)); - functionInstance = module.block(null, [ - module.local_set(temp.index, functionInstance), + let temp = flow.getTempLocal(this.options.usizeType, findUsedLocals(functionPointer)); + functionPointer = module.block(null, [ + module.local_set(temp.index, functionPointer), module.global_set(BuiltinNames.argumentsLength, module.i32(numArguments)), module.local_get(temp.index, nativeSizeType) ], nativeSizeType); flow.freeTempLocal(temp); } else { // simplify - functionInstance = module.block(null, [ + functionPointer = module.block(null, [ module.global_set(BuiltinNames.argumentsLength, module.i32(numArguments)), - functionInstance + functionPointer ], nativeSizeType); } var expr = module.call_indirect( nativeSizeType == NativeType.I64 ? module.unary(UnaryOp.WrapI64, - module.load(8, false, functionInstance, NativeType.I64) + module.load(8, false, functionPointer, NativeType.I64) ) - : module.load(4, false, functionInstance, NativeType.I32), + : module.load(4, false, functionPointer, NativeType.I32), operands, signature.nativeParams, signature.nativeResults From bcd97b467707aaeea3d682c1d42187d79ddf6ae6 Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Sun, 6 Sep 2020 09:49:34 -0400 Subject: [PATCH 6/9] Renaming to use Expr suffix --- src/builtins.ts | 4 ++-- src/compiler.ts | 54 ++++++++++++++++++++++++------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/builtins.ts b/src/builtins.ts index 182cb235d0..6a4de4e4c3 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -2898,7 +2898,7 @@ function builtin_call_indirect(ctx: BuiltinContext): ExpressionRef { } else { returnType = ctx.contextualType; } - var indexArg = compiler.compileExpression(operands[0], Type.u32, Constraints.CONV_IMPLICIT); + var tableIndexExpr = compiler.compileExpression(operands[0], Type.u32, Constraints.CONV_IMPLICIT); var numOperands = operands.length - 1; var operandExprs = new Array(numOperands); var nativeParamTypes = new Array(numOperands); @@ -2907,7 +2907,7 @@ function builtin_call_indirect(ctx: BuiltinContext): ExpressionRef { nativeParamTypes[i] = compiler.currentType.toNativeType(); } compiler.currentType = returnType; - return module.call_indirect(indexArg, operandExprs, createType(nativeParamTypes), returnType.toNativeType()); + return module.call_indirect(tableIndexExpr, operandExprs, createType(nativeParamTypes), returnType.toNativeType()); } builtins.set(BuiltinNames.call_indirect, builtin_call_indirect); diff --git a/src/compiler.ts b/src/compiler.ts index 5456a0a280..405cdc171d 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -6668,7 +6668,7 @@ export class Compiler extends DiagnosticEmitter { var thisExpression = this.resolver.currentThisExpression; var signature: Signature | null; - var functionPointer: ExpressionRef; + var functionPointerExpr: ExpressionRef; switch (target.kind) { // direct call: concrete function @@ -6678,23 +6678,23 @@ export class Compiler extends DiagnosticEmitter { // builtins handle present respectively omitted type arguments on their own return this.compileCallExpressionBuiltin(functionPrototype, expression, contextualType); } - let functionPointer = this.resolver.maybeInferCall(expression, functionPrototype, flow); - if (!functionPointer) return this.module.unreachable(); - target = functionPointer; + let functionPointerExpr = this.resolver.maybeInferCall(expression, functionPrototype, flow); + if (!functionPointerExpr) return this.module.unreachable(); + target = functionPointerExpr; // fall-through } case ElementKind.FUNCTION: { - let functionPointer = target; + let functionPointerExpr = target; let thisArg: ExpressionRef = 0; - if (functionPointer.is(CommonFlags.INSTANCE)) { + if (functionPointerExpr.is(CommonFlags.INSTANCE)) { thisArg = this.compileExpression( assert(thisExpression), - assert(functionPointer.signature.thisType), + assert(functionPointerExpr.signature.thisType), Constraints.CONV_IMPLICIT | Constraints.IS_THIS ); } return this.compileCallDirect( - functionPointer, + functionPointerExpr, expression.args, expression, thisArg, @@ -6708,9 +6708,9 @@ export class Compiler extends DiagnosticEmitter { signature = local.type.signatureReference; if (signature) { if (local.is(CommonFlags.INLINED)) { - functionPointer = module.i32(i64_low(local.constantIntegerValue)); + functionPointerExpr = module.i32(i64_low(local.constantIntegerValue)); } else { - functionPointer = module.local_get(local.index, NativeType.I32); + functionPointerExpr = module.local_get(local.index, NativeType.I32); } break; } @@ -6724,7 +6724,7 @@ export class Compiler extends DiagnosticEmitter { let global = target; signature = global.type.signatureReference; if (signature) { - functionPointer = module.global_get(global.internalName, global.type.toNativeType()); + functionPointerExpr = module.global_get(global.internalName, global.type.toNativeType()); break; } this.error( @@ -6740,7 +6740,7 @@ export class Compiler extends DiagnosticEmitter { if (signature) { let fieldParent = fieldInstance.parent; assert(fieldParent.kind == ElementKind.CLASS); - functionPointer = module.load(4, false, + functionPointerExpr = module.load(4, false, this.compileExpression( assert(thisExpression), (fieldParent).type, @@ -6775,7 +6775,7 @@ export class Compiler extends DiagnosticEmitter { Constraints.CONV_IMPLICIT | Constraints.IS_THIS ); } - functionPointer = this.compileCallDirect(getterInstance, [], expression.expression, thisArg); + functionPointerExpr = this.compileCallDirect(getterInstance, [], expression.expression, thisArg); signature = this.currentType.signatureReference; if (!signature) { this.error( @@ -6792,7 +6792,7 @@ export class Compiler extends DiagnosticEmitter { if (typeArguments !== null && typeArguments.length > 0) { let ftype = typeArguments[0]; signature = ftype.getSignature(); - functionPointer = this.compileExpression(expression.expression, ftype, Constraints.CONV_IMPLICIT); + functionPointerExpr = this.compileExpression(expression.expression, ftype, Constraints.CONV_IMPLICIT); break; } // fall-through @@ -6817,7 +6817,7 @@ export class Compiler extends DiagnosticEmitter { } return this.compileCallIndirect( assert(signature), // FIXME: bootstrap can't see this yet - functionPointer, + functionPointerExpr, expression.args, expression, 0, @@ -7973,7 +7973,7 @@ export class Compiler extends DiagnosticEmitter { /** Compiles an indirect call using an index argument and a signature. */ compileCallIndirect( signature: Signature, - functionPointer: ExpressionRef, + functionPointerExpr: ExpressionRef, argumentExpressions: Expression[], reportNode: Node, thisArg: ExpressionRef = 0, @@ -8004,13 +8004,13 @@ export class Compiler extends DiagnosticEmitter { ); } assert(index == numArgumentsInclThis); - return this.makeCallIndirect(signature, functionPointer, reportNode, operands, immediatelyDropped); + return this.makeCallIndirect(signature, functionPointerExpr, reportNode, operands, immediatelyDropped); } /** Creates an indirect call to the function at `functionInstance` in the function table. */ makeCallIndirect( signature: Signature, - functionPointer: ExpressionRef, + functionPointerExpr: ExpressionRef, reportNode: Node, operands: ExpressionRef[] | null = null, immediatelyDropped: bool = false, @@ -8044,7 +8044,7 @@ export class Compiler extends DiagnosticEmitter { } if (this.options.isWasm64) { - functionPointer = module.unary(UnaryOp.WrapI64, functionPointer); + functionPointerExpr = module.unary(UnaryOp.WrapI64, functionPointerExpr); } // We might be calling a varargs stub here, even if all operands have been @@ -8052,27 +8052,27 @@ export class Compiler extends DiagnosticEmitter { // into the index argument, which becomes executed last after any operands. this.ensureArgumentsLength(); var nativeSizeType = this.options.nativeSizeType; - if (getSideEffects(functionPointer) & SideEffects.WritesGlobal) { + if (getSideEffects(functionPointerExpr) & SideEffects.WritesGlobal) { let flow = this.currentFlow; - let temp = flow.getTempLocal(this.options.usizeType, findUsedLocals(functionPointer)); - functionPointer = module.block(null, [ - module.local_set(temp.index, functionPointer), + let temp = flow.getTempLocal(this.options.usizeType, findUsedLocals(functionPointerExpr)); + functionPointerExpr = module.block(null, [ + module.local_set(temp.index, functionPointerExpr), module.global_set(BuiltinNames.argumentsLength, module.i32(numArguments)), module.local_get(temp.index, nativeSizeType) ], nativeSizeType); flow.freeTempLocal(temp); } else { // simplify - functionPointer = module.block(null, [ + functionPointerExpr = module.block(null, [ module.global_set(BuiltinNames.argumentsLength, module.i32(numArguments)), - functionPointer + functionPointerExpr ], nativeSizeType); } var expr = module.call_indirect( nativeSizeType == NativeType.I64 ? module.unary(UnaryOp.WrapI64, - module.load(8, false, functionPointer, NativeType.I64) + module.load(8, false, functionPointerExpr, NativeType.I64) ) - : module.load(4, false, functionPointer, NativeType.I32), + : module.load(4, false, functionPointerExpr, NativeType.I32), operands, signature.nativeParams, signature.nativeResults From 1bf7b8a061444a32b153296482797e2fd61e2974 Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Sun, 6 Sep 2020 09:50:40 -0400 Subject: [PATCH 7/9] Rename functionInstance in builtin_function_call --- src/builtins.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/builtins.ts b/src/builtins.ts index 6a4de4e4c3..9c1a835d14 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -2997,7 +2997,7 @@ function builtin_function_call(ctx: BuiltinContext): ExpressionRef { compiler.currentType = returnType; return compiler.module.unreachable(); } - var functionInstance = compiler.compileExpression(assert(ctx.thisOperand), ftype, Constraints.CONV_IMPLICIT); + var tableIndexExpr = compiler.compileExpression(assert(ctx.thisOperand), ftype, Constraints.CONV_IMPLICIT); var thisOperand = assert(ctx.operands.shift()); var thisType = signature.thisType; var thisArg: usize = 0; @@ -3010,7 +3010,7 @@ function builtin_function_call(ctx: BuiltinContext): ExpressionRef { ); return compiler.module.unreachable(); } - return compiler.compileCallIndirect(signature, functionInstance, ctx.operands, ctx.reportNode, thisArg, ctx.contextualType == Type.void); + return compiler.compileCallIndirect(signature, tableIndexExpr, ctx.operands, ctx.reportNode, thisArg, ctx.contextualType == Type.void); } function_builtins.set("call", builtin_function_call); From 4f448995bf507ec7c1d265c2675b754896367dc0 Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Sun, 6 Sep 2020 09:51:19 -0400 Subject: [PATCH 8/9] remove log line --- src/compiler.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index 405cdc171d..0b6cef8c82 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -8148,7 +8148,6 @@ export class Compiler extends DiagnosticEmitter { contextualSignature: Signature | null, constraints: Constraints ): ExpressionRef { - console.log("compiling function expression"); var declaration = expression.declaration.clone(); // generic contexts can have multiple assert(!declaration.typeParameters); // function expression cannot be generic var flow = this.currentFlow; From 3a7d3af109984afc9ae0a12069c793f377d3392a Mon Sep 17 00:00:00 2001 From: Duncan Uszkay Date: Mon, 7 Sep 2020 09:43:08 -0400 Subject: [PATCH 9/9] Revert change to builtins, update comment in compiler --- src/builtins.ts | 4 ++-- src/compiler.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/builtins.ts b/src/builtins.ts index 9c1a835d14..61ba56231a 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -2997,7 +2997,7 @@ function builtin_function_call(ctx: BuiltinContext): ExpressionRef { compiler.currentType = returnType; return compiler.module.unreachable(); } - var tableIndexExpr = compiler.compileExpression(assert(ctx.thisOperand), ftype, Constraints.CONV_IMPLICIT); + var functionPointer = compiler.compileExpression(assert(ctx.thisOperand), ftype, Constraints.CONV_IMPLICIT); var thisOperand = assert(ctx.operands.shift()); var thisType = signature.thisType; var thisArg: usize = 0; @@ -3010,7 +3010,7 @@ function builtin_function_call(ctx: BuiltinContext): ExpressionRef { ); return compiler.module.unreachable(); } - return compiler.compileCallIndirect(signature, tableIndexExpr, ctx.operands, ctx.reportNode, thisArg, ctx.contextualType == Type.void); + return compiler.compileCallIndirect(signature, functionPointer, ctx.operands, ctx.reportNode, thisArg, ctx.contextualType == Type.void); } function_builtins.set("call", builtin_function_call); diff --git a/src/compiler.ts b/src/compiler.ts index 0b6cef8c82..87c8e23004 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -8007,7 +8007,7 @@ export class Compiler extends DiagnosticEmitter { return this.makeCallIndirect(signature, functionPointerExpr, reportNode, operands, immediatelyDropped); } - /** Creates an indirect call to the function at `functionInstance` in the function table. */ + /** Creates an indirect call to the first class function pointed to by `functionPointer`. */ makeCallIndirect( signature: Signature, functionPointerExpr: ExpressionRef,