Skip to content

Commit c1173c9

Browse files
authored
Keep Lua class field lifetime semantics aligned with Jass (#1276)
1 parent e655c11 commit c1173c9

6 files changed

Lines changed: 879 additions & 36 deletions

File tree

.github/workflows/build.yml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,15 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
jobs:
14-
# Emit a wider matrix on master pushes (adds macOS), narrow on PRs (saves minutes)
15-
setup:
16-
runs-on: ubuntu-latest
17-
outputs:
18-
matrix: ${{ steps.set-matrix.outputs.matrix }}
19-
steps:
20-
- id: set-matrix
21-
shell: bash
22-
run: |
23-
if [[ "${{ github.event_name }}" == "push" ]]; then
24-
echo 'matrix={"include":[{"os":"ubuntu-latest"},{"os":"windows-latest"},{"os":"macos-latest"},{"os":"macos-15-intel"}]}' >> "$GITHUB_OUTPUT"
25-
else
26-
echo 'matrix={"include":[{"os":"ubuntu-latest"},{"os":"windows-latest"}]}' >> "$GITHUB_OUTPUT"
27-
fi
28-
14+
# Master pushes exercise every supported host. Pull requests use one Linux job
15+
# so that the normal feedback loop does not spend four runner-minutes on the
16+
# same compiler test suite; the full host matrix still runs before release.
2917
build:
3018
name: Gradle build on ${{ matrix.os }}
31-
needs: setup
3219
strategy:
3320
fail-fast: false
34-
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
21+
matrix:
22+
os: ${{ fromJSON(github.event_name == 'push' && '["ubuntu-latest","windows-latest","macos-latest","macos-15-intel"]' || '["ubuntu-latest"]') }}
3523
runs-on: ${{ matrix.os }}
3624
permissions:
3725
checks: write
@@ -96,18 +84,28 @@ jobs:
9684
- name: Setup Gradle (cache)
9785
uses: gradle/actions/setup-gradle@v4
9886

99-
# ---- FAIL FAST: package first (so jlink issues show immediately) ----
87+
# Packaging is a release artifact, not a pull-request gate. Keeping it on
88+
# master avoids paying for a second full build on every PR update.
10089
- name: Package slim runtime (fail fast)
90+
if: github.event_name == 'push'
10191
shell: bash
10292
run: ./gradlew packageSlimCompilerDist --no-daemon --stacktrace
10393

10494
- name: Prepare bundled Lua runtime (Linux)
10595
if: runner.os == 'Linux'
10696
shell: bash
10797
run: |
108-
if [[ -f src/test/resources/lua53 ]]; then
109-
chmod +x src/test/resources/lua53
110-
fi
98+
set -euo pipefail
99+
# Use Ubuntu's maintained Lua 5.3 build. The checked-in portable
100+
# binary is linked against libreadline.so.6, which is absent from
101+
# current runner images.
102+
sudo apt-get update -qq
103+
sudo apt-get install -y --no-install-recommends lua5.3
104+
lua5.3 -e 'assert(_VERSION == "Lua 5.3")'
105+
luac5.3 -v
106+
# These binaries are tracked with mode 0644 for cross-platform
107+
# checkouts; keep them usable as a fallback for local/older images.
108+
chmod +x src/test/resources/lua53 src/test/resources/luac53
111109
112110
- name: Install Lua compiler (macOS)
113111
if: runner.os == 'macOS'
@@ -119,14 +117,14 @@ jobs:
119117
- name: Run tests
120118
shell: bash
121119
run: |
122-
if [[ "${{ runner.os }}" == "Linux" ]]; then
120+
if [[ "${{ github.event_name }}" == "push" && "${{ runner.os }}" == "Linux" ]]; then
123121
./gradlew test jacocoTestReport --no-daemon --stacktrace --quiet
124122
else
125123
./gradlew test --no-daemon --stacktrace --quiet
126124
fi
127125
128126
- name: Upload coverage to Coveralls
129-
if: runner.os == 'Linux'
127+
if: github.event_name == 'push' && runner.os == 'Linux'
130128
uses: coverallsapp/github-action@v2
131129
with:
132130
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -157,6 +155,7 @@ jobs:
157155
retention-days: 14
158156

159157
- name: Upload packaged artifact (per-OS)
158+
if: github.event_name == 'push'
160159
uses: actions/upload-artifact@v4
161160
with:
162161
name: wurst-compiler-${{ matrix.os }}

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/lua/translation/LuaTranslator.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ public LuaVariable initFor(ImClass a) {
207207
* per canonical IM field, indexed by that id; class descriptors remain static tables and are
208208
* reached through {@link #objectClass}. Allocation therefore creates no per-instance table.
209209
*
210-
* <p>Destroy clears every field slot before putting the id on the free stack. As in the Jass
211-
* backend, a stale reference aliases a later object after that id is recycled; before reuse its
210+
* <p>Destroy only removes the live-object descriptor before putting the id on the free stack.
211+
* Field storage intentionally retains its value, matching the Jass backend's array-backed
212+
* fields. A stale reference aliases a later object after that id is recycled; before reuse its
212213
* descriptor is absent, so virtual dispatch fails and {@code instanceof} is false. Capturing
213214
* closures use the same representation and, like Jass closures, retain their id until destroyed.
214215
*/
@@ -1031,12 +1032,6 @@ private void translateClass(ImClass c) {
10311032
LuaFunction cleanup = luaClassCleanup.getFor(c);
10321033
LuaVariable object = LuaAst.LuaVariable("object", LuaAst.LuaNoExpr());
10331034
cleanup.getParams().add(object);
1034-
for (ImVar field : collectFieldsForAllocation(c)) {
1035-
cleanup.getBody().add(LuaAst.LuaAssignment(
1036-
LuaAst.LuaExprArrayAccess(LuaAst.LuaExprVarAccess(fieldStorage(field)),
1037-
LuaAst.LuaExprlist(LuaAst.LuaExprVarAccess(object))),
1038-
LuaAst.LuaExprNull()));
1039-
}
10401035
luaModel.add(cleanup);
10411036
deferMainInit(LuaAst.LuaAssignment(
10421037
LuaAst.LuaExprFieldAccess(LuaAst.LuaExprVarAccess(classVar), "__wurst_dealloc"),

0 commit comments

Comments
 (0)