Skip to content

Commit 5c46e06

Browse files
committed
Sema: Remove isInterfaceTypeNoncopyable()
1 parent f6ec97d commit 5c46e06

File tree

5 files changed

+26
-46
lines changed

5 files changed

+26
-46
lines changed

lib/AST/GenericEnvironment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ GenericEnvironment::maybeApplyOuterContextSubstitutions(Type type) const {
404404

405405
Type GenericEnvironment::mapTypeIntoContext(GenericEnvironment *env,
406406
Type type) {
407-
assert((!type->hasArchetype() || type->hasOpenedExistential()) &&
407+
assert((!type->hasArchetype() || type->hasLocalArchetype()) &&
408408
"already have a contextual type");
409409
assert((env || !type->hasTypeParameter()) &&
410410
"no generic environment provided for type with type parameters");

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,6 @@ static Type containsParameterizedProtocolType(Type inheritedTy) {
8888
return Type();
8989
}
9090

91-
bool swift::isInterfaceTypeNoncopyable(Type type, GenericEnvironment *env) {
92-
assert(!type->hasTypeParameter() || env && "must have a generic environment");
93-
94-
if (env)
95-
type = env->mapTypeIntoContext(type);
96-
97-
return type->isNoncopyable();
98-
}
99-
10091
/// Check the inheritance clause of a type declaration or extension thereof.
10192
///
10293
/// This routine performs detailed checking of the inheritance clause of the
@@ -2753,8 +2744,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
27532744
// accessors since this means that we cannot call mutating methods without
27542745
// copying. We do not want to support types that one cannot define a
27552746
// modify operation via a get/set or a modify.
2756-
if (isInterfaceTypeNoncopyable(var->getInterfaceType(),
2757-
DC->getGenericEnvironmentOfContext())) {
2747+
if (var->getTypeInContext()->isNoncopyable()) {
27582748
if (auto *read = var->getAccessor(AccessorKind::Read)) {
27592749
if (!read->isImplicit()) {
27602750
if (auto *set = var->getAccessor(AccessorKind::Set)) {
@@ -2847,8 +2837,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
28472837

28482838
// Reject noncopyable typed subscripts with read/set accessors since we
28492839
// cannot define modify operations upon them without copying the read.
2850-
if (isInterfaceTypeNoncopyable(SD->getElementInterfaceType(),
2851-
SD->getGenericEnvironment())) {
2840+
if (SD->mapTypeIntoContext(SD->getElementInterfaceType())->isNoncopyable()) {
28522841
if (auto *read = SD->getAccessor(AccessorKind::Read)) {
28532842
if (!read->isImplicit()) {
28542843
if (auto *set = SD->getAccessor(AccessorKind::Set)) {

lib/Sema/TypeCheckStorage.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -793,13 +793,8 @@ OpaqueReadOwnershipRequest::evaluate(Evaluator &evaluator,
793793
if (storage->getAttrs().hasAttribute<BorrowedAttr>())
794794
return usesBorrowed(DiagKind::BorrowedAttr);
795795

796-
GenericEnvironment *env = nullptr;
797-
if (auto *gc = storage->getAsGenericContext())
798-
env = gc->getGenericEnvironment();
799-
else
800-
env = storage->getDeclContext()->getGenericEnvironmentOfContext();
801-
802-
if (isInterfaceTypeNoncopyable(storage->getValueInterfaceType(), env))
796+
if (storage->getInnermostDeclContext()->mapTypeIntoContext(
797+
storage->getValueInterfaceType())->isNoncopyable())
803798
return usesBorrowed(DiagKind::NoncopyableType);
804799

805800
return OpaqueReadOwnership::Owned;

lib/Sema/TypeCheckType.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,6 @@ bool swift::diagnoseMissingOwnership(ParamSpecifier ownership,
25322532
auto options = resolution.getOptions();
25332533

25342534
assert(!ty->hasError());
2535-
assert(!options.contains(TypeResolutionFlags::SILType));
25362535

25372536
if (options.hasBase(TypeResolverContext::EnumElementDecl))
25382537
return false; // no need for ownership in enum cases.
@@ -2879,8 +2878,8 @@ TypeResolver::resolveOpenedExistentialArchetype(
28792878
// The constraint type is written with respect to the surrounding
28802879
// generic environment.
28812880
constraintType = GenericEnvironment::mapTypeIntoContext(
2882-
resolution.getGenericSignature().getGenericEnvironment(),
2883-
constraintType);
2881+
resolution.getGenericSignature().getGenericEnvironment(),
2882+
constraintType);
28842883

28852884
// The opened existential type is formed by mapping the interface type
28862885
// into a new opened generic environment.
@@ -3781,8 +3780,7 @@ TypeResolver::resolveASTFunctionTypeParams(TupleTypeRepr *inputRepr,
37813780

37823781
// Validate the presence of ownership for a noncopyable parameter.
37833782
if (inStage(TypeResolutionStage::Interface)
3784-
&& !ty->hasUnboundGenericType()
3785-
&& !options.contains(TypeResolutionFlags::SILMode)) {
3783+
&& !ty->hasUnboundGenericType()) {
37863784
diagnoseMissingOwnership(ownership, eltTypeRepr, ty, resolution);
37873785

37883786
// @_staticExclusiveOnly types cannot be passed as 'inout' in function
@@ -5243,14 +5241,14 @@ NeverNullType TypeResolver::resolveVarargType(VarargTypeRepr *repr,
52435241
}
52445242

52455243
// do not allow move-only types as the element of a vararg
5246-
if (!element->hasError()
5247-
&& inStage(TypeResolutionStage::Interface)
5248-
&& !options.contains(TypeResolutionFlags::SILMode)
5249-
&& isInterfaceTypeNoncopyable(
5250-
element, getDeclContext()->getGenericEnvironmentOfContext())) {
5251-
diagnoseInvalid(repr, repr->getLoc(), diag::noncopyable_generics_variadic,
5252-
element);
5253-
return ErrorType::get(getASTContext());
5244+
if (inStage(TypeResolutionStage::Interface)) {
5245+
auto contextTy = GenericEnvironment::mapTypeIntoContext(
5246+
resolution.getGenericSignature().getGenericEnvironment(), element);
5247+
if (!contextTy->hasError() && contextTy->isNoncopyable()) {
5248+
diagnoseInvalid(repr, repr->getLoc(), diag::noncopyable_generics_variadic,
5249+
element);
5250+
return ErrorType::get(getASTContext());
5251+
}
52545252
}
52555253

52565254
return element;
@@ -5401,7 +5399,6 @@ NeverNullType TypeResolver::resolvePackElement(PackElementTypeRepr *repr,
54015399
NeverNullType TypeResolver::resolveTupleType(TupleTypeRepr *repr,
54025400
TypeResolutionOptions options) {
54035401
auto &ctx = getASTContext();
5404-
auto *dc = getDeclContext();
54055402

54065403
SmallVector<TupleTypeElt, 8> elements;
54075404
elements.reserve(repr->getNumElements());
@@ -5429,13 +5426,16 @@ NeverNullType TypeResolver::resolveTupleType(TupleTypeRepr *repr,
54295426
// Track the presence of a noncopyable field for diagnostic purposes only.
54305427
// We don't need to re-diagnose if a tuple contains another tuple, though,
54315428
// since we should've diagnosed the inner tuple already.
5432-
if (inStage(TypeResolutionStage::Interface)
5433-
&& !options.contains(TypeResolutionFlags::SILMode)
5434-
&& !ty->hasUnboundGenericType()
5435-
&& isInterfaceTypeNoncopyable(ty, dc->getGenericEnvironmentOfContext())
5436-
&& !ctx.LangOpts.hasFeature(Feature::MoveOnlyTuples)
5437-
&& !moveOnlyElementIndex.has_value() && !isa<TupleTypeRepr>(tyR)) {
5438-
moveOnlyElementIndex = i;
5429+
if (!ctx.LangOpts.hasFeature(Feature::MoveOnlyTuples) &&
5430+
!options.contains(TypeResolutionFlags::SILMode) &&
5431+
inStage(TypeResolutionStage::Interface) &&
5432+
!moveOnlyElementIndex.has_value() &&
5433+
!ty->hasUnboundGenericType() &&
5434+
!isa<TupleTypeRepr>(tyR)) {
5435+
auto contextTy = GenericEnvironment::mapTypeIntoContext(
5436+
resolution.getGenericSignature().getGenericEnvironment(), ty);
5437+
if (contextTy->isNoncopyable())
5438+
moveOnlyElementIndex = i;
54395439
}
54405440

54415441
auto eltName = repr->getElementName(i);

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,10 +1403,6 @@ bool isOverrideBasedOnType(const ValueDecl *decl, Type declTy,
14031403
/// could fulfill a protocol requirement for it.
14041404
bool isMemberOperator(FuncDecl *decl, Type type);
14051405

1406-
/// Given an interface type and possibly a generic environment,
1407-
/// is the type ever noncopyable?
1408-
bool isInterfaceTypeNoncopyable(Type interfaceTy, GenericEnvironment *env);
1409-
14101406
/// Returns `true` iff `AdditiveArithmetic` derived conformances are enabled.
14111407
bool isAdditiveArithmeticConformanceDerivationEnabled(SourceFile &SF);
14121408

0 commit comments

Comments
 (0)