mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Squashed commit of the following: commite5a05ffe44Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Thu Jan 27 17:45:31 2022 +0900 cleanup commit1f751cea5aAuthor: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Thu Jan 27 14:50:33 2022 +0900 cleanups commitc632f3215dAuthor: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Thu Jan 27 14:01:09 2022 +0900 add test for generic from actor decl commit09b8bd50a7Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Thu Jan 27 14:00:58 2022 +0900 cleanups commit31f4d0cffdAuthor: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Thu Jan 27 11:40:51 2022 +0900 fix test commitad4db2fb6cMerge:97227edcca07e2dfda56Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Wed Jan 26 23:31:41 2022 +0900 Merge branch 'main' into wip-zzz commit97227edccaAuthor: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Wed Jan 26 21:01:25 2022 +0900 remove @_dynamic methods! fix tests commit1c79344dbbAuthor: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Wed Jan 19 12:51:09 2022 +0900 cleanup wip stuck fixed the stack cleanups cleanups pretty good now weird load rki works remove hack add take + throw + return fix test more tests fixed more tests fixed more tests fixed commit3ed494c175Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Tue Jan 18 21:09:28 2022 +0900 stack issues in SIL verification commit5cf43a7f86Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Tue Jan 18 09:19:51 2022 +0900 about to call the remoteCall goot to return, but missing subs commitdf8e47122aAuthor: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Thu Jan 13 14:09:49 2022 +0900 [Distributed] Refactor Invocation to Decoder/Encoder getting there done-recording working on the string init stuck trying to get String initializer SILFunction created the remote call target commitfc7bd62f32Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Wed Jan 12 23:01:14 2022 +0900 [Distributed] Pass arguments from Invocation to HBuffer commitcafc2cc058Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Wed Jan 12 22:08:47 2022 +0900 works commita7d01837ffAuthor: Pavel Yaskevich <pyaskevich@apple.com> Date: Tue Jan 11 15:48:58 2022 -0800 [Distributed] Adjust interface of `swift_distributed_execute_target` Since this is a special function, `calleeContext` doesn't point to a direct parent but instead both parent context (uninitialized) and resume function are passed as last arguments which means that `callContext` has to act as an intermediate context in call to accessor. commitc1f830be27Author: Pavel Yaskevich <pyaskevich@apple.com> Date: Tue Jan 11 17:00:08 2022 -0800 [Distributed] Drop optionality from result buffer in `_executeDistributedTarget` `RawPointer?` is lowered into a two arguments since it's a struct, to make it easy let's just allocate an empty pointer for `Void` result. commitc83c2c37b6Author: Pavel Yaskevich <pyaskevich@apple.com> Date: Tue Jan 11 17:02:45 2022 -0800 [Distributed] NFC: Update _remoteCall test-case to check multiple different result types commit29e7cf50e4Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Wed Jan 12 21:32:37 2022 +0900 wip commit9128ecc6f8Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Wed Jan 12 20:46:20 2022 +0900 wip commita6b2a62a67Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Wed Jan 12 20:38:22 2022 +0900 wip commit8b188f0d43Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Wed Jan 12 16:55:10 2022 +0900 wip commit3796bec2b9Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Wed Jan 12 16:55:02 2022 +0900 wip commit0ffc68b5efAuthor: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Tue Jan 11 21:44:58 2022 +0900 [Distributed] Implementing ad-hoc protocol requirements commit78862575e4Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Thu Jan 6 18:03:54 2022 +0900 cleanup commit5f4ab89e25Merge:24a628e7c0fdda6f2ee4Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Thu Jan 6 15:51:39 2022 +0900 Merge branch 'main' into wip-impl-execute-swift commit24a628e7c0Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Thu Jan 6 15:33:21 2022 +0900 wip commit69e7fed09dAuthor: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Wed Dec 22 06:36:45 2021 +0900 [Distributed] comment out distributed_actor_remoteCall for now commit376733a9f6Author: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Tue Dec 21 16:00:06 2021 +0900 reimplement distributed get type info impls commit74ab47886aAuthor: Konrad `ktoso` Malawski <konrad_malawski@apple.com> Date: Wed Dec 15 21:37:08 2021 +0900 [Distributed] Implement func metadata and executeDistributedTarget dont expose new entrypoints able to get all the way to calling _execute
156 lines
5.3 KiB
C++
156 lines
5.3 KiB
C++
//===--- CodeSynthesisDistributedActor.cpp --------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2021 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 "TypeCheckDistributed.h"
|
|
|
|
#include "TypeChecker.h"
|
|
#include "TypeCheckType.h"
|
|
#include "swift/AST/ASTPrinter.h"
|
|
#include "swift/AST/Availability.h"
|
|
#include "swift/AST/Expr.h"
|
|
#include "swift/AST/GenericEnvironment.h"
|
|
#include "swift/AST/Initializer.h"
|
|
#include "swift/AST/ParameterList.h"
|
|
#include "swift/AST/TypeCheckRequests.h"
|
|
#include "swift/Basic/Defer.h"
|
|
#include "swift/ClangImporter/ClangModule.h"
|
|
#include "swift/Sema/ConstraintSystem.h"
|
|
#include "llvm/ADT/SmallString.h"
|
|
#include "llvm/ADT/StringExtras.h"
|
|
#include "DerivedConformances.h"
|
|
using namespace swift;
|
|
|
|
// Note: This would be nice to implement in DerivedConformanceDistributedActor,
|
|
// but we can't since those are lazily triggered and an implementation exists
|
|
// for the 'id' property because 'Identifiable.id' has an extension that impls
|
|
// it for ObjectIdentifier, and we have to instead emit this stored property.
|
|
//
|
|
// The "derived" mechanisms are not really geared towards emitting for
|
|
// what already has a witness.
|
|
static VarDecl *addImplicitDistributedActorIDProperty(
|
|
// DeclContext *parentDC,
|
|
NominalTypeDecl *nominal) {
|
|
if (!nominal || !nominal->isDistributedActor())
|
|
return nullptr;
|
|
|
|
// ==== if the 'id' already exists, return it
|
|
auto &C = nominal->getASTContext();
|
|
// if (auto existing = nominal->lookupDirect(C.Id_id))
|
|
// return existing;
|
|
|
|
// ==== Synthesize and add 'id' property to the actor decl
|
|
Type propertyType = getDistributedActorIDType(nominal);
|
|
|
|
VarDecl *propDecl = new (C)
|
|
VarDecl(/*IsStatic*/false, VarDecl::Introducer::Let,
|
|
SourceLoc(), C.Id_id, nominal);
|
|
propDecl->setImplicit();
|
|
propDecl->setSynthesized();
|
|
propDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true);
|
|
propDecl->setInterfaceType(propertyType);
|
|
|
|
Pattern *propPat = NamedPattern::createImplicit(C, propDecl);
|
|
propPat->setType(propertyType);
|
|
|
|
propPat = TypedPattern::createImplicit(C, propPat, propertyType);
|
|
propPat->setType(propertyType);
|
|
|
|
PatternBindingDecl *pbDecl = PatternBindingDecl::createImplicit(
|
|
C, StaticSpellingKind::None, propPat, /*InitExpr*/ nullptr,
|
|
nominal);
|
|
|
|
propDecl->setIntroducer(VarDecl::Introducer::Let);
|
|
|
|
// mark as nonisolated, allowing access to it from everywhere
|
|
propDecl->getAttrs().add(
|
|
new (C) NonisolatedAttr(/*IsImplicit=*/true));
|
|
|
|
nominal->addMember(propDecl);
|
|
nominal->addMember(pbDecl);
|
|
|
|
return propDecl;
|
|
}
|
|
|
|
/******************************************************************************/
|
|
/************ LOCATING AD-HOC PROTOCOL REQUIREMENT IMPLS **********************/
|
|
/******************************************************************************/
|
|
|
|
AbstractFunctionDecl*
|
|
GetDistributedActorSystemRemoteCallFunctionRequest::evaluate(
|
|
Evaluator &evaluator, NominalTypeDecl *decl, bool isVoidReturn) const {
|
|
auto &C = decl->getASTContext();
|
|
|
|
// It would be nice to check if this is a DistributedActorSystem
|
|
// "conforming" type, but we can't do this as we invoke this function WHILE
|
|
// deciding if the type conforms or not;
|
|
|
|
// Not via `ensureDistributedModuleLoaded` to avoid generating a warning,
|
|
// we won't be emitting the offending decl after all.
|
|
if (!C.getLoadedModule(C.Id_Distributed)) {
|
|
return nullptr;
|
|
}
|
|
|
|
auto callId = isVoidReturn ? C.Id_remoteCallVoid : C.Id_remoteCall;
|
|
|
|
AbstractFunctionDecl *remoteCallFunc = nullptr;
|
|
for (auto value : decl->lookupDirect(callId)) {
|
|
auto func = dyn_cast<AbstractFunctionDecl>(value);
|
|
if (func && func->isDistributedActorSystemRemoteCall(isVoidReturn)) {
|
|
remoteCallFunc = func;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return remoteCallFunc;
|
|
}
|
|
|
|
|
|
/******************************************************************************/
|
|
/************************ SYNTHESIS ENTRY POINT *******************************/
|
|
/******************************************************************************/
|
|
|
|
VarDecl *GetDistributedActorIDPropertyRequest::evaluate(
|
|
Evaluator &evaluator, NominalTypeDecl *actor) const {
|
|
if (!actor->isDistributedActor())
|
|
return nullptr;
|
|
|
|
auto &C = actor->getASTContext();
|
|
|
|
// not via `ensureDistributedModuleLoaded` to avoid generating a warning,
|
|
// we won't be emitting the offending decl after all.
|
|
if (!C.getLoadedModule(C.Id_Distributed))
|
|
return nullptr;
|
|
|
|
return addImplicitDistributedActorIDProperty(actor);
|
|
}
|
|
|
|
VarDecl *GetDistributedActorSystemPropertyRequest::evaluate(
|
|
Evaluator &evaluator, NominalTypeDecl *actor) const {
|
|
if (!actor->isDistributedActor())
|
|
return nullptr;
|
|
|
|
auto &C = actor->getASTContext();
|
|
|
|
// not via `ensureDistributedModuleLoaded` to avoid generating a warning,
|
|
// we won't be emitting the offending decl after all.
|
|
if (!C.getLoadedModule(C.Id_Distributed))
|
|
return nullptr;
|
|
|
|
|
|
if (auto system = actor->lookupDirect(C.Id_actorSystem).begin()) {
|
|
// TODO(distributed): may need to check conformance here?
|
|
return dyn_cast<VarDecl>(*system);
|
|
}
|
|
|
|
return nullptr;
|
|
}
|