Skip to content

Scope loop flags and specialization thisType override to local contexts (A6 phase 2a)#211

Merged
ASDAlexander77 merged 1 commit into
mainfrom
refactor/gencontext-constcast-p2a
Jul 12, 2026
Merged

Scope loop flags and specialization thisType override to local contexts (A6 phase 2a)#211
ASDAlexander77 merged 1 commit into
mainfrom
refactor/gencontext-constcast-p2a

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

A6 phase 2 (copy-on-override), first field group — and both converted sites turned out to be live examples of the latent-leak bug class the plan predicted.

  • Loop flags. DoStatement/WhileStatement/ForStatement now set isLoop/loopLabel on a local loopGenContext passed to their condition/body/incrementor generation (including the for await async-execute body, which now copies from the loop context). Previously they mutated the caller's context through const_cast and never restored — after the first loop in a function, isLoop stayed true for all subsequent code, affecting the mlirGenDisposable LoopScope walk.
  • instantiateSpecializedFunction. The arrow/function-expression thisType = nullptr protection now applies to a function-local context copy (the whole body uses instantiateGenContext); previously the null leaked into the caller's context permanently, which could break this access in code following a generic-arrow instantiation inside a method.

Deliberately unchanged: loopLabel is still assigned after label was cleared (always empty — pre-existing oddity, preserved; the label still reaches the loop op via LABEL_ATTR_NAME). Remaining const_cast sites are the mailbox-pattern fields (generatedStatements ×4, typeAliasMap ×2, mlirGenParameters thisType) for the next slice — those intentionally communicate upward and need honest signatures rather than copies.

Test plan

  • tslang rebuilt cleanly (vs2026 debug)
  • New smoke test covering for + break/continue, while + break, do-while, and nested labeled continue outer — JIT output 12 4 3 3 as expected
  • All eight prior smoke tests identical
  • MLIRGenTests.exe: 12/12 pass

🤖 Generated with Claude Code

@ASDAlexander77 ASDAlexander77 merged commit e47fa7a into main Jul 12, 2026
2 checks passed
@ASDAlexander77 ASDAlexander77 deleted the refactor/gencontext-constcast-p2a branch July 12, 2026 15:22
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