mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #74129 from gottesmm/pr-d17a3faab1ceab8b831d7649c1005be9c49d771c
[region-isolation] Implement function sub typing rules
This commit is contained in:
@@ -3235,6 +3235,16 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
|
||||
return getTypeMatchFailure(locator);
|
||||
}
|
||||
|
||||
// () -> sending T can be a subtype of () -> T... but not vis-a-versa.
|
||||
if (func1->hasSendingResult() != func2->hasSendingResult() &&
|
||||
(!func1->hasSendingResult() || kind < ConstraintKind::Subtype)) {
|
||||
auto *fix = AllowSendingMismatch::create(
|
||||
*this, getConstraintLocator(locator), func1, func2,
|
||||
AllowSendingMismatch::Kind::Result);
|
||||
if (recordFix(fix))
|
||||
return getTypeMatchFailure(locator);
|
||||
}
|
||||
|
||||
if (!matchFunctionIsolations(func1, func2, kind, flags, locator))
|
||||
return getTypeMatchFailure(locator);
|
||||
|
||||
@@ -3665,6 +3675,17 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
|
||||
return getTypeMatchFailure(argumentLocator);
|
||||
}
|
||||
|
||||
// Do not allow for functions that expect a sending parameter to match
|
||||
// with a function that expects a non-sending parameter.
|
||||
if (func1Param.getParameterFlags().isSending() &&
|
||||
!func2Param.getParameterFlags().isSending()) {
|
||||
auto *fix = AllowSendingMismatch::create(
|
||||
*this, getConstraintLocator(argumentLocator), func1, func2,
|
||||
AllowSendingMismatch::Kind::Parameter);
|
||||
if (recordFix(fix))
|
||||
return getTypeMatchFailure(argumentLocator);
|
||||
}
|
||||
|
||||
// FIXME: We should check value ownership too, but it's not completely
|
||||
// trivial because of inout-to-pointer conversions.
|
||||
|
||||
@@ -11785,10 +11806,10 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
|
||||
if (contextualParam->isIsolated() && !flags.isIsolated() && paramDecl)
|
||||
isolatedParams.insert(paramDecl);
|
||||
|
||||
param =
|
||||
param.withFlags(flags.withInOut(contextualParam->isInOut())
|
||||
.withVariadic(contextualParam->isVariadic())
|
||||
.withIsolated(contextualParam->isIsolated()));
|
||||
param = param.withFlags(flags.withInOut(contextualParam->isInOut())
|
||||
.withVariadic(contextualParam->isVariadic())
|
||||
.withIsolated(contextualParam->isIsolated())
|
||||
.withSending(contextualParam->isSending()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11915,6 +11936,12 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
|
||||
closureExtInfo = closureExtInfo.withSendable();
|
||||
}
|
||||
|
||||
// Propagate sending result from the contextual type to the closure.
|
||||
if (auto contextualFnType = contextualType->getAs<FunctionType>()) {
|
||||
if (contextualFnType->hasExtInfo() && contextualFnType->hasSendingResult())
|
||||
closureExtInfo = closureExtInfo.withSendingResult();
|
||||
}
|
||||
|
||||
// Isolated parameters override any other kind of isolation we might infer.
|
||||
if (hasIsolatedParam) {
|
||||
closureExtInfo = closureExtInfo.withIsolation(
|
||||
@@ -15113,6 +15140,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
|
||||
}
|
||||
}
|
||||
|
||||
case FixKind::AllowSendingMismatch:
|
||||
case FixKind::InsertCall:
|
||||
case FixKind::RemoveReturn:
|
||||
case FixKind::RemoveAddressOf:
|
||||
|
||||
Reference in New Issue
Block a user