Skip to content

Commit e9ba8f8

Browse files
authored
Merge pull request #81855 from hnrklssn/swiftify-availability-check-sdk
[Swiftify] Adjust _SwiftifyImport invocation to align with the signature
2 parents 1948907 + 1d1c642 commit e9ba8f8

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9023,16 +9023,25 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
90239023
}
90249024

90259025
namespace {
9026+
ValueDecl *getKnownSingleDecl(ASTContext &SwiftContext, StringRef DeclName) {
9027+
SmallVector<ValueDecl *, 1> decls;
9028+
SwiftContext.lookupInSwiftModule(DeclName, decls);
9029+
assert(decls.size() < 2);
9030+
if (decls.size() != 1) return nullptr;
9031+
return decls[0];
9032+
}
9033+
90269034
class SwiftifyInfoPrinter {
90279035
public:
90289036
static const ssize_t SELF_PARAM_INDEX = -2;
90299037
static const ssize_t RETURN_VALUE_INDEX = -1;
90309038
clang::ASTContext &ctx;
90319039
ASTContext &SwiftContext;
90329040
llvm::raw_ostream &out;
9041+
MacroDecl &SwiftifyImportDecl;
90339042
bool firstParam = true;
9034-
SwiftifyInfoPrinter(clang::ASTContext &ctx, ASTContext &SwiftContext, llvm::raw_ostream &out)
9035-
: ctx(ctx), SwiftContext(SwiftContext), out(out) {
9043+
SwiftifyInfoPrinter(clang::ASTContext &ctx, ASTContext &SwiftContext, llvm::raw_ostream &out, MacroDecl &SwiftifyImportDecl)
9044+
: ctx(ctx), SwiftContext(SwiftContext), out(out), SwiftifyImportDecl(SwiftifyImportDecl) {
90369045
out << "@_SwiftifyImport(";
90379046
}
90389047
~SwiftifyInfoPrinter() { out << ")"; }
@@ -9090,22 +9099,23 @@ class SwiftifyInfoPrinter {
90909099
}
90919100

90929101
void printAvailability() {
9102+
if (!hasMacroParameter("spanAvailability"))
9103+
return;
90939104
printSeparator();
90949105
out << "spanAvailability: ";
90959106
printAvailabilityOfType("Span");
90969107
}
90979108

90989109
private:
9099-
ValueDecl *getDecl(StringRef DeclName) {
9100-
SmallVector<ValueDecl *, 1> decls;
9101-
SwiftContext.lookupInSwiftModule(DeclName, decls);
9102-
assert(decls.size() == 1);
9103-
if (decls.size() != 1) return nullptr;
9104-
return decls[0];
9110+
bool hasMacroParameter(StringRef ParamName) {
9111+
for (auto *Param : *SwiftifyImportDecl.parameterList)
9112+
if (Param->getArgumentName().str() == ParamName)
9113+
return true;
9114+
return false;
91059115
}
91069116

91079117
void printAvailabilityOfType(StringRef Name) {
9108-
ValueDecl *D = getDecl(Name);
9118+
ValueDecl *D = getKnownSingleDecl(SwiftContext, Name);
91099119
out << "\"";
91109120
llvm::SaveAndRestore<bool> hasAvailbilitySeparatorRestore(firstParam, true);
91119121
for (auto attr : D->getSemanticAvailableAttrs(/*includingInactive=*/true)) {
@@ -9269,6 +9279,10 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
92699279
if (ClangDecl->getNumParams() != MappedDecl->getParameters()->size())
92709280
return;
92719281

9282+
MacroDecl *SwiftifyImportDecl = dyn_cast_or_null<MacroDecl>(getKnownSingleDecl(SwiftContext, "_SwiftifyImport"));
9283+
if (!SwiftifyImportDecl)
9284+
return;
9285+
92729286
{
92739287
UnaliasedInstantiationVisitor visitor;
92749288
visitor.TraverseType(ClangDecl->getType());
@@ -9297,7 +9311,7 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
92979311
}
92989312
return false;
92999313
};
9300-
SwiftifyInfoPrinter printer(getClangASTContext(), SwiftContext, out);
9314+
SwiftifyInfoPrinter printer(getClangASTContext(), SwiftContext, out, *SwiftifyImportDecl);
93019315
Type swiftReturnTy;
93029316
if (const auto *funcDecl = dyn_cast<FuncDecl>(MappedDecl))
93039317
swiftReturnTy = funcDecl->getResultInterfaceType();

stdlib/public/core/SwiftifyImport.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ public func _swiftifyOverrideLifetime<
104104
// TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence
105105
// should be expressed by a builtin that is hidden within the function body.
106106
dependent
107-
}
107+
}

0 commit comments

Comments
 (0)