-
Notifications
You must be signed in to change notification settings - Fork 284
Support Array Sizes using Generic arguments to be initialized via {} #6720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Support Array Sizes using Generic arguments to be initialized via {} #6720
Conversation
/format |
🌈 Formatted, please merge the changes from this PR |
Please add a test so that we can prevent a regression. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's definitely quite suspicious to just be inventing the array size 0
out of thin air, if it's true that these are statically known then we should organize things such that we can get that value when it comes time to handle the initializer list.
… via {} Fixes one subissue of shader-slang#6138 This change adds support for initializing Arrays with Generic size arguments via {} and adds a test to verify it. The change checks for an array whose size parameter is a GenericParamIntVal and since the size of such an array will be known at link time, is not considered as a case of the size not being known statically.
a157f4f
to
ac99299
Compare
/format |
🌈 Formatted, please merge the changes from this PR |
@@ -611,7 +611,7 @@ bool SemanticsVisitor::_readAggregateValueFromInitializerList( | |||
{ | |||
elementCount = (UInt)constElementCount->getValue(); | |||
} | |||
else | |||
else if (!as<GenericParamIntVal>(as<TypeCastIntVal>(toElementCount)->getBase())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems wrong. What if toElementCount
isn't a TypeCastIntVal?
Instead of adding the condition here, we should change the behavior inside this branch from emitting a diagnostic to
forming an Expr AST node representing MakeArrayFromScalar(defaultVal(ElementType))
, and make sure it lowers to proper IR in the form of IRMakeArrayFromScalar
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
… via {} Fixes one subissue of shader-slang#6138. Fixes the issue shader-slang#6958. This change adds support for initializing Arrays with Generic size arguments via {} and adds a test to verify it. Support is added by means of adding a new AST Expr node that lowers down to the IR MakeArrayFromElement and the emission of a diagnostic is replaced with the creation of this new AST Expr node.
@@ -139,6 +139,12 @@ class StringLiteralExpr : public LiteralExpr | |||
FIDDLE() String value; | |||
}; | |||
|
|||
FIDDLE() | |||
class ArrayWithGenericSizeExpr : public Expr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This naming is confusing. The Expr node represents an option that is to create an array from a single element value. It doesn't matter if the array type has generic size or not. This should just named MakeArrayFromElementExpr
.
Support Array Sizes using Generic arguments to be initialized via {}
Fixes one subissue of #6138
This change adds support for initializing Arrays with Generic size arguments via {}