perf: fix O(n²) descendant traversal + close #33 (disallow Luau keywords)#59
Merged
Conversation
Analyze() stopped invoking AnalyzeStatements/BindState on the tree entirely, so _states was never populated and every flow-dependent diagnostic (unreachable code, use of uninitialized/maybe-uninitialized variables, assignment to immutable bindings) silently stopped firing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
FlowAnalyzer.AnalyzeStatement had no case for EnumDeclaration (unlike InterfaceDeclaration/EventDeclaration, which both mark their own symbol as initialized), so referencing an enum after declaring it incorrectly tripped "use of uninitialized variable". No existing test exercised an enum declaration through the full pipeline, so this went unnoticed. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Declaring a variable, function, parameter, interface, or trait whose
name is a reserved Luau keyword (and/or, break, do, ..., continue) now
raises a diagnostic in Resolver.DeclareSymbol, since that name would be
invalid wherever Luau emits it literally. Ambient (declare ...) names
are checked too, since their emitted forms (e.g. an interface's `type
X = {...}` alias) are still real Luau text. Enum member names are
exempt: they're always constant-folded to literal values at compile
time and never appear in emitted Luau as an identifier (verified via
LuauGenerator/enum codegen). `self` is intentionally not included.
Renamed the one existing "function" parameter collision (a name used
across several Roblox API method signatures, e.g. BindToRenderStep) to
"callback" in the TypeGenerator's RenameMap and regenerated the shipped
None.loom/PluginSecurity.loom intrinsics to match - otherwise every
compile would immediately fail on the compiler's own bundled bindings.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
PropertyAccess.Render always emitted dot-access (instance.name), with no fallback for a name that's a reserved Luau keyword, which would be invalid Luau (instance.end vs. the required instance["end"]). Each segment in the access chain is now checked against LuauFactory.Keywords and rendered as bracket/string-indexed access when it collides, leaving non-colliding segments untouched. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Qodana for .NET245 new problems were found
☁️ View the detailed Qodana report Detected 1 dependencyThird-party software listThis page lists the third-party software dependencies used in Loom
Contact Qodana teamContact us at qodana-support@jetbrains.com
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Continued hot-path cleanup, plus GitHub issue #33.
Perf
Node.GetDescendants()rebuilt/copied at every level of recursion (O(n²) for deep or chain-like subtrees) — rewritten as a single-pass BFS traversal.TypeChecker.GetReturnTypewalked the entire subtree of a function body (including nested function bodies) viaGetDescendants<Return>(), then filtered back down via an ancestor check — replaced with a bounded traversal that stops at nestedFunctionDeclarationboundaries.Bugs found and fixed along the way
FlowAnalyzer.Analyze()had stopped invoking the actual analysis pass entirely (a droppedBindState(...)call), so every flow-dependent diagnostic — unreachable code, use of uninitialized/maybe-uninitialized variables, assignment to immutable bindings — had silently stopped firing.FlowAnalyzerhad no case forEnumDeclaration(unlikeInterfaceDeclaration/EventDeclaration, which both mark their own symbol as initialized), so referencing an enum after declaring it incorrectly tripped "use of uninitialized variable". No existing test exercised an enum through the full pipeline, so this went unnoticed until flow analysis was actually running again.Issue #33 — disallow Luau keywords as declaration names
LuauFactory.Keywordsset (the 21 standard Lua/Luau keywords + Luau'scontinue).Resolver.DeclareSymbolnow rejects declaring a variable, function, parameter, interface, or trait whose name collides — including inside ambientdeclare ...signatures, since their emitted forms (e.g. an interface'stype X = {...}alias) are still real Luau text.selfis intentionally excluded (not a real collision case).function-named parameter used across several Roblox API bindings (e.g.BindToRenderStep) — renamed tocallbackin the TypeGenerator's rename map and regeneratedNone.loom/PluginSecurity.loomto match, otherwise every compile would have immediately failed against the compiler's own bundled bindings.PropertyAccess.Renderalways emitted dot-access with no bracket-access fallback for a keyword-colliding property name — fixed per-segment.Test plan
dotnet build— succeeds, no warningsdotnet test— 1798/1798 pass (1783 existing + 15 new, covering the new diagnostic, the ambient/enum exemptions, the two flow-analysis fixes, and the bracket-access rendering)Loom.CLIbefore/after the perf changes — output byte-identicallet/fn/parameter/interface (including insidedeclare) now errors with the new diagnostic; an enum with a keyword-named member still compiles and constant-folds correctlyCloses #33
🤖 Generated with Claude Code