Skip to content

Add inferred constructors - #3

Merged
tuckermcclure merged 3 commits into
mainfrom
tucker/add-inferred-constructors
Sep 28, 2026
Merged

tuckermcclure merged 3 commits into
mainfrom
tucker/add-inferred-constructors

Conversation

@tuckermcclure

Copy link
Copy Markdown
Member

Summary

Generated Julia messages can now infer length parameters from constructor inputs. For example, ControlParameters(motors = motors, ...) obtains N from the vector length, while a field declared as MotorParameters{N}[M] obtains N from its concrete elements and M from the collection length.

Design

  • Inferred positional and keyword constructors delegate to the existing explicit Type{N,...} constructor. That constructor remains available and continues to perform length validation, field conversion, and storage reordering.
  • When several inputs imply the same parameter, the constructor checks that they agree. Arrays of nested messages check every element.
  • An inferred constructor is emitted only when every parameter can be determined from the inputs. Otherwise, callers use the explicit constructor.
  • The array check uses a private loop binding that cannot collide with an IDL field or parameter name.

C++ generation and the generated type layouts are unchanged.

Validation

julia --project=test test/runtests.jl passes locally, including compiled C++ interoperability tests. Constructor tests cover regular Julia vectors, nested scalar messages, arrays and matrices of nested messages, conflicting lengths, keyword calls, and a parameter that cannot be inferred.

@tuckermcclure

Copy link
Copy Markdown
Member Author

I'm going ahead with the merge because this is working great for me. Let me know if you see anything weird here though!

@tuckermcclure
tuckermcclure merged commit 3b28b25 into main Sep 28, 2026
4 checks passed
@tuckermcclure
tuckermcclure deleted the tucker/add-inferred-constructors branch September 28, 2026 19:06
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.

1 participant