Skip to content

Give each element of a PartialArray its own skeleton - #1542

Merged
sunxd3 merged 5 commits into
TuringLang:mainfrom
PTWaade:skeleton-of-each-element
Nov 20, 2026
Merged

sunxd3 merged 5 commits into
TuringLang:mainfrom
PTWaade:skeleton-of-each-element

Conversation

@PTWaade

@PTWaade PTWaade commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Dear Turing, and @sunxd3

As @sunxd3 requested, I am here opening a PR for fixing the issue reported in #1540. The PR is drafted by Claude (also incorporating the points raised in the discussion there). I don't know enough of Turing's internals to be able to confidently judge whether this is an appropriate solution, but since it at first glance seemed correct to your developers, I am opening this PR - I hope it is useful. Below is a report by Claude. Let me know if there is anything I can do!

--- Claude ---

Fixes #1540.

skeleton of a PartialArray whose element type is concrete took the skeleton of the first element that is set, and filled every element with it. When the elements hold arrays of different sizes, the round trip in the docstring of skeleton fails: with the shorter array first it throws a BoundsError, and with the longer first it rebuilds arrays of the wrong size. This is what made FlexiChains.parameters_at fail on the chains in the issue.

This PR gives each element that is set its own skeleton, as the branch for an abstract element type already does. As @sunxd3 pointed out, elements of one concrete type can also have skeletons of different types, such as when a field typed Any holds a vector in one element and a matrix in another, so each skeleton is set with BangBang.setindex!!, which widens the array when it has to. Elements that aren't set keep the skeleton of the first element that is set, as before.

Tests: three cases in the skeleton testset of test/varnamedtuple.jl, inner arrays of different sizes in both orders, checked with @inferred and the round trip, and the case with a field typed Any, built directly as a PartialArray, whose skeleton can't be inferred. On main, the first throws the BoundsError, the second rebuilds a different VarNamedTuple, and with new_data[i] = … in place of setindex!! the third throws a convert error. With this PR test/varnamedtuple.jl passes, 50545 tests, and the reproducer from the issue gives back its values. Formatted with JuliaFormatter 1.0.62.

skeleton of a PartialArray whose element type is concrete filled every element with the skeleton of the first element that is set. Elements that hold arrays of different sizes then got skeletons of the wrong size, so rebuilding a VarNamedTuple from the skeleton threw a BoundsError or gave arrays of the wrong size. Each element that is set now gets its own skeleton, set with BangBang.setindex!!, since elements of one concrete type can also have skeletons of different types, such as when a field typed Any holds a vector in one element and a matrix in another.

Fixes TuringLang#1540
@sunxd3
sunxd3 force-pushed the skeleton-of-each-element branch from c5a24ca to f113816 Compare November 19, 2026 20:25
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.11%. Comparing base (702b8c0) to head (2244303).

Files with missing lines Patch % Lines
src/varnamedtuple/skeleton.jl 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1542      +/-   ##
==========================================
- Coverage   85.12%   85.11%   -0.01%     
==========================================
  Files          52       52              
  Lines        4671     4677       +6     
==========================================
+ Hits         3976     3981       +5     
- Misses        695      696       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sunxd3
sunxd3 added this pull request to the merge queue Nov 19, 2026
@sunxd3
sunxd3 removed this pull request from the merge queue due to a manual request Nov 19, 2026
@sunxd3
sunxd3 enabled auto-merge November 19, 2026 21:45
@sunxd3
sunxd3 added this pull request to the merge queue Nov 20, 2026
Merged via the queue into TuringLang:main with commit ec3892d Nov 20, 2026
24 checks passed
@sunxd3

sunxd3 commented Nov 20, 2026

Copy link
Copy Markdown
Member

@PTWaade thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

skeleton gives every element of a PartialArray the skeleton of the first

2 participants