Commit Graph

2390 Commits

Author SHA1 Message Date
Becca Royal-Gordon
c517b45bb4 Merge pull request #38948 from beccadax/the-copypasta-is-stale
[NFC] Factor out ASTContext `operator new`s
2021-08-20 11:04:56 -07:00
Becca Royal-Gordon
59bb325e4b [NFC] Factor out ASTContext operator news
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.
2021-08-19 11:19:52 -07:00
Anthony Latsis
655a81cbe6 AST: Account for protocol compositions and nested types in «findProtocolSelfReferences» 2021-08-16 18:30:26 +03:00
Anthony Latsis
755f0f96e0 NFC: Remove the now dead ProtocolDecl::existentialTypeSupported() 2021-08-16 18:30:26 +03:00
Konrad `ktoso` Malawski
bf37ba6014 [Distributed] Don't duplicate hasUserDefinedInit entry, less guards 2021-08-12 19:35:01 +09:00
Kavon Farvardin
89629fe06f Generalize BodyKind::MemberwiseInitializer
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.
2021-08-12 14:05:31 +09:00
Kavon Farvardin
c9bfccb3b4 [distributed] a number of ctor infra cleanups
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.
2021-08-12 14:04:51 +09:00
Konrad `ktoso` Malawski
1f33a0cc45 [Distributed] move where we invoke dist synthesis; detect transport param 2021-08-12 14:04:50 +09:00
Robert Widmann
d75b34be22 Merge pull request #38753 from CodaFi/modulo-modules
[NFC] Remove Unused Module Parameter to Conformance Lookup
2021-08-11 10:36:39 -07:00
Varun Gandhi
7bbc29a520 Merge pull request #38803 from varungandhi-apple/vg-objc-actors-took-2-weeks-of-my-life
[AST] Treat actors inheriting from NSObject as SwiftNativeNSObjects.
2021-08-09 10:54:01 -07:00
Varun Gandhi
4311a03fbe [AST] Treat actors inheriting from NSObject as SwiftNativeNSObjects.
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.
2021-08-08 00:34:07 -07:00
Robert Widmann
592e90af9b Add Sugar for Variadics
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
2021-08-06 12:51:39 -07:00
Robert Widmann
808220510e [NFC] Remove Unused Module Parameter to Conformance Lookup
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.
2021-08-04 14:43:31 -07:00
willtunnels
319b3e64aa Add support for opaque result types in structural positions (#38392)
* [TypeResolver][TypeChecker] Add support for structural opaque result types

* [TypeResolver][TypeChecker] Clean up changes that add structural opaque result types
2021-08-03 23:45:02 -04:00
Ben Barham
f6a8dab93d [Refactoring] Use known alternative in async refactoring if one exists
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
2021-08-03 08:46:44 +10:00
Ben Barham
7e7b521abd [Diagnostics] Allow matching accessors and functions for a renamed decl
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.
2021-08-03 08:46:44 +10:00
Slava Pestov
4e1c2b2e47 Serialization: Serialize the list of associated types in a protocol
This allows ProtocolDecl::getAssociatedTypeMembers() on a serialized
ProtocolDecl to avoid deserializing the full member list.
2021-07-31 00:25:22 -04:00
Slava Pestov
c44b49e7e4 AST: Cache result of ProtocolDecl::getAssociatedTypeMembers() 2021-07-31 00:25:22 -04:00
Ben Barham
e7e9b57051 Replace @completionHandlerAsync with @available(*, renamed:)
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
2021-07-29 09:14:44 +10:00
Robert Widmann
a1b668b381 Merge pull request #38613 from CodaFi/extended-family-gathering
Nuke IgnoreNewExtensions From High Orbit
2021-07-27 14:32:39 -07:00
Doug Gregor
b86e39d614 Remove "spawn" modifier 2021-07-26 10:22:02 -07:00
Robert Widmann
babe52f512 Nuke IgnoreNewExtensions From High Orbit
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.
2021-07-23 15:35:24 -07:00
Robert Widmann
1329f3cfbd [NFC] Lift getGenericEnvironment() into GenericSignature 2021-07-22 23:33:02 -07:00
Robert Widmann
d86551de67 Lift Requirement and Parameter Accessors up to GenericSignature
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.
2021-07-22 23:27:05 -07:00
Doug Gregor
35dbba20b0 Ignore whether a parameter is "isolated" for the purposes of redeclarations.
Overload resolution won't be able to tell them apart, and they're mangled
identically. Fixes rdar://80918858.
2021-07-22 09:59:35 -07:00
Becca Royal-Gordon
04775d41ea Merge pull request #38419 from beccadax/the-generic-bound-is-cheaper
[IRGen] Fix crashes involving ObjC generic params
2021-07-21 10:15:23 -07:00
Slava Pestov
a5c2b6b594 Merge pull request #38497 from slavapestov/request-evaluator-cycle-cycle
AST: Don't trigger source location deserialization in request evaluator
2021-07-20 09:44:42 -04:00
Becca Royal-Gordon
9da193ec8f [NFC] Unify helpers for checking for ObjC generics
There were two differently-named and slightly differently-implemented checks on nominal type decls. Clean this up a bit.
2021-07-19 19:59:26 -07:00
Slava Pestov
4c5bda2465 AST: Don't trigger source location deserialization in request evaluator
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.
2021-07-19 21:45:21 -04:00
Slava Pestov
3affdd98a1 AST: Make sure that an opaque type descriptor is weak-linked if its naming declaration is
Fixes rdar://problem/80584212.
2021-07-19 17:08:01 -04:00
David Ungar
e060363131 Use getOriginalInit instead of PatternBindingEntry::hasInitStringRepresentation 2021-07-18 14:21:49 -07:00
Konrad `ktoso` Malawski
716a0255c0 [Distributed] Move to ActorIdentity protocol (#38362) 2021-07-15 21:13:55 +09:00
Konrad `ktoso` Malawski
ae9e320215 [Distributed] Handle distributed func witnessess from distributed actor protocols (#38269)
* [Distributed] Handle distributed func witnessess from distributed actor protocols

* [Distributed] Implement dist protocol and nonisolated handling

* revert additional warning check

* [Distributed] Ban mixing nonisolated and distributed on func

* [Distributed] handle nonisolated in distributed contexts
2021-07-12 19:18:20 +09:00
Doug Gregor
06bbc70b3e Module printing and serialization support for @unchecked Sendable 2021-07-11 12:29:54 -07:00
swift-ci
56a82abe35 Merge pull request #38298 from DougGregor/actor-no-class 2021-07-07 17:59:03 -07:00
Doug Gregor
2bb94f855b [SE-0306] Ban "class" methods and properties in actors.
Within actors, one should use "static", not "class".
Fixes rdar://80285441.
2021-07-07 14:44:02 -07:00
Doug Gregor
164505cb2c Merge pull request #38246 from DougGregor/actor-objc-without-nsobject
[SE-0306] Disallow actor inheritance from NSObject, but allow `@objc actor`
2021-07-03 08:07:52 -07:00
Doug Gregor
6406f08661 [SE-0306] Disallow actor inheritance from NSObject, but allow @objc actor.
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
2021-07-02 23:37:09 -07:00
Alex Hoppen
92b7e135b8 Merge pull request #38084 from fwcd/fix-sourcekit-var-types-if-let
[SourceKit] Determine correctly whether typed  variables in `if/guard/while-let`-statements have explicit type annotations
2021-07-02 12:02:32 +02:00
swift-ci
850a84aa2b Merge pull request #38212 from CodaFi/defuse-refuse 2021-07-01 20:30:07 -07:00
Robert Widmann
2f15372040 [NFC] Lazily Construct ErrorExpr/ErrorType When Default Arg Request Fails
Preserve debuggability and save a bit of memory by only constructing
these when the request fails instead of every time.
2021-07-01 16:08:38 -07:00
Doug Gregor
e595b4f68a [SE-0306] Ban "open" and "required" on actors.
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.
2021-06-30 16:34:18 -07:00
Doug Gregor
9ec20776c9 [SE-0306] Make actors semantically "final".
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.
2021-06-30 10:59:49 -07:00
Fredrik Wieczerkowski
b33a20282e Move if-let special case into getTypeReprOrParentPatternTypeRepr
As suggested during PR review.

This mechanism seems to be general enough to fit into
getTypeReprOrParentPatternRepr.
2021-06-26 16:19:22 +02:00
Doug Gregor
92dd8672f2 [Amendment] SE-0296: Allow overloads that differ only in async
Implement the amendment currently under review that allows overloads
that differ only in async vs. non-async.

Implements rdar://79788345.
2021-06-25 11:22:13 -07:00
Konrad `ktoso` Malawski
eada7df0e4 Ban classes from extending Actor and DistributedActor protocol explicitly (#38050)
* [Concurrency,Distributed] ban inheriting Actor and DistActor explicitly by class

* [Distributed] AnyActor can be a marker protocol
2021-06-25 06:06:35 +09:00
Ben Barham
fff50ba791 [AST] Do not return invalid SourceLocs from Decl::getLoc
When loading locations from .swiftsourceinfo, make sure that the offset
is actually within the buffer.

Resolves rdar://78833833
2021-06-10 14:51:20 +10:00
Doug Gregor
0cd0cbc02a Merge pull request #37794 from DougGregor/isolated-parameters
[SE-0313] Implement type system, ABI, and runtime support for isolated parameters
2021-06-08 19:46:20 -07:00
swift-ci
f92f2fe493 Merge pull request #37738 from ktoso/wip-distributed-dynamic-2 2021-06-08 01:19:17 -07:00
Doug Gregor
5bcd5a8e25 Use "isolated" parameters to check for synchronous actor access.
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.
2021-06-08 00:00:12 -07:00