fix(hir-def): don't panic instantiating cross-file extends chains (#236)#256
Open
avrabe wants to merge 2 commits into
Open
fix(hir-def): don't panic instantiating cross-file extends chains (#236)#256avrabe wants to merge 2 commits into
avrabe wants to merge 2 commits into
Conversation
`spar instance` panicked (`index out of bounds: the len is 0 but the index is 0` at instance.rs) when a system implementation `extends` a parent declared in a different file. Cause: `collect_impl_chain` walks the extends chain across trees and collects each inherited subcomponent's `SubcomponentIdx`, but dropped the tree the subcomponent was DECLARED in. The caller then paired every inherited `sub_idx` with the most-derived impl's `loc.tree`. When that derived impl declares no subcomponents of its own, its tree's `subcomponents` slice is empty and `subcomponents[sub_idx]` panics. Fix: carry the originating `tree_idx` per subcomponent through `ImplChainResult.subcomponents`, and use it (not `loc.tree`) at the three consumer sites — recursive instantiation, leaf property map, and anon property map. Regression test `extends_chain_across_files_does_not_panic` builds a base impl (with a subcomponent) and a derived impl that `extends` it from a separate file/tree and declares no own subcomponents — the exact shape that panicked — and asserts the inherited subcomponent instantiates. Closes #236. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Rivet verification gate✅ 20/20 passed
Filter: Failed artifacts(none) Updated automatically by |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
dbfcc44 to
306ad09
Compare
cargo fmt — no behavior change. (Format CI check.) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes #236 —
spar instancepanicked withindex out of bounds: the len is 0 but the index is 0(instance.rs) when a system implementationextendsa parent declared in a different file.Cause
collect_impl_chainwalks theextendschain across trees (files) and collects each inherited subcomponent'sSubcomponentIdx— but dropped the tree it was declared in. The caller then paired every inheritedsub_idxwith the most-derived impl'sloc.tree. When that derived impl declares no subcomponents of its own, its tree'ssubcomponentsslice is empty, sosubcomponents[sub_idx](index 0 into len 0) panicked.Fix
Carry the originating
tree_idxper subcomponent throughImplChainResult.subcomponents, and use it instead ofloc.treeat the three consumer sites: recursive instantiation (Some((sub_tree, sub_idx))),build_leaf_property_map, andbuild_anon_property_map.Verification
dataflow.aadl+dataflow_diagram.aadl+hw.aadl): panic before, full instance tree after.extends_chain_across_files_does_not_panic— base impl with a subcomponent + a derived impl thatextendsit from a separate tree with no own subcomponents (the exact panic shape); asserts the inherited subcomponent instantiates.cargo test -p spar-hir-def: 458 + 1 pass, 0 failures.Note
The reporter's model also surfaces
applies_to path 'my_process.c1' could not be resolvedwarnings for connection properties — that's the separate #237 (properties on connections/features), not addressed here. This PR is scoped to the panic.🤖 Generated with Claude Code