Skip to content

Conversation

jPaolantonio
Copy link
Contributor

This PR extracts result builder type information for variables. This checks for both implicit and explicit (ie. protocol conformance) result builder annotations.

@jPaolantonio
Copy link
Contributor Author

@swift-ci test

for (auto Member : Decl->getMembers()) {
if (auto *VD = dyn_cast<swift::VarDecl>(Member)) {
if (auto *attr = VD->getAttachedResultBuilder()) {
if (VD->getName() == VarDecl->getName()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@artemcm - Is checking equality by identifier the right thing to do here? It properly filtered in my testing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, those are uniqued by the ASTContext, so this should be safe. 👍🏼

JSON.attribute("type",
toFullyQualifiedTypeNameString(attr->getType()));
writeFileInformation(JSON, VD->getASTContext(), attr);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I likely want to break out of this loop when we see a result builder.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be sufficient to break once we've seen a var decl with the name to the one we're looking for, result builder or no result builder, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I think so.

Comment on lines 102 to 103
// CHECK-NEXT: "file": "{{.*}}test{{/|\\\\}}ConstExtraction{{/|\\\\}}ExtractResultBuilders.swift",
// CHECK-NEXT: "line": 24
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For inferred conformances, this is where the protocol is defined. Do we maybe not need file/line information since we have the var file/line above?

Copy link
Contributor

Choose a reason for hiding this comment

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

My intuition is that we don't need file/line for the attribute at all, those are largely mostly relevant for the property decl itself. But perhaps I'm missing some use-case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Removing.

@jPaolantonio jPaolantonio force-pushed the const-extraction-result-builder branch from bf3f0b6 to d4c5ca6 Compare January 19, 2023 01:45
@jPaolantonio
Copy link
Contributor Author

@swift-ci test

for (auto Member : Decl->getMembers()) {
if (auto *VD = dyn_cast<swift::VarDecl>(Member)) {
if (auto *attr = VD->getAttachedResultBuilder()) {
if (VD->getName() == VarDecl->getName()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: getAttachedResultBuilder fires off a request, so I think checking if the VD->getName() is the one we're looking for first could save some unnecessary work for all the other properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense to me. I'll change that order and add the early return.

Copy link
Contributor

@artemcm artemcm left a comment

Choose a reason for hiding this comment

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

A couple of small comments, but otherwise this is looking good!

@jPaolantonio jPaolantonio force-pushed the const-extraction-result-builder branch from d4c5ca6 to 6bccd9f Compare January 19, 2023 21:36
@jPaolantonio
Copy link
Contributor Author

@swift-ci test

@jPaolantonio jPaolantonio merged commit f4a7e4c into swiftlang:main Jan 20, 2023
@jPaolantonio jPaolantonio deleted the const-extraction-result-builder branch January 20, 2023 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants