Skip to content

Commit db97d27

Browse files
authored
Merge pull request #36746 from slavapestov/gsb-conformance-superclass-combo
GSB: The combination of a superclass and conformance requirement might force a type to be concrete
2 parents 45ab4f4 + bcee54b commit db97d27

16 files changed

+420
-234
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,16 +2414,17 @@ NOTE(same_type_redundancy_here,none,
24142414
"same-type constraint %1 == %2 %select{written here|implied here|"
24152415
"inferred from type here}0",
24162416
(unsigned, Type, Type))
2417-
ERROR(requires_superclass_conflict,none,
2418-
"%select{generic parameter %1 cannot|protocol %1 cannot require 'Self' to|"
2419-
"%1 cannot}0 be a subclass of both %2 and %3",
2420-
(unsigned, Type, Type, Type))
2417+
ERROR(conflicting_superclass_constraints,none,
2418+
"type %0 cannot be a subclass of both %1 and %2",
2419+
(Type, Type, Type))
2420+
NOTE(conflicting_superclass_constraint,none,
2421+
"constraint conflicts with %0 : %1",
2422+
(Type, Type))
24212423
WARNING(redundant_superclass_constraint,none,
24222424
"redundant superclass constraint %0 : %1", (Type, Type))
24232425
NOTE(superclass_redundancy_here,none,
2424-
"superclass constraint %1 : %2 %select{written here|implied here|"
2425-
"inferred from type here}0",
2426-
(unsigned, Type, Type))
2426+
"superclass constraint %0 : %1 implied here",
2427+
(Type, Type))
24272428

24282429
ERROR(conflicting_layout_constraints,none,
24292430
"type %0 has conflicting constraints %1 and %2",

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,15 @@ class GenericSignatureBuilder {
427427
Type superclass,
428428
FloatingRequirementSource source);
429429

430+
/// Update the layout constraint for the equivalence class of \c T.
431+
///
432+
/// This assumes that the constraint has already been recorded.
433+
///
434+
/// \returns true if anything in the equivalence class changed, false
435+
/// otherwise.
436+
bool updateLayout(ResolvedType type,
437+
LayoutConstraint layout);
438+
430439
private:
431440
/// Add a new superclass requirement specifying that the given
432441
/// potential archetype has the given type as an ancestor.
@@ -528,8 +537,7 @@ class GenericSignatureBuilder {
528537
LookUpConformanceInBuilder getLookupConformanceFn();
529538

530539
/// Lookup a protocol conformance in a module-agnostic manner.
531-
ProtocolConformanceRef lookupConformance(CanType dependentType,
532-
Type conformingReplacementType,
540+
ProtocolConformanceRef lookupConformance(Type conformingReplacementType,
533541
ProtocolDecl *conformedProtocol);
534542

535543
/// Enumerate the requirements that describe the signature of this
@@ -653,6 +661,8 @@ class GenericSignatureBuilder {
653661

654662
void diagnoseRedundantRequirements() const;
655663

664+
void diagnoseConflictingConcreteTypeRequirements() const;
665+
656666
bool hasExplicitConformancesImpliedByConcrete() const;
657667

658668
/// Describes the relationship between a given constraint and
@@ -696,34 +706,6 @@ class GenericSignatureBuilder {
696706
Diag<Type, T> redundancyDiag,
697707
Diag<unsigned, Type, T> otherNoteDiag);
698708

699-
/// Check a list of constraints, removing self-derived constraints
700-
/// and diagnosing redundant constraints.
701-
///
702-
/// \param isSuitableRepresentative Determines whether the given constraint
703-
/// is a suitable representative.
704-
///
705-
/// \param checkConstraint Checks the given constraint against the
706-
/// canonical constraint to determine which diagnostics (if any) should be
707-
/// emitted.
708-
///
709-
/// \returns the representative constraint.
710-
template<typename T, typename DiagT>
711-
Constraint<T> checkConstraintList(
712-
TypeArrayView<GenericTypeParamType> genericParams,
713-
std::vector<Constraint<T>> &constraints,
714-
RequirementKind kind,
715-
llvm::function_ref<bool(const Constraint<T> &)>
716-
isSuitableRepresentative,
717-
llvm::function_ref<
718-
ConstraintRelation(const Constraint<T>&)>
719-
checkConstraint,
720-
Optional<Diag<unsigned, Type, DiagT, DiagT>>
721-
conflictingDiag,
722-
Diag<Type, DiagT> redundancyDiag,
723-
Diag<unsigned, Type, DiagT> otherNoteDiag,
724-
llvm::function_ref<DiagT(const T&)> diagValue,
725-
bool removeSelfDerived);
726-
727709
/// Check the concrete type constraints within the equivalence
728710
/// class of the given potential archetype.
729711
void checkConcreteTypeConstraints(

lib/AST/GenericSignature.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,7 @@ bool GenericSignatureImpl::isRequirementSatisfied(
440440
if (canFirstType->isTypeParameter())
441441
return requiresProtocol(canFirstType, protocol);
442442
else
443-
return (bool)GSB->lookupConformance(/*dependentType=*/CanType(),
444-
canFirstType, protocol);
443+
return (bool)GSB->lookupConformance(canFirstType, protocol);
445444
}
446445

447446
case RequirementKind::SameType: {

0 commit comments

Comments
 (0)