Skip to content

Commit 83de1da

Browse files
authored
Merge pull request swiftlang#40262 from apple/revert-40170-send-me-an-object
2 parents f8fdcbb + 4d44953 commit 83de1da

31 files changed

+230
-608
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(async, Async,
605605
106)
606606

607607
SIMPLE_DECL_ATTR(Sendable, Sendable,
608-
OnFunc | OnConstructor | OnAccessor | OnAnyClangDecl |
608+
OnFunc | OnConstructor | OnAccessor |
609609
ABIBreakingToAdd | ABIBreakingToRemove |
610610
APIBreakingToAdd | APIBreakingToRemove,
611611
107)

include/swift/AST/Attr.h

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,8 @@ class DeclAttribute : public AttributeBase {
168168
);
169169

170170
SWIFT_INLINE_BITFIELD(SynthesizedProtocolAttr, DeclAttribute,
171-
NumKnownProtocolKindBits+1,
172-
kind : NumKnownProtocolKindBits,
173-
isUnchecked : 1
171+
NumKnownProtocolKindBits,
172+
kind : NumKnownProtocolKindBits
174173
);
175174
} Bits;
176175

@@ -289,9 +288,6 @@ class DeclAttribute : public AttributeBase {
289288

290289
/// Whether this attribute is only valid when distributed is enabled.
291290
DistributedOnly = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 17),
292-
293-
/// Whether this attribute is valid on additional decls in ClangImporter.
294-
OnAnyClangDecl = 1ull << (unsigned(DeclKindIndex::Last_Decl) + 18),
295291
};
296292

297293
LLVM_READNONE
@@ -1280,13 +1276,11 @@ class SynthesizedProtocolAttr : public DeclAttribute {
12801276

12811277
public:
12821278
SynthesizedProtocolAttr(KnownProtocolKind protocolKind,
1283-
LazyConformanceLoader *Loader,
1284-
bool isUnchecked)
1279+
LazyConformanceLoader *Loader)
12851280
: DeclAttribute(DAK_SynthesizedProtocol, SourceLoc(), SourceRange(),
12861281
/*Implicit=*/true), Loader(Loader)
12871282
{
12881283
Bits.SynthesizedProtocolAttr.kind = unsigned(protocolKind);
1289-
Bits.SynthesizedProtocolAttr.isUnchecked = unsigned(isUnchecked);
12901284
}
12911285

12921286
/// Retrieve the known protocol kind naming the protocol to be
@@ -1295,10 +1289,6 @@ class SynthesizedProtocolAttr : public DeclAttribute {
12951289
return KnownProtocolKind(Bits.SynthesizedProtocolAttr.kind);
12961290
}
12971291

1298-
bool isUnchecked() const {
1299-
return bool(Bits.SynthesizedProtocolAttr.isUnchecked);
1300-
}
1301-
13021292
/// Retrieve the lazy loader that will be used to populate the
13031293
/// synthesized conformance.
13041294
LazyConformanceLoader *getLazyLoader() const { return Loader; }
@@ -2227,15 +2217,6 @@ class DeclAttributes {
22272217
return nullptr;
22282218
}
22292219

