Add printable core types and a typed Trap kind in WasmKitError - #391
Merged
Conversation
kateinoigakukun
force-pushed
the
katei/error-kinds
branch
from
July 27, 2026 08:40
7a44fa7 to
46b4b31
Compare
MaxDesiatov
reviewed
Jul 27, 2026
| private func hexByte(_ byte: UInt8) -> String { | ||
| let digits = "0123456789abcdef" | ||
| let high = digits[digits.index(digits.startIndex, offsetBy: Int(byte >> 4))] | ||
| let low = digits[digits.index(digits.startIndex, offsetBy: Int(byte & 0xF))] |
Member
There was a problem hiding this comment.
Could we maybe have digits as an array of ASCII bytes that you can directly index with O(1)?
MaxDesiatov
reviewed
Jul 27, 2026
| extension Value { | ||
| /// Returns the descriptions of `values` joined with ", ". | ||
| public static func descriptionList(_ values: [Value]) -> String { | ||
| values.map { $0.description }.joined(separator: ", ") |
Member
There was a problem hiding this comment.
unfortunate that we don't have description(into: inout UTF8Span) or smth like that, printing values could potentially be a hot path after all (in debugging scenarios at least)
Member
There was a problem hiding this comment.
hm, UTF8Span is immutable? Maybe MutableSpan<UInt8> or whatever, and we can assume Value has a max description length that we can statically preallocate a buffer for, v128 being the longest possible value
kateinoigakukun
force-pushed
the
katei/error-kinds
branch
from
July 29, 2026 10:32
46b4b31 to
96dfae1
Compare
Hand-written descriptions for value/reference/function/limit types so string interpolation does not fall back to reflection, which Embedded Swift lacks. Output is wasm-flavored text instead of the previous reflection dumps.
Groundwork for typed throws in the instantiation path: WasmKitError can wrap a Trap so Trap-throwing sub-operations can participate in a typed throws(WasmKitError) chain. Declares Sendable on Trap/TrapReason and rewrites the few reflection-dependent error messages (arrays, instance handles, backtrace addresses) into explicit formatting so they also compile under Embedded Swift.
kateinoigakukun
force-pushed
the
katei/error-kinds
branch
from
July 29, 2026 10:46
96dfae1 to
790ccd4
Compare
kateinoigakukun
added this pull request to the merge queue
Jul 29, 2026
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.
Part of the Embedded Swift support work (#357), split out for incremental review. Two commits:
Add CustomStringConvertible to core Wasm types — hand-written descriptions for
ValueType,ReferenceType/HeapType,FunctionType,Value,Reference,V128(WasmTypes) andLimits,TableType,GlobalType,Mutability(WasmParser). String interpolation of these types previously fell back to reflection-based stringification, which Embedded Swift lacks; the explicit descriptions produce wasm-flavored text instead, e.g.(i32, i32) -> (i32),i32(5),funcref. Array formatting goes through staticdescriptionList(_:)methods on the element types rather than extensions onArrayitself.WasmKitError: carry Trap as a typed error kind — groundwork for typed throws in the instantiation path.
WasmKitErrorgains atrapkind soTrap-throwing sub-operations can participate in athrows(WasmKitError)chain,Trap/TrapReasonare declaredSendable, and the few reflection-dependent error messages (value arrays, instance handles, backtrace addresses) are rewritten into explicit formatting so they also compile under Embedded Swift. Error message text changes slightly where reflection dumps were previously used; no test relied on the old text.