Skip to content

Commit c043f11

Browse files
committed
Drop the "allows unsafe" modeling as availability
With the move to unsafe effects, we no longer model `unsafe` as an availability problem. Remove all of that supporting code.
1 parent 8bb5bbe commit c043f11

File tree

9 files changed

+4
-63
lines changed

9 files changed

+4
-63
lines changed

include/swift/AST/AvailabilityContext.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ class AvailabilityContext {
8787
/// Returns true if this context is `@_unavailableInEmbedded`.
8888
bool isUnavailableInEmbedded() const;
8989

90-
/// Returns true if this context allows the use of unsafe constructs inside
91-
/// it.
92-
bool allowsUnsafe() const;
93-
9490
/// Constrain with another `AvailabilityContext`.
9591
void constrainWithContext(const AvailabilityContext &other, ASTContext &ctx);
9692

@@ -107,9 +103,6 @@ class AvailabilityContext {
107103
constrainWithDeclAndPlatformRange(const Decl *decl,
108104
const AvailabilityRange &platformRange);
109105

110-
/// Constrain to allow unsafe code.
111-
void constrainWithAllowsUnsafe(ASTContext &ctx);
112-
113106
/// Returns true if `other` is as available or is more available.
114107
bool isContainedIn(const AvailabilityContext other) const;
115108

include/swift/AST/AvailabilityContextStorage.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ struct AvailabilityContext::PlatformInfo {
4343
/// platform.
4444
unsigned IsDeprecated : 1;
4545

46-
/// Whether or not the context allows unsafe code within it, e.g., via the
47-
/// `@unsafe` attribute.
48-
unsigned AllowsUnsafe: 1;
49-
5046
/// Sets each field to the value of the corresponding field in `other` if the
5147
/// other is more restrictive. Returns true if any field changed as a result
5248
/// of adding this constraint.
@@ -67,7 +63,6 @@ struct AvailabilityContext::PlatformInfo {
6763
ID.AddBoolean(IsUnavailableInEmbedded);
6864
ID.AddInteger(static_cast<uint8_t>(UnavailablePlatform));
6965
ID.AddBoolean(IsDeprecated);
70-
ID.AddBoolean(AllowsUnsafe);
7166
}
7267
};
7368

include/swift/AST/Decl.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,10 +1207,6 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
12071207
/// used in a "safe" dialect.
12081208
bool isUnsafe() const;
12091209

1210-
/// Whether this declaration explicitly states that it is allowed to contain
1211-
/// unsafe code.
1212-
bool allowsUnsafe() const;
1213-
12141210
private:
12151211
bool isUnsafeComputed() const {
12161212
return Bits.Decl.IsUnsafeComputed;
@@ -1957,7 +1953,6 @@ class ExtensionDecl final : public GenericContext, public Decl,
19571953
friend class Decl;
19581954
public:
19591955
using Decl::getASTContext;
1960-
using Decl::allowsUnsafe;
19611956

19621957
/// Create a new extension declaration.
19631958
static ExtensionDecl *create(ASTContext &ctx, SourceLoc extensionLoc,
@@ -3435,7 +3430,6 @@ class GenericTypeDecl : public GenericContext, public TypeDecl {
34353430
using DeclContext::operator new;
34363431
using DeclContext::operator delete;
34373432
using TypeDecl::getDeclaredInterfaceType;
3438-
using Decl::allowsUnsafe;
34393433

34403434
static bool classof(const DeclContext *C) {
34413435
if (auto D = C->getAsDecl())

include/swift/AST/DeclContext.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,6 @@ class alignas(1 << DeclContextAlignInBits) DeclContext
718718
/// target. Used for conformance lookup disambiguation.
719719
bool isAlwaysAvailableConformanceContext() const;
720720

721-
/// Determines whether this context is explicitly allowed to use unsafe
722-
/// constructs.
723-
bool allowsUnsafe() const;
724-
725721
/// \returns true if traversal was aborted, false otherwise.
726722
bool walkContext(ASTWalker &Walker);
727723

lib/AST/AvailabilityContext.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ bool AvailabilityContext::PlatformInfo::constrainWith(
4747
CONSTRAIN_BOOL(IsUnavailableInEmbedded, other.IsUnavailableInEmbedded);
4848
}
4949
isConstrained |= CONSTRAIN_BOOL(IsDeprecated, other.IsDeprecated);
50-
isConstrained |= CONSTRAIN_BOOL(AllowsUnsafe, other.AllowsUnsafe);
5150

5251
return isConstrained;
5352
}
@@ -65,7 +64,6 @@ bool AvailabilityContext::PlatformInfo::constrainWith(const Decl *decl) {
6564
}
6665

6766
isConstrained |= CONSTRAIN_BOOL(IsDeprecated, decl->isDeprecated());
68-
isConstrained |= CONSTRAIN_BOOL(AllowsUnsafe, decl->allowsUnsafe());
6967

7068
return isConstrained;
7169
}
@@ -131,8 +129,7 @@ AvailabilityContext::forPlatformRange(const AvailabilityRange &range,
131129
PlatformInfo platformInfo{range, PlatformKind::none,
132130
/*IsUnavailable*/ false,
133131
/*IsUnavailableInEmbedded*/ false,
134-
/*IsDeprecated*/ false,
135-
/*AllowsUnsafe*/ false};
132+
/*IsDeprecated*/ false};
136133
return AvailabilityContext(Storage::get(platformInfo, ctx));
137134
}
138135

@@ -155,8 +152,7 @@ AvailabilityContext::get(const AvailabilityRange &platformAvailability,
155152
? *unavailablePlatform
156153
: PlatformKind::none,
157154
unavailablePlatform.has_value(),
158-
/*IsUnavailableInEmbedded*/ false, deprecated,
159-
/*AllowsUnsafe*/ false};
155+
/*IsUnavailableInEmbedded*/ false, deprecated};
160156
return AvailabilityContext(Storage::get(platformInfo, ctx));
161157
}
162158

@@ -175,10 +171,6 @@ bool AvailabilityContext::isUnavailableInEmbedded() const {
175171
return Info->Platform.IsUnavailableInEmbedded;
176172
}
177173

178-
bool AvailabilityContext::allowsUnsafe() const {
179-
return Info->Platform.AllowsUnsafe;
180-
}
181-
182174
bool AvailabilityContext::isDeprecated() const {
183175
return Info->Platform.IsDeprecated;
184176
}
@@ -195,15 +187,6 @@ void AvailabilityContext::constrainWithDecl(const Decl *decl) {
195187
constrainWithDeclAndPlatformRange(decl, AvailabilityRange::alwaysAvailable());
196188
}
197189

198-
void AvailabilityContext::constrainWithAllowsUnsafe(ASTContext &ctx) {
199-
if (allowsUnsafe())
200-
return;
201-
202-
PlatformInfo platformInfo{Info->Platform};
203-
platformInfo.AllowsUnsafe = true;
204-
Info = Storage::get(platformInfo, ctx);
205-
}
206-
207190
void AvailabilityContext::constrainWithPlatformRange(
208191
const AvailabilityRange &platformRange, ASTContext &ctx) {
209192
PlatformInfo platformAvailability{Info->Platform};
@@ -251,9 +234,6 @@ void AvailabilityContext::print(llvm::raw_ostream &os) const {
251234

252235
if (isDeprecated())
253236
os << " deprecated";
254-
255-
if (allowsUnsafe())
256-
os << " allows_unsafe";
257237
}
258238

259239
void AvailabilityContext::dump() const { print(llvm::errs()); }

lib/AST/Decl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,10 +1094,6 @@ bool Decl::isUnsafe() const {
10941094
false);
10951095
}
10961096

1097-
bool Decl::allowsUnsafe() const {
1098-
return isUnsafe();
1099-
}
1100-
11011097
Type AbstractFunctionDecl::getThrownInterfaceType() const {
11021098
if (!getThrownTypeRepr())
11031099
return ThrownType.getType();

lib/AST/DeclContext.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,10 +1554,3 @@ bool DeclContext::isAlwaysAvailableConformanceContext() const {
15541554

15551555
return deploymentTarget.isContainedIn(conformanceAvailability);
15561556
}
1557-
1558-
bool DeclContext::allowsUnsafe() const {
1559-
if (auto decl = getAsDecl())
1560-
return decl->allowsUnsafe();
1561-
1562-
return false;
1563-
}

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,7 @@ class AvailabilityScopeBuilder : private ASTWalker {
964964
// Are we already constrained by the deployment target and the declaration
965965
// doesn't explicitly allow unsafe constructs in its definition, adding
966966
// new contexts won't change availability.
967-
bool allowsUnsafe = declHasSafeAttr(D);
968-
if (isCurrentScopeContainedByDeploymentTarget() && !allowsUnsafe)
967+
if (isCurrentScopeContainedByDeploymentTarget())
969968
return;
970969

971970
// Enumerate all of the body scopes to apply availability.
@@ -981,11 +980,6 @@ class AvailabilityScopeBuilder : private ASTWalker {
981980
AvailabilityRange::forDeploymentTarget(Context), Context);
982981
}
983982

984-
// Allow unsafe if appropriate for this body.
985-
if (allowsUnsafe) {
986-
availability.constrainWithAllowsUnsafe(Context);
987-
}
988-
989983
nodesAndScopes.push_back({
990984
body,
991985
AvailabilityScope::createForDeclImplicit(

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,7 @@ static bool checkSingleOverride(ValueDecl *override, ValueDecl *base) {
22612261
if (isUnsafe(overrideRef) && !isUnsafe(baseRef)) {
22622262
// Don't diagnose @unsafe overrides if the subclass is @unsafe.
22632263
auto overridingClass = override->getDeclContext()->getSelfClassDecl();
2264-
bool shouldDiagnose = !overridingClass || !overridingClass->allowsUnsafe();
2264+
bool shouldDiagnose = !overridingClass || !overridingClass->isUnsafe();
22652265

22662266
if (shouldDiagnose) {
22672267
diagnoseUnsafeUse(UnsafeUse::forOverride(override, base));

0 commit comments

Comments
 (0)