Skip to content

One scope table for a whole use-resolution, not one per level - #149

Merged
revarbat merged 1 commit into
mainfrom
nested-use-scope-table
Sep 6, 2026
Merged

revarbat merged 1 commit into
mainfrom
nested-use-scope-table

Conversation

@revarbat

@revarbat revarbat commented Sep 6, 2026

Copy link
Copy Markdown
Member

1.4.0 broke use <file>: a file used through another file resolved to undef.

echo(combo());   // ECHO: 107  ->  ECHO: undef

Cause

Moving scopes out of the nodes and into a ScopeTable (#148) made a table per buildScopes() call — and resolveUseScopes recurses, since each use builds its used file's own root Scope. Every level therefore made its own table and only the outermost was kept, so the evaluation had no scope recorded for any node of a used file.

While the scope lived in the node, the nested writes were visible to everyone by construction. In a per-level table they were thrown away.

Fix

The recursion threads one table through, and the outermost root adopts it (openscad_cpp_parser#8's buildScopesInto). Nothing about the include cache changes — the 9× speedup is unaffected.

How it was caught

BelfrySCAD's suite, not this one. All 1153 tests here passed. A nested-use case now lives here too, and it fails if the table stops being shared (verified by re-breaking it).

Verified

  • 1154 C++ tests, 648 parser, 31 binding
  • BelfrySCAD's 1296, BOSL2's 909

🤖 Generated with Claude Code

1.4.0 broke `use <file>`: a file used through another file resolved to
undef.

Moving scopes out of the nodes and into a ScopeTable made a table per
buildScopes() call, and resolveUseScopes recurses -- each `use` builds its
used file's own root Scope. Every level therefore made its own table and
only the outermost was kept, so the evaluation had no scope recorded for any
node of a used file. While the scope lived in the node, the nested writes
were visible to everyone by construction; in a per-level table they were
thrown away.

The recursion now threads one table through and the outermost root adopts it
(openscad_cpp_parser#8's buildScopesInto). Nothing about the include cache
changes.

Caught by BelfrySCAD's suite, not this one, which is why a nested-use case
now lives here too -- it fails if the table stops being shared.

1154 C++ tests, 648 parser, 31 binding, BelfrySCAD's 1296, BOSL2's 909.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@revarbat
revarbat merged commit cca1337 into main Sep 6, 2026
3 checks passed
@revarbat
revarbat deleted the nested-use-scope-table branch September 6, 2026 18:04
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