Skip to content

Commit 1b7707d

Browse files
committed
Remove the now-unused @safe(unchecked)
1 parent c043f11 commit 1b7707d

32 files changed

+19
-236
lines changed

include/swift/AST/Attr.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,26 +2830,6 @@ class RawLayoutAttr final : public DeclAttribute {
28302830
UNIMPLEMENTED_CLONE(RawLayoutAttr)
28312831
};
28322832

2833-
class SafeAttr final : public DeclAttribute {
2834-
public:
2835-
/// The optional message.
2836-
const StringRef message;
2837-
2838-
SafeAttr(SourceLoc atLoc, SourceRange range, StringRef message,
2839-
bool isImplicit = false)
2840-
: DeclAttribute(DeclAttrKind::Safe, atLoc, range, isImplicit),
2841-
message(message) { }
2842-
2843-
static bool classof(const DeclAttribute *DA) {
2844-
return DA->getKind() == DeclAttrKind::Safe;
2845-
}
2846-
2847-
/// Create a copy of this attribute.
2848-
SafeAttr *clone(ASTContext &ctx) const {
2849-
return new (ctx) SafeAttr(AtLoc, Range, message, isImplicit());
2850-
}
2851-
};
2852-
28532833
class LifetimeAttr final : public DeclAttribute {
28542834
LifetimeEntry *entry;
28552835

include/swift/AST/Decl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,10 +1820,6 @@ struct InheritedEntry : public TypeLoc {
18201820
return getOptions().contains(ProtocolConformanceFlags::Unsafe);
18211821
}
18221822

1823-
bool isSafe() const {
1824-
return getOptions().contains(ProtocolConformanceFlags::Safe);
1825-
}
1826-
18271823
bool isSuppressed() const { return IsSuppressed; }
18281824

18291825
void setOption(ProtocolConformanceFlags flag) {

include/swift/AST/DeclAttr.def

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,7 @@ SIMPLE_DECL_ATTR(_addressableForDependencies, AddressableForDependencies,
531531
OnNominalType | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove | UserInaccessible,
532532
163)
533533

534-
DECL_ATTR(safe, Safe,
535-
OnAbstractFunction | OnSubscript | OnVar | OnMacro | OnNominalType |
536-
OnExtension | OnTypeAlias | OnImport | UserInaccessible |
537-
ABIStableToAdd | ABIStableToRemove | APIBreakingToAdd | APIStableToRemove,
538-
164)
534+
// 164 was the never-shipped @safe attribute and can be reused
539535

540536
DECL_ATTR(abi, ABI,
541537
OnAbstractFunction | OnVar /* will eventually add types */ | LongAttribute | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,9 +2111,6 @@ ERROR(parser_new_parser_errors,none,
21112111
"new Swift parser generated errors for code that C++ parser accepted",
21122112
())
21132113

2114-
ERROR(safe_attr_unchecked,none,
2115-
"'@safe' attribute must be written as '@safe(unchecked)'", ())
2116-
21172114
// MARK: Reference Binding Diagnostics
21182115
ERROR(sil_markuncheckedreferencebinding_requires_attribute,none,
21192116
"mark_unchecked_reference_binding requires an attribute like [inout]", ())

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8119,8 +8119,7 @@ GROUPED_WARNING(override_safe_with_unsafe,Unsafe,none,
81198119

81208120
GROUPED_WARNING(preconcurrency_import_unsafe,Unsafe,none,
81218121
"@preconcurrency import is not memory-safe because it can silently "
8122-
"introduce data races; use '@safe(unchecked)' to assert that the "
8123-
"code is memory-safe", ())
8122+
"introduce data races", ())
81248123
GROUPED_WARNING(unsafe_without_unsafe,Unsafe,none,
81258124
"expression uses unsafe constructs but is not marked with 'unsafe'", ())
81268125
WARNING(no_unsafe_in_unsafe,none,

include/swift/AST/NameLookup.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -612,21 +612,17 @@ struct InheritedNominalEntry : Located<NominalTypeDecl *> {
612612
/// The location of the "unsafe" attribute if present.
613613
SourceLoc unsafeLoc;
614614

615-
/// The range of the "safe(unchecked)" attribute if present.
616-
SourceRange safeRange;
617-
618615
/// Whether this inherited entry was suppressed via "~".
619616
bool isSuppressed;
620617

621618
InheritedNominalEntry() { }
622619

623620
InheritedNominalEntry(NominalTypeDecl *item, SourceLoc loc,
624621
SourceLoc uncheckedLoc, SourceLoc preconcurrencyLoc,
625-
SourceLoc unsafeLoc, SourceRange safeRange,
626-
bool isSuppressed)
622+
SourceLoc unsafeLoc, bool isSuppressed)
627623
: Located(item, loc), uncheckedLoc(uncheckedLoc),
628624
preconcurrencyLoc(preconcurrencyLoc), unsafeLoc(unsafeLoc),
629-
safeRange(safeRange), isSuppressed(isSuppressed) {}
625+
isSuppressed(isSuppressed) {}
630626
};
631627

632628
/// Retrieve the set of nominal type declarations that are directly

include/swift/AST/ProtocolConformance.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,6 @@ class NormalProtocolConformance : public RootProtocolConformance,
659659
return getOptions().contains(ProtocolConformanceFlags::Unsafe);
660660
}
661661

662-
/// Whether this is an "safe(unchecked)" conformance.
663-
bool isSafe() const {
664-
return getOptions().contains(ProtocolConformanceFlags::Safe);
665-
}
666-
667662
/// Determine whether we've lazily computed the associated conformance array
668663
/// already.
669664
bool hasComputedAssociatedConformances() const {

include/swift/AST/ProtocolConformanceOptions.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ enum class ProtocolConformanceFlags {
3131
/// @unsafe conformance
3232
Unsafe = 0x04,
3333

34-
/// @safe(unchecked) conformance
35-
Safe = 0x08,
36-
3734
/// @retroactive conformance
38-
Retroactive = 0x10,
35+
Retroactive = 0x08,
3936

4037
// Note: whenever you add a bit here, update
4138
// NumProtocolConformanceOptions below.
@@ -52,7 +49,7 @@ inline ProtocolConformanceOptions operator|(
5249
}
5350

5451
enum : unsigned {
55-
NumProtocolConformanceOptions = 5
52+
NumProtocolConformanceOptions = 4
5653
};
5754

5855
} // end namespace swift

include/swift/AST/TypeAttr.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ SIMPLE_TYPE_ATTR(retroactive, Retroactive)
6161
SIMPLE_TYPE_ATTR(unchecked, Unchecked)
6262
SIMPLE_TYPE_ATTR(preconcurrency, Preconcurrency)
6363
SIMPLE_TYPE_ATTR(unsafe, Unsafe)
64-
SIMPLE_TYPE_ATTR(safe, Safe)
6564
SIMPLE_TYPE_ATTR(_local, Local)
6665
SIMPLE_TYPE_ATTR(_noMetadata, NoMetadata)
6766
TYPE_ATTR(_opaqueReturnTypeOf, OpaqueReturnTypeOf)

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4144,11 +4144,6 @@ class PrintAttribute : public AttributeVisitor<PrintAttribute, void, StringRef>,
41444144
}
41454145
printFoot();
41464146
}
4147-
void visitSafeAttr(SafeAttr *Attr, StringRef label) {
4148-
printCommon(Attr, "safe_attr", label);
4149-
printFieldQuoted(Attr->message, "message");
4150-
printFoot();
4151-
}
41524147
void visitSILGenNameAttr(SILGenNameAttr *Attr, StringRef label) {
41534148
printCommon(Attr, "silgen_name_attr", label);
41544149
printFlag(Attr->Raw, "raw");

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,8 +2875,6 @@ void PrintAST::printInherited(const Decl *decl) {
28752875
Printer << "@preconcurrency ";
28762876
if (inherited.isUnsafe())
28772877
Printer << "@unsafe ";
2878-
if (inherited.isSafe())
2879-
Printer << "@safe(unchecked) ";
28802878
if (inherited.isSuppressed())
28812879
Printer << "~";
28822880
});

lib/AST/Attr.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,18 +1637,6 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
16371637
break;
16381638
}
16391639

