fix(uuid): make v5/v3/version/validate work on the native shim (#5197)#5205
fix(uuid): make v5/v3/version/validate work on the native shim (#5197)#5205proggeramlug wants to merge 2 commits into
Conversation
The native `uuid` shim (used when `uuid` resolves from node_modules and
is NOT in `perry.compilePackages`) was non-functional for several APIs:
- `v5`/`v3` had no runtime function and no dispatch-table entry at all,
so they returned `undefined`.
- `version` had a runtime function (`js_uuid_version`) but was never
wired into the dispatch table → `undefined`.
- `validate` was wired with `NA_F64` arg coercion, but the runtime
signature is `*const StringHeader`; the NaN-boxed bits were passed in
the wrong register so it always read `0`.
- `v4`/`v1`/`v7` were boxed as `NR_PTR` (a generic native handle), so
`v4()` read back as `[object Object]` instead of a string.
Fixes:
- Add `js_uuid_v5` (SHA-1) and `js_uuid_v3` (MD5) to both
perry-ext-uuid and perry-stdlib; enable the uuid crate's `v3`/`v5`
features. The shim supports the string-UUID namespace form (covers
the repro + the `v5.DNS`/`v5.URL` constants); the array-namespace
form remains reachable via `perry.compilePackages`.
- Dispatch table: add `v5`/`v3`/`version` rows, fix `validate`'s arg to
`NA_STR`, and box all string generators as `NR_STR`.
- New `NR_BOOL` return kind boxes the FFI bool-as-f64 (1.0/0.0) result
as a real JS boolean so `validate(...)` prints `true`/`false`, not
`1`/`0`. Used for `uuid.validate`.
- Add matching `API_MANIFEST` entries (+ regenerated docs) for v5/v3/
version so the manifest-consistency drift gate stays green.
The `perry.compilePackages` (real-source) path already produced the
correct id on current main; both paths now match Node exactly:
`v5('perry', '6ba7b810-9dad-11d1-80b4-00c04fd430c8')` →
`6cb3836f-339d-52d8-acc6-8751229b61cf true 5`.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds ChangesUUID v3/v5 support and NativeRetKind::Bool ABI fixes
Commander module method entry
Sequence Diagram(s)sequenceDiagram
participant Client as Perry Application
participant Codegen as lower_native_module_dispatch
participant LLVM as LLVM IR
participant Runtime as Native Runtime
Client->>Codegen: compile native Bool return
Codegen->>LLVM: declare as DOUBLE type
LLVM-->>Runtime: prepare invocation
Runtime-->>LLVM: return f64 (1.0 or 0.0)
Codegen->>Codegen: compare f64 != 0.0
Codegen->>LLVM: select TAG_TRUE or TAG_FALSE
LLVM-->>Client: JS boolean value
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
…existing drift) `every_dispatch_entry_has_manifest_counterpart` (cargo-test) was red on main: #5137 added the `commander::args` dispatch row (a has_receiver getter for `program.args`) plus a `property("commander", "args")` manifest entry, but the drift gate requires a *Method* counterpart for every dispatch row. Add `method("commander", "args", true, None)` alongside the property — the has_receiver method isn't emitted as a module export, so `perry.d.ts` is unchanged; only reference.md gains the `args` instance-method line.
Fixes #5197.
Problem
uuid'sv5()(and friends) were non-functional on the native shim path — i.e. whenuuidresolves fromnode_modulesand is not inperry.compilePackages:v5/v3undefinedversionundefinedvalidate0NA_F64, but runtime takes*const StringHeader→ arg passed in the wrong registerv4/v1/v7[object Object]NR_PTR(generic native handle) instead of a stringThe
perry.compilePackages(real-source) path already produced the correct id on currentmain— both paths now agree.Fix
js_uuid_v5(SHA-1) andjs_uuid_v3(MD5) to bothperry-ext-uuidandperry-stdlib; enable the uuid crate'sv3/v5features.utils_crypto.rs): addv5/v3/versionrows, fixvalidate's arg toNA_STR, box all string generators asNR_STR.NR_BOOLreturn kind boxes the FFI bool-as-f64 (1.0/0.0) result as a real JS boolean sovalidate(...)printstrue/false, not1/0. Used foruuid.validate.API_MANIFESTentries (+ regenerateddocs/) so theapi-docs-driftandmanifest_consistencygates stay green.The shim supports the string-UUID namespace form (covers the repro + the
v5.DNS/v5.URLconstants); the array/Uint8Arraynamespace form remains reachable viaperry.compilePackages.Verification
Both paths now match Node exactly:
perry-ext-uuidreference-vector tests for v5/v3 (verified against Node) — 7/7 pass.manifest_consistencyfailure (commander::args) is pre-existing and unrelated — it fails identically onmainwith this change stashed out.Summary by CodeRabbit
uuid.v3()anduuid.v5()for name-based UUID generation.uuid.version()to retrieve the numeric UUID version.uuid.validate()withuuid.version(), changing the result from boolean to a number.uuid.v3,uuid.v5, anduuid.version.