Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4c41fc9
working on preceding statements implementation
tomblind Aug 29, 2021
69390bf
fixed issues from tests and started adding new tests (which don't pas…
tomblind Aug 30, 2021
c30fa75
fixed issues with short-circuit compound operator expressions
tomblind Aug 31, 2021
af010aa
execution order tests
tomblind Aug 31, 2021
8888089
fixes for remaining broken tests
tomblind Sep 1, 2021
4076afd
switch test (currently broken)
tomblind Sep 2, 2021
7f45420
refactor to expression list transformation
tomblind Sep 2, 2021
52714ef
more refactoring and fixes for expression lists
tomblind Sep 3, 2021
306a5b9
refactored object literals a bit
tomblind Sep 3, 2021
6945c7e
refactorings, including removal of old iife stuff
tomblind Sep 3, 2021
70d463b
snapshot updates
tomblind Sep 3, 2021
0bbf30e
cleanup, fixes, and added some original nodes for source maps
tomblind Sep 3, 2021
c788432
comment update
tomblind Sep 3, 2021
2b3f517
fixed ifelse statements
tomblind Sep 3, 2021
00d6bdb
more things to fix
tomblind Sep 3, 2021
e7ba530
working on fixes to assignments and creating more tests (most of whic…
tomblind Sep 4, 2021
d60b6fd
more fixes. more broken things.
tomblind Sep 4, 2021
ed8bc68
lots of fixes to call expressions and lots of new broken tests
tomblind Sep 5, 2021
73f179b
Merge branch 'master' into preceding-statements
tomblind Sep 6, 2021
54f61e6
more execution order fixes, more tests
tomblind Sep 6, 2021
e579ee2
working on fixes for destructuring exec order
tomblind Sep 8, 2021
770b694
Merge remote-tracking branch 'tomblind/preceding-statements' into tem…
GlassBricks Sep 9, 2021
897b21c
Add benchmarks for all array functions
GlassBricks Sep 7, 2021
b3f525f
Optimize Array.push and add utilities for it
GlassBricks Sep 9, 2021
cb327f3
Replace array.shift with table.remove
GlassBricks Sep 7, 2021
7739e6a
Optimize array.join
GlassBricks Sep 7, 2021
b6a1acb
Optimize array.concat
GlassBricks Sep 7, 2021
e6310a1
Optimize array.every
GlassBricks Sep 7, 2021
2f04d39
Optimize array.filter
GlassBricks Sep 7, 2021
cb3887d
Optimize array.find
GlassBricks Sep 7, 2021
5d88a1f
Optimize array.findIndex
GlassBricks Sep 7, 2021
9504f6f
Optimize array.flat
GlassBricks Sep 7, 2021
6ec0d7f
Optimize array.flat
GlassBricks Sep 7, 2021
ce108b4
Optimize array.flat
GlassBricks Sep 7, 2021
26254df
Optimize array.includes
GlassBricks Sep 7, 2021
56ac6bd
Optimize array.indexOf
GlassBricks Sep 7, 2021
6395ffd
Optimize array.map
GlassBricks Sep 7, 2021
1b505f6
Optimize array.reduce and array.reduceRight
GlassBricks Sep 7, 2021
d395374
Optimize array.reverse
GlassBricks Sep 7, 2021
98d601b
Optimize array.setLength
GlassBricks Sep 7, 2021
ee41dd7
Optimize array.slice
GlassBricks Sep 7, 2021
017592f
Optimize array.some
GlassBricks Sep 7, 2021
743b5d9
Optimize array.splice
GlassBricks Sep 7, 2021
be7a278
Optimize array.toObject
GlassBricks Sep 7, 2021
d45bf6d
Optimize array.unshift
GlassBricks Sep 7, 2021
45ed744
Remove ArrayShift from LuaLibFeature enum
GlassBricks Sep 8, 2021
8880cde
Fix array.flatMap
GlassBricks Sep 8, 2021
db04b77
Add thisArg to all array functions
GlassBricks Sep 8, 2021
535bf1e
Fix formatting
GlassBricks Sep 9, 2021
dbffcbc
Another optimization for array unshift
GlassBricks Sep 9, 2021
73977fa
Optimize many other lualib
GlassBricks Sep 10, 2021
f877eb8
Update switch snapshots to use optimized array push
GlassBricks Sep 10, 2021
8b8d780
Add lualib dependency exactness checks
GlassBricks Sep 10, 2021
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
9 changes: 9 additions & 0 deletions benchmark/src/runtime_benchmarks/array_concat_array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function arrayConcat(): number[] {
const arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
const arr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
const n = 50000;
for (let i = 0; i < n; i++) {
arr1.concat(arr2);
}
return arr1;
}
9 changes: 9 additions & 0 deletions benchmark/src/runtime_benchmarks/array_concat_spread.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function arrayConcat(): number[] {
const arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
const arr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
const n = 50000;
for (let i = 0; i < n; i++) {
arr1.concat(...arr2);
}
return arr1;
}
7 changes: 7 additions & 0 deletions benchmark/src/runtime_benchmarks/array_every.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function arrayEvery() {
const n = 200000;
const array = [1, 2, 3, 4, 5, 6, 7, 8, 7, 10];
for (let i = 0; i < n; i++) {
array.every((item, index) => item > index);
}
}
7 changes: 7 additions & 0 deletions benchmark/src/runtime_benchmarks/array_filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function arrayFilter() {
const n = 100000;
const array = [1, 2, 3, 4, 3, 6, 7, 8, 7, 10];
for (let i = 0; i < n; i++) {
array.filter((item, index) => item > index);
}
}
9 changes: 9 additions & 0 deletions benchmark/src/runtime_benchmarks/array_find.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function arrayFind() {
const n = 50000;
const array = [1, 2, 3, 4, 3, 6, 7, 8, 9, 10];
for (let i = 0; i < n; i++) {
for (let j = 0; j < 10; j++) {
array.find(value => value === j);
}
}
}
9 changes: 9 additions & 0 deletions benchmark/src/runtime_benchmarks/array_findIndex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function arrayFindIndex() {
const n = 50000;
const array = [1, 2, 3, 4, 3, 6, 7, 8, 9, 10];
for (let i = 0; i < n; i++) {
for (let j = 0; j < 10; j++) {
array.findIndex(value => value === j);
}
}
}
7 changes: 7 additions & 0 deletions benchmark/src/runtime_benchmarks/array_flat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function arrayFlat() {
const n = 50000;
const array = [1, 2, [3, [4, 5], 6], 7, [8, 9], 10];
for (let i = 0; i < n; i++) {
array.flat(2);
}
}
13 changes: 13 additions & 0 deletions benchmark/src/runtime_benchmarks/array_flatMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function arrayFlatMap() {
const n = 50000;
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (let i = 0; i < n; i++) {
array.flatMap((el, index) => {
if (index < 5) {
return [el, el + 1];
} else {
return el + 2;
}
});
}
}
10 changes: 10 additions & 0 deletions benchmark/src/runtime_benchmarks/array_foreach.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default function arrayForeach() {
const n = 200000;
const array = [1, 2, 3, 4, 3, 6, 7, 8, 9, 10];
for (let i = 0; i < n; i++) {
array.forEach(value => {
let foo = value * 2;
foo = foo;
});
}
}
9 changes: 9 additions & 0 deletions benchmark/src/runtime_benchmarks/array_includes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function arrayIncludes() {
const n = 50000;
const array = [1, 2, 3, 4, 3, 6, 7, 8, 9, 10];
for (let i = 0; i < n; i++) {
for (let j = 0; j < 10; j++) {
array.includes(j);
}
}
}
9 changes: 9 additions & 0 deletions benchmark/src/runtime_benchmarks/array_indexOf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function arrayIndexOf() {
const n = 50000;
const array = [1, 2, 3, 4, 3, 6, 7, 8, 9, 10];
for (let i = 0; i < n; i++) {
for (let j = 0; j < 10; j++) {
array.indexOf(j);
}
}
}
17 changes: 17 additions & 0 deletions benchmark/src/runtime_benchmarks/array_join.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const array = [1, 2, "3", 4, 3, "6", { foo: 3 }, 8, 9, 10];

const k = 500;
for (let i = 0; i < k; i++) {
if (i % 2 === 0) {
array[i] = i.toString();
} else {
array[i] = i % 3;
}
}

export default function arrayJoin() {
const n = 3000;
for (let i = 0; i < n; i++) {
array.join("|");
}
}
7 changes: 7 additions & 0 deletions benchmark/src/runtime_benchmarks/array_map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function arrayMap() {
const n = 100000;
const array = [1, 2, 3, 4, 3, 6, 7, 8, 9, 10];
for (let i = 0; i < n; i++) {
array.map(value => value * 2);
}
}
9 changes: 9 additions & 0 deletions benchmark/src/runtime_benchmarks/array_push_array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function arrayPush(): number[] {
const n = 200000;
const numberList: number[] = [];
const numbers = [1, 2, 3];
for (let i = 0; i < n; i++) {
numberList.push(...numbers);
}
return numberList;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export default function arrayPush(): number[] {
const n = 1000000;
const n = 200000;
const numberList: number[] = [];
for (let i = 0; i < n; i++) {
numberList[numberList.length] = i * i;
numberList.push(i * i, i + 1);
}
return numberList;
}
8 changes: 8 additions & 0 deletions benchmark/src/runtime_benchmarks/array_push_single.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function arrayPush(): number[] {
const n = 500000;
const numberList: number[] = [];
for (let i = 0; i < n; i++) {
numberList.push(i * i);
}
return numberList;
}
7 changes: 7 additions & 0 deletions benchmark/src/runtime_benchmarks/array_reduce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function arrayReduce() {
const n = 200000;
const array = [1, 2, 3, 4, 5, 6, 7, 8, 7, 10];
for (let i = 0; i < n; i++) {
array.reduce((prev, cur, i) => prev + cur + i, 1);
}
}
7 changes: 7 additions & 0 deletions benchmark/src/runtime_benchmarks/array_reduceRight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function arrayReduce() {
const n = 200000;
const array = [1, 2, 3, 4, 5, 6, 7, 8, 7, 10];
for (let i = 0; i < n; i++) {
array.reduceRight((prev, cur, i) => prev + cur + i, 1);
}
}
7 changes: 7 additions & 0 deletions benchmark/src/runtime_benchmarks/array_reverse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function arrayReverse(): void {
const n = 500000;
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (let i = 0; i < n; i++) {
numbers.reverse();
}
}
9 changes: 9 additions & 0 deletions benchmark/src/runtime_benchmarks/array_slice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function arraySlice() {
const n = 50000;
const array = [1, 2, 3, 4, 3, 6, 7, 8, 9, 10];
for (let i = 0; i < n; i++) {
for (let j = 0; j < 6; j++) {
array.slice(j, -j);
}
}
}
7 changes: 7 additions & 0 deletions benchmark/src/runtime_benchmarks/array_some.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function arraySome() {
const n = 200000;
const array = [1, 2, 3, 4, 5, 6, 7, 8, 7, 10];
for (let i = 0; i < n; i++) {
array.some((item, index) => item < index);
}
}
9 changes: 9 additions & 0 deletions benchmark/src/runtime_benchmarks/array_splice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function arraySplice() {
const n = 20000;
const array = [1, 2, 3, 4, 3, 6, 7, 8, 9, 10];
for (let i = 0; i < n; i++) {
for (let j = 0; j < 10; j++) {
array.splice(j, 2, 1, 2);
}
}
}
9 changes: 9 additions & 0 deletions benchmark/src/runtime_benchmarks/array_unshift.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function arrayUnshift(): number[] {
const n = 2000;
const numberList: number[] = [];
const numbers = [1, 2, 3];
for (let i = 0; i < n; i++) {
numberList.unshift(...numbers);
}
return numberList;
}
49 changes: 36 additions & 13 deletions src/LuaAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ export enum SyntaxKind {
BitwiseNotOperator, // Unary
}

export enum NodeFlags {
None = 0,
Inline = 1 << 0, // Keep function body on same line
Declaration = 1 << 1, // Prefer declaration syntax `function foo()` over assignment syntax `foo = function()`
PossiblyNotUsed = 1 << 2, // for an expression, if in an ExpressionStatement, statement is not emitted
IsUnpackCall = 1 << 3,
}

// TODO maybe name this PrefixUnary? not sure it makes sense to do so, because all unary ops in Lua are prefix
export type UnaryBitwiseOperator = SyntaxKind.BitwiseNotOperator;

Expand Down Expand Up @@ -132,25 +140,36 @@ export interface TextRange {

export interface Node extends TextRange {
kind: SyntaxKind;
flags: NodeFlags;
}

export function createNode(kind: SyntaxKind, tsOriginal?: ts.Node): Node {
export function createNode(kind: SyntaxKind, tsOriginal?: ts.Node, flags: NodeFlags = NodeFlags.None): Node {
if (tsOriginal === undefined) {
return { kind };
return { kind, flags };
}

const sourcePosition = getSourcePosition(tsOriginal);
if (sourcePosition) {
return { kind, line: sourcePosition.line, column: sourcePosition.column };
return { kind, flags, line: sourcePosition.line, column: sourcePosition.column };
} else {
return { kind };
return { kind, flags };
}
}

export function cloneNode<T extends Node>(node: T): T {
return { ...node };
}

export function setNodeFlags<T extends Node>(node: T, flags: NodeFlags): T {
node.flags = flags;
return node;
}

export function addNodeFlags<T extends Node>(node: T, flags: NodeFlags): T {
node.flags |= flags;
return node;
}

export function setNodePosition<T extends Node>(node: T, position: TextRange): T {
node.line = position.line;
node.column = position.column;
Expand Down Expand Up @@ -566,18 +585,23 @@ export function createStringLiteral(value: string, tsOriginal?: ts.Node): String
return expression;
}

export enum FunctionExpressionFlags {
None = 1 << 0,
Inline = 1 << 1, // Keep function body on same line
Declaration = 1 << 2, // Prefer declaration syntax `function foo()` over assignment syntax `foo = function()`
export function isLiteral(
node: Node
): node is NilLiteral | DotsLiteral | BooleanLiteral | NumericLiteral | StringLiteral {
return (
isNilLiteral(node) ||
isDotsLiteral(node) ||
isBooleanLiteral(node) ||
isNumericLiteral(node) ||
isStringLiteral(node)
);
}

export interface FunctionExpression extends Expression {
kind: SyntaxKind.FunctionExpression;
params?: Identifier[];
dots?: DotsLiteral;
body: Block;
flags: FunctionExpressionFlags;
}

export function isFunctionExpression(node: Node): node is FunctionExpression {
Expand All @@ -588,14 +612,13 @@ export function createFunctionExpression(
body: Block,
params?: Identifier[],
dots?: DotsLiteral,
flags = FunctionExpressionFlags.None,
flags = NodeFlags.None,
tsOriginal?: ts.Node
): FunctionExpression {
const expression = createNode(SyntaxKind.FunctionExpression, tsOriginal) as FunctionExpression;
const expression = createNode(SyntaxKind.FunctionExpression, tsOriginal, flags) as FunctionExpression;
expression.body = body;
expression.params = params;
expression.dots = dots;
expression.flags = flags;
return expression;
}

Expand Down Expand Up @@ -807,6 +830,6 @@ export function isInlineFunctionExpression(expression: FunctionExpression): expr
expression.body.statements?.length === 1 &&
isReturnStatement(expression.body.statements[0]) &&
expression.body.statements[0].expressions !== undefined &&
(expression.flags & FunctionExpressionFlags.Inline) !== 0
(expression.flags & NodeFlags.Inline) !== 0
);
}
Loading