delay size pragma for generic types, use it for C++ Atomic[T]
#24204
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 #24159, refs #15928 etc, refs #7674 (fixed but not tested)
When a
sizepragma is applied to a generic type, the pragma is untouched and the type is marked as having "unresolved properties". This is regardless of whether the pragma actually uses any generic parameters, because by the time the pragma is being processed, generic parameters aren't in scope yet. For pragma processing to know that the type is generic, the forward type is temporarily given the flagtfHasMetato mark that it has generic parameters.When this type undergoes generic instantiation, the pragma is found again from the type symbol AST (not sure if this is reliable), the value is instantiated, and the new
sizeis applied to the type. Other pragmas can opt in to this later, currently justsizeis checked.This allows us to do things like
size: sizeof(T)where T is a generic parameter, and this is now used instead ofcompleteStructand the fakerawfield added in #15928 for the size ofAtomic[T]on C++. This fixes the issues related to therawfield like #24159. The restriction of only the values 1, 2, 4 and 8 being allowed for thesizepragma is also removed for imported types for this to be possible.There are a couple reasons I wasn't sure about this solution and some things I'm still not sure about:
deprecatedmessages), just never in a case that actually has an effect on the type system. I didn't want to complicate the type graph even more by adding a dedicated field that's redundant with pragmas. In the future maybe we can use theannexfield ofPSymto store/access pragmas including custom pragmas more efficiently in general, , but then there still needs to be a way to access this in macros.alignaspragma either. I thought thealignpragma did this, which is why I initially generalized this for all "properties".--mm:refcwithThread/Atomic/createThread#24159 on the 2.0 branch, since fixes #9940; genericAssign does not take care of the importC variables in refc [backport] #23761 which caused it was backported.