1640-
case DeclAttrKind::Safe: {
1641-
auto *attr = cast<SafeAttr>(this);
1642-
Printer.printAttrName("@safe");
1643-
Printer << "(unchecked";
1644-
if (!attr->message.empty()) {
1645-
Printer << ", message: ";
1646-
Printer.printEscapedStringLiteral(attr->message);
1647-
}
1648-
Printer << ")";
1649-
break;
1650-
}
1651-
16521640
case DeclAttrKind::ABI: {
16531641
auto *attr = cast<ABIAttr>(this);
16541642
Printer << "@abi(";
@@ -1810,8 +1798,6 @@ StringRef DeclAttribute::getAttrName() const {
18101798
AccessLevel access = cast<AbstractAccessControlAttr>(this)->getAccess();
18111799
return getAccessLevelSpelling(access);
18121800
}
1813-
case DeclAttrKind::Safe:
1814-
return "safe";
18151801
case DeclAttrKind::SPIAccessControl:
18161802
return "_spi";
18171803
case DeclAttrKind::ReferenceOwnership:

lib/AST/ConformanceLookupTable.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ void ConformanceLookupTable::updateLookupTable(NominalTypeDecl *nominal,
328328
addProtocol(proto, found.Loc,
329329
source.withUncheckedLoc(found.uncheckedLoc)
330330
.withPreconcurrencyLoc(found.preconcurrencyLoc)
331-
.withUnsafeLoc(found.unsafeLoc)
332-
.withSafeRange(found.safeRange));
331+
.withUnsafeLoc(found.unsafeLoc));
333332
}
334333
}
335334

