Refactor debug package to inline funcs everywhere#3145
Open
jakebailey wants to merge 22 commits intomainfrom
Open
Refactor debug package to inline funcs everywhere#3145jakebailey wants to merge 22 commits intomainfrom
jakebailey wants to merge 22 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the internal/debug assertion utilities to use generics + “mid-stack inlining” patterns, and updates call sites across the compiler/LS to the new APIs with the goal of making debug assertions cheaper (potentially always-on).
Changes:
- Replaced reflect-based “defined/nil” assertions with generic
Assert/AssertZero/CheckNonZeroand ordered comparisons. - Updated many assertion call sites to use boolean expressions or direct non-zero checks instead of specialized helpers (
AssertNode,AssertIsDefined, etc.). - Removed/renamed debug helpers and adjusted transformer/checker/LS/printer/format code accordingly.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/debug/assert.go | New generic assertion APIs + slow-path outlining for inlining. |
| internal/debug/noassert.go | Updated no-op implementations to match new debug API surface. |
| internal/transformers/estransforms/optionalchain.go | Replaced AssertNotNode usage with explicit boolean assertions. |
| internal/transformers/estransforms/objectrestspread.go | Replaced AssertNode with Assert(ast.IsX(...)) style checks. |
| internal/transformers/estransforms/esdecorator.go | Updated various assertions to new debug.Assert usage. |
| internal/transformers/estransforms/classfields.go | Updated assertions; one site replaced an assert-only helper with FailBadSyntaxKind. |
| internal/printer/namegenerator.go | Updated identifier-kind assertion. |
| internal/printer/factory.go | Updated computed temp variables assertion to Assert/non-zero pattern. |
| internal/ls/inlay_hints.go | Updated type node “must exist” assertions. |
| internal/ls/importTracker.go | Replaced CheckDefined with CheckNonZero. |
| internal/ls/findallreferences.go | Updated symbol/value declaration assertions. |
| internal/ls/completions.go | Updated assertions including AssertZero for nil tokens. |
| internal/ls/change/delete.go | Updated various “must exist” assertions. |
| internal/ls/callhierarchy.go | Updated declaration-name “must exist” assertion. |
| internal/ls/autoimport/import_adder.go | Updated parent-module-symbol assertion. |
| internal/ls/autoimport/fix.go | Updated assertions for nil/default-import/type-only import handling. |
| internal/format/span.go | Updated list presence assertion for formatting span processing. |
| internal/format/indent.go | Updated else-keyword presence assertion. |
| internal/checker/nodebuilderscopes.go | Updated scope assertions; replaced optional-node helper with explicit condition. |
| internal/checker/nodebuilderimpl.go | Replaced CheckDefined usage with explicit non-nil assertion. |
| internal/checker/jsx.go | Updated inference-context assertion. |
| internal/checker/checker.go | Updated multiple “must exist” assertions (symbols, declarations, type params, etc.). |
You can also share your feedback on Copilot code review. Take the survey.
01dbb62 to
00e75ce
Compare
Member
Author
|
I'm refactoring this package even more, down to just having |
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.
I've been wanting to see if we can speed up the debug asserts such that they could be always on.
To do this I've made a few changes to satisfy the Go compiler:
reflectfor checkingnil-ness.Regarding "function outlining", the pattern is to do something like this:
Go supports "mid stack inlining", where instead of it just being leaf functions that can be inlined, small functions in the middle can be inlined. In this case, restructuring such that the slow code is in another function lets the compiler inline the outer function in its caller, which is typically just a branch (which, should always predict false).
Now, when calling these,
-m=2says things like:The PR's been updated to go further. Now there is just
debug.Assert. Asserts are now always enabled.