Skip to content

Commit d3aec5d

Browse files
committed
Exclude compiler-owned declarations however they got into the set.
The affected set is seeded from the functions which ask for a stack trace before any filtering happens, so filtering what the traversal adds missed an intrinsic seeded that way. Jass removed those and Lua did not, and on Lua the signature check then failed the build rather than letting the lowering quietly not happen - either way -lua -stacktraces was broken for that input. The removal now happens once, after both branches.
1 parent 24c4f73 commit d3aec5d

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imtranslation/StackTraceInjector2.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,23 @@ public void visit(ImFuncRef imFuncRef) {
124124
.filter((ImFunction f) ->
125125
!f.hasFlag(FunctionFlagEnum.IS_NATIVE)
126126
&& !f.hasFlag(FunctionFlagEnum.IS_BJ)
127-
&& !f.hasFlag(FunctionFlagEnum.IS_EXTERN)
128-
&& !isCompilerOwned(f))
127+
&& !f.hasFlag(FunctionFlagEnum.IS_EXTERN))
129128
.collect(Collectors.toCollection(() -> affectedFuncs));
130129
affectedFuncs.removeAll(configOnlyFuncs);
131130

132131
} else {
133132
for (ImFunction stackTraceUse : stackTraceGets.keys()) {
134133
callRelationTr.get(stackTraceUse).forEach(affectedFuncs::add);
135134
}
136-
affectedFuncs.removeIf(StackTraceInjector2::isCompilerOwned);
137135
}
138136

139137

138+
// After both branches, and after the seeding from stackTraceGets above: a declaration
139+
// the compiler owns is never instrumented, however it came to be in the set. Filtering
140+
// only what each branch adds would miss one seeded there by its own use of a stack trace,
141+
// and would then trip the check below rather than doing nothing.
142+
affectedFuncs.removeIf(StackTraceInjector2::isCompilerOwned);
143+
140144
passStacktraceParams(calls, affectedFuncs);
141145
addStackTracePush(calls, affectedFuncs);
142146
addStackTracePop(affectedFuncs);

de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/LuaTranslationTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,35 @@ public void stackTracesLeaveCompilerOwnedDeclarationsAlone() throws IOException
20732073
assertTrue("stack traces must actually be on", compiled.contains("wurst_stack_depth"));
20742074
}
20752075

2076+
/**
2077+
* The rule has to hold for an intrinsic which asks for a stack trace itself.
2078+
*
2079+
* <p>Such a function is seeded into the affected set before any filtering, so excluding only
2080+
* what the traversal adds would leave it instrumented - and the signature check would then
2081+
* fail the build rather than let the lowering quietly not happen. Either way `-lua
2082+
* -stacktraces` would be broken for this input.
2083+
*/
2084+
@Test
2085+
public void aCompilerOwnedDeclarationUsingAStackTraceIsStillLeftAlone() throws IOException {
2086+
test().testLua(true).stacktraces().withStdLib().lines(
2087+
"package Test",
2088+
"@compilerintrinsic public function wurstTraced(int a) returns string",
2089+
" return getStackTraceString() + a.toString()",
2090+
"init",
2091+
" print(wurstTraced(1))",
2092+
"endpackage");
2093+
2094+
String compiled = Files.toString(
2095+
new File("test-output/lua/LuaTranslationTests_aCompilerOwnedDeclarationUsingAStackTraceIsStillLeftAlone.lua"),
2096+
Charsets.UTF_8);
2097+
2098+
String signature = compiled.substring(compiled.indexOf("function wurstTraced"));
2099+
signature = signature.substring(0, signature.indexOf(")") + 1);
2100+
assertFalse("a compiler-owned declaration must not gain a trace parameter: " + signature,
2101+
signature.contains("stackPos"));
2102+
assertTrue("stack traces must actually be on", compiled.contains("wurst_stack_depth"));
2103+
}
2104+
20762105
@Test
20772106
public void keyedTableStaysNativeWithStackTraces() throws IOException {
20782107
test().testLua(true).stacktraces().inline().withStdLib().lines(keyedTableSource(

0 commit comments

Comments
 (0)