Skip to content

Commit e401bff

Browse files
authored
Deprecated @tupleReturn and various lualib improvements (TypeScriptToLua#1075)
* Add test for lualib dependencies and refactor tupleReturn/multiReturn * Deprecated @tupleReturn * No longer add not needed tostring calls to string += statements * upgrade lua-types version to one without @tupleReturn * Fix linter and make execution not fail when there are only warning diagnostics * Fix benchmark code for new lua-types * Disable benchmark workflow
1 parent 8a330e4 commit e401bff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+451
-460
lines changed

.github/workflows/ci.yml

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -39,80 +39,80 @@ jobs:
3939
- if: matrix.os == 'ubuntu-latest'
4040
uses: codecov/codecov-action@v1
4141

42-
benchmark:
43-
name: Benchmark
44-
runs-on: ubuntu-latest
45-
steps:
46-
- name: Lua Install
47-
run: sudo apt-get install lua5.3 luajit
48-
- name: Glow Install
49-
run: brew install glow
50-
# Checkout master & commit
51-
- name: Checkout master
52-
uses: actions/checkout@v2
53-
with:
54-
ref: master
55-
path: master
56-
- name: Checkout commit
57-
uses: actions/checkout@v2
58-
with:
59-
path: commit
60-
- name: Use Node.js 12.13.1
61-
uses: actions/setup-node@v1
62-
with:
63-
node-version: 12.13.1
64-
# NPM
65-
- name: NPM master
66-
run: npm ci && npm run build
67-
working-directory: master
68-
- name: NPM commit
69-
run: npm ci && npm run build
70-
working-directory: commit
71-
# Benchmark directory setup
72-
- name: Ensure benchmark data dir exists
73-
run: mkdir -p ./benchmark/data
74-
working-directory: commit
75-
- name: Copy commit benchmark to master
76-
run: rm -rf ./master/benchmark && cp -rf ./commit/benchmark ./master/benchmark
77-
# Run master benchmark first and output to commit benchmark data
78-
- name: Build benchmark Lua 5.3 master
79-
run: node ../../commit/dist/tstl.js -p tsconfig.53.json
80-
working-directory: master/benchmark
81-
- name: Run benchmark Lua 5.3 master
82-
id: benchmark-lua-master
83-
run: lua5.3 -- run.lua ../../../commit/benchmark/data/benchmark_master_53.json
84-
working-directory: master/benchmark/dist
85-
- name: Build benchmark LuaJIT master
86-
run: node ../../commit/dist/tstl.js -p tsconfig.jit.json
87-
working-directory: master/benchmark
88-
- name: Run benchmark LuaJIT master
89-
id: benchmark-jit-master
90-
run: luajit -- run.lua ../../../commit/benchmark/data/benchmark_master_jit.json
91-
working-directory: master/benchmark/dist
92-
# Run commit benchmark and compare with master
93-
- name: Build benchmark Lua 5.3 commit
94-
run: node ../../commit/dist/tstl.js -p tsconfig.53.json
95-
working-directory: commit/benchmark
96-
- name: Run benchmark Lua 5.3 commit
97-
id: benchmark-lua-commit
98-
run: lua5.3 -- run.lua ../data/benchmark_master_vs_commit_53.json ../data/benchmark_master_53.json
99-
working-directory: commit/benchmark/dist
100-
- name: Build benchmark LuaJIT commit
101-
run: node ../../commit/dist/tstl.js -p tsconfig.jit.json
102-
working-directory: commit/benchmark
103-
- name: Run benchmark LuaJIT commit
104-
id: benchmark-jit-commit
105-
run: luajit -- run.lua ../data/benchmark_master_vs_commit_jit.json ../data/benchmark_master_jit.json
106-
working-directory: commit/benchmark/dist
107-
- name: Combine benchmark results
108-
id: script-combine-results
109-
uses: actions/github-script@v3
110-
with:
111-
benchmark-result-path-lua: commit/benchmark/data/benchmark_master_vs_commit_53.json
112-
benchmark-result-path-jit: commit/benchmark/data/benchmark_master_vs_commit_jit.json
113-
result-encoding: string
114-
script: |
115-
const createBenchmarkCheck = require(`${process.env.GITHUB_WORKSPACE}/commit/.github/scripts/create_benchmark_check.js`);
116-
return createBenchmarkCheck({ github, context, core });
117-
- name: Benchmark results
118-
run: echo "${{steps.script-combine-results.outputs.result}}" | glow -s dark -w 120 -
42+
# benchmark:
43+
# name: Benchmark
44+
# runs-on: ubuntu-latest
45+
# steps:
46+
# - name: Lua Install
47+
# run: sudo apt-get install lua5.3 luajit
48+
# - name: Glow Install
49+
# run: brew install glow
50+
# # Checkout master & commit
51+
# - name: Checkout master
52+
# uses: actions/checkout@v2
53+
# with:
54+
# ref: master
55+
# path: master
56+
# - name: Checkout commit
57+
# uses: actions/checkout@v2
58+
# with:
59+
# path: commit
60+
# - name: Use Node.js 12.13.1
61+
# uses: actions/setup-node@v1
62+
# with:
63+
# node-version: 12.13.1
64+
# # NPM
65+
# - name: NPM master
66+
# run: npm ci && npm run build
67+
# working-directory: master
68+
# - name: NPM commit
69+
# run: npm ci && npm run build
70+
# working-directory: commit
71+
# # Benchmark directory setup
72+
# - name: Ensure benchmark data dir exists
73+
# run: mkdir -p ./benchmark/data
74+
# working-directory: commit
75+
# - name: Copy commit benchmark to master
76+
# run: rm -rf ./master/benchmark && cp -rf ./commit/benchmark ./master/benchmark
77+
# # Run master benchmark first and output to commit benchmark data
78+
# - name: Build benchmark Lua 5.3 master
79+
# run: node ../../commit/dist/tstl.js -p tsconfig.53.json
80+
# working-directory: master/benchmark
81+
# - name: Run benchmark Lua 5.3 master
82+
# id: benchmark-lua-master
83+
# run: lua5.3 -- run.lua ../../../commit/benchmark/data/benchmark_master_53.json
84+
# working-directory: master/benchmark/dist
85+
# - name: Build benchmark LuaJIT master
86+
# run: node ../../commit/dist/tstl.js -p tsconfig.jit.json
87+
# working-directory: master/benchmark
88+
# - name: Run benchmark LuaJIT master
89+
# id: benchmark-jit-master
90+
# run: luajit -- run.lua ../../../commit/benchmark/data/benchmark_master_jit.json
91+
# working-directory: master/benchmark/dist
92+
# # Run commit benchmark and compare with master
93+
# - name: Build benchmark Lua 5.3 commit
94+
# run: node ../../commit/dist/tstl.js -p tsconfig.53.json
95+
# working-directory: commit/benchmark
96+
# - name: Run benchmark Lua 5.3 commit
97+
# id: benchmark-lua-commit
98+
# run: lua5.3 -- run.lua ../data/benchmark_master_vs_commit_53.json ../data/benchmark_master_53.json
99+
# working-directory: commit/benchmark/dist
100+
# - name: Build benchmark LuaJIT commit
101+
# run: node ../../commit/dist/tstl.js -p tsconfig.jit.json
102+
# working-directory: commit/benchmark
103+
# - name: Run benchmark LuaJIT commit
104+
# id: benchmark-jit-commit
105+
# run: luajit -- run.lua ../data/benchmark_master_vs_commit_jit.json ../data/benchmark_master_jit.json
106+
# working-directory: commit/benchmark/dist
107+
# - name: Combine benchmark results
108+
# id: script-combine-results
109+
# uses: actions/github-script@v3
110+
# with:
111+
# benchmark-result-path-lua: commit/benchmark/data/benchmark_master_vs_commit_53.json
112+
# benchmark-result-path-jit: commit/benchmark/data/benchmark_master_vs_commit_jit.json
113+
# result-encoding: string
114+
# script: |
115+
# const createBenchmarkCheck = require(`${process.env.GITHUB_WORKSPACE}/commit/.github/scripts/create_benchmark_check.js`);
116+
# return createBenchmarkCheck({ github, context, core });
117+
# - name: Benchmark results
118+
# run: echo "${{steps.script-combine-results.outputs.result}}" | glow -s dark -w 120 -

benchmark/src/util.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,21 @@ export function readFile(path: string): string {
3030
}
3131

3232
export function readAll(file: LuaFile): string {
33-
const content = file.read(_VERSION === "Lua 5.3" ? "a" : ("*a" as any)) as [string | undefined];
33+
const content = file.read(_VERSION === "Lua 5.3" ? "a" : ("*a" as any));
3434

35-
if (content[0]) {
36-
return content[0];
35+
if (content) {
36+
return content as string;
3737
}
3838
throw Error(`Can't readAll for file ${file}`);
3939
}
4040

4141
export function readDir(dir: string): string[] {
42-
const findHandle = io.popen(isWindows ? `dir /A-D /B ${dir}` : `find '${dir}' -maxdepth 1 -type f`);
42+
const [findHandle] = io.popen(isWindows ? `dir /A-D /B ${dir}` : `find '${dir}' -maxdepth 1 -type f`);
43+
44+
if (!findHandle) {
45+
throw new Error(`Failed to read dir ${dir}`);
46+
}
47+
4348
const findResult = readAll(findHandle);
4449

4550
if (!findHandle.close()) {

package-lock.json

Lines changed: 43 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"javascript-stringify": "^2.0.1",
6363
"jest": "^26.0.1",
6464
"jest-circus": "^25.1.0",
65-
"lua-types": "^2.8.0",
65+
"lua-types": "2.10.1",
6666
"lua-wasm-bindings": "^0.2.2",
6767
"prettier": "^2.3.2",
6868
"ts-jest": "^26.3.0",

src/LuaLib.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,27 @@ const luaLibDependencies: Partial<Record<LuaLibFeature, LuaLibFeature[]>> = {
9696
ArrayConcat: [LuaLibFeature.ArrayIsArray],
9797
ArrayFlat: [LuaLibFeature.ArrayConcat, LuaLibFeature.ArrayIsArray],
9898
ArrayFlatMap: [LuaLibFeature.ArrayConcat, LuaLibFeature.ArrayIsArray],
99-
Decorate: [LuaLibFeature.CloneDescriptor],
99+
Decorate: [LuaLibFeature.ObjectGetOwnPropertyDescriptor, LuaLibFeature.SetDescriptor, LuaLibFeature.ObjectAssign],
100+
DelegatedYield: [LuaLibFeature.StringAccess],
100101
Delete: [LuaLibFeature.ObjectGetOwnPropertyDescriptors],
101-
Error: [LuaLibFeature.New, LuaLibFeature.Class],
102+
Error: [LuaLibFeature.Class, LuaLibFeature.ClassExtends, LuaLibFeature.New],
102103
FunctionBind: [LuaLibFeature.Unpack],
103104
Generator: [LuaLibFeature.Symbol],
104105
InstanceOf: [LuaLibFeature.Symbol],
105106
Iterator: [LuaLibFeature.Symbol],
107+
NumberToString: [LuaLibFeature.StringAccess],
106108
ObjectDefineProperty: [LuaLibFeature.CloneDescriptor, LuaLibFeature.SetDescriptor],
107109
ObjectFromEntries: [LuaLibFeature.Iterator, LuaLibFeature.Symbol],
110+
ParseFloat: [LuaLibFeature.StringAccess],
111+
ParseInt: [LuaLibFeature.StringSubstr, LuaLibFeature.StringSubstring],
112+
SetDescriptor: [LuaLibFeature.CloneDescriptor],
113+
StringSplit: [LuaLibFeature.StringSubstring, LuaLibFeature.StringAccess],
114+
SymbolRegistry: [LuaLibFeature.Symbol],
108115
Map: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
109116
Set: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
110117
WeakMap: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
111118
WeakSet: [LuaLibFeature.InstanceOf, LuaLibFeature.Iterator, LuaLibFeature.Symbol, LuaLibFeature.Class],
112-
Spread: [LuaLibFeature.Iterator, LuaLibFeature.Unpack],
113-
StringSplit: [LuaLibFeature.StringSubstring, LuaLibFeature.StringAccess],
114-
SymbolRegistry: [LuaLibFeature.Symbol],
119+
Spread: [LuaLibFeature.Iterator, LuaLibFeature.StringAccess, LuaLibFeature.Unpack],
115120
};
116121
/* eslint-enable @typescript-eslint/naming-convention */
117122

src/lualib/ArrayIsArray.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
declare type NextEmptyCheck = (this: void, table: any, index: undefined) => unknown | undefined;
2+
13
function __TS__ArrayIsArray(this: void, value: any): value is any[] {
24
// Workaround to determine if value is an array or not (fails in case of objects without keys)
35
// See discussion in: https://github.com/TypeScriptToLua/TypeScriptToLua/pull/7

src/lualib/ArrayReduce.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// https://www.ecma-international.org/ecma-262/9.0/index.html#sec-array.prototype.reduce
2-
function __TS__ArrayReduce<T>(
2+
function __TS__ArrayReduce<TElement, TAccumulator>(
33
this: void,
4-
arr: T[],
5-
callbackFn: (accumulator: T, currentValue: T, index: number, array: T[]) => T,
6-
...initial: T[]
7-
): T {
4+
arr: TElement[],
5+
callbackFn: (accumulator: TAccumulator, currentValue: TElement, index: number, array: TElement[]) => TAccumulator,
6+
...initial: TAccumulator[]
7+
): TAccumulator {
88
const len = arr.length;
99

1010
let k = 0;
11-
let accumulator = undefined;
11+
let accumulator: TAccumulator = undefined;
1212

1313
// Check if initial value is present in function call
1414
if (select("#", ...initial) !== 0) {
15-
accumulator = select(1, ...initial);
15+
[accumulator] = select(1, ...initial);
1616
} else if (len > 0) {
17-
accumulator = arr[0];
17+
accumulator = arr[0] as unknown as TAccumulator;
1818
k = 1;
1919
} else {
2020
throw "Reduce of empty array with no initial value";

src/lualib/ArrayReduceRight.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// https://www.ecma-international.org/ecma-262/9.0/index.html#sec-array.prototype.reduce
2-
function __TS__ArrayReduceRight<T>(
2+
function __TS__ArrayReduceRight<TElement, TAccumulator>(
33
this: void,
4-
arr: T[],
5-
callbackFn: (accumulator: T, currentValue: T, index: number, array: T[]) => T,
6-
...initial: T[]
7-
): T {
4+
arr: TElement[],
5+
callbackFn: (accumulator: TAccumulator, currentValue: TElement, index: number, array: TElement[]) => TAccumulator,
6+
...initial: TAccumulator[]
7+
): TAccumulator {
88
const len = arr.length;
99

1010
let k = len - 1;
11-
let accumulator = undefined;
11+
let accumulator: TAccumulator = undefined;
1212

1313
// Check if initial value is present in function call
1414
if (select("#", ...initial) !== 0) {
15-
accumulator = select(1, ...initial);
15+
[accumulator] = select(1, ...initial);
1616
} else if (len > 0) {
17-
accumulator = arr[k];
17+
accumulator = arr[k] as unknown as TAccumulator;
1818
k -= 1;
1919
} else {
2020
throw "Reduce of empty array with no initial value";

src/lualib/ArraySplice.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// https://www.ecma-international.org/ecma-262/9.0/index.html#sec-array.prototype.splice
2-
function __TS__ArraySplice<T>(this: void, list: T[], ...args: unknown[]): T[] {
2+
function __TS__ArraySplice<T>(this: void, list: T[], ...args: T[]): T[] {
33
const len = list.length;
44

55
const actualArgumentCount = select("#", ...args);
6-
const start = select(1, ...args) as number;
7-
const deleteCount = select(2, ...args) as number;
6+
const start = select(1, ...args)[0] as unknown as number;
7+
const deleteCount = select(2, ...args)[0] as unknown as number;
88

99
let actualStart: number;
1010

@@ -67,7 +67,7 @@ function __TS__ArraySplice<T>(this: void, list: T[], ...args: unknown[]): T[] {
6767

6868
let j = actualStart;
6969
for (const i of $range(3, actualArgumentCount)) {
70-
list[j] = select(i, ...args) as T;
70+
list[j] = select(i, ...args)[0];
7171
j++;
7272
}
7373

0 commit comments

Comments
 (0)