Skip to content

fix: cache compiled programs by predeclared name set (SLT-17)#73

Merged
vt128 merged 1 commit into
masterfrom
fix/slt-17-cache-key
Jun 13, 2026
Merged

fix: cache compiled programs by predeclared name set (SLT-17)#73
vt128 merged 1 commit into
masterfrom
fix/slt-17-cache-key

Conversation

@vt128

@vt128 vt128 commented Jun 13, 2026

Copy link
Copy Markdown
Member

What

Cache.Run keyed its compiled-program cache (c.scripts) by filename only, but SourceProgramOptions resolves each identifier as predeclared vs global against the current predeclared name set (dict.Has). So running the same file under a different set of globals reused a stale program:

  • first Run("p.star", {"x":1}) compiles out = x with x predeclared → ok;
  • then Run("p.star", nil) reuses that program and fails at run time with internal error: predeclared variable x is uninitialized (or, in the reverse direction, silently reuses a program resolved under the wrong name set).

This is the starlight twin of the issue already fixed in starlet's exec.go getCacheKey.

Fix

Fold the sorted predeclared name set into the cache key (scriptCacheKey); the dialect is fixed (dialectOptions), so filename + names suffices. Forget now drops every key belonging to a filename (a file may have several entries, one per distinct global-name set).

Test-first

TestCachePredeclaredNameSet reproduces the stale-program internal error before the fix and pins the corrected behavior (clean undefined: x resolve error; same-name-set runs still hit the cache).

Verification

go test -race -count=2 ./..., go vet, gofmt -l clean, and the Docker golang:1.19 race run all green.

Backlog: SLT-17

Cache.Run keyed c.scripts by filename only, but SourceProgramOptions
resolves each identifier as predeclared vs global against the current
global-name set (dict.Has). Running the same file under a different set
of globals reused a stale program: it failed at run time with "internal
error: predeclared variable X is uninitialized", or silently reused a
program that was resolved under the wrong name set.

Fold the sorted predeclared name set into the cache key (the dialect is
fixed, so filename + names suffice) and update Forget to drop every key
belonging to a filename. Mirrors starlet's exec.go getCacheKey.

Test-first: TestCachePredeclaredNameSet reproduces the stale-program
internal error before the fix. Backlog: SLT-17.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Jun 13, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 14 complexity · 0 duplication

Metric Results
Complexity 14
Duplication 0

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.16% coverage variation

Metric Results
Coverage variation +0.16% coverage variation (-1.00%)
Diff coverage 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (300e254) 2124 1915 90.16%
Head commit (3da891e) 2139 (+15) 1932 (+17) 90.32% (+0.16%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#73) 19 19 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.32%. Comparing base (300e254) to head (3da891e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #73      +/-   ##
==========================================
+ Coverage   87.12%   87.32%   +0.19%     
==========================================
  Files           8        8              
  Lines        1662     1672      +10     
==========================================
+ Hits         1448     1460      +12     
+ Misses        131      130       -1     
+ Partials       83       82       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vt128 vt128 merged commit bde646d into master Jun 13, 2026
14 checks passed
@vt128 vt128 deleted the fix/slt-17-cache-key branch June 13, 2026 06:50
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