-
-
Notifications
You must be signed in to change notification settings - Fork 158
fix(hir,fetch): preserve Hono response state #8982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
proggeramlug
merged 2 commits into
PerryTS:main
from
proggeramlug:fix/8968-hono-context-private-elements
Aug 28, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| `perry run <dir>` now resolves the directory to its project entry instead of passing the directory itself into module collection. | ||
|
|
||
| An explicit directory input is treated as a project root: its `perry.toml` entry is read relative to that directory, falling back to `<dir>/src/main.ts` then `<dir>/main.ts`. Previously `perry run .` read `perry.toml` from the current working directory and handed the directory straight to module collection, which fails on Windows. | ||
|
|
||
| Fixes #8908. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| The private-member guard moved to its call sites, taking a call off every | ||
| ordinary property read and write. | ||
|
|
||
| #8970 made the private-member name test cheap but left the CALL. In a pure | ||
| property-read loop (`o[k]` with pre-built keys, no concat) that showed up as | ||
| `private_member_get_by_name` 11.4% plus `private_member_storage_name` 5.4% — | ||
| **16.8% of the loop, the largest single item** — essentially all of it call | ||
| overhead for keys that are rejected on their length before doing anything. | ||
|
|
||
| The guard is now invoked at the three call sites (the generic read entry, the | ||
| class-field read miss, and the generic write), so an ordinary property | ||
| operation makes no call into the private-member path at all. Keys that pass | ||
| the guard take exactly the original path. | ||
|
|
||
| Interleaved A/B, min-of-21 (under heavy co-tenant load, so read the ratios | ||
| rather than the absolutes): pure property read 26 → 22 ms (−15%), computed-key | ||
| read 51 → 45 ms (−12%), combined overwrite 50 → 46 ms (−8%), write unchanged. | ||
|
|
||
| Output on a private-member exercise — instance fields, `static #instances`, | ||
| private methods, private getters, `#x in obj`, subclassing, and an ordinary key | ||
| literally named `#<perry:private-member:1:x>` — is byte-identical to before the | ||
| change. Computed-key differential vs node is byte-identical. Suite 2779 passed. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Fixed | ||
|
|
||
| - Refusing a runtime-string `Function` in a `dyn-eval`-off AOT binary now throws a catchable `TypeError` instead of aborting at the runtime FFI boundary, allowing zod v4 and other capability-probing libraries to select their non-eval fallback. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Fixed three defects that together broke Hono response state. | ||
|
|
||
| - The read half of a compound or logical private-member assignment (`this.#x ||= v`) now lowers through the same brand guard and class-mangled storage key as an ordinary private read, instead of a differently-keyed path. | ||
| - A runtime `HeadersInit` record passed through a non-literal `Response` init object is preserved rather than dropped. | ||
| - The Fetch default `text/plain;charset=UTF-8` is installed for string bodies without overriding an explicit content type, and pending BodyInit metadata is cleared across reuse. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| Two dead-work removals on the property read path. The computed-key read loop | ||
| now **matches node** (23 ms vs 23 ms on the same host), and the pure property | ||
| read drops 21 → 17 ms. | ||
|
|
||
| **1. Typed-feedback observation is skipped when recording is off.** Recording | ||
| is off by default, and `guard_observe` and `record_fallback_call` both | ||
| early-return in that mode — but the property wrappers built the whole | ||
| `Observation` first, hashing the key and resolving the receiver's shape, purely | ||
| to hand it to functions that discard it. `js_typed_feedback_object_get_field_by_name_f64` | ||
| was 10% of an isolated property-read loop, nearly all of it that. The array | ||
| index wrappers have carried #5094's gate for exactly this reason, and #8951 | ||
| gave it to the fast store path; the property get/set wrappers never got it. | ||
|
|
||
| Behaviour is unchanged in both modes: with recording off `guard_observe` | ||
| returns `contract_valid` unmodified and the fallback recorder is a no-op, so | ||
| the wrapper already reduced to precisely the underlying call it now makes | ||
| directly. | ||
|
|
||
| **2. The slot bound stops copying a descriptor to read four bytes.** | ||
| `shape_descriptor_by_id` returns `ShapeDescriptor` **by value**, so | ||
| `object_live_slot_count` — consulted on essentially every property read and | ||
| write — lifted the whole ~48-byte record and kept only | ||
| `live_inline_slot_count`. It now reads that field through the table's record | ||
| using the same way-cache probe and the same epoch validation. | ||
| `shape_descriptor_by_id` was 10.1% of the same loop. | ||
|
|
||
| Interleaved A/B, min-of-21, node on the same host in brackets: | ||
|
|
||
| | loop | base | this PR | | | ||
| |---|---|---|---| | ||
| | pure property read | 21 ms (4) | **17 ms** | −19% | | ||
| | computed-key read | 27 ms (23) | **23 ms** | −15% — now at parity with node | | ||
| | combined overwrite | 46 ms (31) | **41 ms** | −11% | | ||
| | write only | 21 ms (23) | 21 ms | unchanged; already faster than node | | ||
|
|
||
| Suite 2779 passed (including the 55 typed-feedback tests). Private-member | ||
| output is byte-identical to base; computed-key differential is byte-identical | ||
| to node. |
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
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
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
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
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
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
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
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
64 changes: 64 additions & 0 deletions
64
crates/perry/tests/issue_8968_private_compound_assignment.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| //! Regression for #8968: the read half of assignment to a private member used | ||
| //! the source spelling (`#x`) instead of the field's mangled storage key. | ||
|
|
||
| use std::path::PathBuf; | ||
| use std::process::Command; | ||
|
|
||
| fn run_source(source: &str) -> String { | ||
| let dir = tempfile::tempdir().expect("tempdir"); | ||
| let entry = dir.path().join("main.ts"); | ||
| let output = dir.path().join("main_bin"); | ||
| std::fs::write(&entry, source).expect("write source"); | ||
| let compile = Command::new(PathBuf::from(env!("CARGO_BIN_EXE_perry"))) | ||
| .current_dir(dir.path()) | ||
| .args([ | ||
| "compile", | ||
| entry.to_str().unwrap(), | ||
| "-o", | ||
| output.to_str().unwrap(), | ||
| ]) | ||
| .env("PERRY_NO_CACHE", "1") | ||
| .output() | ||
| .expect("run perry compile"); | ||
| assert!( | ||
| compile.status.success(), | ||
| "compile failed\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&compile.stdout), | ||
| String::from_utf8_lossy(&compile.stderr) | ||
| ); | ||
| let run = Command::new(output).output().expect("run compiled program"); | ||
| assert!( | ||
| run.status.success(), | ||
| "program failed\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&run.stdout), | ||
| String::from_utf8_lossy(&run.stderr) | ||
| ); | ||
| String::from_utf8_lossy(&run.stdout).trim().to_string() | ||
| } | ||
|
|
||
| #[test] | ||
| fn private_assignment_reads_the_declared_member() { | ||
| let stdout = run_source( | ||
| r#"class Context { | ||
| #res: any; | ||
| #count = 10; | ||
| get res(): any { return this.#res ||= { status: 200 }; } | ||
| set res(value: any) { this.#res = value; } | ||
| bump(): number { this.#count += 2; return this.#count; } | ||
| } | ||
| const context = new Context(); | ||
| const finalized = { status: 404 }; | ||
| context.res = finalized; | ||
| console.log(context.res.status, context.res === finalized, context.bump()); | ||
|
|
||
| class Accessor { | ||
| #raw = 7; | ||
| get #value(): number { return this.#raw; } | ||
| set #value(value: number) { this.#raw = value; } | ||
| bump(): number { this.#value += 1; return this.#raw; } | ||
| } | ||
| console.log(new Accessor().bump()); | ||
| "#, | ||
| ); | ||
| assert_eq!(stdout.lines().collect::<Vec<_>>(), ["404 true 12", "8"]); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| //! Regression for the Response header failures exposed by Hono in #8968. | ||
|
|
||
| use std::path::PathBuf; | ||
| use std::process::Command; | ||
|
|
||
| #[test] | ||
| fn response_preserves_runtime_headers_and_string_content_type() { | ||
| let dir = tempfile::tempdir().expect("tempdir"); | ||
| let entry = dir.path().join("main.ts"); | ||
| let output = dir.path().join("main_bin"); | ||
| std::fs::write( | ||
| &entry, | ||
| r#"function show(label: string, response: Response): void { | ||
| console.log(label, response.status, JSON.stringify(response.headers.get("content-type"))); | ||
| } | ||
| const spread: any = { "Content-Type": "application/json", ...(undefined as any) }; | ||
| show("coalesce", new Response("x", { headers: (undefined as any) ?? spread })); | ||
| const init: any = { status: 404, headers: { "content-type": "application/json" } }; | ||
| show("runtime-init", new Response("x", init)); | ||
| show("headers", new Response("x", { headers: new Headers(spread) })); | ||
| show("default", new Response("x")); | ||
| show("explicit", new Response("x", { headers: { "content-type": "text/html" } })); | ||
| show("bytes", new Response(new Uint8Array([1, 2, 3]) as any)); | ||
| show("empty", new Response()); | ||
| function badInit(): any { throw new Error("boom"); } | ||
| try { new Response("must not leak", badInit()); } catch {} | ||
| show("after-throw", new Response()); | ||
| "#, | ||
| ) | ||
| .expect("write source"); | ||
| let compile = Command::new(PathBuf::from(env!("CARGO_BIN_EXE_perry"))) | ||
| .current_dir(dir.path()) | ||
| .args([ | ||
| "compile", | ||
| entry.to_str().unwrap(), | ||
| "-o", | ||
| output.to_str().unwrap(), | ||
| ]) | ||
| .env("PERRY_NO_CACHE", "1") | ||
| .output() | ||
| .expect("run perry compile"); | ||
| assert!( | ||
| compile.status.success(), | ||
| "compile failed\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&compile.stdout), | ||
| String::from_utf8_lossy(&compile.stderr) | ||
| ); | ||
| let run = Command::new(output).output().expect("run compiled program"); | ||
| assert!( | ||
| run.status.success(), | ||
| "program failed\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&run.stdout), | ||
| String::from_utf8_lossy(&run.stderr) | ||
| ); | ||
| assert_eq!( | ||
| String::from_utf8_lossy(&run.stdout) | ||
| .lines() | ||
| .collect::<Vec<_>>(), | ||
| [ | ||
| r#"coalesce 200 "application/json""#, | ||
| r#"runtime-init 404 "application/json""#, | ||
| r#"headers 200 "application/json""#, | ||
| r#"default 200 "text/plain;charset=UTF-8""#, | ||
| r#"explicit 200 "text/html""#, | ||
| "bytes 200 null", | ||
| "empty 200 null", | ||
| "after-throw 200 null", | ||
| ] | ||
| ); | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use stack-scoped pending BodyInit metadata. A single thread-local slot cannot preserve the outer constructor state when an
initexpression creates a nestedResponse. The outer string marker, or pending stream id, is cleared or consumed by the inner constructor.crates/perry-stdlib/src/fetch/mod.rs#L279-L286: replace the singleCellwith per-construction stack or guard state.crates/perry-stdlib/src/fetch/dispatch.rs#L41-L45: write and consume metadata in the active construction frame instead of the shared slot.📍 Affects 2 files
crates/perry-stdlib/src/fetch/mod.rs#L279-L286(this comment)crates/perry-stdlib/src/fetch/dispatch.rs#L41-L45🤖 Prompt for AI Agents