Skip to content

Commit 13b0a5b

Browse files
committed
[nfc] Clang format changes.
1 parent 74d76e2 commit 13b0a5b

File tree

18 files changed

+257
-241
lines changed

18 files changed

+257
-241
lines changed

include/swift/Basic/Compiler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@
180180

181181
// Tells Swift's ClangImporter to import a C++ type as a foreign reference type.
182182
#if __has_attribute(swift_attr)
183-
#define SWIFT_IMPORT_REFERENCE __attribute__((swift_attr("import_reference")))
183+
#define SWIFT_IMPORT_REFERENCE __attribute__((swift_attr("import_reference"))) \
184+
__attribute__((swift_attr("retain:immortal"))) \
185+
__attribute__((swift_attr("release:immortal")))
184186
#else
185187
#define SWIFT_IMPORT_REFERENCE
186188
#endif

include/swift/ClangImporter/ClangImporterRequests.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ struct CustomRefCountingOperationDescriptor final {
295295
CustomRefCountingOperationKind kind)
296296
: decl(decl), kind(kind) {}
297297

298-
friend llvm::hash_code hash_value(const CustomRefCountingOperationDescriptor &desc) {
298+
friend llvm::hash_code
299+
hash_value(const CustomRefCountingOperationDescriptor &desc) {
299300
return llvm::hash_combine(desc.decl, desc.kind);
300301
}
301302

@@ -310,12 +311,17 @@ struct CustomRefCountingOperationDescriptor final {
310311
}
311312
};
312313

313-
void simple_display(llvm::raw_ostream &out, CustomRefCountingOperationDescriptor desc);
314+
void simple_display(llvm::raw_ostream &out,
315+
CustomRefCountingOperationDescriptor desc);
314316
SourceLoc extractNearestSourceLoc(CustomRefCountingOperationDescriptor desc);
315317

316318
struct CustomRefCountingOperationResult {
317319
enum CustomRefCountingOperationResultKind {
318-
noAttribute, immortal, notFound, tooManyFound, foundOperation
320+
noAttribute,
321+
immortal,
322+
notFound,
323+
tooManyFound,
324+
foundOperation
319325
};
320326

321327
CustomRefCountingOperationResultKind kind;
@@ -341,11 +347,11 @@ class CustomRefCountingOperation
341347
friend SimpleRequest;
342348

343349
// Evaluation.
344-
CustomRefCountingOperationResult evaluate(Evaluator &evaluator,
345-
CustomRefCountingOperationDescriptor desc) const;
350+
CustomRefCountingOperationResult
351+
evaluate(Evaluator &evaluator,
352+
CustomRefCountingOperationDescriptor desc) const;
346353
};
347354

348-
349355
#define SWIFT_TYPEID_ZONE ClangImporter
350356
#define SWIFT_TYPEID_HEADER "swift/ClangImporter/ClangImporterTypeIDZone.def"
351357
#include "swift/Basic/DefineTypeIDZone.h"

lib/AST/Decl.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
#include "swift/AST/Decl.h"
18-
#include "swift/AST/AccessRequests.h"
19-
#include "swift/AST/AccessScope.h"
2018
#include "swift/AST/ASTContext.h"
21-
#include "swift/AST/ASTWalker.h"
2219
#include "swift/AST/ASTMangler.h"
20+
#include "swift/AST/ASTWalker.h"
21+
#include "swift/AST/AccessRequests.h"
22+
#include "swift/AST/AccessScope.h"
2323
#include "swift/AST/Attr.h"
2424
#include "swift/AST/CaptureInfo.h"
2525
#include "swift/AST/DiagnosticEngine.h"
@@ -32,7 +32,6 @@
3232
#include "swift/AST/GenericSignature.h"
3333
#include "swift/AST/Initializer.h"
3434
#include "swift/AST/LazyResolver.h"
35-
#include "swift/AST/ASTMangler.h"
3635
#include "swift/AST/Module.h"
3736
#include "swift/AST/NameLookup.h"
3837
#include "swift/AST/NameLookupRequests.h"
@@ -44,12 +43,17 @@
4443
#include "swift/AST/ResilienceExpansion.h"
4544
#include "swift/AST/SourceFile.h"
4645
#include "swift/AST/Stmt.h"
46+
#include "swift/AST/SwiftNameTranslation.h"
4747
#include "swift/AST/TypeCheckRequests.h"
4848
#include "swift/AST/TypeLoc.h"
49-
#include "swift/AST/SwiftNameTranslation.h"
5049
#include "swift/Basic/Defer.h"
51-
#include "swift/ClangImporter/ClangModule.h"
50+
#include "swift/Basic/Range.h"
51+
#include "swift/Basic/Statistic.h"
52+
#include "swift/Basic/StringExtras.h"
53+
#include "swift/Basic/TypeID.h"
5254
#include "swift/ClangImporter/ClangImporterRequests.h"
55+
#include "swift/ClangImporter/ClangModule.h"
56+
#include "swift/Demangling/ManglingMacros.h"
5357
#include "swift/Parse/Lexer.h" // FIXME: Bad dependency
5458
#include "clang/Lex/MacroInfo.h"
5559
#include "llvm/ADT/SmallPtrSet.h"
@@ -58,11 +62,6 @@
5862
#include "llvm/ADT/Statistic.h"
5963
#include "llvm/Support/Compiler.h"
6064
#include "llvm/Support/raw_ostream.h"
61-
#include "swift/Basic/Range.h"
62-
#include "swift/Basic/StringExtras.h"
63-
#include "swift/Basic/Statistic.h"
64-
#include "swift/Basic/TypeID.h"
65-
#include "swift/Demangling/ManglingMacros.h"
6665

6766
#include "clang/Basic/CharInfo.h"
6867
#include "clang/Basic/Module.h"
@@ -5229,16 +5228,17 @@ bool ClassDecl::isForeignReferenceType() const {
52295228
}
52305229

52315230
bool ClassDecl::hasRefCountingAnnotations() const {
5232-
return evaluateOrDefault(
5233-
getASTContext().evaluator,
5234-
CustomRefCountingOperation({this, CustomRefCountingOperationKind::release}), {}).kind != CustomRefCountingOperationResult::immortal;
5231+
return evaluateOrDefault(getASTContext().evaluator,
5232+
CustomRefCountingOperation(
5233+
{this, CustomRefCountingOperationKind::release}),
5234+
{})
5235+
.kind != CustomRefCountingOperationResult::immortal;
52355236
}
52365237

52375238
ReferenceCounting ClassDecl::getObjectModel() const {
52385239
if (isForeignReferenceType())
5239-
return hasRefCountingAnnotations()
5240-
? ReferenceCounting::Custom
5241-
: ReferenceCounting::None;
5240+
return hasRefCountingAnnotations() ? ReferenceCounting::Custom
5241+
: ReferenceCounting::None;
52425242

52435243
if (checkAncestry(AncestryFlags::ObjCObjectModel))
52445244
return ReferenceCounting::ObjC;

lib/ClangImporter/ClangImporter.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6081,23 +6081,28 @@ CustomRefCountingOperationResult CustomRefCountingOperation::evaluate(
60816081
auto operation = desc.kind;
60826082
auto &ctx = swiftDecl->getASTContext();
60836083

6084-
std::string operationStr = operation == CustomRefCountingOperationKind::retain ? "retain:" : "release:";
6084+
std::string operationStr = operation == CustomRefCountingOperationKind::retain
6085+
? "retain:"
6086+
: "release:";
60856087

60866088
auto decl = cast<clang::RecordDecl>(swiftDecl->getClangDecl());
60876089
if (!decl->hasAttrs())
60886090
return {CustomRefCountingOperationResult::noAttribute, nullptr, ""};
60896091

6090-
auto retainFnAttr = llvm::find_if(decl->getAttrs(),
6091-
[&operationStr](auto *attr) {
6092-
if (auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr))
6093-
return swiftAttr->getAttribute().startswith(operationStr);
6094-
return false;
6095-
});
6092+
auto retainFnAttr =
6093+
llvm::find_if(decl->getAttrs(), [&operationStr](auto *attr) {
6094+
if (auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr))
6095+
return swiftAttr->getAttribute().startswith(operationStr);
6096+
return false;
6097+
});
60966098
if (retainFnAttr == decl->getAttrs().end()) {
60976099
return {CustomRefCountingOperationResult::noAttribute, nullptr, ""};
60986100
}
60996101

