Skip to content

[Swiftify] Adjust _SwiftifyImport invocation to align with the signature #81855

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

Merged
merged 2 commits into from
Jun 30, 2025

Conversation

hnrklssn
Copy link
Contributor

of the macro in the currently laoded macro module

Stdlib macros are shipped with the SDK, so we need to make sure that the way we invoke the macro matches the version of the macro in the SDK. This patch skips the spanAvailability parameter if it isn't present. There's no good way to test this, because we will always pick up the current macro in our llvm-lit test suite, but I've tested it manually.

rdar://152278292

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@Xazax-hun Xazax-hun left a comment

Choose a reason for hiding this comment

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

Couple questions inline, otherwise looks good to me.

assert(SwiftifyImportDecl);
if (!SwiftifyImportDecl)
return false;
for (auto *Param : *SwiftifyImportDecl->parameterList)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be replaced with llvm::find_if or something similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could be replaced with any_of, but it wouldn't really be any easier to read imo (nor more concise), and is a bit more annoying to debug with the jumping between stack frames

bool hasMacroParameter(StringRef ParamName) {
ValueDecl *D = getDecl("_SwiftifyImport");
auto *SwiftifyImportDecl = dyn_cast_or_null<MacroDecl>(D);
assert(SwiftifyImportDecl);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could the compiler ever be used with on old enough SDK that does not have this macro? Or could the compiler be used without the SDK at all? If yes, maybe we don't want to assert here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If that's the case I think we have bigger issues: the macro will still be attached. This only handles whether to use the new or old signature. But it's a good point. @DougGregor what's our stance on using this with an SDK that doesn't contain the macro at all?

Copy link
Member

Choose a reason for hiding this comment

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

Personally, I tend to be defensive against using the compiler with older SDKs unless it's a ton of work. Here, if you can just safely return false on a null SwiftifyImportDecl, I'd do that.

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 added an early exit in swiftify instead, if @_SwiftifyImport doesn't exit

hnrklssn added 2 commits June 27, 2025 19:10
of the macro in the currently laoded macro module

Stdlib macros are shipped with the SDK, so we need to make sure that the
way we invoke the macro matches the version of the macro in the SDK.
This patch skips the `spanAvailability` parameter if it isn't present.
There's no good way to test this, because we will always pick up the
current macro in our llvm-lit test suite, but I've tested it manually.

rdar://152278292
@hnrklssn hnrklssn force-pushed the swiftify-availability-check-sdk branch from 80834ca to 1d1c642 Compare June 28, 2025 04:38
@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

1 similar comment
@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

@Xazax-hun this is finally ready for another round of review :)

Copy link
Contributor

@Xazax-hun Xazax-hun left a comment

Choose a reason for hiding this comment

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

I have one small question but overall looks good to me.

}

void printAvailabilityOfType(StringRef Name) {
ValueDecl *D = getDecl(Name);
ValueDecl *D = getKnownSingleDecl(SwiftContext, Name);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also be defensive here in case e.g., Span is not available in the standard library used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory probably yes, but on the other hand we only reach this if _SwiftifyImport is present, and if that's present and Span isn't I would imagine something is very wrong

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good!

@hnrklssn hnrklssn merged commit e9ba8f8 into swiftlang:main Jun 30, 2025
3 checks passed
hnrklssn added a commit to hnrklssn/swift that referenced this pull request Jun 30, 2025
…y-check-sdk

[Swiftify] Adjust _SwiftifyImport invocation to align with the signature

(cherry picked from commit e9ba8f8)
hnrklssn added a commit that referenced this pull request Jul 3, 2025
…check

Cherry-pick "Merge pull request #81855 from hnrklssn/swiftify-availability-check-sdk"
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.

3 participants