compiler,reflect: add support for [...]T -> []T in reflect#3761
Conversation
|
Pull in a commit from #3570 |
aykevl
left a comment
There was a problem hiding this comment.
Seems good to me (but see the comment below). Also, can you add a test, for example to testdata/reflect.go?
Unfortunately, this does increase binary size quite substantially (for a relatively rare feature): more than half of the driver smoke tests increased in size by some amount, and a number of them by >100 bytes. Overall it says 0.27% increase, which is quite a lot IMHO.
I suspect a significant contributor is all the unexported fields in src/device, some of which are arrays for padding (like [20]byte). Maybe a flag to not emit reflect information for unexported fields would help? I'm thinking -reflect=[full|minimal|none], where "minimal" could mean "no unexported fields".
| return Value{ | ||
| typecode: sliceType, | ||
| value: unsafe.Pointer(&hdr), | ||
| flags: v.flags, |
There was a problem hiding this comment.
Does this work correctly with both small and large arrays? I'm thinking about valueFlagIndirect.
There was a problem hiding this comment.
Oh, good point. Let me add some more tests for that.
|
While I was expecting some size increase, all the |
|
I wonder if that size increase (above the array->slice pointers) is the actual new reflect code that isn't getting stripped? |
Unfortunately not. Reflect data is highly recursive, so using a PWM interface in a driver is enough to keep data for machine.PWM, which refers to data for nrf.PWM_Type, which contains a number of padding arrays of varying sizes. Even when no reflect features are used and the struct fields themselves are entirely useless (they're |
So For embedded code, minimal could be the default? I wonder if the compiler could detect the needed level of reflection support. Finally wouldn't adding a flag like this be a feature to add in a separate PR? |
Yeah. But that also means removing some other language features like hashmaps with arbitrary keys, so maybe it's not such a great idea.
That's certainly something we could consider, as long as it doesn't affect too much existing code.
Sadly not (except for trivial cases which are probably already optimized). You quickly run into halting-problem level of difficulty.
Oh definitely, this is not something that should be part of this PR. |
I did a quick test with |
|
So we are waiting for some additional tests and then we will merge this PR? |
|
Seems like with the size increase we probably want to leave this for now. |
As a long time user of TinyGo for embedded systems for hobby and just recently professional use I'd like to chime in and say this change would not affect me much since I'm almost entirely using the Raspberry Pi Pico (0.25% increase is a measly 30 bytes diff of the 264kB available). Surely there's other targets where a 30 or 100bytes increase is noticeable or even mission critical, but I don't think it's the case for Pico users which would warrant |
|
What code that does not currently compile does this PR unlock for us? That would make it easier to help decide if the cost in bytes is worth it. |
|
I'm careful with things like "it's only 0.25%" because binaries in the 0.28.0 release caused a ~10% increase in binary size, and I think the majority of that is these small seemingly insignificant binary size increases. In embedded systems, that could just be what's pushing the firmware size over the edge and make it too big for a flash chip.
This would be very helpful indeed. |
|
I think I found this trying to make the |
|
These are the top 5 size increased in the smoketests from this PR: Make of the smoketests did not change size at all. I wonder why these changed by the largest percentage? |
|
Suggest releasing without this feature, then landing it right after release. Time marches on. |
@dkegel-fastly that is very sensible advice. Moving milestone. |
|
The time has come to merge this PR and unlock the additional refection compatibility it brings. Thank you very much for all your work on this feature @dgryski and to everyone else for your helpful comments and feedback. |
No description provided.