6100-
auto name = cast<clang::SwiftAttrAttr>(*retainFnAttr)->getAttribute().drop_front(StringRef(operationStr).size()).str();
6102+
auto name = cast<clang::SwiftAttrAttr>(*retainFnAttr)
6103+
->getAttribute()
6104+
.drop_front(StringRef(operationStr).size())
6105+
.str();
61016106

61026107
if (name == "immortal")
61036108
return {CustomRefCountingOperationResult::immortal, nullptr, name};
@@ -6106,7 +6111,8 @@ CustomRefCountingOperationResult CustomRefCountingOperation::evaluate(
61066111
ctx.lookupInModule(swiftDecl->getParentModule(), name, results);
61076112

61086113
if (results.size() == 1)
6109-
return {CustomRefCountingOperationResult::foundOperation, results.front(), name};
6114+
return {CustomRefCountingOperationResult::foundOperation, results.front(),
6115+
name};
61106116

61116117
if (results.empty())
61126118
return {CustomRefCountingOperationResult::notFound, nullptr, name};
@@ -6117,12 +6123,12 @@ CustomRefCountingOperationResult CustomRefCountingOperation::evaluate(
61176123
void swift::simple_display(llvm::raw_ostream &out,
61186124
CustomRefCountingOperationDescriptor desc) {
61196125
out << "Finding custom (foreign reference) reference counting operation '"
6120-
<< (desc.kind == CustomRefCountingOperationKind::retain ? "retain" : "release")
6121-
<< "for '"
6122-
<< desc.decl->getNameStr()
6123-
<< "'.\n";
6126+
<< (desc.kind == CustomRefCountingOperationKind::retain ? "retain"
6127+
: "release")
6128+
<< "for '" << desc.decl->getNameStr() << "'.\n";
61246129
}
61256130

6126-
SourceLoc swift::extractNearestSourceLoc(CustomRefCountingOperationDescriptor desc) {
6131+
SourceLoc
6132+
swift::extractNearestSourceLoc(CustomRefCountingOperationDescriptor desc) {
61276133
return SourceLoc();
61286134
}

lib/ClangImporter/ImportDecl.cpp

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,8 +2418,6 @@ namespace {
24182418
}
24192419
}
24202420

2421-
2422-
24232421
result->setMemberLoader(&Impl, 0);
24242422
return result;
24252423
}
@@ -2437,54 +2435,77 @@ namespace {
24372435
if (operationFn->getParameters()->size() != 1)
24382436
return false;
24392437

2440-
if (operationFn->getParameters()->get(0)->getInterfaceType()->isEqual(classDecl->getInterfaceType()))
2438+
if (operationFn->getParameters()->get(0)->getInterfaceType()->isEqual(
2439+
classDecl->getInterfaceType()))
24412440
return false;
24422441

24432442
return true;
24442443
};
24452444

24462445
auto retainOperation = evaluateOrDefault(
24472446
Impl.SwiftContext.evaluator,
2448-
CustomRefCountingOperation({classDecl, CustomRefCountingOperationKind::retain}), {});
2449-
if (retainOperation.kind == CustomRefCountingOperationResult::noAttribute) {
2447+
CustomRefCountingOperation(
2448+
{classDecl, CustomRefCountingOperationKind::retain}),
2449+
{});
2450+
if (retainOperation.kind ==
2451+
CustomRefCountingOperationResult::noAttribute) {
24502452
HeaderLoc loc(decl->getLocation());
2451-
Impl.diagnose(loc, diag::reference_type_must_have_retain_attr, decl->getNameAsString());
2452-
} else if (retainOperation.kind == CustomRefCountingOperationResult::notFound) {
2453+
Impl.diagnose(loc, diag::reference_type_must_have_retain_attr,
2454+
decl->getNameAsString());
2455+
} else if (retainOperation.kind ==
2456+
CustomRefCountingOperationResult::notFound) {
24532457
HeaderLoc loc(decl->getLocation());
2454-
Impl.diagnose(loc, diag::foreign_reference_types_cannot_find_retain, retainOperation.name, decl->getNameAsString());
2455-
} else if (retainOperation.kind == CustomRefCountingOperationResult::tooManyFound) {
2458+
Impl.diagnose(loc, diag::foreign_reference_types_cannot_find_retain,
2459+
retainOperation.name, decl->getNameAsString());
2460+
} else if (retainOperation.kind ==
2461+
CustomRefCountingOperationResult::tooManyFound) {
24562462
HeaderLoc loc(decl->getLocation());
2457-
Impl.diagnose(loc, diag::too_many_reference_type_retain_operations, retainOperation.name, decl->getNameAsString());
2458-
} else if (retainOperation.kind == CustomRefCountingOperationResult::foundOperation) {
2463+
Impl.diagnose(loc, diag::too_many_reference_type_retain_operations,
2464+
retainOperation.name, decl->getNameAsString());
2465+
} else if (retainOperation.kind ==
2466+
CustomRefCountingOperationResult::foundOperation) {
24592467
if (!isValidOperation(retainOperation.operation)) {
24602468
HeaderLoc loc(decl->getLocation());
2461-
Impl.diagnose(loc, diag::foreign_reference_types_invalid_retain, retainOperation.name, decl->getNameAsString());
2469+
Impl.diagnose(loc, diag::foreign_reference_types_invalid_retain,
2470+
retainOperation.name, decl->getNameAsString());
24622471
}
24632472
} else {
24642473
// Nothing to do.
2465-
assert(retainOperation.kind == CustomRefCountingOperationResult::immortal);
2474+
assert(retainOperation.kind ==
2475+
CustomRefCountingOperationResult::immortal);
24662476
}
24672477

24682478
auto releaseOperation = evaluateOrDefault(
24692479
Impl.SwiftContext.evaluator,
2470-
CustomRefCountingOperation({classDecl, CustomRefCountingOperationKind::release}), {});
2471-
if (releaseOperation.kind == CustomRefCountingOperationResult::noAttribute) {
2480+
CustomRefCountingOperation(
2481+
{classDecl, CustomRefCountingOperationKind::release}),
2482+
{});
2483+
if (releaseOperation.kind ==
2484+
CustomRefCountingOperationResult::noAttribute) {
24722485
HeaderLoc loc(decl->getLocation());
2473-
Impl.diagnose(loc, diag::reference_type_must_have_release_attr, decl->getNameAsString());
2474-
} else if (releaseOperation.kind == CustomRefCountingOperationResult::notFound) {
2486+
Impl.diagnose(loc, diag::reference_type_must_have_release_attr,
2487+
decl->getNameAsString());
2488+
} else if (releaseOperation.kind ==
2489+
CustomRefCountingOperationResult::notFound) {
24752490
HeaderLoc loc(decl->getLocation());
2476-
Impl.diagnose(loc, diag::foreign_reference_types_cannot_find_release, releaseOperation.name, decl->getNameAsString());
2477-
} else if (releaseOperation.kind == CustomRefCountingOperationResult::tooManyFound) {
2491+
Impl.diagnose(loc, diag::foreign_reference_types_cannot_find_release,
2492+
releaseOperation.name, decl->getNameAsString());
2493+
} else if (releaseOperation.kind ==
2494+
CustomRefCountingOperationResult::tooManyFound) {
24782495
HeaderLoc loc(decl->getLocation());
2479-
Impl.diagnose(loc, diag::too_many_reference_type_release_operations, releaseOperation.name, decl->getNameAsString());
2480-
} else if (releaseOperation.kind == CustomRefCountingOperationResult::foundOperation) {
2496+
Impl.diagnose(loc, diag::too_many_reference_type_release_operations,
2497+
releaseOperation.name, decl->getNameAsString());
2498+
} else if (releaseOperation.kind ==
2499+
CustomRefCountingOperationResult::foundOperation) {
24812500
if (!isValidOperation(releaseOperation.operation)) {
24822501
HeaderLoc loc(decl->getLocation());
2483-
Impl.diagnose(loc, diag::foreign_reference_types_invalid_release, releaseOperation.name, decl->getNameAsString());
2502+
Impl.diagnose(loc, diag::foreign_reference_types_invalid_release,
2503+
releaseOperation.name, decl->getNameAsString());
24842504
}
24852505
} else {
24862506
// Nothing to do.
2487-
assert(releaseOperation.kind == CustomRefCountingOperationResult::immortal);
2507+
assert(releaseOperation.kind ==
2508+
CustomRefCountingOperationResult::immortal);
24882509
}
24892510
}
24902511

