Skip to content

Fix aarch64 context switch - #138

Merged
lalinsky merged 3 commits into
mainfrom
fix-aarch64-context-switch
Nov 12, 2025
Merged

lalinsky merged 3 commits into
mainfrom
fix-aarch64-context-switch

Conversation

@lalinsky

@lalinsky lalinsky commented Nov 12, 2025 •

Copy link
Copy Markdown
Owner

LLVM ignores x30 in clobber list, needs to be written as lr. :(

rust-lang/rust@60b7c2a

Fixes #135

@coderabbitai

coderabbitai Bot commented Nov 12, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Build configuration now enforces --release=safe mode across all zig build commands in CI. The switchContext function is marked inline for potential optimization, and the ARM64 clobber register is corrected from .x30 to .lr with explanatory comment.

Changes

Cohort / File(s) Summary
Build CI Configuration
.github/workflows/test.yml
Added --release=safe flag to all four zig build steps (Build, tests, examples, benchmarks) to enforce safe release builds in CI
Coroutine Context Switching
src/coroutines.zig
Made switchContext function inline; updated ARM64 clobber register from .x30 to .lr with rationale comment referencing Rust's aarch64 handling

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • The test.yml changes follow a repetitive pattern (same flag addition across multiple lines), requiring minimal cognitive load
  • The ARM64 clobber register swap needs verification: confirm that .lr is the correct register name in Zig's inline assembly context for ARM64, and that this aligns with actual ARM64 ABI conventions
  • Inline keyword addition is straightforward, but verify no performance regression and that the function's asm semantics work correctly when inlined

Poem

⚙️ Safe releases now the way,
Context switches, inline they play,
ARM registers realigned,
Performance and safety combined. 🔒

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive No description was provided by the author, making it impossible to evaluate whether any description relates to the changeset. Add a description explaining why the aarch64 context switch needed fixing and what the changes accomplish.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix aarch64 context switch' directly matches the main change: fixing ARM64 context switch handling by correcting the clobber register from .x30 to .lr.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-aarch64-context-switch

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60e33c1 and e2bcee6.

📒 Files selected for processing (2)
  • .github/workflows/test.yml (1 hunks)
  • src/coroutines.zig (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: test (windows-latest, native)
  • GitHub Check: test (ubuntu-latest, riscv64-linux, qemu-riscv64-static, epoll)
  • GitHub Check: test (macos-latest, native)
  • GitHub Check: test (ubuntu-latest, x86_64-linux)
  • GitHub Check: test (ubuntu-latest, aarch64-linux, qemu-aarch64-static, epoll)
🔇 Additional comments (3)
.github/workflows/test.yml (1)

41-54: Consistent addition of --release=safe across all build commands.

Enabling safety checks with optimizations in CI is a good call. This will catch issues that only show up in optimized builds while still maintaining runtime safety checks.

src/coroutines.zig (2)

75-75: Inlining context switch function for performance.

Makes sense to inline this since it's called from hot paths (step, yield, yieldTo) and eliminating call overhead matters for context switching.


258-261: Critical fix: Correctly mark link register as clobbered.

This is the fix. Using .lr instead of .x30 ensures LLVM recognizes the clobber. Without this, the compiler would assume x30 is preserved across the context switch, leading to incorrect code where it reuses stale values from the link register. The reference to Rust's implementation is helpful documentation.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

examples/http-server not work in Release mode

1 participant