Table lookup collision lint and safe table indexing#2252
Merged
Conversation
These files are regenerated every time das2rst runs and don't need to be tracked. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add table_lookup_collision (40216) lint error detecting multiple lookups of the same table in a single expression (tab[a] = tab[b], fun(tab[a], tab[b]), etc.) - Add ExprAt::underDeref flag set by ExprRef2Value to mark value lookups as safe (no collision risk when result is copied out) - Change unsafe_table_lookup default to false. Single tab[key] is now safe; the linter catches the actually dangerous patterns - Fix crash when global variable init contains a table lookup (push/pop collision set in preVisitGlobalLetInit/visitGlobalLetInit) - Update language docs (tables.rst, unsafe.rst, options.rst) and generated stdlib docs (ExprAtFlags, CodeOfPolicies) - Add expect test: failed_table_lookup_collision.das (6 collision cases + 3 safe cases) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Exercises the push/pop fix in preVisitGlobalLetInit that prevented a crash when table lookups appeared in global variable initializers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The gitignore rule excludes generated RST files but the directory itself must exist for das2rst to write into it. Add .gitkeep so CI checkout has the directory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This reverts commit 697b722.
The write_to_detail macro handler runs during compilation, before das2rst main creates the directory. With detail/ gitignored, CI checkout has no directory to write into. Co-Authored-By: Claude Opus 4.6 <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
table_lookup_collision(40216) lint error that detects multiple lookups of the same table in a single expression (tab[a] = tab[b],fun(tab[a], tab[b]), etc.) — these cause undefined behavior because table insertion can rehash and invalidate referencesExprAt::underDerefflag, set byExprRef2Value, to mark value lookups as safe (no collision risk when the result is immediately copied out)unsafe_table_lookupdefault tofalse— singletab[key]is now safe; the linter catches the actually dangerous multi-lookup patternspreVisitGlobalLetInit/visitGlobalLetInit)doc/source/stdlib/detail/(generated by das2rst, no need to track)Test plan
failed_table_lookup_collision.das— 6 collision cases (copy, clone, move, field access, swap, function call) + 3 safe cases (different tables, value lookups, separate expressions)tests/language/suite to verify no regressions🤖 Generated with Claude Code