Update view ABI to support returning queries#3685
Merged
Conversation
Collaborator
joshua-spacetime
left a comment
There was a problem hiding this comment.
Can you update the bindings to use the new ABI?
joshua-spacetime
approved these changes
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 bot
pushed a commit
that referenced
this pull request
Jan 31, 2026
# Description of Changes This change implements the module bindings changes to Views that where updated with core in #3685 and the Rust module bindings implementation in #3819. Updates the C# module bindings to use new header-first view ABI (`ViewResultHeader`) and updates the return codes for the `__call_view__` and `__call_view_anon__` module exports. This is a prerequsite for `Query` builder support being added to C# modules. # API and ABI breaking changes Not breaking. Existing modules will continue to use the old ABI. New modules will use the new ABI. However previous host versions will not support modules built using this version of the bindings. # Expected complexity level and risk 2 # Testing This is an internal refactor. All existing tests should continue to pass. All existing tests should continue to pass. The only tests that needed updating were the C# codegen snapshot tests (`Codegen.Tests`) because the generated view dispatcher bodies changed (they now prefix `ViewResultHeader.RowData` before the existing row payload).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 aViewResultHeader::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
datafield 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.