Skip to content

Commit

Permalink
codegen: do not funcRef for func var decl/iife
Browse files Browse the repository at this point in the history
some small test262 regressions but mostly false positives so it is worth it

test262: 42.48% (-0.05) | πŸ§ͺ 48414 | 🀠 20568 (-23) | ❌ 6350 (-31) | πŸ’€ 15243 (+4) | πŸ—οΈ 115 (+51) | πŸ’₯ 296 | ⏰ 28 | πŸ“ 5814 (-1)
  • Loading branch information
CanadaHonk committed Sep 12, 2024
1 parent 8702232 commit 9098f77
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions compiler/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {

// opt: virtualize iifes
if (isFuncType(decl.callee.type)) {
const [ func ] = generateFunc(scope, decl.callee);
const [ func ] = generateFunc(scope, decl.callee, true);
name = func.name;
}

Expand Down Expand Up @@ -2999,7 +2999,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
// hack for let a = function () { ... }
if (!init.id) {
init.id = { name };
generateFunc(scope, init);
generateFunc(scope, init, true);
return out;
}
}
Expand Down Expand Up @@ -5988,7 +5988,7 @@ const funcByIndex = idx => {
};
const funcByName = name => funcByIndex(funcIndex[name]);

const generateFunc = (scope, decl) => {
const generateFunc = (scope, decl, forceNoExpr = false) => {
const name = decl.id ? decl.id.name : `#anonymous${uniqId()}`;
if (decl.type.startsWith('Class')) {
const out = generateClass(scope, {
Expand Down Expand Up @@ -6271,7 +6271,7 @@ const generateFunc = (scope, decl) => {
// force generate all for precompile
if (globalThis.precompile) func.generate();

const out = decl.type.endsWith('Expression') ? funcRef(func) : [];
const out = decl.type.endsWith('Expression') && !forceNoExpr ? funcRef(func) : [];
astCache.set(decl, out);
return [ func, out ];
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "porffor",
"description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
"version": "0.42.2+801066453",
"version": "0.42.3+c5814d029",
"author": "CanadaHonk",
"license": "MIT",
"scripts": {},
Expand Down
2 changes: 1 addition & 1 deletion runner/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import fs from 'node:fs';
globalThis.version = '0.42.2+801066453';
globalThis.version = '0.42.3+c5814d029';

// deno compat
if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
Expand Down
1 change: 1 addition & 0 deletions test262/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var assert = mustBeTrue => {

throw new Test262Error('assert failed');
};
assert; // idk why exactly but this fixes many tests by forcing indirect ref

var __assert_throws = (expectedErrorConstructor, func) => {
if (typeof func !== 'function') {
Expand Down
2 changes: 1 addition & 1 deletion test262/history.json

Large diffs are not rendered by default.

0 comments on commit 9098f77

Please sign in to comment.