Skip to content

fix: store each imported file's source once per artifact - #450

Closed
mr-zwets wants to merge 1 commit into
nextfrom
fix/dedupe-debug-sources
Closed

mr-zwets wants to merge 1 commit into
nextfrom
fix/dedupe-debug-sources

Conversation

@mr-zwets

Copy link
Copy Markdown
Member

Opened on behalf of Mathieu G. (mr-zwets) by Claude Opus 5.5.

Closes #449

Why this matters

Every debug frame of an imported function or constant carried the full text of its declaring file, so an artifact embedded that file once per distinct definition it used. On ParyonUSD V2 (31 contracts, shared constants.cash / identifiers.cash), compiling with this branch takes the artifacts from 814 KB to 558 KB (-31%, the largest from 77 KB to 41 KB), with identical bytecode.

What changes

  • Compiler: frames keep only sourceFile, and the artifact keeps each imported file's text once in debug.sources: { [sourceFile]: string }. Omitted when nothing is imported.
  • Unique names: sourceFile was not unique per file. The disk resolver names a package file by the path after the last node_modules/, so a local ./pkg/math.cash and the package pkg/math.cash, or two nested copies of one package, got the same name. Names are now assigned once the import graph is collected: any name held by more than one file is replaced by each file's path relative to the contract, repeated until no name is shared (a replacement can meet another file's short name when the contract itself sits in node_modules). Names that don't clash are unchanged.
  • Readers: the new getDebugFrameSource(sources, frame) export of @cashscript/utils is used by the SDK's frame resolution and the BitAuth IDE rendering. It still accepts the per-frame source written by 0.14.0-next.1 to next.5, so those artifacts keep debugging correctly. DebugFrame.source stays in the type, marked deprecated; happy to drop it instead if you'd rather not carry it into 0.14.0.
  • TS artifacts: object keys that are not identifiers are quoted, since debug.sources keys are file names. No existing artifact output changes.
  • Docs (compiler/artifacts.md) and a release-notes line.

Tests

  • cashc: one copy of a file however many of its definitions are used; no debug.sources without imports; distinct names for the local/package clash and for a contract inside node_modules (new clash/ fixtures); diamond fixture and provenance assertions updated.
  • SDK: an artifact in the old per-frame layout still gives the right failing-require message, failing statement and BitAuth rendering.
  • utils: getDebugFrameSource and TS key quoting.
  • yarn build, yarn lint, yarn spellcheck and yarn test pass.

Every debug frame of an imported function or constant carried the full
text of its declaring file, so an artifact embedded that file once per
distinct definition it used. The text now lives once in `debug.sources`,
keyed by the frames' `sourceFile`. Readers resolve a frame's text through
`getDebugFrameSource`, which still accepts the per-frame `source` of
artifacts from earlier 0.14.0-next pre-releases.

Since frames now share one entry per `sourceFile`, two different files
must never get the same name. The short package path could collide with
a local file or another installed copy of the package, so any name held
by more than one imported file is replaced by each file's path relative
to the contract, repeated until no name is shared. Names that don't
clash are unchanged.

TS artifacts quote object keys that are not identifiers, since the
`debug.sources` keys are file names.

Closes #449

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cashscript Ready Ready Preview Sep 24, 2026 1:03pm UTC

Request Review

@codecov

codecov Bot commented Sep 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.22%. Comparing base (9f7662b) to head (3b0125c).

Files with missing lines Patch % Lines
packages/cashc/src/dependency-resolution.ts 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next     #450      +/-   ##
==========================================
+ Coverage   88.63%   89.22%   +0.58%     
==========================================
  Files          61       61              
  Lines        4980     5002      +22     
  Branches      922      929       +7     
==========================================
+ Hits         4414     4463      +49     
+ Misses        436      420      -16     
+ Partials      130      119      -11     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rkalis

rkalis commented Sep 25, 2026

Copy link
Copy Markdown
Member

We're replacing this PR with another implementation today.

This branch was successfully deployed

1 active deployment
Preview — 3b0125c2 Deployed Sep 24, 2026 by vercel[bot]
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.

Artifacts repeat an imported file's full source in every debug frame from that file

2 participants