Skip to content

fix(cache): key the object cache on all codegen-affecting env vars (#6394)#6526

Merged
proggeramlug merged 1 commit into
mainfrom
fix/object-cache-key-codegen-env-vars
Jul 17, 2026
Merged

fix(cache): key the object cache on all codegen-affecting env vars (#6394)#6526
proggeramlug merged 1 commit into
mainfrom
fix/object-cache-key-codegen-env-vars

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Problem

The object cache (node_modules/.cache/perry) keys on source + compiler identity + a curated set of codegen-affecting environment variables — but that set was incomplete. Nine vars were keyed (PERRY_WRITE_BARRIERS, PERRY_SHADOW_STACK, PERRY_TARGET_CPU, …), while ~16 other PERRY_* vars that perry-codegen reads at compile time — and that change the emitted .o — were not. Setting any of those against a warm cache silently reused an object built without it: the switch appears to do nothing, and any A/B or bisection built on it is vacuous.

(Contrary to the issue title, PERRY_WRITE_BARRIERS itself is already keyed — the env block exists. This PR closes the remaining gap so that no codegen env var can silently no-op with a warm cache.)

Fix

Add the missing compile-time codegen env vars to compute_object_cache_key_with_env
(crates/perry/src/commands/compile/object_cache.rs):

PERRY_TYPED_FEEDBACK, PERRY_TYPED_FEEDBACK_TRACE, PERRY_FULL_OUTLINE_IC,
PERRY_FULL_OUTLINE_IC_MIN_FUNCS, PERRY_OUTLINE_METHOD_DISPATCH, PERRY_INLINE_NEW,
PERRY_INLINE_CTOR, PERRY_STRING_INIT_CHUNK_SIZE, PERRY_LL_O0_THRESHOLD_BYTES,
PERRY_LL_SIZE_OPT, PERRY_LL_SIZE_OPT_MAX_FN_BYTES, PERRY_ENTRY_SYMBOL,
PERRY_CODEGEN_UNITS, PERRY_CODEGEN_UNIT_SIZE, PERRY_SETJMP_VOLATILE,
PERRY_GC_MOVING_LOOP_POLLS.

Each is a std::env::var read in perry-codegen that changes emitted IR or the
.ll.o compile decision (typed-feedback site emission, IC inline/outline, method-dispatch
outlining, inline new/ctor, string-init chunking, per-unit -O0/-Os selection, entry-symbol
rename, codegen-unit partitioning, volatile-setjmp promotion, and loop GC-poll emission).

Deliberately excluded

  • Runtime globals, not compile-time env: PERRY_CLASS_FIELD_INLINE_GUARD_DISABLED,
    PERRY_TA_VIEW_GUARD, PERRY_TA_KIND_CACHE — codegen emits loads of @PERRY_* globals
    resolved at run time, so the emitted bytes are identical regardless of the compile-time
    environment.
  • Diagnostics / side files only: PERRY_LLVM_KEEP_IR, PERRY_SAVE_LL, PERRY_NATIVE_REPS*,
    PERRY_NO_CLANG_PROBE.
  • Final-link step, not per-module .o: PERRY_LD.
  • Already captured indirectly: PERRY_WATCHOS_ARM64_32 (folds into the resolved target
    triple, already hashed as tgt); PERRY_GLOBAL_SCRIPT_THIS / PERRY_EVAL_CSP /
    PERRY_ALLOW_UNIMPLEMENTED (affect AST→HIR lowering, captured by the hir fingerprint).

Over-inclusion only costs an unnecessary cache miss when a rarely-set var is present;
under-inclusion is the silent-wrong-result bug — so the classification errs toward inclusion
for anything that changes emitted bytes.

The auto-optimize archive cache (target/perry-auto-*, keyed by
auto_optimized_cache_key) is a separate mechanism that keys the Rust build of the
runtime/stdlib static archives, not the per-module TS .o; it does not share this blind spot
and is out of scope.

Test

Extends key_changes_with_codegen_env_vars to assert every newly-keyed var (unset vs set vs a
different value) produces a distinct key, via the existing compute_object_cache_key_with_env
seam (no process-environment mutation).

Closes #6394

Summary by CodeRabbit

  • Bug Fixes
    • Improved build cache accuracy by including additional code-generation and tracing-related environment settings in the object-cache key.
    • Prevented reuse of previously cached object files when compile-time tuning options differ between builds.
  • Tests
    • Expanded cache invalidation tests to cover more code-generation configuration environment variables, verifying distinct cache keys for different unset/set combinations.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 88c8dbf6-9137-482e-a30f-95f875829146

📥 Commits

Reviewing files that changed from the base of the PR and between de8a087 and 20b143e.

📒 Files selected for processing (2)
  • crates/perry/src/commands/compile/object_cache.rs
  • crates/perry/src/commands/compile/object_cache/object_cache_tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/perry/src/commands/compile/object_cache/object_cache_tests.rs

📝 Walkthrough

Walkthrough

The object-cache key now incorporates additional compile-time perry-codegen environment variables, and its invalidation test covers the expanded set of tuning and emission controls.

Changes

Codegen cache key invalidation

Layer / File(s) Summary
Hash codegen settings and test invalidation
crates/perry/src/commands/compile/object_cache.rs, crates/perry/src/commands/compile/object_cache/object_cache_tests.rs
compute_object_cache_key_with_env hashes additional codegen environment variables, while key_changes_with_codegen_env_vars verifies that setting or changing each variable produces distinct cache keys.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: andrewtdiz

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main cache-key change.
Description check ✅ Passed The description covers the problem, fix, exclusions, and test approach, though it doesn't use the exact template headings.
Linked Issues check ✅ Passed The change keys the cache on the added compile-time codegen env vars and excludes runtime-only ones, matching #6394's objective.
Out of Scope Changes check ✅ Passed The patch stays focused on cache-keying and the corresponding test updates, with no clear unrelated code changes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/object-cache-key-codegen-env-vars

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.

…6394)

The object cache keyed on a curated but incomplete set of codegen env
vars. ~16 PERRY_* vars that perry-codegen reads at compile time and that
change the emitted .o — typed-feedback site emission, IC and method-dispatch
outlining, inline new/ctor, string-init chunking, per-unit -O0/-Os selection,
entry-symbol rename, codegen-unit partitioning, volatile-setjmp promotion,
and loop GC-poll emission — were absent from the key. Setting any of them
against a warm cache silently reused an object built without it: the switch
appears to do nothing, and any A/B or bisection built on it is vacuous.

Add them to compute_object_cache_key_with_env. Deliberately excluded:
runtime-global loads (@PERRY_CLASS_FIELD_INLINE_GUARD_DISABLED /
@PERRY_TA_VIEW_GUARD / @PERRY_TA_KIND_CACHE — codegen emits them identically
regardless of the compile-time env), diagnostics-only vars, the final-link
PERRY_LD, and vars already captured via the resolved target triple
(PERRY_WATCHOS_ARM64_32) or the HIR fingerprint (PERRY_GLOBAL_SCRIPT_THIS,
PERRY_EVAL_CSP, PERRY_ALLOW_UNIMPLEMENTED).

Extends key_changes_with_codegen_env_vars to assert every newly-keyed var
(unset vs set vs different value) yields a distinct key.

Closes #6394
@proggeramlug
proggeramlug force-pushed the fix/object-cache-key-codegen-env-vars branch from de8a087 to 20b143e Compare July 17, 2026 14:24
@proggeramlug
proggeramlug merged commit 78218f5 into main Jul 17, 2026
2 checks passed
@proggeramlug
proggeramlug deleted the fix/object-cache-key-codegen-env-vars branch July 17, 2026 14:29
proggeramlug pushed a commit that referenced this pull request Jul 17, 2026
Version + CHANGELOG for the three fixes that green the repo-wide lint job:

- #6528 (v0.5.1261): version-invariant Cargo.toml fingerprint in the
  public-baseline freshness gate.
- #6531 (v0.5.1262): split widget_decl.rs under the 2000-line file-size cap.
- #6394/#6526 (v0.5.1263): key the object cache on all codegen-affecting
  env vars.

Bumps [workspace.package] 0.5.1260 -> 0.5.1263. The version bump no longer
invalidates the benchmark freshness gate (fixed by #6528).
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.

build: the object cache doesn't key on codegen env vars — PERRY_WRITE_BARRIERS=0 silently does nothing with a warm cache

1 participant