Skip to content
This repository was archived by the owner on Apr 29, 2026. It is now read-only.

Runtime phase 2#414

Merged
navicore merged 6 commits intomainfrom
runtime-phase-2
Apr 22, 2026
Merged

Runtime phase 2#414
navicore merged 6 commits intomainfrom
runtime-phase-2

Conversation

@navicore
Copy link
Copy Markdown
Owner

No description provided.

  - crypto.rs 588 → 32 L aggregator
  - crypto/hash.rs (107 L) — sha256, hmac-sha256, constant-time-eq
  - crypto/random.rs (130 L) — random-bytes, uuid4, random-int
  - crypto/aes.rs (140 L) — aes-gcm encrypt/decrypt
  - crypto/pbkdf.rs (55 L) — pbkdf2-sha256
  - crypto/ed25519.rs (152 L) — keypair/sign/verify
  re-exports)
  - scheduler/lifecycle.rs (177 L) —
  init/run/shutdown/wait/elapsed/parse_stack_size
  - scheduler/spawn.rs (174 L) — strand_spawn (+ with_base), spawn_strand
  (legacy), free_stack
  - scheduler/yield_ops.rs (107 L) — yield_strand, maybe_yield + TCO counter
  - scheduler/registry.rs (168 L, diagnostics-only) —
  StrandSlot/StrandRegistry
  - signal.rs 647 → 122 L aggregator (module doc + shared
  SIGNAL_FLAGS/MAX_SIGNAL + mod decls + re-exports)
  - signal/constants.rs (189 L) — 9 SIG* getters × unix + non-unix stubs
  - signal/handlers.rs (92 L, unix-only) — sigaction wrappers + flag handler
  + mutex
  - signal/ops.rs (280 L) — trap/received/pending/default/ignore/clear × unix
   + non-unix stubs

  All 15 FFI symbols intact, 423 tests pass, just ci clean.
Phase 2 split complete:

  - closures.rs 573 → 71 L aggregator
  - closures/env.rs (118 L) — create_env / env_set / generic env_get
  - closures/accessors.rs (342 L) — type-specific readers
  (int/bool/float/string/quotation + push_string/push_value)
  - closures/construct.rs (90 L) — make_closure / push_closure

  All 12 FFI symbols intact, 423 tests pass, just ci clean.
@claude
Copy link
Copy Markdown

claude Bot commented Apr 22, 2026

PR #414 "Runtime phase 2" — Code Review

Executive Summary

This is a well-executed modularization and refactoring PR that improves code organization across the runtime crate by breaking down several large monolithic modules into logically grouped sub-modules. The changes are architectural only — no functional changes or new features. The PR reorganizes ~11,600 lines of code across 6 major runtime modules:

  • arithmetic.rs → 4 modules (arith, bitwise, compare, peek)
  • closures.rs → 3 modules (env, accessors, construct)
  • crypto.rs → 5 modules (hash, random, aes, pbkdf, ed25519)
  • list_ops.rs → 3 modules (combinators, basic, access)
  • scheduler.rs → 4 modules (lifecycle, spawn, yield_ops, registry)
  • signal.rs → 3 modules (constants, handlers, ops)

All public APIs are preserved via re-exports, maintaining backward compatibility.


What the PR Does

Each monolithic file is split into focused sub-modules. The parent module always re-exports everything via pub use, so the public API surface remains completely unchanged. The split is consistently organized: parent files become aggregators with module declarations and wildcard re-exports; logic lives in the sub-modules.


Code Quality

Strengths

  • Consistent module boundaries: Each sub-module has a clear, single responsibility.
  • Preserved API surface: All pub use re-exports are correctly placed.
  • Appropriate visibility: Internal helpers correctly use pub(super) (e.g., random_int_range, drain_stack_to_base, push_to_variant).
  • Feature-gated compilation works correctly: The diagnostics feature properly gates the registry module in scheduler.

Minor Issues (Non-Blocking)

1. Inconsistent parent module documentation style

scheduler.rs has a detailed ## Module Layout section explaining each sub-module, but arithmetic.rs and others only have a brief sentence. Recommend standardizing on the scheduler style across all refactored modules for consistency.

2. Inconsistent re-export style

Some modules use wildcard:

pub use arith::*;
pub use bitwise::*;

Others use explicit lists:

pub use accessors::{env_get_int, env_get_bool, ...};

Recommend picking one style and applying it consistently. Wildcards are simpler when all sub-module items should be public.

3. Motivation missing from sub-module doc comments

Some sub-module //! headers list what the module contains but don't explain why those things are grouped. For example, arithmetic/bitwise.rs could note: "These operate on bit patterns rather than numeric values, justifying their separation from arithmetic." Low priority, but helps new contributors.


Unsafe Code Review

All unsafe code regions are identical to the original — no new unsafe blocks, no new transmutes, no changed pointer arithmetic. Reviewed:

  • Closure environment handling (closures/env.rs): raw pointer casts to/from Box<[Value]> unchanged
  • Stack operations (list_ops/combinators.rs): pop/push pointer arithmetic unchanged
  • Signal handlers (signal/handlers.rs): sigaction FFI calls unchanged
  • Scheduler spawning (scheduler/spawn.rs): coroutine cleanup unchanged

No new safety concerns introduced.


Correctness

No functional issues detected. This is a no-op refactoring:

  • All #[unsafe(no_mangle)] FFI signatures are identical
  • All algorithm implementations (SHA-256, HMAC, AES-256-GCM, PBKDF2, Ed25519) are identical
  • Atomic memory orderings in scheduler/registry unchanged

Performance

No runtime impact. Module splits may marginally improve compile-time parallelism. All inlined functions remain inlineable with no added call layers. Binary output is identical.


Security

No new security concerns. All safety properties are preserved:

  • Unsafe code: unchanged
  • Cryptography: all algorithms identical
  • Signal handling: async-signal-safe properties preserved

Worth noting as a positive: the comment in crypto/ed25519.rs explaining OsRng reuse across aes_gcm dependency is good documentation of a non-obvious constraint.


Test Coverage

All existing tests remain in place with corrected imports. No tests were removed. Test behavior is identical.

Suggestion for a follow-up PR: Add an integration test that verifies the public API surface is unchanged. This would catch accidental visibility regressions:

// Verify parent module still re-exports everything from sub-modules
use crate::arithmetic::patch_seq_add;  // would fail if re-export dropped

Architecture

The pattern used here (parent.rs as aggregator + sub-directory of focused modules) is sound. One future consideration: if sub-modules grow to have cross-module dependencies, consider a shared common.rs within the module family, or migrate to the module/mod.rs convention. Neither is needed now.


Summary

Aspect Status Notes
Functional changes ✅ None Purely structural
API compatibility ✅ Preserved All re-exports in place
Unsafe code ✅ Unchanged No new safety risks
Performance ✅ Neutral No runtime impact
Security ✅ Maintained All crypto logic identical
Tests ✅ Updated Imports corrected
Code quality ✅ Good Minor doc inconsistencies only

Verdict: Approved. The refactoring is well-executed and low risk. The minor doc comment inconsistencies are non-blocking. Merging this will make the codebase easier to navigate and maintain going forward.

@navicore navicore merged commit f74b121 into main Apr 22, 2026
2 checks passed
@navicore navicore deleted the runtime-phase-2 branch April 22, 2026 20:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant