Skip to content

[cxx-interop] A few misc. changes from #38675. #39432

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 1 commit into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,8 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl) {
// Note: Namespaces are not really enums, but since namespaces are
// imported as enums, be consistent.
appendOperator("O");
} else if (isa<clang::ClassTemplateDecl>(namedDecl)) {
appendIdentifier(nominal->getName().str());
} else {
llvm_unreachable("unknown imported Clang type");
}
Expand Down
32 changes: 16 additions & 16 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
}
}


Printer.callPrintDeclPre(D, Options.BracketOptions);

bool haveFeatureChecks = Options.PrintCompatibilityFeatureChecks &&
Expand Down Expand Up @@ -2784,14 +2784,14 @@ static bool usesFeatureImplicitSelfCapture(Decl *decl) {
/// want a baseline version.
static std::vector<Feature> getFeaturesUsed(Decl *decl) {
std::vector<Feature> features;

// Go through each of the features, checking whether the declaration uses that
// feature. This also ensures that the resulting set is in sorted order.
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description, Option) \
if (usesFeature##FeatureName(decl)) \
features.push_back(Feature::FeatureName);
#include "swift/Basic/Features.def"

return features;
}

Expand Down Expand Up @@ -2852,7 +2852,7 @@ bool swift::printCompatibilityFeatureChecksPre(
if (features.empty())
return false;

printer.printNewline();
printer.printNewline();
printer << "#if compiler(>=5.3) && ";
llvm::interleave(features.begin(), features.end(),
[&](Feature feature) {
Expand Down Expand Up @@ -2977,7 +2977,7 @@ void PrintAST::visitPoundDiagnosticDecl(PoundDiagnosticDecl *PDD) {
if (PDD->isError()) {
Printer << tok::pound_error;
} else {
Printer << tok::pound_warning;
Printer << tok::pound_warning;
}

Printer << "(\"" << PDD->getMessage()->getValue() << "\")";
Expand Down Expand Up @@ -3609,7 +3609,7 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
}

printBodyIfNecessary(decl);

// If the function has an opaque result type, print the opaque type decl.
if (auto opaqueResult = decl->getOpaqueResultTypeDecl()) {
Printer.printNewline();
Expand Down Expand Up @@ -4939,7 +4939,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
});
Printer << ">";
}

void visitGenericFunctionType(GenericFunctionType *T) {
Printer.callPrintStructurePre(PrintStructureKind::FunctionType);
SWIFT_DEFER {
Expand Down Expand Up @@ -5021,7 +5021,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
PrintAST::PrintRequirements);
Printer << " ";
}

// If this is a substituted function type, then its generic signature is
// independent of the enclosing context, and defines the parameters active
// in the interface params and results. Unsubstituted types use the existing
Expand All @@ -5044,7 +5044,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
PrintAST::PrintRequirements);
sub->Printer << " ";
}

// Capture list used here to ensure we don't print anything using `this`
// printer, but only the sub-Printer.
[T, sub, &subOptions] {
Expand Down Expand Up @@ -5226,7 +5226,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
Printer << "@opened(\"" << T->getOpenedExistentialID() << "\") ";
visit(T->getOpenedExistentialType());
}

void printArchetypeCommon(ArchetypeType *T,
const AbstractTypeParamDecl *Decl) {
if (Options.AlternativeTypeNames) {
Expand All @@ -5251,11 +5251,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
visitParentType(T->getParent());
printArchetypeCommon(T, T->getAssocType());
}

void visitPrimaryArchetypeType(PrimaryArchetypeType *T) {
printArchetypeCommon(T, T->getInterfaceType()->getDecl());
}

void visitOpaqueTypeArchetypeType(OpaqueTypeArchetypeType *T) {
switch (Options.OpaqueReturnTypePrinting) {
case PrintOptions::OpaqueReturnTypePrintingMode::WithOpaqueKeyword:
Expand All @@ -5272,14 +5272,14 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
// type.
Printer << "@_opaqueReturnTypeOf(";
OpaqueTypeDecl *decl = T->getDecl();

Printer.printEscapedStringLiteral(
decl->getOpaqueReturnTypeIdentifier().str());

Printer << ", " << T->getInterfaceType()
->castTo<GenericTypeParamType>()
->getIndex();

// The identifier after the closing parenthesis is irrelevant and can be
// anything. It just needs to be there for the @_opaqueReturnTypeOf
// attribute to apply to, but the attribute alone references the opaque
Expand Down Expand Up @@ -5433,7 +5433,7 @@ void LayoutConstraintInfo::print(ASTPrinter &Printer,
break;
}
}

void LayoutConstraint::dump() const {
if (!*this) {
llvm::errs() << "(null)\n";
Expand Down
9 changes: 5 additions & 4 deletions lib/ClangImporter/ImportName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,11 +1709,12 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
case clang::DeclarationName::CXXOperatorName: {
auto op = D->getDeclName().getCXXOverloadedOperator();
auto functionDecl = dyn_cast<clang::FunctionDecl>(D);
if (!functionDecl) {
// This can happen for example for templated operators functions.
// We don't support those, yet.

if (auto functionTemplate = dyn_cast<clang::FunctionTemplateDecl>(D))
functionDecl = functionTemplate->getAsFunction();
Copy link
Contributor

Choose a reason for hiding this comment

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

Since VisitFunctionTemplateDecl already calls this logic with decl->getAsFunction(), I think this line won't be executed. Are you planning to tweak VisitFunctionTemplateDecl to import decl as is, not as decl->getAsFunction()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I don't think this path is taken yet. This is needed for lazy member loading, when we import the name of every NamedDecl member.

I'm not going to remove decl->getAsFunction yet as it is still needed for some non-operator cases. But that might be a good follow up.


if (!functionDecl)
return ImportedName();
}

switch (op) {
case clang::OverloadedOperatorKind::OO_Plus:
Expand Down