Skip to content

[AutoDiff] Peel off @sendable implicit conversion when checking for unsupported differentiable function conversion #77869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6550,7 +6550,19 @@ maybeDiagnoseUnsupportedDifferentiableConversion(ConstraintSystem &cs,
maybeDiagnoseFunctionRef(unwrappedFnExpr);
return;
}
} else if (auto conv = dyn_cast<FunctionConversionExpr>(semanticExpr)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also ABISafeConversionExpr which does the same thing for l-value types, in case that matters in some other case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, thanks! I just do not have example in hand, but we'll see.

// Look through a function conversion that only adds or removes
// `@Sendable`.
auto ty1 = conv->getType()->castTo<AnyFunctionType>();
auto ty2 = conv->getSubExpr()->getType()->castTo<AnyFunctionType>();

if (ty1->withExtInfo(ty1->getExtInfo().withSendable(false))
->isEqual(ty2->withExtInfo(ty2->getExtInfo().withSendable(false)))) {
maybeDiagnoseFunctionRef(conv->getSubExpr()->getSemanticsProvidingExpr());
return;
}
}

ctx.Diags.diagnose(expr->getLoc(),
diag::invalid_differentiable_function_conversion_expr);
};
Expand Down