mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #7047 from rjmccall/track-access-dc-in-constraints
Track the actual DC of a member access in the constraint system.
This commit is contained in:
@@ -1323,8 +1323,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
|
||||
// Obviously, this must not happen at the top level, or the
|
||||
// algorithm would not terminate.
|
||||
addUnsolvedConstraint(Constraint::create(*this, kind, type1, type2,
|
||||
DeclName(),
|
||||
FunctionRefKind::Compound,
|
||||
getConstraintLocator(locator)));
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
@@ -2207,6 +2205,7 @@ commit_to_conversions:
|
||||
ConstraintSystem::SolutionKind
|
||||
ConstraintSystem::simplifyConstructionConstraint(
|
||||
Type valueType, FunctionType *fnType, TypeMatchOptions flags,
|
||||
DeclContext *useDC,
|
||||
FunctionRefKind functionRefKind, ConstraintLocator *locator) {
|
||||
|
||||
// Desugar the value type.
|
||||
@@ -2281,9 +2280,9 @@ ConstraintSystem::simplifyConstructionConstraint(
|
||||
}
|
||||
|
||||
NameLookupOptions lookupOptions = defaultConstructorLookupOptions;
|
||||
if (isa<AbstractFunctionDecl>(DC))
|
||||
if (isa<AbstractFunctionDecl>(useDC))
|
||||
lookupOptions |= NameLookupFlags::KnownPrivate;
|
||||
auto ctors = TC.lookupConstructors(DC, valueType, lookupOptions);
|
||||
auto ctors = TC.lookupConstructors(useDC, valueType, lookupOptions);
|
||||
if (!ctors)
|
||||
return SolutionKind::Error;
|
||||
|
||||
@@ -2300,7 +2299,8 @@ ConstraintSystem::simplifyConstructionConstraint(
|
||||
// variable T. T2 is the result type provided via the construction
|
||||
// constraint itself.
|
||||
addValueMemberConstraint(MetatypeType::get(valueType, TC.Context), name,
|
||||
FunctionType::get(tv, resultType), functionRefKind,
|
||||
FunctionType::get(tv, resultType),
|
||||
useDC, functionRefKind,
|
||||
getConstraintLocator(
|
||||
fnLocator,
|
||||
ConstraintLocator::ConstructorMember));
|
||||
@@ -2342,7 +2342,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
|
||||
if (flags.contains(TMF_GenerateConstraints)) {
|
||||
addUnsolvedConstraint(
|
||||
Constraint::create(*this, kind, type, protocol->getDeclaredType(),
|
||||
DeclName(), FunctionRefKind::Compound,
|
||||
getConstraintLocator(locator)));
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
@@ -2435,8 +2434,7 @@ ConstraintSystem::simplifyCheckedCastConstraint(
|
||||
if (flags.contains(TMF_GenerateConstraints)) {
|
||||
addUnsolvedConstraint(
|
||||
Constraint::create(*this, ConstraintKind::CheckedCast, fromType,
|
||||
toType, DeclName(), FunctionRefKind::Compound,
|
||||
getConstraintLocator(locator)));
|
||||
toType, getConstraintLocator(locator)));
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
@@ -2566,8 +2564,7 @@ ConstraintSystem::simplifyOptionalObjectConstraint(
|
||||
if (flags.contains(TMF_GenerateConstraints)) {
|
||||
addUnsolvedConstraint(
|
||||
Constraint::create(*this, ConstraintKind::OptionalObject, optLValueTy,
|
||||
second, DeclName(), FunctionRefKind::Compound,
|
||||
getConstraintLocator(locator)));
|
||||
second, getConstraintLocator(locator)));
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
@@ -3135,6 +3132,7 @@ ConstraintSystem::SolutionKind
|
||||
ConstraintSystem::simplifyMemberConstraint(ConstraintKind kind,
|
||||
Type baseTy, DeclName member,
|
||||
Type memberTy,
|
||||
DeclContext *useDC,
|
||||
FunctionRefKind functionRefKind,
|
||||
TypeMatchOptions flags,
|
||||
ConstraintLocatorBuilder locatorB) {
|
||||
@@ -3166,8 +3164,8 @@ ConstraintSystem::simplifyMemberConstraint(ConstraintKind kind,
|
||||
// If requested, generate a constraint.
|
||||
if (flags.contains(TMF_GenerateConstraints)) {
|
||||
addUnsolvedConstraint(
|
||||
Constraint::create(*this, kind, baseTy, memberTy, member,
|
||||
functionRefKind, locator));
|
||||
Constraint::createMember(*this, kind, baseTy, memberTy, member, useDC,
|
||||
functionRefKind, locator));
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
@@ -3183,7 +3181,7 @@ ConstraintSystem::simplifyMemberConstraint(ConstraintKind kind,
|
||||
|
||||
// If we found viable candidates, then we're done!
|
||||
if (!result.ViableCandidates.empty()) {
|
||||
addOverloadSet(memberTy, result.ViableCandidates, locator,
|
||||
addOverloadSet(memberTy, result.ViableCandidates, useDC, locator,
|
||||
result.getFavoredChoice());
|
||||
|
||||
return SolutionKind::Solved;
|
||||
@@ -3221,7 +3219,7 @@ ConstraintSystem::simplifyMemberConstraint(ConstraintKind kind,
|
||||
|
||||
// Look through one level of optional.
|
||||
addValueMemberConstraint(baseObjTy->getOptionalObjectType(),
|
||||
member, memberTy, functionRefKind, locator);
|
||||
member, memberTy, useDC, functionRefKind, locator);
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
return SolutionKind::Error;
|
||||
@@ -3238,7 +3236,6 @@ ConstraintSystem::simplifyDefaultableConstraint(
|
||||
if (flags.contains(TMF_GenerateConstraints)) {
|
||||
addUnsolvedConstraint(
|
||||
Constraint::create(*this, ConstraintKind::Defaultable, first, second,
|
||||
DeclName(), FunctionRefKind::Compound,
|
||||
getConstraintLocator(locator)));
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
@@ -3263,7 +3260,6 @@ ConstraintSystem::simplifyDynamicTypeOfConstraint(
|
||||
if (flags.contains(TMF_GenerateConstraints)) {
|
||||
addUnsolvedConstraint(
|
||||
Constraint::create(*this, ConstraintKind::DynamicTypeOf, type1, type2,
|
||||
DeclName(), FunctionRefKind::Compound,
|
||||
getConstraintLocator(locator)));
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
@@ -3325,8 +3321,7 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1,
|
||||
if (flags.contains(TMF_GenerateConstraints)) {
|
||||
addUnsolvedConstraint(
|
||||
Constraint::create(*this, ConstraintKind::BridgingConversion, type1,
|
||||
type2, DeclName(), FunctionRefKind::Compound,
|
||||
getConstraintLocator(locator)));
|
||||
type2, getConstraintLocator(locator)));
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
@@ -3550,9 +3545,7 @@ ConstraintSystem::simplifyEscapableFunctionOfConstraint(
|
||||
if (flags.contains(TMF_GenerateConstraints)) {
|
||||
addUnsolvedConstraint(
|
||||
Constraint::create(*this, ConstraintKind::EscapableFunctionOf,
|
||||
type1, type2,
|
||||
DeclName(), FunctionRefKind::Compound,
|
||||
getConstraintLocator(locator)));
|
||||
type1, type2, getConstraintLocator(locator)));
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
@@ -3625,8 +3618,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(
|
||||
if (flags.contains(TMF_GenerateConstraints)) {
|
||||
addUnsolvedConstraint(
|
||||
Constraint::create(*this, ConstraintKind::ApplicableFunction, type1,
|
||||
type2, DeclName(), FunctionRefKind::Compound,
|
||||
getConstraintLocator(locator)));
|
||||
type2, getConstraintLocator(locator)));
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
@@ -3696,6 +3688,7 @@ retry:
|
||||
|
||||
// Construct the instance from the input arguments.
|
||||
return simplifyConstructionConstraint(instance2, func1, subflags,
|
||||
/*FIXME?*/ DC,
|
||||
FunctionRefKind::SingleApply,
|
||||
getConstraintLocator(outerLocator));
|
||||
}
|
||||
@@ -3950,18 +3943,12 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
|
||||
if (flags.contains(TMF_GenerateConstraints)) {
|
||||
auto int8Con = Constraint::create(*this, ConstraintKind::Bind,
|
||||
baseType2, TC.getInt8Type(DC),
|
||||
DeclName(),
|
||||
FunctionRefKind::Compound,
|
||||
getConstraintLocator(locator));
|
||||
auto uint8Con = Constraint::create(*this, ConstraintKind::Bind,
|
||||
baseType2, TC.getUInt8Type(DC),
|
||||
DeclName(),
|
||||
FunctionRefKind::Compound,
|
||||
getConstraintLocator(locator));
|
||||
auto voidCon = Constraint::create(*this, ConstraintKind::Bind,
|
||||
baseType2, TC.Context.TheEmptyTupleType,
|
||||
DeclName(),
|
||||
FunctionRefKind::Compound,
|
||||
getConstraintLocator(locator));
|
||||
|
||||
Constraint *disjunctionChoices[] = {int8Con, uint8Con, voidCon};
|
||||
@@ -4290,8 +4277,7 @@ void ConstraintSystem::addConstraint(ConstraintKind kind, Type first,
|
||||
case SolutionKind::Error:
|
||||
// Add a failing constraint, if needed.
|
||||
if (shouldAddNewFailingConstraint()) {
|
||||
auto c = Constraint::create(*this, kind, first, second, DeclName(),
|
||||
FunctionRefKind::Compound,
|
||||
auto c = Constraint::create(*this, kind, first, second,
|
||||
getConstraintLocator(locator));
|
||||
if (isFavored) c->setFavored();
|
||||
addNewFailingConstraint(c);
|
||||
@@ -4317,9 +4303,7 @@ void ConstraintSystem::addExplicitConversionConstraint(
|
||||
// Coercion (the common case).
|
||||
Constraint *coerceConstraint =
|
||||
Constraint::create(*this, ConstraintKind::Conversion,
|
||||
fromType, toType, DeclName(),
|
||||
FunctionRefKind::Compound,
|
||||
locatorPtr);
|
||||
fromType, toType, locatorPtr);
|
||||
coerceConstraint->setFavored();
|
||||
constraints.push_back(coerceConstraint);
|
||||
|
||||
@@ -4328,9 +4312,7 @@ void ConstraintSystem::addExplicitConversionConstraint(
|
||||
// The source type can be explicitly converted to the destination type.
|
||||
Constraint *bridgingConstraint =
|
||||
Constraint::create(*this, ConstraintKind::BridgingConversion,
|
||||
fromType, toType, DeclName(),
|
||||
FunctionRefKind::Compound,
|
||||
locatorPtr);
|
||||
fromType, toType, locatorPtr);
|
||||
constraints.push_back(bridgingConstraint);
|
||||
}
|
||||
|
||||
@@ -4408,7 +4390,8 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
|
||||
|
||||
case ConstraintKind::BindOverload:
|
||||
resolveOverload(constraint.getLocator(), constraint.getFirstType(),
|
||||
constraint.getOverloadChoice());
|
||||
constraint.getOverloadChoice(),
|
||||
constraint.getOverloadUseDC());
|
||||
return SolutionKind::Solved;
|
||||
|
||||
case ConstraintKind::ConformsTo:
|
||||
@@ -4452,6 +4435,7 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
|
||||
constraint.getFirstType(),
|
||||
constraint.getMember(),
|
||||
constraint.getSecondType(),
|
||||
constraint.getMemberUseDC(),
|
||||
constraint.getFunctionRefKind(),
|
||||
TMF_GenerateConstraints,
|
||||
constraint.getLocator());
|
||||
|
||||
Reference in New Issue
Block a user