Wire Mach-O direct backend and add std.fs.appendBytes - #207
Open
harshav167 wants to merge 2 commits into
Open
Conversation
- Lower IR_VALUE_BYTE_VIEW_EQ to inline AArch64 byte-by-byte compare. - Lower IR_VALUE_FS_EXISTS, IR_VALUE_FS_IS_DIR, IR_VALUE_FS_MAKE_DIR, IR_VALUE_FS_REMOVE, IR_VALUE_FS_REMOVE_DIR to inline Darwin syscalls. - Lower IR_VALUE_FS_WRITE_PATH, IR_VALUE_FS_WRITE_BYTES_PATH, IR_VALUE_FS_READ_PATH, IR_VALUE_FS_READ_BYTES_PATH to inline open + read/write + close sequences. - Use the shared z_aarch64_emit primitives; no runtime helper, no extra link plan, matching the ELF64 design.
- Reserve IR_VALUE_FS_APPEND_BYTES_PATH and register it in the std signature table, checker, lowerer, and MIR verifier. - Lower the ELF64 emit case alongside writeBytes, switching open flags between O_CREAT|O_TRUNC and O_CREAT|O_APPEND. - Lower the Mach-O direct emit case the same way for darwin-arm64. - Bump the compiler-metrics budgets that grow with the new opcode case lines: emit_macho64.c, emit_elf64.c::elf_emit_value, ir.c::ir_lower_expr and strcmp count, checker.c::std_call_arg_type, mir_verify.c::mir_verify_direct_value_kind_contract, main.c. - Document the API in docs/articles/modules/fs.md and add a native conformance test that appends two byte spans and reads them back.
|
@harshav167 is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
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.
What
Adds the missing AArch64 Mach-O backend coverage for filesystem opcodes that already work on ELF64, and reserves a new
std.fs.appendBytesAPI alongside it.Two commits:
Wire Mach-O direct backend for std.mem.eql and path-form std.fs helpers — lowers
IR_VALUE_BYTE_VIEW_EQ, theFS_EXISTS / FS_IS_DIR / FS_MAKE_DIR / FS_REMOVE / FS_REMOVE_DIRfamily, and theFS_WRITE_PATH / FS_WRITE_BYTES_PATH / FS_READ_PATH / FS_READ_BYTES_PATHfamily to inline AArch64 syscalls using the sharedz_aarch64_emitprimitives. No runtime helper, no extra link plan — matches the ELF64 design.Add std.fs.appendBytes — new
IR_VALUE_FS_APPEND_BYTES_PATHreturningMaybe<usize>. Lowered on both ELF64 and Mach-O by reusing the existing write codepath withO_APPENDflags. Bumps the relevantcompiler-metricsbudgets for the changed files and functions. Includes a conformance test that appends two byte spans and reads the file back.Why
Before this PR, programs that hit
std.mem.eqlor anystd.fs.*path-form helper ondarwin-arm64errored withCGEN004even though the IR opcodes existed and the ELF64 backend already lowered them. The exe builds for darwin-arm64 had to route through the object backend (and external linker), which is the slower path. This PR closes that parity gap.std.fs.appendBytesis a small addition that programs need when they want to accumulate to a file across calls (logging, ledgers, line-by-line accumulation) without first reading the existing contents or threading an ownedFilehandle through every call site.Verification
Locally on
darwin-arm64:make -C native/zero-c— clean build with-std=c11 -Wall -Wextra -Wpedantic -Os.pnpm run conformance:local— provenance guardrails, type core smoke, MIR verifier smoke, row syntax smoke, and conformance all ok.pnpm run native:test:local—http runtime smoke ok,native conformance ok.pnpm run command-contracts:local— snapshots ok.pnpm run docs:test— pass.pnpm run test:zero— pass.pnpm run reliability:smoke— ok.The new conformance test
conformance/native/pass/std-fs-append.0builds end-to-end viazero build --backend zero-macho64 --emit exeand printsfs append okafter writing the expectedhelo\nwobyte sequence.Notes
svc #0x80convention with the syscall number inx16and the carry flag indicating error.FS_IS_DIRcarves a 144-bytestruct stat64from the stack, callsSYS_stat64, and checksS_IFMT & st_mode == S_IFDIRat offset 4.std.fs.appendBytesis exposed as(path: String, bytes: Span<u8>) -> Maybe<usize>— matching the shape ofstd.fs.writeBytes.