Skip to content

refactor(gnovm): derive IsAssignable from NameSources, drop StaticBlock.UnassignableNames - #6089

Open
ltzmaxwell wants to merge 4 commits into
gnolang:masterfrom
ltzmaxwell:remove-unassignable-names
Open

refactor(gnovm): derive IsAssignable from NameSources, drop StaticBlock.UnassignableNames#6089
ltzmaxwell wants to merge 4 commits into
gnolang:masterfrom
ltzmaxwell:remove-unassignable-names

Conversation

@ltzmaxwell

@ltzmaxwell ltzmaxwell commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Description

StaticBlock.UnassignableNames (introduced in #3198) only ever had one writer: the non-method *FuncDecl case in initStaticBlocks, which appended the func decl's name immediately after Reserve(false, nx, n, NSFuncDecl, -1) recorded the same fact in NameSources. Despite its general-sounding name, the slice never held any other kind of unassignable name — constants are const-folded (and tracked in Consts), type names fold to constTypeExpr, and uverse names are refused by an explicit branch in IsAssignable.

This PR deletes the field and answers IsAssignable from the declaring block's NameSources instead: NameSources[idx].Type != NSFuncDecl — the same idiom already used for NSTypeDecl lookups in preprocess.go. Indexing by a GetLocalIndex result is safe because Define2 enforces NumNames == len(NameSources).

Changes

  • nodes.go — drop the UnassignableNames field (slot retired with a blank _ struct{} \amino:"reserved"`field, the mechanism from #5301, so field numbers are unchanged and old encoded data carrying field 8 is skipped on decode); rewriteIsAssignableto an O(1)NameSourceslookup instead of an O(n) scan, now shaped exactly like its siblingGetIsConst`.
  • preprocess.go — drop the duplicate append in initStaticBlocks2.
  • gnolang.proto, pb3_gen.go — regenerated with misc/genproto2 (emits reserved 8;).
  • gnovm/adr/pr6089_remove_unassignable_names.md — ADR.

Verification

  • go test ./gnovm/pkg/gnolang/ -short: failure set identical to pristine master on the same machine (10 pre-existing go/types wording goldens, diffed test-by-test) — nothing new.
  • go test ./gno.land/pkg/sdk/vm/ -run Gas, go test ./gno.land/pkg/integration/ -run TestTestdata, go test ./tm2/pkg/amino/...: all pass.
  • Decoder verified to skip reserved field 8 in old encoded data (note block nodes are not persisted to the store backend today — SetBlockNode's backend write is a TODO — so this is schema hygiene, not a live migration).

Possible follow-ups (out of scope)

  • IsAssignableAt(store, path): the AssignStmt call site already has a resolved ValuePath, so the name walk could become O(depth) pointer hops, mirroring GetIsConstAt. Needs care around blank identifiers and path-refill timing.
  • Merge Consts into NameSources the same way, retiring the last parallel name-list and its // TODO consider merging with Names.

Context: grew out of review discussion on #6083, where the addressability check leans on IsAssignable and the field's name suggested a completeness ("all unassignable names") it never had.

AI-assisted: implementation and ADR drafted with Claude, reviewed by the author.

🤖 Generated with Claude Code

…bleNames

StaticBlock.UnassignableNames only ever held package-level func decl
names -- the same fact Reserve already records as NSFuncDecl in
NameSources, aligned by the same local index. Answer IsAssignable from
the NameSource type instead and delete the duplicate slice: one less
serialized field, and an O(1) check instead of an O(n) scan.

The amino slot is retired with a blank amino:"reserved" field, the
mechanism introduced for Externs in gnolang#5301, so field numbers are
unchanged and old encoded data carrying field 8 is skipped on decode.
@Gno2D2

Gno2D2 commented Aug 24, 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

Avoids confusion with type assignability (checkAssignableTo,
mustAssignableTo): this predicate is about the name's object kind
(func decl / uverse name vs. assignable), not about types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📦 🤖 gnovm Issues or PRs gnovm related

Projects

Development

Successfully merging this pull request may close these issues.

2 participants