Skip to content

Commit 05f0a7e

Browse files
Merge pull request #4540 from swiftwasm/release/5.7
[pull] swiftwasm-release/5.7 from release/5.7
2 parents e9f214d + 9edb00e commit 05f0a7e

15 files changed

+137
-13
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10931,6 +10931,24 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
1093110931

1093210932
auto *argList = getArgumentList(getConstraintLocator(locator));
1093310933

10934+
// If argument list has trailing closures and this is `init` call to
10935+
// a callable type, let's not filter anything since there is a possibility
10936+
// that it needs an implicit `.callAsFunction` to work.
10937+
if (argList && argList->hasAnyTrailingClosures()) {
10938+
if (disjunction->getLocator()
10939+
->isLastElement<LocatorPathElt::ConstructorMember>()) {
10940+
auto choice = disjunction->getNestedConstraints()[0]->getOverloadChoice();
10941+
if (auto *decl = choice.getDeclOrNull()) {
10942+
auto *dc = decl->getDeclContext();
10943+
if (auto *parent = dc->getSelfNominalTypeDecl()) {
10944+
auto type = parent->getDeclaredInterfaceType();
10945+
if (type->isCallableNominalType(DC))
10946+
return false;
10947+
}
10948+
}
10949+
}
10950+
}
10951+
1093410952
// Consider each of the constraints in the disjunction.
1093510953
retry_after_fail:
1093610954
bool hasUnhandledConstraints = false;

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,13 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(
564564
}
565565