lib/AST/ConformanceLookupTable.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ class ConformanceLookupTable : public ASTAllocated<ConformanceLookupTable> {
9898
/// The location of the "unsafe" attribute, if there is one.
9999
SourceLoc unsafeLoc;
100100

101-
/// The range of the "@safe(unchecked)" attribute, if there is one.
102-
SourceRange safeRange;
103-
104101
ConformanceSource(void *ptr, ConformanceEntryKind kind)
105102
: Storage(ptr), Kind(kind) { }
106103

@@ -168,15 +165,6 @@ class ConformanceLookupTable : public ASTAllocated<ConformanceLookupTable> {
168165
return result;
169166
}
170167

171-
/// Return a new conformance source with the given range of
172-
/// "@safe(unchecked)".
173-
ConformanceSource withSafeRange(SourceRange safeRange) {
174-
ConformanceSource result(*this);
175-
if (safeRange.isValid())
176-
result.safeRange = safeRange;
177-
return result;
178-
}
179-
180168
ProtocolConformanceOptions getOptions() const {
181169
ProtocolConformanceOptions options;
182170
if (getUncheckedLoc().isValid())
@@ -185,8 +173,6 @@ class ConformanceLookupTable : public ASTAllocated<ConformanceLookupTable> {
185173
options |= ProtocolConformanceFlags::Preconcurrency;
186174
if (getUnsafeLoc().isValid() || isUnsafeContext(getDeclContext()))
187175
options |= ProtocolConformanceFlags::Unsafe;
188-
if (getSafeRange().isValid())
189-
options |= ProtocolConformanceFlags::Safe;
190176
return options;
191177
}
192178

@@ -242,11 +228,6 @@ class ConformanceLookupTable : public ASTAllocated<ConformanceLookupTable> {
242228
return unsafeLoc;
243229
}
244230

245-
/// The range of the @safe(unchecked) attribute, if any.
246-
SourceRange getSafeRange() const {
247-
return safeRange;
248-
}
249-
250231
/// For an inherited conformance, retrieve the class declaration
251232
/// for the inheriting class.
252233
ClassDecl *getInheritingClass() const {

lib/AST/Decl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,8 +1676,6 @@ InheritedEntry::InheritedEntry(const TypeLoc &typeLoc)
16761676
setOption(ProtocolConformanceFlags::Retroactive);
16771677
if (typeRepr->findAttrLoc(TypeAttrKind::Unsafe).isValid())
16781678
setOption(ProtocolConformanceFlags::Unsafe);
1679-
if (typeRepr->findAttrLoc(TypeAttrKind::Safe).isValid())
1680-
setOption(ProtocolConformanceFlags::Safe);
16811679
if (typeRepr->findAttrLoc(TypeAttrKind::Preconcurrency).isValid())
16821680
setOption(ProtocolConformanceFlags::Preconcurrency);
16831681
}

lib/AST/NameLookup.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3941,22 +3941,20 @@ void swift::getDirectlyInheritedNominalTypeDecls(
39413941
SourceLoc uncheckedLoc;
39423942
SourceLoc preconcurrencyLoc;
39433943
SourceLoc unsafeLoc;
3944-
SourceRange safeRange;
39453944
auto inheritedTypes = InheritedTypes(decl);
39463945
bool isSuppressed = inheritedTypes.getEntry(i).isSuppressed();
39473946
if (TypeRepr *typeRepr = inheritedTypes.getTypeRepr(i)) {
39483947
loc = typeRepr->getLoc();
39493948
uncheckedLoc = typeRepr->findAttrLoc(TypeAttrKind::Unchecked);
39503949
preconcurrencyLoc = typeRepr->findAttrLoc(TypeAttrKind::Preconcurrency);
39513950
unsafeLoc = typeRepr->findAttrLoc(TypeAttrKind::Unsafe);
3952-
safeRange = typeRepr->findAttrLoc(TypeAttrKind::Safe);
39533951
}
39543952

39553953
// Form the result.
39563954
for (auto nominal : nominalTypes) {
39573955
result.push_back(
39583956
{nominal, loc, uncheckedLoc, preconcurrencyLoc, unsafeLoc,
3959-
safeRange, isSuppressed});
3957+
isSuppressed});
39603958
}
39613959
}
39623960

