-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Compile Time Constant Extraction] Add extraction of tuples #62436
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
[Compile Time Constant Extraction] Add extraction of tuples #62436
Conversation
lib/ConstExtract/ConstExtract.cpp
Outdated
for (auto elementExpr : tupleExpr->getElements()) { | ||
elements.push_back({Optional<std::string>(), elementExpr->getType(), | ||
extractCompileTimeValue(elementExpr)}); | ||
} |
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.
@artemcm - I wasn't able to exercise this codepath. Do you happen to know under what circumstances tupleExpr->hasElementNames()
would be false?
I had thought let t1: (String, Bar) = ("foo", Bar())
would cause that, but instead the tuple expression's identifier is .empty()
.
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.
Looks like the parser sets things up with empty identifiers rather than no identifiers.
One example I see where hasElementNames()
would return false
is an empty tuple. And it's possible there is other places where the compiler itself synthesizes a tuple where labels are omitted. So it should be fine to keep this code-path as-is for safety.
lib/ConstExtract/ConstExtract.cpp
Outdated
std::vector<TupleElement> elements; | ||
if (tupleExpr->hasElementNames()) { | ||
for (auto pair : | ||
llvm::zip(tupleExpr->getElements(), tupleExpr->getElementNames())) { |
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.
There is an assumption here that when tupleExpr->hasElementNames()
is true, getElements()
and getElementNames()
have the same number of items. I can add a check, but thought it was currently unnecessary.
@swift-ci test |
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.
Cool!
@swift-ci test macOS platform |
ac9b5bc
to
f6c6c26
Compare
@swift-ci test |
@swift-ci test Windows platform |
f6c6c26
to
10b2e14
Compare
@swift-ci test |
@swift-ci test Windows platform |
1 similar comment
@swift-ci test Windows platform |
10b2e14
to
bc5f64d
Compare
@swift-ci test |
bc5f64d
to
db67e10
Compare
@swift-ci test |
db67e10
to
0177c12
Compare
@swift-ci test |
0177c12
to
c07c84b
Compare
@swift-ci test |
c07c84b
to
4ed167b
Compare
JSON.attributeArray("value", [&] { | ||
for (auto TV : tupleValue->getElements()) { | ||
JSON.object([&] { | ||
if (auto Label = TV.Label) { |
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.
@quinntaylor - Removed null labels
4ed167b
to
0a1c65f
Compare
@swift-ci test |
Statically extract tuples with named and unnamed elements.
This change also:
Expr -> CompileTimeValue
into a recursive function to allow proper nesting of extracted values.t
for tuple,d
for dictionary, etc.)