Skip to content

[send-not-sendable] Eliminate relative includes and add a file header. #68104

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
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
4 changes: 4 additions & 0 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
return const_cast<Expr *>(this)->getValueProvidingExpr();
}

/// Find the original type of a value, looking through various implicit
/// conversions.
Type findOriginalType() const;

/// If this is a reference to an operator written as a member of a type (or
/// extension thereof), return the underlying operator reference.
DeclRefExpr *getMemberOperatorRef();
Expand Down
3 changes: 3 additions & 0 deletions include/swift/SIL/SILType.h
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,9 @@ class SILType {

bool isMarkedAsImmortal() const;

ProtocolConformanceRef conformsToProtocol(SILFunction *fn,
ProtocolDecl *protocol) const;

//
// Accessors for types used in SIL instructions:
//
Expand Down
25 changes: 25 additions & 0 deletions lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2789,3 +2789,28 @@ FrontendStatsTracer::getTraceFormatter<const Expr *>() {
return &TF;
}

Type Expr::findOriginalType() const {
auto *expr = this;
do {
expr = expr->getSemanticsProvidingExpr();

if (auto inout = dyn_cast<InOutExpr>(expr)) {
expr = inout->getSubExpr();
continue;
}

if (auto ice = dyn_cast<ImplicitConversionExpr>(expr)) {
expr = ice->getSubExpr();
continue;
}

if (auto open = dyn_cast<OpenExistentialExpr>(expr)) {
expr = open->getSubExpr();
continue;
}

break;
} while (true);

return expr->getType()->getRValueType();
}
5 changes: 5 additions & 0 deletions lib/SIL/IR/SILType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,3 +1211,8 @@ SILType SILType::removingMoveOnlyWrapperToBoxedType(const SILFunction *fn) {
boxTy->getSubstitutions());
return SILType::getPrimitiveObjectType(newBoxType);
}

ProtocolConformanceRef
SILType::conformsToProtocol(SILFunction *fn, ProtocolDecl *protocol) const {
return fn->getParentModule()->conformsToProtocol(getASTType(), protocol);
}
38 changes: 24 additions & 14 deletions lib/SILOptimizer/Mandatory/SendNonSendable.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#include "../../Sema/TypeCheckConcurrency.h"
#include "../../Sema/TypeChecker.h"
//===--- SendNonSendable.cpp ----------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include "swift/AST/DiagnosticsSIL.h"
#include "swift/AST/Expr.h"
#include "swift/AST/Type.h"
Expand Down Expand Up @@ -256,18 +266,17 @@ class PartitionOpTranslator {
switch (type.getASTType()->getKind()) {
case TypeKind::BuiltinNativeObject:
case TypeKind::BuiltinRawPointer:
// these are very unsafe... definitely not Sendable
// These are very unsafe... definitely not Sendable.
return true;
default:
// consider caching this if it's a performance bottleneck
return TypeChecker::conformsToProtocol(
type.getASTType(), sendableProtocol, function->getParentModule())
// Consider caching this if it's a performance bottleneck.
return type.conformsToProtocol(function, sendableProtocol)
.hasMissingConformance(function->getParentModule());
}
}

// used to statefully track the instruction currently being translated,
// for insertion into generated PartitionOps
// Used to statefully track the instruction currently being translated, for
// insertion into generated PartitionOps.
SILInstruction *currentInstruction;

// ===========================================================================
Expand Down Expand Up @@ -1586,12 +1595,13 @@ class PartitionAnalysis {
if (!argExpr)
assert(false && "sourceExpr should be populated for ApplyExpr consumptions");

function->getASTContext().Diags.diagnose(
argExpr->getLoc(), diag::call_site_consumption_yields_race,
findOriginalValueType(argExpr),
isolationCrossing.value().getCallerIsolation(),
isolationCrossing.value().getCalleeIsolation(),
numDisplayed, numDisplayed != 1, numHidden > 0, numHidden)
function->getASTContext()
.Diags
.diagnose(argExpr->getLoc(), diag::call_site_consumption_yields_race,
argExpr->findOriginalType(),
isolationCrossing.value().getCallerIsolation(),
isolationCrossing.value().getCalleeIsolation(), numDisplayed,
numDisplayed != 1, numHidden > 0, numHidden)
.highlight(argExpr->getSourceRange());
return true;
}
Expand Down
29 changes: 1 addition & 28 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1837,33 +1837,6 @@ static void noteGlobalActorOnContext(DeclContext *dc, Type globalActor) {
}
}

/// Find the original type of a value, looking through various implicit
/// conversions.
Type swift::findOriginalValueType(Expr *expr) {
do {
expr = expr->getSemanticsProvidingExpr();

if (auto inout = dyn_cast<InOutExpr>(expr)) {
expr = inout->getSubExpr();
continue;
}

if (auto ice = dyn_cast<ImplicitConversionExpr>(expr)) {
expr = ice->getSubExpr();
continue;
}

if (auto open = dyn_cast<OpenExistentialExpr>(expr)) {
expr = open->getSubExpr();
continue;
}

break;
} while (true);

return expr->getType()->getRValueType();
}

bool swift::diagnoseApplyArgSendability(ApplyExpr *apply, const DeclContext *declContext) {
auto isolationCrossing = apply->getIsolationCrossing();
if (!isolationCrossing.has_value())
Expand Down Expand Up @@ -1904,7 +1877,7 @@ bool swift::diagnoseApplyArgSendability(ApplyExpr *apply, const DeclContext *dec
// Determine the type of the argument, ignoring any implicit
// conversions that could have stripped sendability.
if (Expr *argExpr = arg.getExpr()) {
argType = findOriginalValueType(argExpr);
argType = argExpr->findOriginalType();
}
}

Expand Down
4 changes: 0 additions & 4 deletions lib/Sema/TypeCheckConcurrency.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,6 @@ struct SendableCheckContext {
bool isExplicitSendableConformance() const;
};

/// Find the original type of a value, looking through various implicit
/// conversions.
Type findOriginalValueType(Expr *expr);

/// Diagnose any non-Sendable types that occur within the given type, using
/// the given diagnostic.
///
Expand Down