perry: experimental patches for context-mode native compilation - #1
Open
bradmccormack wants to merge 3 commits into
Open
perry: experimental patches for context-mode native compilation#1bradmccormack wants to merge 3 commits into
bradmccormack wants to merge 3 commits into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Experimental patches for context-mode native compilation
This PR is targeted at the personal fork
bradmccormack/perry, not upstreamPerryTS/perry. It's the same experimental work previously raised (inadvertently) against upstream as PR PerryTS#7225, which has been closed with an apology comment.Experimental, opt-in. This is a set of small forward-compat patches to
perry-hirthat let the auto-optimizer's dyn-eval interpreter ride along forKnownLibraryCodegen(ajv, fast-json-stringify, find-my-way) call sites, and that trackconst F = Function-style aliases of the globalFunctionconstructor through theglobalThis.Functionpath. Together they unblock compilingcontext-mode(a Node.js MCP server) into a native 16 MB binary withnode:sqlite+ FTS5 + HTTP MCP transport working end-to-end.Full write-up — including the 7 upstream Perry issues worked around and the file-level diff inventory — is in
CONTEXT-MODE-COMPAT.mdat the repo root.Why these patches exist
A real-world downstream consumer (
context-mode, the MCP server that lives next to this checkout) compiles fine into Node.js but runs into three concrete gaps in the currentperry-hir:dyn-evalinterpreter when onlyKnownLibraryCodegen(bucket-2) sites are present. It only consultshas_deferred_dynamic_code_sites(). ajv'snew Function()then throws at the first call.const F = Functionto keep the globalFunctionconstructor reachable.perry-hirdid not recognise that as aFunctionalias, sonew F(...)degraded to a user-classnewand lost the dyn-eval route.globalThis.Function = <local>style aliases (also a real downstream pattern) hit the same gap.What changes
crates/perry-hir/src/eval_classifier.rsKNOWN_CODEGEN_SITE_COUNT+has_known_codegen_sites()so the auto-optimizer can opt into dyn-eval when only bucket-2 sites are present.crates/perry-hir/src/destructuring/var_decl/alias_tracking.rs'Function'arm tois_global_this_valuesoglobalThis.Functionaliases are recognised.crates/perry-hir/src/lower/expr_new.rsfunction_aliasresolution viaresolve_class_alias— recogniseconst F = Functionas the global Function constructor.crates/perry-hir/src/lib.rshas_known_codegen_sitesfrom the crate root.crates/perry/src/commands/compile/optimized_libs/freshness.rsknowngen=key in the auto-opt cache +has_dyn_eval || has_knowngate so the dyn-eval interpreter is included in the cache key when the new bucket-2 site detector fires.CONTEXT-MODE-COMPAT.mdchangelog.d/<this-pr>-context-mode-patches.mdgh pr createreturns.Verification
context-modeis currently built and shipped at:context-mode16 MB, optimized release (lto=true, opt-level=3, strip=true)ctx_index,ctx_search,ctx_execute,ctx_execute_file,ctx_batch_execute,ctx_fetch_and_index,ctx_stats,ctx_doctor,ctx_purge,ctx_upgrade,ctx_insight127.0.0.1:9999(configurable viaCONTEXT_MODE_PORT)node:sqliteper-pid FTS5 at/tmp/context-mode-<pid>.dbThe 11-tool verified end-to-end trace and the build commands are in
CONTEXT-MODE-COMPAT.md.What is unchanged
perryruntime features; only the HIR + the auto-opt freshness key.KNOWN_CODEGEN_SITE_COUNTispub(crate)— no public-API change.changelog.d/).Scope note
These are local, fork-only patches. The earlier PR PerryTS#7225 against
PerryTS/perrywas opened by mistake and has been closed. This PR is the corrected target.