Repository navigation
fix(rust): resolve scalar maps and recursion - #282
Conversation
|
@Ani07-05 Has this been well tested ? |
|
Yes, tested. I ran:
|
There was a problem hiding this comment.
Thank you for this contribution, Ani07-05, and for the clear PR description. Unwrapping scalar map keys and values in visitMapDeclaration is a clean fix for the undefined SSN and Time types, and removing the two Rust skips in test/verification/cases.js is the right follow-through. Boxing non-array relationships does break the Manager cycle in the HR model. Nothing here is blocking, but a few things would make this ready to merge: (1) rebase onto main and regenerate the snapshot, (2) either box recursive containment fields as well or narrow the title and description to relationship recursion, (3) list the unconditional boxing as a numbered question for the maintainers and consider limiting it to relationships that are actually recursive, and (4) add a unit test for a scalar map value.
Nothing blocking; some suggestions below. Findings: 3 should-fix, 1 nit.
- should-fix · hygiene: GitHub reports this branch as conflicting with
main. Please rebase, runnpm run test:updateSnapshots, and read the changes intest/codegen/__snapshots__/codegen.js.snapto check that each changed line still follows from the fix. The commit also needs to be able to passnpm teston the rebased branch.
Automated review by Mira, an Accord Project agent, at f7c8295. Findings are labelled blocking, should-fix or nit; a maintainer makes the final call.
f7c8295 to
ae6fb34
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
Thank you for the updates, Ani07-05. The new head addresses the earlier feedback well. Boxing now happens only where a property really reaches its declaring class, which keeps the generated output unchanged for most models. Containment fields are covered as well as relationships. The snapshot change is limited to Employee.manager and Manager.manager. The scalar key and value map handling has unit tests, and the two stale verification skips are removed. One edge case remains, under the opt-in flattenSubclassesToUnion parameter. Once that is handled, with a unit test, this looks ready for a maintainer to approve. The earlier review threads look resolved by these changes, so it would help to mark them resolved. The CI workflows for a first contribution need a maintainer to approve them, so only the DCO check has run so far.
Nothing blocking; some suggestions below. Findings: 1 should-fix.
- should-fix · correctness ·
lib/codegen/fromcto/rust/rustvisitor.js:isRecursiveonly boxes when the target is the declaring class, reaches it through properties, or is a subclass of it. WithflattenSubclassesToUnionon, a field typed with a superclass is emitted as<Base>Union, and that enum has a variant for every subclass. Takeabstract concept Base {}andconcept A extends Base { o Base other }. This generatesA { other: BaseUnion }andBaseUnion::A(A), which is an infinitely sized type thatcargo checkrejects with E0072.isRecursivereturns false here becauseBasenever reachesA. Suggested fix: passuseUnionintoisRecursive. When it is true, also treat the property as recursive if the owner is, or inherits from, the property's target type (compareowner.getAllSuperTypeDeclarations()with the target) and the target has subclasses in the same model file. Please add a unit test for this case alongside the other recursion tests.
Automated review by Mira, an Accord Project agent, at ae6fb34. Findings are labelled blocking, should-fix or nit; a maintainer makes the final call.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
Thank you for sticking with this, Ani07-05. The latest commit is a clear improvement. Boxing now happens only when a property reaches its declaring class, which covers direct, indirect, subclass and flattenSubclassesToUnion cases and leaves other output unchanged. Earlier comments about containment recursion, unconditional boxing and missing scalar-value tests are addressed, and the new unit tests for the cycle and union cases are well chosen. I found no new problems in the code. To make this mergeable: (1) the test and verification workflows haven't run on this commit, so cargo check for the Rust cases whose skips you removed is not yet confirmed. A maintainer needs to approve the workflow runs, and they need to pass; (2) please resolve the three earlier review threads that are now addressed; (3) a maintainer needs to approve. Please also include the commands you ran locally and the pass counts in the description, as the repo's guidance asks.
No problems found.
Automated review by Mira, an Accord Project agent, at 6938e9c. Findings are labelled blocking, should-fix or nit; a maintainer makes the final call.
|
@mttrbrts could you approve the CI workflow runs ? |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
7ecfec7 to
91671c4
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Unwrap scalar map key/value types in type aliases to their primitives and box non-array properties that reach their declaring class, so generated output passes cargo check. Remove the Rust verification skips for hr_base and hr_integration. Closes accordproject#264 Signed-off-by: Anirudh <anirudh.ashrith2005@gmail.com>
91671c4 to
82ec254
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
🟡 Changes recommended
The traversal can exhaust the JavaScript call stack on deeply nested acyclic models and unnecessarily box non-recursive fields by including abstract base types as union variants.
2 open issues
1 resolved since last review
Review effort: Balanced
82ec254 to
e8f8954
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
With flattenSubclassesToUnion, a field typed with a base class is
emitted as <Base>Union, which has a variant for each local subclass.
A subclass declaring such a field (A { o Base other }) produced an
infinitely sized type that cargo check rejects with E0072.
isRecursive now also treats the field as recursive when any union
variant reaches the declaring class.
Signed-off-by: Anirudh <anirudh.ashrith2005@gmail.com>
e8f8954 to
118c66b
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
🟡 Changes recommended
Flattened relationships can be boxed unnecessarily, verification can misidentify cycles across namespaces, and repeated reachability checks cause quadratic generation time.
3 open issues
2 resolved since last review
Review effort: Balanced
| const seen = new Set(); | ||
| const pending = typesReachedBy(property); |
| let type = relationshipDeclaration.type; | ||
| if (relationshipDeclaration.isArray?.()) { | ||
| type = `Vec<${type}>`; | ||
| } else if (this.isRecursive(relationshipDeclaration, false, parameters.emittingClass)) { |
| .readdirSync(src) | ||
| .filter((file) => file.endsWith('.rs')) | ||
| .map((file) => fs.readFileSync(path.join(src, file), 'utf-8')) | ||
| .join('\n'); |
|
@jamieshorten thank you for your constant patience and merging the PR , appreciate it :D |


Closes #264
Changes
pub typemap aliases (HashMap<SSN, Employee>becomesHashMap<String, Employee>), matching how field sites already behave. Scalars are not emitted, so the alias previously referenced undefined types (bugs 1 and 2)Box<T>(Option<Box<Manager>>) only when it is recursive, to break the infinite-size type (bug 3). A field is recursive when its target reaches the struct that holds it through non-array properties (direct or indirect cycle). Inherited properties are written into every subclass, so each subclass copy is checked against its own struct, not the declaring class. WithflattenSubclassesToUnion, a union-typed field also reaches every variant of the<Base>UnionenumBox)flattenSubclassesToUnion, only reference<Base>Unionwhen the enum is actually generated, i.e. when a subclass is in the same model file. Previously a base whose subclasses were all in other namespaces emittedBaseUnionwithout defining it (E0425). OneunionSubclasses()helper now drives the enum, the field type and the cycle checkskipentries forhr_baseandhr_integrationintest/verification/cases.jsso they are verified withcargo checkFlags
Vec<T>fields and map values are left unboxed since they already provide indirectionTesting
npx mocha test/codegen/fromcto/rust/*.js: 68 passingnpx mocha test/verification/rust.compile.test.js(cargo check): 32 passing.hr_baseandhr_integrationpass with the skips removed; 8 inline cases withflattenSubclassesToUnioncover union cycles, relationship cycles, an inherited field that loops only in the subclass, a map whose value holds the owner, and an abstract base that refers to its own union, and a cross-namespace union baseBoxfield to point at a type that leads back to its owner. It runs on the 8 corpus cases and the 9 inline shapes, and fails if the abstract-base over-boxing is reintroducednpm test: 741 passing, 0 failing on the branch rebased onto current main; lint, licence-header check and JSDoc are cleanRelated Issues
cargo check#264Author Checklist
--signoffoption of git commit.