Skip to content

Conversation

@jsdt
Copy link
Contributor

@jsdt jsdt commented Nov 18, 2025

Description of Changes

This adds some changes for how we return data from view functions. Originally, we interpreted the output of a view function as a bsatn encoding of an array of rows. Since we also want to be able to return queries from view functions, we need to be able to return different types too. At this point, this is effectively not a functional change, since we don't use the new format, and we don't actually try to parse the new format.

This introduces a new format for view returns, which is a ViewResultHeader, potentially followed by additional data. For example, if a view were returning rows directly, it would write a ViewResultHeader::RowData, followed by an array of rows. Note that we could have given that object a byte array with the rows instead of using a header an a separate object, but that would force us create an extra copy when encoding and when decoding.

To make this backward compatible with existing views, we have a different way to return the new format. For v8 views, if they return a byte array, we assume it is the old format. If they return an object, we expect the data field of that object to be the actual return data.

For wasm views, we interpret a return code of 2 to mean that it uses the new format.

On the host side, we handle this naively: we will perform the query, and we will act as though the view has a read dependency on the tables in the query. In follow up PRs we can make this more efficient.

API and ABI breaking changes

This is not a breaking change, but it does make the ABI more complicated (specifically to avoid breaking it).

Expected complexity level and risk

1.5. This should not affect the existing return style.

Testing

I've done manual testing of this with a version of the typescript bindings that returns queries.

@jsdt jsdt marked this pull request as ready for review November 19, 2025 18:27
@bfops bfops added the release-any To be landed in any release window label Nov 24, 2025
@jsdt jsdt changed the title Define new return types for the view ABI Update view ABI to support returning queries Nov 24, 2025
Copy link
Collaborator

@joshua-spacetime joshua-spacetime left a comment

Choose a reason for hiding this comment

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

Can you update the bindings to use the new ABI?

@joshua-spacetime joshua-spacetime added release-1.11.0 and removed release-any To be landed in any release window labels Dec 2, 2025
@jsdt jsdt enabled auto-merge December 3, 2025 17:53
@jsdt jsdt added this pull request to the merge queue Dec 3, 2025
github-merge-queue bot pushed a commit that referenced this pull request Dec 3, 2025
# Description of Changes

This adds some changes for how we return data from view functions.
Originally, we interpreted the output of a view function as a bsatn
encoding of an array of rows. Since we also want to be able to return
queries from view functions, we need to be able to return different
types too. At this point, this is effectively not a functional change,
since we don't use the new format, and we don't actually try to parse
the new format.

This introduces a new format for view returns, which is a
`ViewResultHeader`, potentially followed by additional data. For
example, if a view were returning rows directly, it would write a
`ViewResultHeader::RowData`, followed by an array of rows. Note that we
could have given that object a byte array with the rows instead of using
a header an a separate object, but that would force us create an extra
copy when encoding and when decoding.

To make this backward compatible with existing views, we have a
different way to return the new format. For v8 views, if they return a
byte array, we assume it is the old format. If they return an object, we
expect the `data` field of that object to be the actual return data.

For wasm views, we interpret a return code of 2 to mean that it uses the
new format.

On the host side, we handle this naively: we will perform the query, and
we will act as though the view has a read dependency on the tables in
the query. In follow up PRs we can make this more efficient.

# API and ABI breaking changes

This is not a breaking change, but it does make the ABI more complicated
(specifically to avoid breaking it).

# Expected complexity level and risk

1.5. This should not affect the existing return style.

# Testing

I've done manual testing of this with a version of the typescript
bindings that returns queries.
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 3, 2025
@jsdt jsdt added this pull request to the merge queue Dec 3, 2025
Merged via the queue into master with commit 9989416 Dec 3, 2025
39 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants