Skip to content

AST: Fix computeSelfParam() to respect __consuming on class methods #29579

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
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
7 changes: 2 additions & 5 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2431,7 +2431,8 @@ AnyFunctionType::Param swift::computeSelfParam(AbstractFunctionDecl *AFD,
if (isInitializingCtor) {
// initializing constructors of value types always have an implicitly
// inout self.
selfAccess = SelfAccessKind::Mutating;
if (!containerTy->hasReferenceSemantics())
selfAccess = SelfAccessKind::Mutating;
} else {
// allocating constructors have metatype 'self'.
isStatic = true;
Expand Down Expand Up @@ -2459,10 +2460,6 @@ AnyFunctionType::Param swift::computeSelfParam(AbstractFunctionDecl *AFD,
if (isStatic)
return AnyFunctionType::Param(MetatypeType::get(selfTy, Ctx));

// Reference types have 'self' of type T.
if (containerTy->hasReferenceSemantics())
return AnyFunctionType::Param(selfTy);

auto flags = ParameterTypeFlags();
switch (selfAccess) {
case SelfAccessKind::Consuming:
Expand Down
6 changes: 2 additions & 4 deletions lib/SIL/SILFunctionType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,10 +983,8 @@ class DestructureInputs {
for (auto i : indices(substTupleTy.getElementTypes())) {
auto &elt = substTupleTy->getElement(i);
auto ownership = elt.getParameterFlags().getValueOwnership();
// FIXME(swift3): Once the entire parameter list is no longer a
// target for substitution, re-enable this.
// assert(ownership == ValueOwnership::Default);
// assert(!elt.isVararg());
assert(ownership == ValueOwnership::Default);
assert(!elt.isVararg());
visit(ownership, forSelf,
origType.getTupleElementType(i),
CanType(elt.getRawType()), rep);
Expand Down
7 changes: 7 additions & 0 deletions test/SILGen/value_ownership_class.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-swift-emit-silgen %s | %FileCheck %s

class ConsumingClass {
__consuming func consumingMethod() {}
}

// CHECK-LABEL: sil hidden [ossa] @$s21value_ownership_class14ConsumingClassC15consumingMethodyyF : $@convention(method) (@owned ConsumingClass) -> () {
7 changes: 4 additions & 3 deletions test/decl/protocol/protocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ struct DoesNotConform : Up {

// Circular protocols

protocol CircleMiddle : CircleStart { func circle_middle() } // expected-error 3 {{protocol 'CircleMiddle' refines itself}}
protocol CircleStart : CircleEnd { func circle_start() }
// expected-note@-1 3 {{protocol 'CircleStart' declared here}}
protocol CircleMiddle : CircleStart { func circle_middle() } // expected-error 2 {{protocol 'CircleMiddle' refines itself}}
// expected-note@-1 {{protocol 'CircleMiddle' declared here}}
protocol CircleStart : CircleEnd { func circle_start() } // expected-error {{protocol 'CircleStart' refines itself}}
// expected-note@-1 2 {{protocol 'CircleStart' declared here}}
protocol CircleEnd : CircleMiddle { func circle_end()} // expected-note 3 {{protocol 'CircleEnd' declared here}}

protocol CircleEntry : CircleTrivial { }
Expand Down