Skip to content

refactor(toyk2): encode state using borrow-array take/put not Option - #497

Draft
acl-cqc wants to merge 2 commits into
feat/toyk2_encodefrom
acl/toyk2_encode
Draft

acl-cqc wants to merge 2 commits into
feat/toyk2_encodefrom
acl/toyk2_encode

Conversation

@acl-cqc

@acl-cqc acl-cqc commented Oct 22, 2026 •

Copy link
Copy Markdown

Into #407.

Replace the array[Option[RuntimeBlock],...] with array[RuntimeBlock] and use put and take (about once each) and guppy's built-in notion of borrowing from arrays to simplify many functions on state. This saves quite a few lines....

@acl-cqc acl-cqc changed the title refactor(toyk2): encode state using borrow-array take/put not Option refactor(toyk2): encode state using borrow-array take/put not Option; @mapped decorator Oct 25, 2026
@acl-cqc acl-cqc changed the title refactor(toyk2): encode state using borrow-array take/put not Option; @mapped decorator refactor(toyk2): encode state using borrow-array take/put not Option Nov 4, 2026
Comment on lines +812 to +815
for i in range(len(state.blocks)):
if not state.blocks.is_borrowed(i):
state.blocks.take(i).discard()
state.blocks.discard_all_taken()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should panic here if a block has been borrowed. I don't expect a scenario in which there is a block that has been borrowed, and we are discarding the state.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm wrong here, please ignore me.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I guess it's the responsibility of whomever took the block to discard it, in case state_discard is called before they put it back? Yeah, I don't think that'll happen, and if it did this seems like the correct behaviour to me.

@PabloAndresCQ
PabloAndresCQ force-pushed the acl/toyk2_encode branch 2 times, most recently from 9fcaa8b to 61d84cb Compare November 4, 2026 19:33

@PabloAndresCQ PabloAndresCQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Much cleaner! Thanks Alan

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.

3 participants