@@ -3988,8 +3986,8 @@ swift::getDirectlyInheritedNominalTypeDecls(
39883986
auto loc = attr->getLocation();
39893987
result.push_back(
39903988
{attr->getProtocol(), loc, attr->isUnchecked() ? loc : SourceLoc(),
3991-
/*preconcurrencyLoc=*/SourceLoc(), SourceLoc(), SourceLoc(),
3992-
/*isSuppressed=*/false});
3989+
/*preconcurrencyLoc=*/SourceLoc(), SourceLoc(),
3990+
/*isSuppressed=*/false});
39933991
}
39943992

39953993
// Else we have access to this information on the where clause.
@@ -4001,8 +3999,7 @@ swift::getDirectlyInheritedNominalTypeDecls(
40013999
// the source location.
40024000
for (auto inheritedNominal : selfBounds.decls)
40034001
result.emplace_back(inheritedNominal, SourceLoc(), SourceLoc(),
4004-
SourceLoc(), SourceLoc(), SourceLoc(),
4005-
/*isSuppressed=*/false);
4002+
SourceLoc(), SourceLoc(), /*isSuppressed=*/false);
40064003

40074004
return result;
40084005
}

lib/ASTGen/Sources/ASTGen/DeclAttrs.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ extension ASTGenVisitor {
166166
return handle(self.generateProjectedValuePropertyAttr(attribute: node)?.asDeclAttribute)
167167
case .rawLayout:
168168
fatalError("unimplemented")
169-
case .safe:
170-
fatalError("unimplemented")
171169
case .section:
172170
return handle(self.generateSectionAttr(attribute: node)?.asDeclAttribute)
173171
case .semantics:

lib/ASTGen/Sources/ASTGen/TypeAttrs.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ extension ASTGenVisitor {
9191
case .isolated:
9292
return self.generateIsolatedTypeAttr(attribute: node)
9393

94-
case .safe:
95-
fatalError("unimplemented")
96-
9794
// SIL type attributes are not supported.
9895
case .autoreleased,
9996
.blockStorage,

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ class InheritedProtocolCollector {
489489
static ProtocolConformanceOptions filterOptions(ProtocolConformanceOptions options) {
490490
options -= ProtocolConformanceFlags::Preconcurrency;
491491
options -= ProtocolConformanceFlags::Retroactive;
492-
options -= ProtocolConformanceFlags::Safe;
493492
return options;
494493
}
495494

lib/IDE/CompletionLookup.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3182,7 +3182,6 @@ void CompletionLookup::getTypeAttributeKeywordCompletions(
31823182
case TypeAttrKind::Preconcurrency:
31833183
case TypeAttrKind::Unchecked:
31843184
case TypeAttrKind::Unsafe:
3185-
case TypeAttrKind::Safe:
31863185
// These attributes are only available in inheritance clasuses.
31873186
return;
31883187
default:

0 commit comments

Comments
 (0)