Skip to content

Commit e42bb73

Browse files
authored
Merge pull request #68968 from apple/revert-68285-effects-diagnostic
Revert "[Diagnostics] Require explicit releasenone."
2 parents 547437c + a9e03df commit e42bb73

File tree

7 files changed

+17
-201
lines changed

7 files changed

+17
-201
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ ERROR(exclusivity_access_required_unknown_decl_moveonly,none,
102102
NOTE(exclusivity_conflicting_access,none,
103103
"conflicting access is here", ())
104104

105-
WARNING(error_attr_effects_consume_requires_explicit_releasenone_self,none,
106-
"annotation implies no releases, but consumes self", ())
107-
WARNING(error_attr_effects_consume_requires_explicit_releasenone,none,
108-
"annotation implies no releases, but consumes parameter %0", (DeclName))
109-
NOTE(note_attr_effects_consume_requires_explicit_releasenone,none,
110-
"parameter %0 defined here", (DeclName))
111-
NOTE(fixit_attr_effects_consume_requires_explicit_releasenone,none,"add explicit @_effects(releasenone) if this is intended", ())
112-
113105
ERROR(unsupported_c_function_pointer_conversion,none,
114106
"C function pointer signature %0 is not compatible with expected type %1",
115107
(Type, Type))

lib/SIL/IR/SILFunctionBuilder.cpp

Lines changed: 9 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
#include "swift/SIL/SILFunctionBuilder.h"
1414
#include "swift/AST/AttrKind.h"
1515
#include "swift/AST/Availability.h"
16-
#include "swift/AST/Decl.h"
1716
#include "swift/AST/DiagnosticsParse.h"
18-
#include "swift/AST/DiagnosticsSIL.h"
1917
#include "swift/AST/DistributedDecl.h"
18+
#include "swift/AST/Decl.h"
2019
#include "swift/AST/ParameterList.h"
2120
#include "swift/AST/SemanticAttrs.h"
2221

@@ -61,8 +60,6 @@ void SILFunctionBuilder::addFunctionAttributes(
6160
if (auto *A = Attrs.getAttribute(DAK_EmitAssemblyVisionRemarks))
6261
F->addSemanticsAttr(semantics::FORCE_EMIT_OPT_REMARK_PREFIX);
6362

64-
auto *attributedFuncDecl = constant.getAbstractFunctionDecl();
65-
6663
// Propagate @_specialize.
6764
for (auto *A : Attrs.getAttributes<SpecializeAttr>()) {
6865
auto *SA = cast<SpecializeAttr>(A);
@@ -107,74 +104,21 @@ void SILFunctionBuilder::addFunctionAttributes(
107104
}
108105
}
109106

110-
EffectsAttr const *writeNoneEffect = nullptr;
111-
EffectsAttr const *releaseNoneEffect = nullptr;
112107
llvm::SmallVector<const EffectsAttr *, 8> customEffects;
113108
if (constant) {
114109
for (auto *attr : Attrs.getAttributes<EffectsAttr>()) {
115110
auto *effectsAttr = cast<EffectsAttr>(attr);
116-
switch (effectsAttr->getKind()) {
117-
case EffectsKind::Custom:
111+
if (effectsAttr->getKind() == EffectsKind::Custom) {
118112
customEffects.push_back(effectsAttr);
119-
// Proceed to the next attribute, don't set the effects kind based on
120-
// this attribute.
121-
continue;
122-
case EffectsKind::ReadNone:
123-
case EffectsKind::ReadOnly:
124-
writeNoneEffect = effectsAttr;
125-
break;
126-
case EffectsKind::ReleaseNone:
127-
releaseNoneEffect = effectsAttr;
128-
break;
129-
default:
130-
break;
131-
}
132-
if (effectsAttr->getKind() == EffectsKind::Custom)
133-
continue;
134-
if (F->getEffectsKind() != EffectsKind::Unspecified) {
135-
// If multiple known effects are specified, the most restrictive one
136-
// is used.
137-
F->setEffectsKind(
138-
std::min(effectsAttr->getKind(), F->getEffectsKind()));
139-
} else {
140-
F->setEffectsKind(effectsAttr->getKind());
141-
}
142-
}
143-
}
144-
145-
if (writeNoneEffect && !releaseNoneEffect) {
146-
auto constantType = mod.Types.getConstantFunctionType(
147-
TypeExpansionContext::minimal(), constant);
148-
SILFunctionConventions fnConv(constantType, mod);
149-
150-
auto selfIndex = fnConv.getSILArgIndexOfSelf();
151-
for (auto index : indices(fnConv.getParameters())) {
152-
auto param = fnConv.getParameters()[index];
153-
if (!param.isConsumed())
154-
continue;
155-
if (index == selfIndex) {
156-
mod.getASTContext().Diags.diagnose(
157-
writeNoneEffect->getLocation(),
158-
diag::
159-
error_attr_effects_consume_requires_explicit_releasenone_self);
160113
} else {
161-
auto *pd = attributedFuncDecl->getParameters()->get(index);
162-
mod.getASTContext().Diags.diagnose(
163-
writeNoneEffect->getLocation(),
164-
diag::error_attr_effects_consume_requires_explicit_releasenone,
165-
pd->getName());
166-
mod.getASTContext().Diags.diagnose(
167-
pd->getNameLoc(),
168-
diag::note_attr_effects_consume_requires_explicit_releasenone,
169-
pd->getName());
114+
if (F->getEffectsKind() != EffectsKind::Unspecified &&
115+
F->getEffectsKind() != effectsAttr->getKind()) {
116+
mod.getASTContext().Diags.diagnose(effectsAttr->getLocation(),
117+
diag::warning_in_effects_attribute, "mismatching function effects");
118+
} else {
119+
F->setEffectsKind(effectsAttr->getKind());
120+
}
170121
}
171-
mod.getASTContext()
172-
.Diags
173-
.diagnose(
174-
writeNoneEffect->getLocation(),
175-
diag::fixit_attr_effects_consume_requires_explicit_releasenone)
176-
.fixItInsertAfter(writeNoneEffect->getRange().End,
177-
" @_effects(releasenone)");
178122
}
179123
}
180124

lib/SILGen/SILGen.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,11 +749,11 @@ SILFunction *SILGenModule::getFunction(SILDeclRef constant,
749749

750750
// Note: Do not provide any SILLocation. You can set it afterwards.
751751
SILGenFunctionBuilder builder(*this);
752-
auto &SGM = *this;
752+
auto &IGM = *this;
753753
auto *F = builder.getOrCreateFunction(
754754
getBestLocation(constant), constant, forDefinition,
755-
[&SGM](SILLocation loc, SILDeclRef constant) -> SILFunction * {
756-
return SGM.getFunction(constant, NotForDefinition);
755+
[&IGM](SILLocation loc, SILDeclRef constant) -> SILFunction * {
756+
return IGM.getFunction(constant, NotForDefinition);
757757
});
758758

759759
assert(F && "SILFunction should have been defined");

stdlib/public/core/ArrayShared.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func _deallocateUninitializedArray<Element>(
7373
#if !INTERNAL_CHECKS_ENABLED
7474
@_alwaysEmitIntoClient
7575
@_semantics("array.finalize_intrinsic")
76-
@_effects(readnone) @_effects(releasenone)
76+
@_effects(readnone)
7777
@_effects(escaping array.value** => return.value**)
7878
@_effects(escaping array.value**.class*.value** => return.value**.class*.value**)
7979
public // COMPILER_INTRINSIC

stdlib/public/core/SmallString.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ extension _SmallString {
345345
extension _SmallString {
346346
// Resiliently create from a tagged cocoa string
347347
//
348-
@_effects(readonly) @_effects(releasenone) // @opaque
348+
@_effects(readonly) // @opaque
349349
@usableFromInline // testable
350350
internal init?(taggedCocoa cocoa: AnyObject) {
351351
self.init()
@@ -367,7 +367,7 @@ extension _SmallString {
367367
self._invariantCheck()
368368
}
369369

370-
@_effects(readonly) @_effects(releasenone) // @opaque
370+
@_effects(readonly) // @opaque
371371
internal init?(taggedASCIICocoa cocoa: AnyObject) {
372372
self.init()
373373
var success = true

stdlib/public/core/StringInterpolation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ extension String {
230230
/// print(message)
231231
/// // Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
232232
@inlinable
233-
@_effects(readonly) @_effects(releasenone)
233+
@_effects(readonly)
234234
public init(stringInterpolation: DefaultStringInterpolation) {
235235
self = stringInterpolation.make()
236236
}
@@ -254,7 +254,7 @@ extension Substring {
254254
/// print(message)
255255
/// // Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
256256
@inlinable
257-
@_effects(readonly) @_effects(releasenone)
257+
@_effects(readonly)
258258
public init(stringInterpolation: DefaultStringInterpolation) {
259259
self.init(stringInterpolation.make())
260260
}

test/SIL/diagnose_effects.swift

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)