Implement std.codec.hexEncode and std.codec.utf8Valid direct emitters#258
Open
555aaditya wants to merge 2 commits into
Open
Implement std.codec.hexEncode and std.codec.utf8Valid direct emitters#258555aaditya wants to merge 2 commits into
555aaditya wants to merge 2 commits into
Conversation
|
@555aaditya is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
- Implement zero_hex_encode and zero_utf8_valid runtime helpers in C - Add IR lowering and verification for std.codec.hexEncode and std.codec.utf8Valid - Wire direct AArch64 Mach-O and x64 ELF emitters to bypass System V struct-return ABI - Adjust metrics budgets and update embedded runtime sources
dd7b9e7 to
3bbbea3
Compare
Author
|
Hi @ctate, I have implemented the compiler direct emitters and C runtime helpers for All native conformance tests, JS CLI tests, ZLS self-tests, and compiler metrics budgets are passing cleanly. Could you please take a look, review, and authorize/merge this when you get a chance? Thanks! |
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
Why this change was made
This PR implements direct compilation support and native runtime implementation for two core standard library codec helpers:
std.codec.hexEncodeandstd.codec.utf8Valid.Currently, direct backend executables are required to compile standard library helpers natively without a generic interpreter fallback. Adding these emitters is a vital step toward enabling fully direct-compiled Zero applications to compile, validate, and serialize standard data formats.
How it improves or helps
Bypasses Calling Convention Complexity:
Returning a 24-byte struct (like
Maybe<String>) by value is a complex operation under AMD64/AArch64 System V ABIs, which would normally require caller-allocated stack slots passed via a hidden pointer.Instead, we utilize a clean struct-return bypass:
zero_hex_encodereturns a simpleint64_tbyte count (or-1on failure).x64) and Mach-O (ARM64) emitters intercept the call, execute the function enregistered, test the returned value inrax/x0, and dynamically unpack the returned length onto the stack variable slot ofMaybe<String>in-place.Robust Multi-Byte UTF-8 Validation:
Implements fully compliant UTF-8 validation (
zero_utf8_valid) in the C runtime for enregisteredZeroByteViewstructs.Pristine Verification and Verification Pipelines:
Integrates seamlessly with the compiler's MIR verifier, target facts metrics auditor, and strict size/complexity line-budget guardrails.
Key Changes
zero_hex_encodeand state-machinezero_utf8_validinnative/zero-c/runtime/zero_runtime.c.elf_emit_utf8_valid_callandelf_emit_hex_encode_to_localwith stack variable unpacking.macho_emit_utf8_valid_call_atandmacho_emit_hex_encode_to_localwith scratch-spill register safety and condition checks.native/zero-c/src/ir.cforstd.codec.hexEncodeandstd.codec.utf8Valid.scripts/compiler-metrics.mts.How the improvement can be verified
1. Native Build and Run
Recompile the native compiler from source and execute the standard data format tests:
2. Run the Full Test Suite Locally
Verify that all conformance, language server, metrics, and documentation tests pass cleanly:
Closes #257