Skip to content

Commit fa1fe8b

Browse files
authored
Merge pull request #72919 from slavapestov/fix-rdar126079282
AST: Remove incorrect optimization from ASTContext::getOpenedExistentialSignature()
2 parents 1931bb5 + b208655 commit fa1fe8b

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5866,18 +5866,6 @@ ASTContext::getOpenedExistentialSignature(Type type, GenericSignature parentSig)
58665866
assert(parentSig || !constraint->hasTypeParameter() &&
58675867
"Interface type here requires a parent signature");
58685868

5869-
// The opened archetype signature for a protocol type is identical
5870-
// to the protocol's own canonical generic signature if there aren't any
5871-
// outer generic parameters to worry about.
5872-
if (parentSig.isNull()) {
5873-
if (const auto protoTy = dyn_cast<ProtocolType>(constraint)) {
5874-
return protoTy->getDecl()->getGenericSignature().getCanonicalSignature();
5875-
}
5876-
}
5877-
5878-
// Otherwise we need to build a generic signature that captures any outer
5879-
// generic parameters. This ensures that we keep e.g. generic superclass
5880-
// existentials contained in a well-formed generic context.
58815869
auto canParentSig = parentSig.getCanonicalSignature();
58825870
auto key = std::make_pair(constraint, canParentSig.getPointer());
58835871
auto found = getImpl().ExistentialSignatures.find(key);

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -792,18 +792,6 @@ GenericSignatureRequest::evaluate(Evaluator &evaluator,
792792
parentSig = extendedNominal->getGenericSignatureOfContext();
793793
genericParams = nullptr;
794794
}
795-
796-
// Re-use the signature of the type being extended by default.
797-
// For tuple extensions, always build a new signature to get
798-
// the right sugared types, since we don't want to expose the
799-
// name of the generic parameter of BuiltinTupleDecl itself.
800-
if (extraReqs.empty() && !ext->getTrailingWhereClause() &&
801-
!isa<BuiltinTupleDecl>(extendedNominal) &&
802-
false/*!ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)*/) {
803-
// FIXME: Recover this optimization even with NoncopyableGenerics on.
804-
return parentSig;
805-
}
806-
807795
} else {
808796
llvm_unreachable("Unknown generic declaration kind");
809797
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swift-frontend -emit-sil -O %s -enable-experimental-feature NoncopyableGenerics | %FileCheck %s
2+
3+
protocol P: ~Copyable {}
4+
5+
@_optimize(none)
6+
func f<T: P>(_: T) {}
7+
8+
public struct S: P {
9+
@_optimize(none)
10+
init() {}
11+
}
12+
13+
// CHECK-LABEL: sil @$s44sil_combine_concrete_existential_noncopyable1gyyF : $@convention(thin) () -> () {
14+
// CHECK: [[S_ADDR:%.*]] = alloc_stack $S
15+
// CHECK: [[INIT_FN:%.*]] = function_ref @$s44sil_combine_concrete_existential_noncopyable1SVACycfC : $@convention(method) (@thin S.Type) -> S
16+
// CHECK: [[S:%.*]] = apply [[INIT_FN]]({{%.*}}) : $@convention(method) (@thin S.Type) -> S
17+
// CHECK: store [[S]] to [[S_ADDR]]
18+
// CHECK: [[CALLEE_FN:%.*]] = function_ref @$s44sil_combine_concrete_existential_noncopyable1fyyxAA1PRzlF : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
19+
// CHECK: apply [[CALLEE_FN]]<S>([[S_ADDR]])
20+
// CHECK: return
21+
22+
public func g() {
23+
let e: any P = S()
24+
f(e)
25+
}

0 commit comments

Comments
 (0)