Skip to content

Commit

Permalink
SILGen: Fix inout re-abstraction for default witnesses
Browse files Browse the repository at this point in the history
This came up when a requirement was mutating whereas the witness
was not.
  • Loading branch information
slavapestov committed Mar 10, 2016
1 parent 46ce8b4 commit 0029448
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/SILGen/SILGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1814,13 +1814,10 @@ SILGenModule::emitProtocolWitness(ProtocolConformance *conformance,
if (conformance) {
selfType = conformance->getType();

// For default implementations, Self is the contextual type of the
// extension (or, once we add default implementations inside protocols,
// the protocol's Self type).
// For default implementations, Self is the protocol archetype.
} else {
DeclContext *dc = witness.getDecl()->getDeclContext();
assert(dc->getAsProtocolOrProtocolExtensionContext());
selfType = dc->getDeclaredTypeOfContext();
auto *proto = cast<ProtocolDecl>(requirement.getDecl()->getDeclContext());
selfType = proto->getProtocolSelf()->getArchetype();
}
}

Expand Down
17 changes: 17 additions & 0 deletions test/SILGen/protocol_resilience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public protocol ResilientStorage {
var mutableGenericPropertyWithDefault: T { get set }

subscript(x: T) -> T { get set }

var mutatingGetterWithNonMutatingDefault: Int { mutating get set }
}

extension ResilientStorage {
Expand Down Expand Up @@ -151,6 +153,18 @@ extension ResilientStorage {
set { }
}

// CHECK-LABEL: sil [transparent] [thunk] @_TFP19protocol_resilience16ResilientStorageg36mutatingGetterWithNonMutatingDefaultSi
// CHECK-LABEL: sil @_TFE19protocol_resiliencePS_16ResilientStorageg36mutatingGetterWithNonMutatingDefaultSi
// CHECK-LABEL: sil [transparent] [thunk] @_TFP19protocol_resilience16ResilientStorages36mutatingGetterWithNonMutatingDefaultSi
// CHECK-LABEL: sil @_TFE19protocol_resiliencePS_16ResilientStorages36mutatingGetterWithNonMutatingDefaultSi
// CHECK-LABEL: sil [transparent] [thunk] @_TFP19protocol_resilience16ResilientStoragem36mutatingGetterWithNonMutatingDefaultSi
// CHECK-LABEL: sil [transparent] @_TFFP19protocol_resilience16ResilientStoragem36mutatingGetterWithNonMutatingDefaultSiU_T_
public var mutatingGetterWithNonMutatingDefault: Int {
get {
return 0
}
set { }
}
}


Expand Down Expand Up @@ -248,6 +262,9 @@ protocol InternalProtocol {
// CHECK-NEXT: method #ResilientStorage.subscript!getter.1: @_TFP19protocol_resilience16ResilientStorageg9subscriptFwx1TwxS1_
// CHECK-NEXT: method #ResilientStorage.subscript!setter.1: @_TFP19protocol_resilience16ResilientStorages9subscriptFwx1TwxS1_
// CHECK-NEXT: method #ResilientStorage.subscript!materializeForSet.1: @_TFP19protocol_resilience16ResilientStoragem9subscriptFwx1TwxS1_
// CHECK-NEXT: method #ResilientStorage.mutatingGetterWithNonMutatingDefault!getter.1: @_TFP19protocol_resilience16ResilientStorageg36mutatingGetterWithNonMutatingDefaultSi
// CHECK-NEXT: method #ResilientStorage.mutatingGetterWithNonMutatingDefault!setter.1: @_TFP19protocol_resilience16ResilientStorages36mutatingGetterWithNonMutatingDefaultSi
// CHECK-NEXT: method #ResilientStorage.mutatingGetterWithNonMutatingDefault!materializeForSet.1: @_TFP19protocol_resilience16ResilientStoragem36mutatingGetterWithNonMutatingDefaultSi
// CHECK-NEXT: }

// CHECK-LABEL: sil_default_witness_table ResilientOperators {
Expand Down

0 comments on commit 0029448

Please sign in to comment.