Skip to content

fix(check): read the ~ operator sites the parser records instead of walking the tree - #566

Merged
HuiJun merged 3 commits into
developfrom
fix/undefined-operator-walk
Sep 24, 2026
Merged

HuiJun merged 3 commits into
developfrom
fix/undefined-operator-walk

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What and why

UndefinedOperatorPass found every ~x by running ast.Inspect, a reflection-based walk over every node of every document, on each analysis. A CPU profile of BenchmarkLoadModel/elements=1000 put that walk at 7.6% of total load time, about 40% of the validate slowdown against 0.8.1, for a warning that almost never fires.

The parser is the one place that builds an OpBitNot expression (parseUnary), so it now records those sites and the pass reads the list:

type RootNamespace struct {
    Members            []Node
    UndefinedOperators []*OperatorExpr // `~` expressions in source order
}
  • Parser.undefinedOps is appended in parseUnary; parseCheckpoint carries its length and restore truncates it, so an abandoned try-parse leaves nothing behind; ParseFile hands the list to the root.
  • astcodec encodes/decodes the field for RootNamespace (typed pointer slice, same pattern as regions/ends), so the on-disk index cache keeps it. The embedded stdlib.snapshot is regenerated for the format change.
  • UndefinedOperatorPass.Run iterates root.UndefinedOperators; level, code and message are unchanged.

ast.Inspect stays: the export tests, hygiene tests and the doc-counts census still use it.

BenchmarkLoadModel/elements=1000 (-benchtime 20x, -count 3): develop 108.2/111.8/120.8 ms → 103.2/103.3/106.6 ms, about 7% faster.

How it was verified

  • New TestUndefinedOperators* in internal/syntax/parser: source order, nested ~~x, positions inside calc bodies and invocation arguments.
  • New tests/parser fixture undefined-operator.sysml (golden added) and TestUndefinedOperatorsCoversFixtures, which parses every parse fixture and checks the recorded list against an independent reflective count of OpBitNot nodes.
  • Existing undefined_operator_test.go passes unchanged; astcodec round-trip/sharing tests pass.
  • gofmt -l . empty, go build ./..., go vet ./..., go test ./internal/syntax/... ./internal/check/... ./tests/parser ./internal/workspace/..., TestStdlibConformance, python3 scripts/changelog.py check.

Checklist

  • make test and make lint pass locally
  • Tests added or updated for the change
  • Documentation extended where it already covers the surface (see CONTRIBUTING.md)
  • Changelog entry added as changes/unreleased/<slug>.<section>.md, not as an edit to CHANGELOG.md
  • baselines regenerated and make docs-counts run if a gate count moved (compliance rows need nothing: the census is counted at docs build)
  • No internal work-item labels (waves, slices, F4, K5) in the body, docs, or changelog

…alking the tree

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review September 24, 2026 19:25
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration Bot and others added 2 commits September 24, 2026 19:29
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
@HuiJun
HuiJun merged commit 1d02c68 into develop Sep 24, 2026
15 checks passed
@HuiJun
HuiJun deleted the fix/undefined-operator-walk branch September 24, 2026 20:17
@devin-ai-integration devin-ai-integration Bot mentioned this pull request Sep 24, 2026
6 tasks
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