mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CSBindings] Split literals from other protocol requirements
Literal protocol requirements are handled differently from other protocols, they require additional contextual information (such as coverage, direct/transitive distinction), and participate in binding inference (could be turned into default bindings).
This commit is contained in:
@@ -4700,6 +4700,8 @@ private:
|
||||
return BindingSource.get<ConstraintLocator *>();
|
||||
}
|
||||
|
||||
Constraint *getSource() const { return BindingSource.get<Constraint *>(); }
|
||||
|
||||
PotentialBinding withType(Type type) const {
|
||||
return {type, Kind, BindingSource};
|
||||
}
|
||||
@@ -4725,6 +4727,13 @@ private:
|
||||
using BindingScore =
|
||||
std::tuple<bool, bool, bool, bool, bool, unsigned char, int>;
|
||||
|
||||
/// - Constraint * - The source of the literal requirement;
|
||||
/// - bool - Determines whether this literal is a direct requirement
|
||||
/// of the current type variable;
|
||||
/// - Constraint * - If the literal is covered, this points to the
|
||||
/// source of the binding;
|
||||
using LiteralInfo = std::tuple<Constraint *, bool, Constraint *>;
|
||||
|
||||
/// The constraint system this type variable and its bindings belong to.
|
||||
ConstraintSystem &CS;
|
||||
|
||||
@@ -4740,6 +4749,14 @@ private:
|
||||
/// subtype/conversion/equivalence relations with other type variables.
|
||||
Optional<llvm::SmallPtrSet<Constraint *, 4>> TransitiveProtocols;
|
||||
|
||||
/// The set of unique literal protocol requirements placed on this
|
||||
/// type variable or inferred transitively through subtype chains.
|
||||
///
|
||||
/// Note that ordering is important when it comes to bindings, we'd
|
||||
/// like to add any "direct" default types first to attempt them
|
||||
/// before transitive ones.
|
||||
llvm::SmallMapVector<ProtocolDecl *, LiteralInfo, 2> Literals;
|
||||
|
||||
/// The set of constraints which would be used to infer default types.
|
||||
llvm::SmallDenseMap<CanType, Constraint *, 2> Defaults;
|
||||
|
||||
@@ -4949,6 +4966,8 @@ private:
|
||||
|
||||
void addDefault(Constraint *constraint);
|
||||
|
||||
void addLiteral(Constraint *constraint);
|
||||
|
||||
/// Add a potential binding to the list of bindings,
|
||||
/// coalescing supertype bounds when we are able to compute the meet.
|
||||
void addPotentialBinding(PotentialBinding binding,
|
||||
|
||||
Reference in New Issue
Block a user