Skip to content

Keep a loop through ExecuteFunc apart - #1488

Merged
Frotty merged 1 commit into
masterfrom
fix-execute-func-cycles
Oct 17, 2026
Merged

Frotty merged 1 commit into
masterfrom
fix-execute-func-cycles

Conversation

@Frotty

@Frotty Frotty commented Oct 17, 2026

Copy link
Copy Markdown
Member

CyclicFunctionRemover merged functions which reach each other only through ExecuteFunc into one function with a funcChoice parameter, and turned each ExecuteFunc into a direct call of it. So the target no longer ran on a new thread with its own op limit, which is what ExecuteFunc is for. A loop through ExecuteFunc needs no merging: the call finds its target by name when it runs, so nothing has to be declared first. The cycle search now follows only the edges which order the functions (UsedFunctions.orderingRelevantTargets: calls other than ExecuteFunc, function references, method calls).

That exposed a second case in the Jass emitter: a cycle of one ExecuteFunc and one ordinary call back (valid Jass) was reported as a cyclic dependency, because the traversal descended into the ExecuteFunc target while its caller was still on the stack. Such a target is now queued and translated after the ordered traversal, and it takes its place in the script when it is translated rather than when its caller first names it; otherwise it would land before a function it calls (pjass: Undeclared function outer, checked by removing that half). No other function moves, since only an ExecuteFunc target can be named before it is translated.

The Lua backend does not use either of these.

Tests in BugTests, all red before the change (pjass on): executeFuncLoopIsNotMergedIntoOneFunction (no_opts, inlopt, stacktraceinlopt), executeFuncTargetCallingBackIntoItsCallerCompiles (Jass unit), executeFuncTargetCallingBackAboveItsCallerCompiles. Green locally (Windows): BugTests, OptimizerTests, ClassesTests, DispatchImplementationTests, NewFeatureTests, ModuleTests, ClosureTests, DeterministicChecks.

CyclicFunctionRemover merged functions which reach each other only
through ExecuteFunc into one function, which turned each ExecuteFunc
into a direct call: the new thread and its own op limit were gone. A
loop through ExecuteFunc needs no merging, since ExecuteFunc finds its
target by name when it runs.

Leaving such a loop apart reached the Jass emitter with a cycle of one
ExecuteFunc and one ordinary call, which it reported as a cyclic
dependency although it is valid Jass. An ExecuteFunc target is now
emitted after the ordered traversal, and takes its place in the script
when it is translated rather than when its caller names it, so it comes
after the functions it calls.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T16:58:21.604381Z 3a1df21 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Frotty
Frotty merged commit 22dd09f into master Oct 17, 2026
2 checks passed
@Frotty
Frotty deleted the fix-execute-func-cycles branch October 17, 2026 17:33
@Frotty

Frotty commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

Measured on the 3.0.0 client, with a Jass map built by master before and after this change (-inline -localOptimizations): two functions which call each other through ExecuteFunc, 20 rounds of 25,000 loop iterations, started from a timer. Before the change the merged function stopped after 9 rounds, at the op limit of its one thread; with it all 21 calls ran. A cycle of one ExecuteFunc and one call back loads and runs in the game (3 calls).

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