566566
if (auto *UDE = getAsExpr<UnresolvedDotExpr>(anchor)) {
567+
if (UDE->isImplicit() &&
568+
UDE->getName().getBaseName() == Context.Id_callAsFunction) {
569+
return getConstraintLocator(anchor,
570+
{LocatorPathElt::ApplyFunction(),
571+
LocatorPathElt::ImplicitCallAsFunction()});
572+
}
573+
567574
return getConstraintLocator(
568575
anchor, TypeChecker::getSelfForInitDelegationInConstructor(DC, UDE)
569576
? ConstraintLocator::ConstructorMember

lib/Sema/MiscDiagnostics.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3541,11 +3541,12 @@ void swift::performAbstractFuncDeclDiagnostics(AbstractFunctionDecl *AFD) {
35413541
}
35423542

35433543
// Perform MiscDiagnostics on Switch Statements.
3544-
static void checkSwitch(ASTContext &ctx, const SwitchStmt *stmt) {
3544+
static void checkSwitch(ASTContext &ctx, const SwitchStmt *stmt,
3545+
DeclContext *DC) {
35453546
// We want to warn about "case .Foo, .Bar where 1 != 100:" since the where
35463547
// clause only applies to the second case, and this is surprising.
35473548
for (auto cs : stmt->getCases()) {
3548-
TypeChecker::checkExistentialTypes(ctx, cs);
3549+
TypeChecker::checkExistentialTypes(ctx, cs, DC);
35493550

35503551
// The case statement can have multiple case items, each can have a where.
35513552
// If we find a "where", and there is a preceding item without a where, and
@@ -5038,10 +5039,10 @@ void swift::performSyntacticExprDiagnostics(const Expr *E,
50385039
void swift::performStmtDiagnostics(const Stmt *S, DeclContext *DC) {
50395040
auto &ctx = DC->getASTContext();
50405041

5041-
TypeChecker::checkExistentialTypes(ctx, const_cast<Stmt *>(S));
5042-
5042+
TypeChecker::checkExistentialTypes(ctx, const_cast<Stmt *>(S), DC);
5043+
50435044
if (auto switchStmt = dyn_cast<SwitchStmt>(S))
5044-
checkSwitch(ctx, switchStmt);
5045+
checkSwitch(ctx, switchStmt, DC);
50455046

50465047
checkStmtConditionTrailingClosure(ctx, S);
50475048

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,8 @@ namespace {
26522652
func->diagnose(
26532653
diag::local_function_executed_concurrently,
26542654
func->getDescriptiveKind(), func->getName())
2655-
.fixItInsert(func->getAttributeInsertionLoc(false), "@Sendable ");
2655+
.fixItInsert(func->getAttributeInsertionLoc(false), "@Sendable ")
2656+
.warnUntilSwiftVersion(6);
26562657

26572658
// Add the @Sendable attribute implicitly, so we don't diagnose
26582659
// again.

lib/Sema/TypeCheckType.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4371,6 +4371,11 @@ void TypeChecker::checkExistentialTypes(Decl *decl) {
43714371
if (!decl || decl->isInvalid())
43724372
return;
43734373

4374+
// Skip diagnosing existential `any` requirements in swiftinterfaces.
4375+
auto sourceFile = decl->getDeclContext()->getParentSourceFile();
4376+
if (sourceFile && sourceFile->Kind == SourceFileKind::Interface)
4377+
return;
4378+
43744379
auto &ctx = decl->getASTContext();
43754380
if (auto *protocolDecl = dyn_cast<ProtocolDecl>(decl)) {
43764381
checkExistentialTypes(ctx, protocolDecl->getTrailingWhereClause());
@@ -4401,10 +4406,16 @@ void TypeChecker::checkExistentialTypes(Decl *decl) {
44014406
decl->walk(visitor);
44024407
}
44034408

4404-
void TypeChecker::checkExistentialTypes(ASTContext &ctx, Stmt *stmt) {
4409+
void TypeChecker::checkExistentialTypes(ASTContext &ctx, Stmt *stmt,
4410+
DeclContext *DC) {
44054411
if (!stmt)
44064412
return;
44074413

4414+
// Skip diagnosing existential `any` requirements in swiftinterfaces.
4415+
auto sourceFile = DC->getParentSourceFile();
4416+
if (sourceFile && sourceFile->Kind == SourceFileKind::Interface)
4417+
return;
4418+
44084419
ExistentialTypeVisitor visitor(ctx, /*checkStatements=*/true);
44094420
stmt->walk(visitor);
44104421
}

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ Expr *resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *Context,
295295
void checkExistentialTypes(Decl *decl);
296296

297297
/// Check for invalid existential types in the given statement.
298-
void checkExistentialTypes(ASTContext &ctx, Stmt *stmt);
298+
void checkExistentialTypes(ASTContext &ctx, Stmt *stmt, DeclContext *DC);
299299

300300
/// Check for invalid existential types in the underlying type of
301301
/// the given type alias.

lib/Serialization/Deserialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6354,6 +6354,7 @@ Expected<Type> TypeDeserializer::getTypeCheckedImpl() {
63546354
CASE(SequenceArchetype)
63556355
CASE(GenericTypeParam)
63566356
CASE(ProtocolComposition)
6357+
CASE(ParameterizedProtocol)
63576358
CASE(Existential)
63586359
CASE(DependentMember)
63596360
CASE(BoundGeneric)

stdlib/public/Concurrency/Clock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import Swift
3232
/// `SuspendingClock`.
3333
@available(SwiftStdlib 5.7, *)
3434
public protocol Clock: Sendable {
35-
associatedtype Duration: DurationProtocol
35+
associatedtype Duration
3636
associatedtype Instant: InstantProtocol where Instant.Duration == Duration
3737

3838
var now: Instant { get }

test/Concurrency/actor_isolation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ func checkLocalFunctions() async {
690690
i = 17
691691
}
692692

693-
func local2() { // expected-error{{concurrently-executed local function 'local2()' must be marked as '@Sendable'}}{{3-3=@Sendable }}
693+
func local2() { // expected-warning{{concurrently-executed local function 'local2()' must be marked as '@Sendable'}}{{3-3=@Sendable }}
694694
j = 42
695695
}
696696

@@ -721,7 +721,7 @@ func checkLocalFunctions() async {
721721
}
722722
}
723723

724-
func local3() { // expected-error{{concurrently-executed local function 'local3()' must be marked as '@Sendable'}}
724+
func local3() { // expected-warning{{concurrently-executed local function 'local3()' must be marked as '@Sendable'}}
725725
k = 25 // expected-error{{mutation of captured var 'k' in concurrently-executing code}}
726726
}
727727

test/Constraints/callAsFunction.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,25 @@ struct Test {
2929
}
3030
}
3131
}
32+
33+
// rdar://92912878 - filtering prevents disambiguation of `.callAsFunction`
34+
func test_no_filtering_of_overloads() {
35+
struct S {
36+
init() {}
37+
init(_: String) {}
38+
39+
func callAsFunction<T>(_ fn: () -> T) -> T {
40+
fn()
41+
}
42+
}
43+
44+
func test(_: () -> Void) {
45+
}
46+
47+
test {
48+
_ = S() { // Ok
49+
_ = 42
50+
print("Hello")
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)