Skip to content

Revert "[Diagnostics] Require explicit releasenone." #68968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ ERROR(exclusivity_access_required_unknown_decl_moveonly,none,
NOTE(exclusivity_conflicting_access,none,
"conflicting access is here", ())

WARNING(error_attr_effects_consume_requires_explicit_releasenone_self,none,
"annotation implies no releases, but consumes self", ())
WARNING(error_attr_effects_consume_requires_explicit_releasenone,none,
"annotation implies no releases, but consumes parameter %0", (DeclName))
NOTE(note_attr_effects_consume_requires_explicit_releasenone,none,
"parameter %0 defined here", (DeclName))
NOTE(fixit_attr_effects_consume_requires_explicit_releasenone,none,"add explicit @_effects(releasenone) if this is intended", ())

ERROR(unsupported_c_function_pointer_conversion,none,
"C function pointer signature %0 is not compatible with expected type %1",
(Type, Type))
Expand Down
74 changes: 9 additions & 65 deletions lib/SIL/IR/SILFunctionBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
#include "swift/SIL/SILFunctionBuilder.h"
#include "swift/AST/AttrKind.h"
#include "swift/AST/Availability.h"
#include "swift/AST/Decl.h"
#include "swift/AST/DiagnosticsParse.h"
#include "swift/AST/DiagnosticsSIL.h"
#include "swift/AST/DistributedDecl.h"
#include "swift/AST/Decl.h"
#include "swift/AST/ParameterList.h"
#include "swift/AST/SemanticAttrs.h"

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

auto *attributedFuncDecl = constant.getAbstractFunctionDecl();

// Propagate @_specialize.
for (auto *A : Attrs.getAttributes<SpecializeAttr>()) {
auto *SA = cast<SpecializeAttr>(A);
Expand Down Expand Up @@ -107,74 +104,21 @@ void SILFunctionBuilder::addFunctionAttributes(
}
}

EffectsAttr const *writeNoneEffect = nullptr;
EffectsAttr const *releaseNoneEffect = nullptr;
llvm::SmallVector<const EffectsAttr *, 8> customEffects;
if (constant) {
for (auto *attr : Attrs.getAttributes<EffectsAttr>()) {
auto *effectsAttr = cast<EffectsAttr>(attr);
switch (effectsAttr->getKind()) {
case EffectsKind::Custom:
if (effectsAttr->getKind() == EffectsKind::Custom) {
customEffects.push_back(effectsAttr);
// Proceed to the next attribute, don't set the effects kind based on
// this attribute.
continue;
case EffectsKind::ReadNone:
case EffectsKind::ReadOnly:
writeNoneEffect = effectsAttr;
break;
case EffectsKind::ReleaseNone:
releaseNoneEffect = effectsAttr;
break;
default:
break;
}
if (effectsAttr->getKind() == EffectsKind::Custom)
continue;
if (F->getEffectsKind() != EffectsKind::Unspecified) {
// If multiple known effects are specified, the most restrictive one
// is used.
F->setEffectsKind(
std::min(effectsAttr->getKind(), F->getEffectsKind()));
} else {
F->setEffectsKind(effectsAttr->getKind());
}
}
}

if (writeNoneEffect && !releaseNoneEffect) {
auto constantType = mod.Types.getConstantFunctionType(
TypeExpansionContext::minimal(), constant);
SILFunctionConventions fnConv(constantType, mod);

auto selfIndex = fnConv.getSILArgIndexOfSelf();
for (auto index : indices(fnConv.getParameters())) {
auto param = fnConv.getParameters()[index];
if (!param.isConsumed())
continue;
if (index == selfIndex) {
mod.getASTContext().Diags.diagnose(
writeNoneEffect->getLocation(),
diag::
error_attr_effects_consume_requires_explicit_releasenone_self);
} else {
auto *pd = attributedFuncDecl->getParameters()->get(index);
mod.getASTContext().Diags.diagnose(
writeNoneEffect->getLocation(),
diag::error_attr_effects_consume_requires_explicit_releasenone,
pd->getName());
mod.getASTContext().Diags.diagnose(
pd->getNameLoc(),
diag::note_attr_effects_consume_requires_explicit_releasenone,
pd->getName());
if (F->getEffectsKind() != EffectsKind::Unspecified &&
F->getEffectsKind() != effectsAttr->getKind()) {
mod.getASTContext().Diags.diagnose(effectsAttr->getLocation(),
diag::warning_in_effects_attribute, "mismatching function effects");
} else {
F->setEffectsKind(effectsAttr->getKind());
}
}
mod.getASTContext()
.Diags
.diagnose(
writeNoneEffect->getLocation(),
diag::fixit_attr_effects_consume_requires_explicit_releasenone)
.fixItInsertAfter(writeNoneEffect->getRange().End,
" @_effects(releasenone)");
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,11 +749,11 @@ SILFunction *SILGenModule::getFunction(SILDeclRef constant,

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

assert(F && "SILFunction should have been defined");
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/ArrayShared.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func _deallocateUninitializedArray<Element>(
#if !INTERNAL_CHECKS_ENABLED
@_alwaysEmitIntoClient
@_semantics("array.finalize_intrinsic")
@_effects(readnone) @_effects(releasenone)
@_effects(readnone)
@_effects(escaping array.value** => return.value**)
@_effects(escaping array.value**.class*.value** => return.value**.class*.value**)
public // COMPILER_INTRINSIC
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/SmallString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ extension _SmallString {
extension _SmallString {
// Resiliently create from a tagged cocoa string
//
@_effects(readonly) @_effects(releasenone) // @opaque
@_effects(readonly) // @opaque
@usableFromInline // testable
internal init?(taggedCocoa cocoa: AnyObject) {
self.init()
Expand All @@ -367,7 +367,7 @@ extension _SmallString {
self._invariantCheck()
}

@_effects(readonly) @_effects(releasenone) // @opaque
@_effects(readonly) // @opaque
internal init?(taggedASCIICocoa cocoa: AnyObject) {
self.init()
var success = true
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/StringInterpolation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ extension String {
/// print(message)
/// // Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
@inlinable
@_effects(readonly) @_effects(releasenone)
@_effects(readonly)
public init(stringInterpolation: DefaultStringInterpolation) {
self = stringInterpolation.make()
}
Expand All @@ -254,7 +254,7 @@ extension Substring {
/// print(message)
/// // Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars."
@inlinable
@_effects(readonly) @_effects(releasenone)
@_effects(readonly)
public init(stringInterpolation: DefaultStringInterpolation) {
self.init(stringInterpolation.make())
}
Expand Down
120 changes: 0 additions & 120 deletions test/SIL/diagnose_effects.swift

This file was deleted.