From a92724b09c90f2bc9dfa0a7e5c49bd98ebb5b023 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 31 Jan 2020 15:28:30 -0800 Subject: [PATCH 1/2] AST: Fix computeSelfParam() to respect __consuming on class methods Fixes . --- lib/AST/ASTContext.cpp | 7 ++----- test/SILGen/value_ownership_class.swift | 7 +++++++ test/decl/protocol/protocols.swift | 7 ++++--- 3 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 test/SILGen/value_ownership_class.swift diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index ef6969430da40..a5d494d2805df 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -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; @@ -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: diff --git a/test/SILGen/value_ownership_class.swift b/test/SILGen/value_ownership_class.swift new file mode 100644 index 0000000000000..0c8fbe81ea54a --- /dev/null +++ b/test/SILGen/value_ownership_class.swift @@ -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) -> () { diff --git a/test/decl/protocol/protocols.swift b/test/decl/protocol/protocols.swift index f0b6bf4977bc6..2ed52c88bd3b7 100644 --- a/test/decl/protocol/protocols.swift +++ b/test/decl/protocol/protocols.swift @@ -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 { } From 62ca2aaf22f76f63ce8924da5e1ff1dbda356d1a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 31 Jan 2020 15:29:11 -0800 Subject: [PATCH 2/2] SIL: Fix an old FIXME --- lib/SIL/SILFunctionType.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/SIL/SILFunctionType.cpp b/lib/SIL/SILFunctionType.cpp index 6e0fac061678f..8b667f595bdb2 100644 --- a/lib/SIL/SILFunctionType.cpp +++ b/lib/SIL/SILFunctionType.cpp @@ -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);