Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

psruthikNV
Copy link
Contributor

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 {}

@psruthikNV
Copy link
Contributor Author

/format

@slangbot
Copy link
Contributor

slangbot commented Apr 1, 2025

🌈 Formatted, please merge the changes from this PR

@jkwak-work
Copy link
Collaborator

Please add a test so that we can prevent a regression.

Copy link
Collaborator

@expipiplus1 expipiplus1 left a 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.
@psruthikNV psruthikNV force-pushed the sruthik/6138_generic_array_size branch from a157f4f to ac99299 Compare April 9, 2025 07:01
@psruthikNV
Copy link
Contributor Author

/format

@slangbot
Copy link
Contributor

slangbot commented Apr 9, 2025

🌈 Formatted, please merge the changes from this PR

@psruthikNV psruthikNV marked this pull request as ready for review April 9, 2025 07:03
@psruthikNV psruthikNV requested a review from a team as a code owner April 9, 2025 07:03
@psruthikNV psruthikNV added the pr: non-breaking PRs without breaking changes label Apr 9, 2025
@@ -611,7 +611,7 @@ bool SemanticsVisitor::_readAggregateValueFromInitializerList(
{
elementCount = (UInt)constElementCount->getValue();
}
else
else if (!as<GenericParamIntVal>(as<TypeCastIntVal>(toElementCount)->getBase()))
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

psruthikNV added 2 commits May 7, 2025 18:00
… 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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: non-breaking PRs without breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants