Skip to content

Commit 7bdc04d

Browse files
committed
[NoncopyableGenerics] remove incorrect fast-path
It's not technically correct to ask the generic signature without first reducing the type, i.e., we really have to do this: ``` auto ty = sig->getReducedType(this) // fast path if (ty.isTypeParamter()) return sig->requiresProtocol(s, copyable) // slow path mapTypeIntoContext(...) ``` Since reducing the type is basically what `mapTypeIntoContext` is also going to do, it's not really worth doing this or having the fast-path at all. This need to reduce the type originally came while building the stdlib. We ran into a problem with this: ``` extension Slice { public func initialize<S>( from source: S ) -> (unwritten: S.Iterator, index: Index) where S: Sequence, Base == UnsafeMutableBufferPointer<S.Element> } ``` where we have `struct Slice<Base: Collection>` and ``` extension Slice: Collection { typealias Index = Base.Index // ... } ```
1 parent f71daba commit 7bdc04d

File tree

1 file changed

+0
-14
lines changed

1 file changed

+0
-14
lines changed

lib/AST/Type.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,6 @@ static bool alwaysNoncopyable(Type ty) {
181181
/// context to substitute unbound types.
182182
bool TypeBase::isNoncopyable(const DeclContext *dc) {
183183
assert(dc);
184-
auto &ctx = dc->getASTContext();
185-
186-
// Fast-path for type parameters; ask the generic signature directly.
187-
if (isTypeParameter() &&
188-
ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
189-
auto canType = getCanonicalType();
190-
191-
auto *copyable = ctx.getProtocol(KnownProtocolKind::Copyable);
192-
if (!copyable)
193-
llvm_unreachable("missing Copyable protocol!");
194-
195-
auto sig = dc->getGenericSignatureOfContext();
196-
return !sig->requiresProtocol(canType, copyable);
197-
}
198184

199185
if (!hasArchetype() || hasOpenedExistential())
200186
if (auto env = dc->getGenericEnvironmentOfContext())

0 commit comments

Comments
 (0)