lib/IRGen/ClassTypeInfo.h

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ class ClassTypeInfo : public HeapTypeInfo<ClassTypeInfo> {
6464
void emitScalarRelease(IRGenFunction &IGF, llvm::Value *value,
6565
Atomicity atomicity) const override {
6666
if (getReferenceCounting() == ReferenceCounting::Custom) {
67-
auto releaseFn = evaluateOrDefault(
68-
getClass()->getASTContext().evaluator,
69-
CustomRefCountingOperation({getClass(), CustomRefCountingOperationKind::release}), {}).operation;
67+
auto releaseFn =
68+
evaluateOrDefault(
69+
getClass()->getASTContext().evaluator,
70+
CustomRefCountingOperation(
71+
{getClass(), CustomRefCountingOperationKind::release}),
72+
{})
73+
.operation;
7074
IGF.emitForeignReferenceTypeLifetimeOperation(releaseFn, value);
7175
return;
7276
}
@@ -77,9 +81,13 @@ class ClassTypeInfo : public HeapTypeInfo<ClassTypeInfo> {
7781
void emitScalarRetain(IRGenFunction &IGF, llvm::Value *value,
7882
Atomicity atomicity) const override {
7983
if (getReferenceCounting() == ReferenceCounting::Custom) {
80-
auto retainFn = evaluateOrDefault(
81-
getClass()->getASTContext().evaluator,
82-
CustomRefCountingOperation({getClass(), CustomRefCountingOperationKind::retain}), {}).operation;
84+
auto retainFn =
85+
evaluateOrDefault(
86+
getClass()->getASTContext().evaluator,
87+
CustomRefCountingOperation(
88+
{getClass(), CustomRefCountingOperationKind::retain}),
89+
{})
90+
.operation;
8391
IGF.emitForeignReferenceTypeLifetimeOperation(retainFn, value);
8492
return;
8593
}
@@ -93,9 +101,13 @@ class ClassTypeInfo : public HeapTypeInfo<ClassTypeInfo> {
93101
Atomicity atomicity) const override {
94102
if (getReferenceCounting() == ReferenceCounting::Custom) {
95103
llvm::Value *value = e.claimNext();
96-
auto retainFn = evaluateOrDefault(
97-
getClass()->getASTContext().evaluator,
98-
CustomRefCountingOperation({getClass(), CustomRefCountingOperationKind::retain}), {}).operation;
104+
auto retainFn =
105+
evaluateOrDefault(
106+
getClass()->getASTContext().evaluator,
107+
CustomRefCountingOperation(
108+
{getClass(), CustomRefCountingOperationKind::retain}),
109+
{})
110+
.operation;
99111
IGF.emitForeignReferenceTypeLifetimeOperation(retainFn, value);
100112
return;
101113
}
@@ -107,9 +119,13 @@ class ClassTypeInfo : public HeapTypeInfo<ClassTypeInfo> {
107119
Atomicity atomicity) const override {
108120
if (getReferenceCounting() == ReferenceCounting::Custom) {
109121
llvm::Value *value = e.claimNext();
110-
auto releaseFn = evaluateOrDefault(
111-
getClass()->getASTContext().evaluator,
112-
CustomRefCountingOperation({getClass(), CustomRefCountingOperationKind::release}), {}).operation;
122+
auto releaseFn =
123+
evaluateOrDefault(
124+
getClass()->getASTContext().evaluator,
125+
CustomRefCountingOperation(
126+
{getClass(), CustomRefCountingOperationKind::release}),
127+
{})
128+
.operation;
113129
IGF.emitForeignReferenceTypeLifetimeOperation(releaseFn, value);
114130
return;
115131
}

0 commit comments

Comments
 (0)