Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.5.1 — per-invocation object staging; per-run parity scratch dir (#5940)

The two concurrent-compile contamination P0s from the 2026-07-02 audit (the documented events.once-era trap, critical now that multiple dev agents compile in sibling worktrees daily). Per-module objects landed at CWD-relative name-only paths (object_output_dir = current_dir()), so two concurrent compiles sharing a working directory overwrote each other's <module>.o mid-link and each deleted the other's intermediates — deterministically wrong binaries on any object-cache bypass — and the fixed-name _perry_stubs.o/_perry_failed_stubs.o collided even with the cache ON. Objects now stage under temp_dir()/perry-objs-<pid>-<nanos> (the linker.rs #509 discipline; embedded-asset objects inherit the fix; dir removed with the intermediates). run_parity_tests.sh compiled every test to a fixed /tmp/perry_parity_<id> path — two concurrent suite runs executed each other's compiler output; binaries now live in a per-run mktemp dir (trap-cleaned). Follow-ups: shared cache-key env allowlist; port-parameterize the TLS-upgrade fixture's 17892.

## v0.5.1225 — GC scans descriptor/proxy side tables; static-field globals rooted (#5937)

Three GC P0s from the 2026-07-02 audit (the #5042/#5142 family: a side table holds the only live reference and GC can't see it). ACCESSOR_DESCRIPTORS holds the ONLY reference to Object.defineProperty getter/setter closures — unscanned, a minor GC swept or moved them and the next property read invoked freed memory; PROPERTY_DESCRIPTORS owner keys went stale on evacuation (frozen/non-writable attrs silently detached or fired on a new tenant at a reused address). PROXIES target/handler are commonly reachable only through the registry; REFLECT_METADATA keys go stale on target moves. New scan_descriptor_roots_mut + scan_proxy_roots_mut (semantically ported from the stranded codex-branch be73b4f8d, rewritten against main's current table shapes; the codex policy hunk is superseded by main's registered_root_scanners_block_budgeted_gc guards) visit the closure/target/handler slots and rekey owners in the metadata-rewrite phase, mirroring the symbol-keyed twins. @perry_static_<mod>__<Class>__<field> globals — NaN-boxed any-values whose GC_STORE_AUDIT(ROOT) comment was aspirational — are now registered via register_module_globals_as_gc_roots walking ctx.static_field_globals (deduped; cross-module duplicates harmless). e2e gc_side_table_roots_evacuation.rs: accessor + proxy + static-field object survive 20k-allocation churn + gc() under PERRY_GC_FORCE_EVACUATE=1 with PERRY_GC_VERIFY_EVACUATION=1 armed; gc-stress green on the labeled run.
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

Perry is a native TypeScript compiler written in Rust that compiles TypeScript source code directly to native executables. It uses SWC for TypeScript parsing and LLVM for code generation.

**Current Version:** 0.5.1225
**Current Version:** 0.5.10.5.1225


## TypeScript Parity Status
Expand Down
30 changes: 27 additions & 3 deletions crates/perry/src/commands/compile/run_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,25 @@ pub fn run_with_parse_cache(

let total_codegen_modules = ctx.native_modules.len();
let codegen_modules_started = AtomicUsize::new(0);
let object_output_dir = std::env::current_dir()?;
// Per-invocation object staging dir (2026-07-02 audit fleet P0).
// Objects used to land at CWD-relative name-only paths, so two
// concurrent perry compiles sharing a working directory overwrote each
// other's `<module>.o` mid-link and each deleted the other's objects
// afterwards — deterministically wrong binaries whenever the object
// cache was bypassed (--no-cache / trace modes / store errors), and the
// fixed-name stub objects collided even with the cache ON. pid + a
// strictly-monotonic wall component (the linker.rs #509 discipline)
// keeps simultaneous invocations disjoint; the dir is removed with the
// intermediates below.
let object_output_dir = {
let nanos = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_nanos())
.unwrap_or(0);
let dir = std::env::temp_dir().join(format!("perry-objs-{}-{}", std::process::id(), nanos));
std::fs::create_dir_all(&dir)?;
dir
};
let compile_results: Vec<Result<NativeObjectArtifact, String>> = ctx
.native_modules
.par_iter()
Expand Down Expand Up @@ -4676,7 +4694,7 @@ pub fn run_with_parse_cache(
}
let stub_bytes =
perry_codegen::stubs::generate_stub_object(&md, &mf, &mi, target.as_deref())?;
let stub_path = PathBuf::from("_perry_stubs.o");
let stub_path = object_output_dir.join("_perry_stubs.o");
fs::write(&stub_path, &stub_bytes)?;
obj_cleanup_paths.push(stub_path.clone());
obj_paths.push(stub_path);
Expand Down Expand Up @@ -5058,7 +5076,7 @@ pub fn run_with_parse_cache(
&stub_wrapper_names,
target.as_deref(),
)?;
let stub_path = PathBuf::from("_perry_failed_stubs.o");
let stub_path = object_output_dir.join("_perry_failed_stubs.o");
fs::write(&stub_path, &stub_bytes)?;
obj_cleanup_paths.push(stub_path.clone());
obj_paths.push(stub_path);
Expand Down Expand Up @@ -5257,6 +5275,9 @@ pub fn run_with_parse_cache(
for obj_path in &obj_cleanup_paths {
let _ = fs::remove_file(obj_path);
}
// Best-effort: drop the per-invocation staging dir (only when
// empty — keep_intermediates or stray files leave it in place).
let _ = fs::remove_dir(&object_output_dir);
}

let codegen_cache_stats = if object_cache.is_enabled() {
Expand Down Expand Up @@ -5393,6 +5414,9 @@ pub fn run_with_parse_cache(
for obj_path in &obj_cleanup_paths {
let _ = fs::remove_file(obj_path);
}
// Best-effort: drop the per-invocation staging dir (only when
// empty — keep_intermediates or stray files leave it in place).
let _ = fs::remove_dir(&object_output_dir);
}

let codegen_cache_stats = if object_cache.is_enabled() {
Expand Down
8 changes: 7 additions & 1 deletion run_parity_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ TEST_DIR="$SCRIPT_DIR/test-files"
NODE_SUITE_DIR="$SCRIPT_DIR/test-parity/node-suite"
OUTPUT_DIR="$SCRIPT_DIR/test-parity/output"
REPORT_DIR="$SCRIPT_DIR/test-parity/reports"
# Per-run scratch dir for compiled test binaries (2026-07-02 audit): the old
# fixed /tmp/perry_parity_<test-id> paths meant two concurrent suite runs
# (two agents / two worktrees on one machine) executed EACH OTHER'S compiler
# output — cross-contaminated pass/fail attributed to the wrong build.
PARITY_TMP="$(mktemp -d "${TMPDIR:-/tmp}/perry-parity.XXXXXX")"
trap 'rm -rf "$PARITY_TMP"' EXIT

# LLVM is the only backend post-Phase K hard cutover. The --llvm /
# --cranelift flags and PERRY_BACKEND env var are kept as no-ops for
Expand Down Expand Up @@ -560,7 +566,7 @@ for test_file in "${TEST_FILES[@]}"; do
safe_test_id="${test_id//\//__}"
node_output_file="$OUTPUT_DIR/node/${safe_test_id}.txt"
perry_output_file="$OUTPUT_DIR/perry/${safe_test_id}.txt"
perry_binary="/tmp/perry_parity_$safe_test_id"
perry_binary="$PARITY_TMP/perry_parity_$safe_test_id"
parity_argv_line=$(sed -n -E 's|^[[:space:]]*//[[:space:]]*parity-argv:[[:space:]]*(.*)$|\1|p' "$test_file" | head -1)
parity_node_argv_line=$(sed -n -E 's|^[[:space:]]*//[[:space:]]*parity-node-argv:[[:space:]]*(.*)$|\1|p' "$test_file" | head -1)
parity_env_line=$(sed -n -E 's|^[[:space:]]*//[[:space:]]*parity-env:[[:space:]]*(.*)$|\1|p' "$test_file" | head -1)
Expand Down
Loading