Skip to content

Propagate Lua target to compiletime interpreter - #1215

Merged
Frotty merged 13 commits into
masterfrom
migrate-compiletime-scalars
Aug 2, 2026
Merged

Propagate Lua target to compiletime interpreter#1215
Frotty merged 13 commits into
masterfrom
migrate-compiletime-scalars

Conversation

@Frotty

@Frotty Frotty commented Aug 1, 2026

Copy link
Copy Markdown
Member

What changed

  • Initialize MagicFunctions_isLua in the compiletime interpreter from the translator target.
  • Use an untracked interpreter write so the backend constant is not treated as user-mutated scalar state or replayed at runtime.
  • Evaluate lazy global initializers in an untracked scope so their ordinary side effects are not persisted and duplicated when runtime initialization repeats them.
  • Add Jass/Lua regressions for backend detection and lazy-initializer side effects.

Supported migration boundary

Compiletime-to-runtime state migration covers writes performed explicitly by compiletime functions.

Side effects encountered only while lazily evaluating a global initializer are intentionally not recorded for migration, because runtime executes that initializer again. Compiletime-only side effects hidden inside a lazy initializer are therefore unsupported; persistent mutation should be performed by an explicit compiletime function after initialization.

This boundary avoids speculative runtime re-execution and keeps initializer ordering and side-effect behavior deterministic.

Why

-lua correctly reached RunArgs and ImTranslator, but the compiletime interpreter lazily evaluated the source declaration of MagicFunctions.isLua, whose Jass-safe default is false. Compiletime functions therefore observed Jass mode even for Lua builds.

Separately, tracking side effects produced by lazy initializer evaluation caused those writes to be replayed before runtime repeated the initializer, duplicating state.

Validation

  • LuaBackendAuditTests.compiletimeInterpreterSeesLuaTarget
  • complete CompiletimeTests
  • complete LuaBackendAuditTests
  • complete Gradle test suite
  • git diff --check

@Frotty
Frotty marked this pull request as ready for review August 1, 2026 16:49

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb5abfa8ad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty
Frotty force-pushed the migrate-compiletime-scalars branch from cb5abfa to db672b6 Compare August 1, 2026 17:29
@Frotty

Frotty commented Aug 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a47851f196

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Aug 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 293d5d7e74

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 181aa19010

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/WurstOperator.java Outdated
@Frotty

Frotty commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 637f4ebc96

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/WurstOperator.java Outdated
@Frotty

Frotty commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f4406c845

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty

Frotty commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f23f12a851

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Frotty commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 439c74b1fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Frotty commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0332ef4e61

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Frotty commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 840fcca323

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Frotty commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fdbfb27b6b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +862 to +864
if (!writesAreTracked()) {
setArrayValUntracked(v, indexes, val);
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Track suppressed global-array writes

When a lazy initializer writes a global array before branching on it, this path applies the value without recording that the array was written while suppression was active. The runtime probe only checks the scalar-only wasWrittenWhileSuppressed, so it reconstructs the array from its declaration and may falsely classify the branch as runtime-divergent; for example, guard[0] = 1; if guard[0] == 1; counter++ persists counter and then increments it again during runtime initialization, producing 2. Fresh evidence beyond the earlier scalar prior-write report is that the new suppression marker does not cover arrays.

AGENTS.md reference: AGENTS.md:L75-L80

Useful? React with 👍 / 👎.

private static @Nullable ILconstBool evaluateRuntimeBooleanExpression(ImExpr expression,
ProgramState globalState,
LocalState localState) {
SideEffectAnalyzer effects = new SideEffectAnalyzer(globalState.getProg());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Cache side-effect analysis for runtime probes

Every suppressed if or exitwhen reaches this method, and each invocation creates a fresh SideEffectAnalyzer; the following calledNatives and usedVariables calls rebuild program-wide call-relation and used-global data. Consequently, a lazy initializer with N branch evaluations or loop iterations repeatedly scans the entire P-sized program, introducing O(NP) compile-time work where condition evaluation was previously local. Reuse analysis for the same ImProg rather than reconstructing it per condition.

AGENTS.md reference: AGENTS.md:L88-L91

Useful? React with 👍 / 👎.

Frotty commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 077589985a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (!effects.calledNatives(expression).isEmpty()) {
return null;
}
Set<ImVar> usedVariables = effects.usedVariables(expression);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve global initializer evaluation order

When a short-circuited runtime operand reads multiple lazily initialized globals whose initializers share state—for example, a = next(), b = next(), followed by compiletime or a < b—collecting the globals into an unordered Set and eagerly preparing them can initialize b before a, unlike the runtime's source/access order. The probe can consequently predict the opposite branch, persist its writes as compiletime-only, and then have runtime repeat those writes. Preserve deterministic initializer order, ideally by retaining lazy expression evaluation.

AGENTS.md reference: AGENTS.md:L77-L80

Useful? React with 👍 / 👎.

Comment on lines +179 to +180
if (sourceState.wasWrittenWhileSuppressed(variable)) {
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scope suppressed-write markers to each initializer

When an earlier lazy initializer performs an ordinary write such as guard = true, this permanent marker makes every later runtime probe involving guard unresolved. A later initializer using if compiletime or not guard therefore suppresses writes from its compiletime-selected arm even though runtime skips that arm, losing the migrated state. Fresh evidence beyond the prior-write report is that suppressedWrites persists across independent lazy initializers rather than representing only the runtime-equivalent state of the initializer currently being analyzed.

AGENTS.md reference: AGENTS.md:L77-L80

Useful? React with 👍 / 👎.

@Frotty
Frotty merged commit 16414af into master Aug 2, 2026
6 checks passed
@Frotty
Frotty deleted the migrate-compiletime-scalars branch August 2, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant