Skip to content

fix(gnovm): persist function-local declared types referenced by saved values#5894

Closed
ltzmaxwell wants to merge 8 commits into
gnolang:masterfrom
ltzmaxwell:fix/maxwell/local_type_persist
Closed

fix(gnovm): persist function-local declared types referenced by saved values#5894
ltzmaxwell wants to merge 8 commits into
gnolang:masterfrom
ltzmaxwell:fix/maxwell/local_type_persist

Conversation

@ltzmaxwell

@ltzmaxwell ltzmaxwell commented Jul 3, 2026

Copy link
Copy Markdown
Contributor
  • Function-local declared types are never SetType'd (only package-level types are, at addpkg), so persisting a value referencing one writes a dangling RefType; after a node restart every access panics with unexpected type with id ... — the realm state is permanently unreadable. Reproduces on master via interface-typed package vars and closure captures.
  • Fix: a localTypeSaver walk in saveObject persists reachable function-local types before SetObject; copyTypeWithRefs preserves ParentLoc so the local type's TypeID survives the persist/reload round trip.
  • Defense-in-depth: a debugAssert-gated invariant in SetObject panics at save time on any dangling function-local type ref, so a missed route fails loudly inside the rolled-back tx instead of committing unreadable state.
  • Tests: restart txtars are the true reproducers (fail on master) — interface var / closure / bound method value, cross-realm, p/-package local type, map-key TypeID stability, reload→mutate→resave across two restarts; zrealm_localtype* filetests guard the save side under -tags debugAssert and pin the on-the-wire RefType shape.
  • Also unblocks fix(gnovm): match Go's call-time dispatch for interface-bound method values #5737, whose call-time method dispatch persists the interface-boxed operand and newly hits this hole. ADR: gnovm/adr/pr5894_local_type_persist.md.

@Gno2D2

Gno2D2 commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: ltzmaxwell/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

@ltzmaxwell ltzmaxwell changed the title fix(gnovm): persist function-local declared types referenced by saved values WIP fix(gnovm): persist function-local declared types referenced by saved values Jul 3, 2026
@ltzmaxwell ltzmaxwell changed the title WIP fix(gnovm): persist function-local declared types referenced by saved values fix(gnovm): persist function-local declared types referenced by saved values Jul 6, 2026
@ltzmaxwell ltzmaxwell requested review from davd-gzl, omarsy and thehowl July 6, 2026 05:06
Comment on lines +50 to +52
- **`SetType` at declaration time (`OpTypeDecl`)**: persists types whose
values never escape — store bloat and gas for dead types; also detaches the
write from the save path that defines what actually needs resolving.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this approach is actually more sensible.

Other types may never end up being saved as values but we save them nonetheless. It just makes sense that the cost of storing a type is entirely at package init; not "on-demand". Also considering the fact that doing this on-demand has a hefty traversal cost we'd have to do; while if we just did this at preprocessing it wouldn't entail any further traversals.

@ltzmaxwell

Copy link
Copy Markdown
Contributor Author

working on an alternative.

@ltzmaxwell

Copy link
Copy Markdown
Contributor Author

close in favor of #5935.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related

Projects

Development

Successfully merging this pull request may close these issues.

3 participants