2230-
/// Returns the "winning" \c NonSendableAttr or \c SendableAttr in this
2231-
/// attribute list, or \c nullptr if there are none.
2232-
const DeclAttribute *getEffectiveSendableAttr() const;
2233-
2234-
DeclAttribute *getEffectiveSendableAttr() {
2235-
return const_cast<DeclAttribute *>(
2236-
const_cast<const DeclAttributes *>(this)->getEffectiveSendableAttr());
2237-
}
2238-
22392220
private:
22402221
/// Predicate used to filter MatchingAttributeRange.
22412222
template <typename ATTR, bool AllowInvalid> struct ToAttributeKind {

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ NOTE(unresolvable_clang_decl_is_a_framework_bug,none,
8585
WARNING(clang_swift_attr_unhandled,none,
8686
"Ignoring unknown Swift attribute or modifier '%0'", (StringRef))
8787

88-
WARNING(clang_error_code_must_be_sendable,none,
89-
"cannot make error code type '%0' non-sendable because Swift errors "
90-
"are always sendable", (StringRef))
91-
9288
WARNING(implicit_bridging_header_imported_from_module,none,
9389
"implicit import of bridging header '%0' via module %1 "
9490
"is deprecated and will be removed in a later version of Swift",

include/swift/AST/FileUnit.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
#include "swift/AST/RawComment.h"
1818
#include "swift/Basic/BasicSourceInfo.h"
1919

20-
#include "llvm/ADT/PointerIntPair.h"
21-
2220
namespace swift {
23-
class SynthesizedFileUnit;
24-
2521
/// A container for module-scope declarations that itself provides a scope; the
2622
/// smallest unit of code organization.
2723
///
@@ -37,25 +33,19 @@ class FileUnit : public DeclContext, public ASTAllocated<FileUnit> {
3733
friend class DirectOperatorLookupRequest;
3834
friend class DirectPrecedenceGroupLookupRequest;
3935

40-
// The pointer is FileUnit insted of SynthesizedFileUnit to break circularity.
41-
llvm::PointerIntPair<FileUnit *, 3, FileUnitKind> SynthesizedFileAndKind;
36+
// FIXME: Stick this in a PointerIntPair.
37+
const FileUnitKind Kind;
4238

4339
protected:
4440
FileUnit(FileUnitKind kind, ModuleDecl &M)
45-
: DeclContext(DeclContextKind::FileUnit, &M),
46-
SynthesizedFileAndKind(nullptr, kind) {
41+
: DeclContext(DeclContextKind::FileUnit, &M), Kind(kind) {
4742
}
4843

4944
public:
5045
FileUnitKind getKind() const {
51-
return SynthesizedFileAndKind.getInt();
46+
return Kind;
5247
}
5348

54-
/// Returns the synthesized file for this source file, if it exists.
55-
SynthesizedFileUnit *getSynthesizedFile() const;
56-
57-
SynthesizedFileUnit &getOrCreateSynthesizedFile();
58-
5949
/// Look up a (possibly overloaded) value set at top-level scope
6050
/// (but with the specified access path, which may come from an import decl)
6151
/// within this file.

include/swift/AST/PrintOptions.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,6 @@ struct PrintOptions {
235235
/// Whether to print unavailable parts of the AST.
236236
bool SkipUnavailable = false;
237237

238-
/// Whether to print synthesized extensions created by '@_nonSendable', even
239-
/// if SkipImplicit or SkipUnavailable is set.
240-
bool AlwaysPrintNonSendableExtensions = true;
241-
242238
bool SkipSwiftPrivateClangDecls = false;
243239

244240
/// Whether to skip internal stdlib declarations.
@@ -671,7 +667,6 @@ struct PrintOptions {
671667
PO.ShouldQualifyNestedDeclarations = QualifyNestedDeclarations::TypesOnly;
672668
PO.PrintParameterSpecifiers = true;
673669
PO.SkipImplicit = true;
674-
PO.AlwaysPrintNonSendableExtensions = false;
675670
PO.AlwaysTryPrintParameterLabels = true;
676671
return PO;
677672
}

include/swift/AST/ProtocolConformance.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,6 @@ class NormalProtocolConformance : public RootProtocolConformance,
514514
return ContextAndBits.getInt() & UncheckedFlag;
515515
}
516516

517-
/// Mark the conformance as unchecked (equivalent to the @unchecked
518-
/// conformance attribute).
519-
void setUnchecked() {
520-
// OK to mutate because the flags are not part of the folding set node ID.
521-
ContextAndBits.setInt(ContextAndBits.getInt() | UncheckedFlag);
522-
}
523-
524517
/// Get the kind of source from which this conformance comes.
525518
ConformanceEntryKind getSourceKind() const {
526519
return SourceKindAndImplyingConformance.getInt();

include/swift/AST/SourceFile.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class SourceFile final : public FileUnit {
8989
/// same module.
9090
mutable Identifier PrivateDiscriminator;
9191

92+
/// A synthesized file corresponding to this file, created on-demand.
93+
SynthesizedFileUnit *SynthesizedFile = nullptr;
94+
9295
/// The root TypeRefinementContext for this SourceFile.
9396
///
9497
/// This is set during type checking.
@@ -406,6 +409,11 @@ class SourceFile final : public FileUnit {
406409
Optional<ExternalSourceLocs::RawLocs>
407410
getExternalRawLocsForDecl(const Decl *D) const override;
408411

412+
/// Returns the synthesized file for this source file, if it exists.
413+
SynthesizedFileUnit *getSynthesizedFile() const { return SynthesizedFile; };
414+
415+
SynthesizedFileUnit &getOrCreateSynthesizedFile();
416+
409417
virtual bool walk(ASTWalker &walker) override;
410418

411419
/// The buffer ID for the file that was imported, or None if there

include/swift/AST/SynthesizedFileUnit.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
namespace swift {
2020

21+
class SourceFile;
22+
2123
/// A container for synthesized declarations, attached to a `SourceFile`.
2224
///
2325
/// Currently, only module-level synthesized declarations are supported.
2426
class SynthesizedFileUnit final : public FileUnit {
2527
/// The parent source file.
26-
FileUnit &FU;
28+
SourceFile &SF;
2729

2830
/// Synthesized top level declarations.
2931
TinyPtrVector<Decl *> TopLevelDecls;
@@ -34,11 +36,11 @@ class SynthesizedFileUnit final : public FileUnit {
3436
mutable Identifier PrivateDiscriminator;
3537

3638
public:
37-
SynthesizedFileUnit(FileUnit &FU);
39+
SynthesizedFileUnit(SourceFile &SF);
3840
~SynthesizedFileUnit() = default;
3941

4042
/// Returns the parent source file.
41-
FileUnit &getFileUnit() const { return FU; }
43+
SourceFile &getSourceFile() const { return SF; }
4244

4345
/// Add a synthesized top-level declaration.
4446
void addTopLevelDecl(Decl *D) { TopLevelDecls.push_back(D); }

lib/AST/ASTPrinter.cpp

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,24 +1769,6 @@ bool ShouldPrintChecker::shouldPrint(const Pattern *P,
17691769
return ShouldPrint;
17701770
}
17711771

1772-
bool isNonSendableExtension(const Decl *D) {
1773-
ASTContext &ctx = D->getASTContext();
1774-
1775-
const ExtensionDecl *ED = dyn_cast<ExtensionDecl>(D);
1776-
if (!ED || !ED->getAttrs().isUnavailable(ctx))
1777-
return false;
1778-
1779-
auto nonSendable =
1780-
ED->getExtendedNominal()->getAttrs().getEffectiveSendableAttr();
1781-
if (!isa_and_nonnull<NonSendableAttr>(nonSendable))
1782-
return false;
1783-
1784-
// GetImplicitSendableRequest::evaluate() creates its extension with the
1785-
// attribute's AtLoc, so this is a good way to quickly check if the extension
1786-
// was synthesized for an '@_nonSendable' attribute.
1787-
return ED->getLocFromSource() == nonSendable->AtLoc;
1788-
}
1789-
17901772
bool ShouldPrintChecker::shouldPrint(const Decl *D,
17911773
const PrintOptions &Options) {
17921774
#if SWIFT_BUILD_ONLY_SYNTAXPARSERLIB
@@ -1809,19 +1791,16 @@ bool ShouldPrintChecker::shouldPrint(const Decl *D,
18091791
return false;
18101792
}
18111793

1812-
// Optionally skip these checks for extensions synthesized for '@_nonSendable'
1813-
if (!Options.AlwaysPrintNonSendableExtensions || !isNonSendableExtension(D)) {
1814-
if (Options.SkipImplicit && D->isImplicit()) {
1815-
const auto &IgnoreList = Options.TreatAsExplicitDeclList;
1816-
if (!llvm::is_contained(IgnoreList, D))
1794+
if (Options.SkipImplicit && D->isImplicit()) {
1795+
const auto &IgnoreList = Options.TreatAsExplicitDeclList;
1796+
if (std::find(IgnoreList.begin(), IgnoreList.end(), D) == IgnoreList.end())
18171797
return false;
1818-
}
1819-
1820-
if (Options.SkipUnavailable &&
1821-
D->getAttrs().isUnavailable(D->getASTContext()))
1822-
return false;
18231798
}
18241799

1800+
if (Options.SkipUnavailable &&
1801+
D->getAttrs().isUnavailable(D->getASTContext()))
1802+
return false;
1803+
18251804
if (Options.ExplodeEnumCaseDecls) {
18261805
if (isa<EnumElementDecl>(D))
18271806
return true;
@@ -5927,7 +5906,6 @@ swift::getInheritedForPrinting(
59275906
// Collect synthesized conformances.
59285907
auto &ctx = decl->getASTContext();
59295908
llvm::SetVector<ProtocolDecl *> protocols;
5930-
llvm::TinyPtrVector<ProtocolDecl *> uncheckedProtocols;
59315909
for (auto attr : decl->getAttrs().getAttributes<SynthesizedProtocolAttr>()) {
59325910
if (auto *proto = ctx.getProtocol(attr->getProtocolKind())) {
59335911
// The SerialExecutor conformance is only synthesized on the root
@@ -5940,14 +5918,11 @@ swift::getInheritedForPrinting(
59405918
cast<EnumDecl>(decl)->hasRawType())
59415919
continue;
59425920
protocols.insert(proto);
5943-
if (attr->isUnchecked())
5944-
uncheckedProtocols.push_back(proto);
59455921
}
59465922
}
59475923

59485924
for (size_t i = 0; i < protocols.size(); i++) {
59495925
auto proto = protocols[i];
5950-
bool isUnchecked = llvm::is_contained(uncheckedProtocols, proto);
59515926

59525927
if (!options.shouldPrint(proto)) {
59535928
// If private stdlib protocols are skipped and this is a private stdlib
@@ -5958,14 +5933,12 @@ swift::getInheritedForPrinting(
59585933
proto->isPrivateStdlibDecl(!options.SkipUnderscoredStdlibProtocols)) {
59595934
auto inheritedProtocols = proto->getInheritedProtocols();
59605935
protocols.insert(inheritedProtocols.begin(), inheritedProtocols.end());
5961-
if (isUnchecked)
5962-
copy(inheritedProtocols, std::back_inserter(uncheckedProtocols));
59635936
}
59645937
continue;
59655938
}
59665939

59675940
Results.push_back({TypeLoc::withoutLoc(proto->getDeclaredInterfaceType()),
5968-
isUnchecked});
5941+
/*isUnchecked=*/false});
59695942
}
59705943
}
59715944

lib/AST/Attr.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ DeclAttrKind DeclAttribute::getAttrKindFromString(StringRef Str) {
131131

132132
/// Returns true if this attribute can appear on the specified decl.
133133
bool DeclAttribute::canAttributeAppearOnDecl(DeclAttrKind DK, const Decl *D) {
134-
if ((getOptions(DK) & OnAnyClangDecl) && D->hasClangNode())
135-
return true;
136134
return canAttributeAppearOnDeclKind(DK, D->getKind());
137135
}
138136

@@ -701,13 +699,6 @@ void DeclAttributes::print(ASTPrinter &Printer, const PrintOptions &Options,
701699
if (Options.excludeAttrKind(DA->getKind()))
702700
continue;
703701

704-
// If this attribute is only allowed because this is a Clang decl, don't
705-
// print it.
706-
if (D && D->hasClangNode()
707-
&& !DeclAttribute::canAttributeAppearOnDeclKind(
708-
DA->getKind(), D->getKind()))
709-
continue;
710-
711702
// Be careful not to coalesce `@available(swift 5)` with other short
712703
// `available' attributes.
713704
if (auto *availableAttr = dyn_cast<AvailableAttr>(DA)) {
@@ -2111,23 +2102,6 @@ TypeSequenceAttr *TypeSequenceAttr::create(ASTContext &Ctx, SourceLoc atLoc,
21112102
return new (mem) TypeSequenceAttr(atLoc, range);
21122103
}
21132104

2114-
const DeclAttribute *
2115-
DeclAttributes::getEffectiveSendableAttr() const {
2116-
const NonSendableAttr *assumedAttr = nullptr;
2117-
2118-
for (auto attr : getAttributes<NonSendableAttr>()) {
2119-
if (attr->Specificity == NonSendableKind::Specific)
2120-
return attr;
2121-
if (!assumedAttr)
2122-
assumedAttr = attr;
2123-
}
2124-
2125-
if (auto sendableAttr = getAttribute<SendableAttr>())
2126-
return sendableAttr;
2127-
2128-
return assumedAttr;
2129-
}
2130-
21312105
void swift::simple_display(llvm::raw_ostream &out, const DeclAttribute *attr) {
21322106
if (attr)
21332107
attr->print(out);

0 commit comments

Comments
 (0)