Skip to content

[region-isolation] Create a non-"callee" kind of error for async let. #73448

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
Show file tree
Hide file tree
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
61 changes: 61 additions & 0 deletions lib/SILOptimizer/Mandatory/TransferNonSendable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,35 @@ class UseAfterTransferDiagnosticEmitter {
emitRequireInstDiagnostics();
}

void
emitNamedIsolationCrossingError(SILLocation loc, Identifier name,
SILIsolationInfo namedValuesIsolationInfo,
ApplyIsolationCrossing isolationCrossing,
DeclName calleeDeclName,
DescriptiveDeclKind calleeDeclKind) {
// Emit the short error.
diagnoseError(loc, diag::regionbasedisolation_named_transfer_yields_race,
name)
.highlight(loc.getSourceRange())
.limitBehaviorIf(getBehaviorLimit());

// Then emit the note with greater context.
SmallString<64> descriptiveKindStr;
{
if (!namedValuesIsolationInfo.isDisconnected()) {
llvm::raw_svector_ostream os(descriptiveKindStr);
namedValuesIsolationInfo.printForDiagnostics(os);
os << ' ';
}
}

diagnoseNote(
loc, diag::regionbasedisolation_named_info_transfer_yields_race_callee,
name, descriptiveKindStr, isolationCrossing.getCalleeIsolation(),
calleeDeclKind, calleeDeclName, isolationCrossing.getCallerIsolation());
emitRequireInstDiagnostics();
}

void emitTypedIsolationCrossing(SILLocation loc, Type inferredType,
ApplyIsolationCrossing isolationCrossing) {
diagnoseError(
Expand Down Expand Up @@ -872,6 +901,38 @@ struct UseAfterTransferDiagnosticInferrer::AutoClosureWalker : ASTWalker {
if (declRef->getDecl() == targetDecl) {
// Found our target!
visitedCallExprDeclRefExprs.insert(declRef);

// See if we can find a valueDecl/name for our callee so we can
// emit a nicer error.
ConcreteDeclRef concreteDecl =
callExpr->getDirectCallee()->getReferencedDecl();

// If we do not find a direct one, see if we are calling a method
// on a nominal type.
if (!concreteDecl) {
if (auto *dot = dyn_cast<DotSyntaxCallExpr>(
callExpr->getDirectCallee())) {
concreteDecl = dot->getSemanticFn()->getReferencedDecl();
}
}

if (concreteDecl) {
auto *valueDecl = concreteDecl.getDecl();
assert(valueDecl &&
"Should be non-null if concreteDecl is valid");
if (valueDecl->hasName()) {
foundTypeInfo.diagnosticEmitter
.emitNamedIsolationCrossingError(
foundTypeInfo.baseLoc,
targetDecl->getBaseIdentifier(),
targetDeclIsolationInfo, *isolationCrossing,
valueDecl->getName(),
valueDecl->getDescriptiveKind());
return Action::Continue(expr);
}
}

// Otherwise default back to the "callee" error.
foundTypeInfo.diagnosticEmitter.emitNamedIsolationCrossingError(
foundTypeInfo.baseLoc, targetDecl->getBaseIdentifier(),
targetDeclIsolationInfo, *isolationCrossing);
Expand Down
Loading