static_show: Use reinterpret
for types with non-default constructors
#58627
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.
The idea here is that we can reasonably expect that types with default inner constructors can be constructed as
Foo(field1, field2, field3)
in most cases. That's because, if an outer constructor "covers" the full-length default constructor, then it can only construct the object it needs via@invoke
,reinterpret
,Expr(:new, ...)
or similar workarounds (the full-length default constructor is not available via dispatch and neither isnew
)This gives us a compact output for the majority of
isbits
types:but also evaluates to the correct value when inner constructors are present that do strange things:
Mostly a proof-of-concept to illustrate this approach. Lots of tests still needed (and
hasdefaultctors
may need to be tracked very differently)