Many, many, many types in the Swift compiler are intended to only be allocated in the ASTContext. We have previously implemented this by writing several `operator new` and `operator delete` implementations into these types. Factor those out into a new base class instead.
We'd like to support factor initializers
for distributed actor types that are
synthesized by SILGen.
We already do something similar for
memberwise initializers for structs.
Thus, this patch generalizes that
concept into a new BodyKind for
AbstractFunctionDecls called
BodyKind::SILSynthesize.
In addition, to help differentiate the
kinds of AFDs that are SILSynthesized
into different families for SILGen to
recognize, we also have a new enum
SILSynthesizeKind to indicate whether it
is a memberwise init, etc.
1. We're no longer synthesizing the local
init. All designated inits of a dist actor
must have exactly one ActorTransport parameter.
This parameter is used in the init's prologue
to initialize some of its members.
2. We're synthesizing a factory function for
the resolve initialization, instead of an
actor-member named `init` to serve that
purpose.
As such, much of the earlier infrastructure
is no longer needed, etc.
Previously, there was a divergence in behavior between marking an actor as:
- objc: This would lead to usage of Swift reference counting.
- subclass of NSObject but not objc: This would lead to usage of ObjC
reference counting.
By itself, this might seem OK, after all, the two reference counting
schemes are compatible (you can pass things from one language to another).
However, there is a difference here because actors have a multi-step
deinitialization process due to the way the reference accounting works
with tasks. When the last reference is released, the destroy() method is
called which only puts the actor into a Zombie_Latching state and deallocation
happens later on.
In contrast, when the ObjC runtime releases the last reference, it
immediately deallocates the actor, without calling the destroy() method
or having any awareness about actors.
This mismatch leads to a use-after-free in the Swift runtime; normally,
the actor would be in the Zombie_Latching state and when the final running
task finishes, it would end up deallocating the actor. This expectation
is not met when the memory is freed by the ObjC runtime, hence the UAF.
Normally, I would find it a bit odd to see a commit come with acknowledgements
but in this case I think maybe it's okay, given that this took me 2+ weeks to
investigate and fix. Thanks to:
- Dani C. in helping reproduce the issue with a large and small test case.
- John for answering questions about the actor and job lifecycle.
- Mike Ash for providing generous help with debugging.
Fixes rdar://80863853.
We used to represent the interface type of variadic parameters directly
with ArraySliceType. This was awfully convenient for the constraint
solver since it could just canonicalize and open [T] to Array<$T>
wherever it saw a variadic parameter. However, this both destroys the
sugaring of T... and locks the representation to Array<T>. In the
interest of generalizing this in the future, introduce
VariadicSequenceType. For now, it canonicalizes to Array<T> just like
the old representation. But, as you can guess, this is a new staging
point for teaching the solver how to munge variadic generic type bindings.
rdar://81628287
It's been quite a long time since this unused parameter was introduced.
The intent is to produce the module as a root for the search - that is,
computing the set of conformances visible from that module, not the set
of conformances inside of that module. Callers have since been providing
all manner of module-scoped contexts to it.
Let's just get rid of it. When we want to teach protocol conformance
lookup to do this, we can revert this commit as a starting point and try
again.
* [TypeResolver][TypeChecker] Add support for structural opaque result types
* [TypeResolver][TypeChecker] Clean up changes that add structural opaque result types
Update the async refactorings to use the name from the async alternative
if one is known, rather than always assuming the name matches the
synchronous function.
Note that this could also be used to determine whether results remain
optional or not, but that has been left for a future patch.
Resolves rdar://80612521
A lookup on the name provided by `renamed` in `@available` returns the
VarDecl. If the name specified a getter or setter, make sure to grab the
corresponding accessor when comparing candidates.
We currently ignore the basename and parameters specified in the name
for accessors. Checking them would only cause a getter/setter not to
match, there can never be a conflict. Since this is a best effort match
anyway, this seems fine.
Instead of a new attribute `@completionHandlerAsync`, allow the use of
the existing `renamed` parameter of `@available` to specify the
asynchronous alternative of a synchronous function.
No errors will be output from invalid names as `@completionHandlerAsync`
had, but if a function is correctly matched then it will be used to
output warnings when using the synchronous function in an asynchronous
context (as before).
Resolves rdar://80612731
This flag was always a hack to get clients that were not properly
handling circular constructions (module loading, associated type
inference) to stop crashing. Technically, it is unsound, but by sheer
coinicidence of the structure of the name lookup requests and the cache
faulting here we have never observed that unsoundness in the wild.
Start treating the null {Can}GenericSignature as a regular signature
with no requirements and no parameters. This not only makes for a much
safer abstraction, but allows us to simplify a lot of the clients of
GenericSignature that would previously have to check for null before
using the abstraction.
Deserializing a source location will compute the declaration's USR, which
might trigger another request cycle, etc.
Tentative fix for rdar://problem/80546848, but I don't have a test case.
Allow an actor to be exposed to Objective-C via `@objc` without
inheriting from `NSObject`, and remove the loophole that allowed
actors to inherit from `NSObject`.
Fixes rdar://78333614
Because actors don't have inheritance, ban "open" and "required", which
don't make sense. We will permit "final" which, although it doesn't
have any semantic impact, is still used to determine whether the ABI
of the actor itself might permit subclassing in the future. This
leaves the door slightly ajar for actor inheritance should we need to
revisit that decision.
Fixes SR-14785 / rdar://79401150.
Treat actors as being semantically `final` throughout the type checker.
This allows, for example, a non-`required` initializer to satisfy a
protocol requirement.
We're leaving the ABI open for actor inheritance should we need it.
Addresses rdar://78269551.
Rework the checking of actor member access to rely on "isolated" parameters
(and captures thereof) to determine whether one can synchronously access
an actor or not. This allows synchronous access via an "isolated" parameter
as a general notion, which subsumes the declaration-based "self" access.
Simplify the checking of and diagnostic reporting for actor member
access by collapsing a number of redundant diagnostics down into a
single, parameterized diagnostic with a single point of emission. This
normalizes the logic a bit.