Fix correctness bugs and reduce hot-path allocations found in code review - #43
Merged
Merged
Conversation
- Location.Equals/GetHashCode now compare File + Position (was column-only, which made different lines with the same column compare equal and violated the equals/hash contract) - TypeChecker.VisitIf visits the else branch before reading its exit state, so definite-assignment sees terminating else branches correctly - Escape backslashes and string delimiters in generated Luau strings; emit an extra leading newline in long-bracket strings (Luau swallows the first) - RenderState.PopIndent uses Indent.Length instead of hardcoded 2 - Parser no longer silently swallows 'mut' when not followed by an array literal; 'for x : mut arr' still parses via a guard in ParseFor - TypeSolver.CheckCircular rebuilds unions/intersections so circular members are actually replaced with never (ref writes were lost through the lambda) - Lexer terminates string scanning at newlines so the unterminated-string diagnostic fires instead of silently spanning lines - Remove NodeId.Map (unbounded static node retention, unsynchronized Add); MustImportRuntimeLibrary now records intrinsic-ness at reference time - VisitAssignmentOperator bails gracefully on malformed nested assignments instead of throwing NRE/InvalidCastException - Orphaned <=/>= comparisons are no longer emitted as bare expression statements (invalid Luau) - DiagnosticBag fail-fast exits with a stable code instead of a randomized string hash - Guard Parser.Expect/PeekKind against out-of-range token indexing Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…stics - Gate BindType's per-node debug diagnostics (Simplify + formatted message + diagnostic hashing, which forced line/character resolution) behind the new TypeChecker.EmitDebugDiagnostics flag, default off - Type.IsNever/IsUnknown are pattern matches instead of full Equals calls through the static visited-set guard - Cache the empty MacroContext and classify invocation macro references once per visit instead of twice per identifier/property access - Replace LINQ Where/Cast/OrderBy chains in the Node constructor with plain loops and List.Sort (runs for every node constructed during parsing) - Cache Diagnostic.SourceLines instead of re-splitting the source per access - DiagnosticBag.ContainsErrors no longer allocates intermediate bags - Remove dead lexer code left over from the operator-trie migration (GetLiteralMatch, MatchesPatternAt, LiteralRulesByFirstCharacter) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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
A code review pass over the compiler surfaced a batch of correctness bugs and hot-path performance issues. This PR lands them in two commits: one
fix:commit for behavior bugs and oneperf:commit for allocation/overhead reductions.Correctness (
fix:commit)Location.Equalscompared only file + column, so positions on different lines with the same column were "equal", andGetHashCodedisagreed withEquals. Now both use file + position.TypeChecker.VisitIfread the else branch's exit state before visiting it, so a terminating else branch (else { return }) was invisible to definite-assignment merging.\or the quote delimiter, producing broken output; long-bracket strings also lost a leading newline (Luau swallows the first one after[[).RenderState.PopIndenthardcoded 2 characters, breaking any non-defaultIndent.mutin expression position when not followed by an array literal; it now reports a diagnostic (for x : mut arrstill parses).TypeSolver.CheckCircularlost itsrefwrites through a lambda copy, so circular union/intersection members were never replaced withnever.\n. Strings now terminate at newlines and the existing diagnostic fires (matches the existingLexerTestexpectation).NodeId.Mapretained every AST node ever constructed in an unsynchronized static dictionary. Removed;MustImportRuntimeLibraryrecords what it needs at reference time in the resolver instead.VisitAssignmentOperatorcould throw NRE/InvalidCastExceptionon malformed nested assignments instead of leaving a diagnostic.<=/>=comparisons were emitted as bare expression statements (invalid Luau) because the assignment check only excluded==/~=.1.Parser.Expect/PeekKindcould index out of range at position 0 / past the token list.Performance (
perf:commit)BindTyperanTypeSimplifier.Simplify, formatted a message, and hashed a debug diagnostic (forcing line/character resolution) for every node bind. Now gated behindTypeChecker.EmitDebugDiagnostics(default off) — this restores the benefit of the recent TextSpan work for the type-checking stage.Type.IsNever/IsUnknownare pattern matches instead ofEqualscalls through the static visited-set guard (twoHashSetoperations per call).MacroContextis cached and invocation-macro classification runs once per visit instead of twice per identifier/property access.Nodeconstruction uses plain loops +List.Sortinstead of LINQWhere/Cast/OrderBy/ToListchains.Diagnostic.SourceLinesis cached instead of re-splitting the whole file per access;DiagnosticBag.ContainsErrorsno longer allocates intermediate bags.Test plan
Locationequality contract, theVisitIfexit-state fix, string escaping, and the orphaned-mutdiagnostic).json_stringifyLuau snapshot was updated for the now-correct\\nescaping.🤖 Generated with Claude Code