Skip to content

Commit 2be3004

Browse files
authored
Merge pull request #3882 from swiftwasm/main
[pull] swiftwasm from main
2 parents 0450382 + 1ca3b93 commit 2be3004

23 files changed

+208
-68
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4505,25 +4505,34 @@ ERROR(distributed_actor_isolated_method,none,
45054505
"only 'distributed' instance methods can be called on a potentially remote distributed actor",
45064506
())
45074507
ERROR(distributed_actor_func_param_not_codable,none,
4508-
"distributed instance method parameter '%0' of type %1 does not conform to 'Codable'",
4509-
(StringRef, Type))
4508+
"parameter '%0' of type %1 in %2 does not conform to '%3'",
4509+
(StringRef, Type, DescriptiveDeclKind, StringRef))
45104510
ERROR(distributed_actor_func_result_not_codable,none,
4511-
"distributed instance method result type %0 does not conform to 'Codable'",
4512-
(Type))
4511+
"result type %0 of %1 does not conform to '%2'",
4512+
(Type, DescriptiveDeclKind, StringRef))
45134513
ERROR(distributed_actor_remote_func_implemented_manually,none,
4514-
"distributed function's %0 remote counterpart %1 cannot not be implemented manually.",
4514+
"distributed instance method's %0 remote counterpart %1 cannot not be implemented manually.",
45154515
(Identifier, Identifier))
45164516
ERROR(nonisolated_distributed_actor_storage,none,
45174517
"'nonisolated' can not be applied to distributed actor stored properties",
45184518
())
45194519
ERROR(distributed_actor_func_nonisolated, none,
4520-
"function %0 cannot be both 'nonisolated' and 'distributed'",
4520+
"cannot declare method %0 as both 'nonisolated' and 'distributed'",
45214521
(DeclName))
45224522
ERROR(distributed_actor_func_private, none,
45234523
"%0 %1 cannot be 'private'",
45244524
(DescriptiveDeclKind, DeclName))
4525+
ERROR(distributed_actor_func_inout, none,
4526+
"cannot declare 'inout' argument %0 in %1 %2",
4527+
(DeclName, DescriptiveDeclKind, DeclName))
4528+
ERROR(distributed_actor_func_closure, none,
4529+
"%0 %1 cannot declare closure arguments, as they cannot be serialized",
4530+
(DescriptiveDeclKind, DeclName))
4531+
ERROR(distributed_actor_func_variadic, none,
4532+
"cannot declare variadic argument %0 in %1 %2",
4533+
(DeclName, DescriptiveDeclKind, DeclName))
45254534
ERROR(distributed_actor_remote_func_is_not_static,none,
4526-
"remote function %0 must be static.",
4535+
"remote function %0 must be static",
45274536
(DeclName))
45284537
ERROR(distributed_actor_remote_func_is_not_async_throws,none,
45294538
"remote function %0 must be 'async throws'.",
@@ -4654,7 +4663,7 @@ ERROR(distributed_actor_func_static,none,
46544663
"'distributed' method cannot be 'static'",
46554664
())
46564665
ERROR(distributed_actor_func_not_in_distributed_actor,none,
4657-
"'distributed' function can only be declared within 'distributed actor'",
4666+
"'distributed' method can only be declared within 'distributed actor'",
46584667
())
46594668
ERROR(distributed_actor_designated_ctor_must_have_one_transport_param,none,
46604669
"designated distributed actor initializer %0 must accept exactly one "

lib/IRGen/IRGenSIL.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6790,9 +6790,15 @@ void IRGenSILFunction::visitCopyAddrInst(swift::CopyAddrInst *i) {
67906790
// bind_memory and rebind_memory are no-ops because Swift TBAA info is not
67916791
// lowered to LLVM IR TBAA, and the output token is ignored except for
67926792
// verification.
6793-
void IRGenSILFunction::visitBindMemoryInst(swift::BindMemoryInst *) {}
6793+
void IRGenSILFunction::visitBindMemoryInst(swift::BindMemoryInst *i) {
6794+
LoweredValue &token = getUndefLoweredValue(i->getType());
6795+
setLoweredValue(i, std::move(token));
6796+
}
67946797

6795-
void IRGenSILFunction::visitRebindMemoryInst(swift::RebindMemoryInst *) {}
6798+
void IRGenSILFunction::visitRebindMemoryInst(swift::RebindMemoryInst *i) {
6799+
LoweredValue &token = getUndefLoweredValue(i->getType());
6800+
setLoweredValue(i, std::move(token));
6801+
}
67966802

67976803
void IRGenSILFunction::visitDestroyAddrInst(swift::DestroyAddrInst *i) {
67986804
SILType addrTy = i->getOperand()->getType();

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,7 @@ void swift::visitAccessedAddress(SILInstruction *I,
23872387
case SILInstructionKind::EndCOWMutationInst:
23882388
case SILInstructionKind::BeginUnpairedAccessInst:
23892389
case SILInstructionKind::BindMemoryInst:
2390+
case SILInstructionKind::RebindMemoryInst:
23902391
case SILInstructionKind::CheckedCastValueBranchInst:
23912392
case SILInstructionKind::CondFailInst:
23922393
case SILInstructionKind::CopyBlockInst:

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3046,9 +3046,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
30463046
requireSameType(rbi->getInToken()->getType(),
30473047
SILType::getBuiltinWordType(F.getASTContext()),
30483048
"rebind_memory token must be a Builtin.Int64");
3049-
require(isa<BindMemoryInst>(rbi->getInToken())
3050-
|| isa<RebindMemoryInst>(rbi->getInToken()),
3051-
"rebind_memory token must originate from bind_memory");
30523049
}
30533050

30543051
void checkIndexAddrInst(IndexAddrInst *IAI) {

lib/SILOptimizer/Utils/CanonicalOSSALifetime.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ llvm::Statistic swift::NumCopiesGenerated = {
8080
STATISTIC(NumDestroysEliminated,
8181
"number of destroy_value instructions removed");
8282
STATISTIC(NumDestroysGenerated, "number of destroy_value instructions created");
83-
STATISTIC(NumUnknownUsers, "number of functions with unknown users");
8483

8584
//===----------------------------------------------------------------------===//
8685
// MARK: General utilities

lib/SILOptimizer/Utils/CanonicalizeBorrowScope.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535

3636
using namespace swift;
3737

38-
STATISTIC(NumOuterCopies, "number of copy_value instructions added for a "
39-
"borrow scope");
40-
4138
//===----------------------------------------------------------------------===//
4239
// MARK: Local utilities
4340
//===----------------------------------------------------------------------===//

lib/SILOptimizer/Utils/CanonicalizeInstruction.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@
3333

3434
using namespace swift;
3535

36-
// STATISTIC uses the default DEBUG_TYPE.
37-
#define DEBUG_TYPE CanonicalizeInstruction::defaultDebugType
38-
STATISTIC(NumSimplified, "Number of instructions simplified");
39-
4036
// Tracing within the implementation can also be activiated by the pass.
41-
#undef DEBUG_TYPE
4237
#define DEBUG_TYPE pass.debugType
4338

4439
// Vtable anchor.

lib/SILOptimizer/Utils/DistributedActor.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,13 @@ void emitActorTransportWitnessCall(
6868
ProtocolConformanceRef transportConfRef;
6969

7070
// If the transport is an existential open it.
71-
bool openedExistential = false;
7271
if (transportASTType->isAnyExistentialType()) {
7372
OpenedArchetypeType *opened;
7473
transportASTType =
7574
transportASTType->openAnyExistentialType(opened)->getCanonicalType();
7675
transport = B.createOpenExistentialAddr(
7776
loc, transport, F.getLoweredType(transportASTType),
7877
OpenedExistentialAccess::Immutable);
79-
openedExistential = true;
8078
}
8179

8280
if (transportASTType->isTypeParameter() ||

lib/Sema/CSBindings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,8 @@ bool BindingSet::favoredOverDisjunction(Constraint *disjunction) const {
10101010
}
10111011
}
10121012

1013-
return type->is<StructType>() || type->is<EnumType>();
1013+
return type->is<StructType>() || type->is<EnumType>() ||
1014+
type->is<BuiltinType>();
10141015
})) {
10151016
// Result type of subscript could be l-value so we can't bind it early.
10161017
if (!TypeVar->getImpl().isSubscriptResultType() &&

lib/Sema/TypeCheckDistributed.cpp

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ void swift::diagnoseDistributedFunctionInNonDistributedActorProtocol(
6969
}
7070
}
7171

72+
73+
/// Add Fix-It text for the given nominal type to adopt Codable.
74+
///
75+
/// Useful when 'Codable' is the 'SerializationRequirement' and a non-Codable
76+
/// function parameter or return value type is detected.
77+
void swift::addCodableFixIt(
78+
const NominalTypeDecl *nominal, InFlightDiagnostic &diag) {
79+
if (nominal->getInherited().empty()) {
80+
SourceLoc fixItLoc = nominal->getBraces().Start;
81+
diag.fixItInsert(fixItLoc, ": Codable");
82+
} else {
83+
ASTContext &ctx = nominal->getASTContext();
84+
SourceLoc fixItLoc = nominal->getInherited().back().getSourceRange().End;
85+
fixItLoc = Lexer::getLocForEndOfToken(ctx.SourceMgr, fixItLoc);
86+
diag.fixItInsert(fixItLoc, ", Codable");
87+
}
88+
}
89+
7290
// ==== ------------------------------------------------------------------------
7391

7492
bool IsDistributedActorRequest::evaluate(
@@ -119,28 +137,53 @@ bool swift::checkDistributedFunction(FuncDecl *func, bool diagnose) {
119137
auto paramTy = func->mapTypeIntoContext(param->getInterfaceType());
120138
if (TypeChecker::conformsToProtocol(paramTy, encodableType, module).isInvalid() ||
121139
TypeChecker::conformsToProtocol(paramTy, decodableType, module).isInvalid()) {
122-
if (diagnose)
123-
func->diagnose(
140+
if (diagnose) {
141+
auto diag = func->diagnose(
124142
diag::distributed_actor_func_param_not_codable,
125-
param->getArgumentName().str(),
126-
param->getInterfaceType()
127-
);
128-
// TODO: suggest a fixit to add Codable to the type?
143+
param->getArgumentName().str(), param->getInterfaceType(),
144+
func->getDescriptiveKind(), "Codable");
145+
if (auto paramNominalTy = paramTy->getAnyNominal()) {
146+
addCodableFixIt(paramNominalTy, diag);
147+
} // else, no nominal type to suggest the fixit for, e.g. a closure
148+
}
149+
return true;
150+
}
151+
152+
if (param->isInOut()) {
153+
param->diagnose(
154+
diag::distributed_actor_func_inout,
155+
param->getName(),
156+
func->getDescriptiveKind(), func->getName()
157+
).fixItRemove(SourceRange(param->getTypeSourceRangeForDiagnostics().Start,
158+
param->getTypeSourceRangeForDiagnostics().Start.getAdvancedLoc(1)));
159+
// FIXME(distributed): the fixIt should be on param->getSpecifierLoc(), but that Loc is invalid for some reason?
129160
return true;
130161
}
162+
163+
if (param->isVariadic()) {
164+
param->diagnose(
165+
diag::distributed_actor_func_variadic,
166+
param->getName(),
167+
func->getDescriptiveKind(), func->getName()
168+
);
169+
}
131170
}
132171

133172
// --- Result type must be either void or a codable type
134173
auto resultType = func->mapTypeIntoContext(func->getResultInterfaceType());
135174
if (!resultType->isVoid()) {
136175
if (TypeChecker::conformsToProtocol(resultType, decodableType, module).isInvalid() ||
137176
TypeChecker::conformsToProtocol(resultType, encodableType, module).isInvalid()) {
138-
if (diagnose)
139-
func->diagnose(
177+
if (diagnose) {
178+
auto diag = func->diagnose(
140179
diag::distributed_actor_func_result_not_codable,
141-
func->getResultInterfaceType()
180+
func->getResultInterfaceType(), func->getDescriptiveKind(),
181+
"Codable" // Codable is a typealias, easier to diagnose like that
142182
);
143-
// TODO: suggest a fixit to add Codable to the type?
183+
if (auto resultNominalType = resultType->getAnyNominal()) {
184+
addCodableFixIt(resultNominalType, diag);
185+
}
186+
}
144187
return true;
145188
}
146189
}

0 commit comments

Comments
 (0)