fix(compile): imported default ctor arity matches the synthesized forwarding ctor (#10258) - #10259
proggeramlug wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe compiler now derives imported class constructor arity from the shared synthesis rules. Classes with runtime-value parents use the forwarding arity, so cross-module construction passes arguments to the parent. A regression test covers exports, re-exports, inheritance, accessors, methods, and multi-argument constructors. ChangesImported constructor arity
Priority: ⬆️ High Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: High Sequence Diagram(s)sequenceDiagram
participant imported_class_from_hir
participant context_free_ctor_param_count
participant synthesized_ctor_param_count
imported_class_from_hir->>context_free_ctor_param_count: derive constructor_param_count
context_free_ctor_param_count-->>imported_class_from_hir: return fixed arity or None
imported_class_from_hir->>synthesized_ctor_param_count: use matching forwarding arity
synthesized_ctor_param_count-->>imported_class_from_hir: forward constructor arguments
Merge Risk: ⚪ Minimal · up to The constructor-forwarding fix is covered across imported runtime-parent classes and related inheritance forms, with no remaining actionable merge risk identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
|
Scope note after further testing: this PR fixes only the heritage form that lowers to |
Fixes #10258 (OpenCode v1.18.30 runtime wall, tracker #10107).
Root cause
For an exported class with no own constructor whose
extendsclause is a runtime value (class SystemError extends Data.Error {}— effect v4'sData.Erroris an IIFE-returned class re-exported as a const), the two modules disagreed about the standalone constructor's arity:<prefix>__<Class>_constructor(this, __forward_arg0..7):ctor_arity::synthesized_ctor_param_countcannot resolve the parent's arity by name, so it forwards the fixedUNRESOLVED_PARENT_FWD_ARITY = 8band;ImportedClass.constructor_param_countfrom the class's own constructor only (run_pipeline.rs imported_class_from_hir) = 0, declared the symbol as(double this), andmarshal_imported_ctor_argstruncated the call to zero arguments.The callee then read its forwarding parameters from registers the caller never set: the parent ran without the argument object (with an unfixed compiler the repro's three-argument case even prints
[7,1.385e-309,0]). Same-module construction and explicitconstructor(a) { super(a) }were unaffected, because they do not go through the imported symbol with a mismatched arity.In OpenCode this made effect's
PlatformError.SystemErrorlose_tag/module/method, soEffect.catchReason("PlatformError", "NotFound", …)inFSUtil.readFileStringSafenever matched and the first missing optional config file (~/.config/opencode/config.json) became a fatalError: Unexpected error / [object Object]for every command.Fix
perry_codegen::context_free_ctor_param_count(class)(incodegen/ctor_arity.rs, next tosynthesized_ctor_param_countand documented as having to agree with it) answers the arity whenever it is decidable from the class definition alone: own constructor → its params, native parent → 0, no heritage → 0, runtime-value heritage only (extends_expr, noextends_name) →UNRESOLVED_PARENT_FWD_ARITY. It returnsNonewhen the ancestor walk is needed.constructor_param_countand keeps the previous value forNone, so every other shape is unchanged.Verification (perrymaster, Linux x86_64, release build on main 4945fc1 + #10250)
crates/perry/tests/source_graph_export_regressions/issue_10258.rs(4 modules): empty subclass, subclass withget message(), with a method, with an explicit constructor, a 3-argument runtime parent, a namespace-importnew P.Empty(...), same-module construction, and a main-module subclass of the imported class. Its program compiled with the patched compiler prints exactly bun 1.3.14's output; with the unpatched compiler it prints,,true …/[7,1.385e-309,0].https://claude.ai/code/session_01As1fetJAqDFib4n7Wm5Suo
Summary by CodeRabbit
Bug Fixes
Tests