Commit Graph

123 Commits

Author SHA1 Message Date
Michael Gottesman
9a8af70f1d [move-only] Teach SILGen how to emit deinits for nominal non-class move only types.
Even though with this change we emit the deinit, it isn't used yet since we
still need to implement the move only deinit table/teach the checker how to call
these/teach IRGen how to call this from the destroying value witness.
2022-09-20 15:19:31 -07:00
Hamish Knight
ab7b691cca [Profiler] Fix distributed deinit crash when emitting coverage
We need to emit the profiler increment in the
`deinitBodyBB` if we're within a distributed
actor.
2022-09-01 20:29:50 +01:00
Hamish Knight
19e1e2f7a2 [SILGen] Fix deinit coverage mapping
Stop profiling the deallocating deinitializer
function for non-ObjC classes, and instead profile
the destructor, which is where we emit the user's
code written in a `deinit`.

rdar://54443107
2022-08-11 15:09:53 +01:00
Michael Gottesman
1e6187c4f4 [sil] Update all usages of old API SILValue::getOwnershipKind() in favor of new ValueBase::getOwnershipKind().
Andy some time ago already created the new API but didn't go through and update
the old occurences. I did that in this PR and then deprecated the old API. The
tree is clean, so I could just remove it, but I decided to be nicer to
downstream people by deprecating it first.
2022-07-26 11:46:23 -07:00
Konrad `ktoso` Malawski
027c4a69c9 [Distributed] Prevent remote distributed actor from running deinit body 2022-07-14 17:56:03 +09:00
Dario Rexin
ba0de89a52 Addressed more review feedback 2022-03-09 13:56:47 -08:00
Dario Rexin
06aa3349dc Address review feedback 2022-03-03 09:24:46 -08:00
Dario Rexin
542c395e00 Addressed more review feedback 2022-02-22 14:59:35 -08:00
Dario Rexin
0f58bf60f1 Add tests for generics and fix handling of generics 2022-02-21 11:08:31 -08:00
Dario Rexin
d61e3863e4 Add tests and incorporate feedback 2022-02-19 12:31:45 -08:00
Dario Rexin
014fd2bb94 Small cleanup 2022-02-18 16:10:43 -08:00
Dario Rexin
ec0750c5dc [SILGen] Optimize generated dealloc for linearly recursive data structures
Adds detection of linearly recursive data structures by finding stored properties that share the type of the class the dealloc is being generated for. Each link will then be deallocated in a loop, while ensuring to keep the next link alive to prevent the recursion. This prevents stack overflows for long chains while also improving performance.

rdar://89162954
2022-02-18 13:45:07 -08:00
Erik Eckstein
383c52aa35 SIL: rename dealloc_ref [stack] -> dealloc_stack_ref
Introduce a new instruction `dealloc_stack_ref ` and remove the `stack` flag from `dealloc_ref`.

The `dealloc_ref [stack]` was confusing, because all it does is to mark the deallocation of the stack space for a stack promoted object.
2022-01-07 16:20:27 +01:00
Kavon Farvardin
b7d5e0aff7 invoke resignIdentity in an async failable initializer
For distributed actors, their async initializers will call
actorReady prior to the end of the initializer.
If that happens, we need to resign the identity if we end
up in the failure path of the init.
2021-10-21 19:41:31 -07:00
Kavon Farvardin
8d3c9b0e15 refactor some of SILGen's distributed actor code 2021-10-21 19:41:31 -07:00
Joe Groff
fdc0e08d60 SILGen: Emit literal closures at the abstraction level of their context.
Literal closures are only ever directly referenced in the context of the expression they're written in,
so it's wasteful to emit them at their fully-substituted calling convention and then reabstract them if
they're passed directly to a generic function. Avoid this by saving the abstraction pattern of the context
before emitting the closure, and then lowering its main entry point's calling convention at that
level of abstraction. Generalize some of the prolog/epilog code to handle converting arguments and returns
to the correct representation for a different abstraction level.
2021-09-09 13:42:02 -07:00
Joe Groff
3abe16f40f Revert "SILGen: Emit literal closures at the abstraction level of their context. [take 2]" (#39228) 2021-09-09 11:53:43 -05:00
Joe Groff
43506a29a2 SILGen: Emit literal closures at the abstraction level of their context.
Literal closures are only ever directly referenced in the context of the expression they're written in,
so it's wasteful to emit them at their fully-substituted calling convention and then reabstract them if
they're passed directly to a generic function. Avoid this by saving the abstraction pattern of the context
before emitting the closure, and then lowering its main entry point's calling convention at that
level of abstraction. Generalize some of the prolog/epilog code to handle converting arguments and returns
to the correct representation for a different abstraction level.
2021-09-07 11:55:29 -07:00
Holly Borla
86e1014399 Revert " SILGen: Emit literal closures at the abstraction level of their context." 2021-08-18 09:03:23 -07:00
Konrad `ktoso` Malawski
d414a26ef1 [Distributed] cleanup some warnings in SILGenDistributed (#38901)
* [Distributed] cleanup some warnings in SILGenDistributed

* [Distributed] cleanup SILGenDestructor, move dist logic to
SILGenDistributed

* [Distributed] de-duplicate SIL gen for if remote/local branch
2021-08-17 13:36:05 +09:00
Joe Groff
309500d4bf SILGen: Emit literal closures at the abstraction level of their context.
Literal closures are only ever directly referenced in the context of the expression they're written in,
so it's wasteful to emit them at their fully-substituted calling convention and then reabstract them if
they're passed directly to a generic function. Avoid this by saving the abstraction pattern of the context
before emitting the closure, and then lowering its main entry point's calling convention at that
level of abstraction. Generalize some of the prolog/epilog code to handle converting arguments and returns
to the correct representation for a different abstraction level.
2021-08-16 09:39:19 -07:00
Konrad `ktoso` Malawski
4e8ca79072 [Distributed] deinit aware of remote "properties" (lack thereof in storage) 2021-08-13 19:43:53 +09:00
Konrad `ktoso` Malawski
0ec4251c55 [Distributed] remove distributed aware emitClassMemberDestruction for now 2021-08-12 18:05:17 +09:00
Konrad `ktoso` Malawski
a99e935050 [Distributed] implemented storing transport in resolve 2021-08-12 14:09:02 +09:00
Konrad `ktoso` Malawski
f1a06653ad [Distributed] move SILGen for destructor resignIdentity to
SILGenDistributed
2021-08-12 14:09:02 +09:00
Konrad `ktoso` Malawski
716a0255c0 [Distributed] Move to ActorIdentity protocol (#38362) 2021-07-15 21:13:55 +09:00
Konrad `ktoso` Malawski
04a2dd9203 [Distributed] only emit resignAddress for local actor 2021-07-01 18:16:49 +09:00
Konrad `ktoso` Malawski
3e77eaca10 [Distributed] DA deinit must resign address from the transport 2021-07-01 15:39:55 +09:00
Erik Eckstein
ec64f2a255 SILLocation: replace CleanupLocation::get(loc) with CleanupLocation(loc)
No need to have a static get function - the constructor can be used directly.
NFC
2021-01-29 20:28:21 +01:00
Andrew Trick
5b37728f2a Fix OSSA in SILGenFunction::emitIVarDestroyer
It is illegal to borrow an unowned value. Unowned values are only
allowed to have specific instantaneous uses.

In this case, an unchecked conversion is valid because there is an
assumption that within a destructor, self is guaranteed.
2021-01-01 19:22:19 -08:00
John McCall
d874479290 Add builtins to initialize and destroy a default-actor member.
It would be more abstractly correct if this got DI support so
that we destroy the member if the constructor terminates
abnormally, but we can get to that later.
2020-12-10 19:18:53 -05:00
John McCall
945011d39f Handle default actors by special-casing layout in IRGen instead
of adding a property.

This better matches what the actual implementation expects,
and it avoids some possibilities of weird mismatches.  However,
it also requires special-case initialization, destruction, and
dynamic-layout support, none of which I've added yet.

In order to get NSObject default actor subclasses to use Swift
refcounting (and thus avoid the need for the default actor runtime
to generally use ObjC refcounting), I've had to introduce a
SwiftNativeNSObject which we substitute as the superclass when
inheriting directly from NSObject.  This is something we could
do in all NSObject subclasses; for now, I'm just doing it in
actors, although it's all actors and not just default actors.
We are not yet taking advantage of our special knowledge of this
class anywhere except the reference-counting code.

I went around in circles exploring a number of alternatives for
doing this; at one point I basically had a completely parallel
"ForImplementation" superclass query.  That proved to be a lot
of added complexity and created more problems than it solved.
We also don't *really* get any benefit from this subclassing
because there still wouldn't be a consistent superclass for all
actors.  So instead it's very ad-hoc.
2020-12-02 18:47:13 -05:00
Michael Gottesman
c026e95cce [ownership] Extract out SILOwnershipKind from ValueOwnershipKind into its own type and rename Invalid -> Any.
This makes it easier to understand conceptually why a ValueOwnershipKind with
Any ownership is invalid and also allowed me to explicitly document the lattice
that relates ownership constraints/value ownership kinds.
2020-11-10 14:29:11 -08:00
Hamish Knight
28246a7596 [SILGen] Use getTypecheckedBody
Use `getTypecheckedBody` to allow lazy
type-checking when emitting function definitions.
2020-09-04 13:24:35 -07:00
Slava Pestov
3547122997 SILGen: Simplify prepareEpilog() utility method 2020-02-18 17:43:54 -05:00
Michael Gottesman
9b9760eb4c [silgen] Change silgen destructor to access ref_element_addr through begin_access [deinit]. 2020-01-08 12:49:05 -08:00
Arnold Schwaighofer
33f4f57cc4 SILGen: Add TypeExpansionContext to SILGen 2019-11-11 14:21:52 -08:00
Slava Pestov
472787bab7 SIL: isNonThrowing parameter of SILBuilder::create{Begin,}Apply() defaults to false
Also remove the overload of createApply() that does not take a SubstitutionMap.
It accomplishes nothing except creating ambiguity.
2019-04-25 22:27:38 -04:00
Slava Pestov
9a1abf705a SILGen: Remove SILGenSILBuilder
This reverts commit 59cc3c1216fbb1719e5357dcef3f8b249528fc74.
2019-04-25 02:06:14 -04:00
John McCall
7da688d75a Always manage subobject projections with formal-access cleanups.
To make that work, enter appropriate scopes (ArgumentScopes and
FormalEvaluationScopes) at a bunch of places.  But note that l-value
emission generally can't enter such a scope, so in generic routines
like emitOpenExistentialExpr we have to just assert that we're
already in a scope.
2018-11-03 02:14:06 -04:00
Doug Gregor
4b5abbddbc [SIL] Teach *ApplyInst to traffic in SubstitutionMap.
Push SubstitutionMaps through most of SILGen and the SIL optimizers
that involve the various *ApplyInsts.
2018-05-11 13:18:06 -07:00
David Zarzycki
8c0c55539f [SIL] NFC: Rename misleading getSwiftRValueType() to getASTType()
Reference storage types are not RValues. Also, use more SILType helper
methods to avoid line wrap.
2018-05-04 08:14:38 -04:00
Slava Pestov
e849ba5836 SIL: Use getConstantFunctionType() instead of getConstantType() in a few places 2018-01-10 13:58:47 -08:00
Vedant Kumar
dd560d2aa6 [Coverage] Refactor SIL generation for profiling
This patch moves the ownership of profiling state from SILGenProfiling
to SILFunction, where it always belonged. Similarly, it moves ownership
of the profile reader from SILGenModule to SILModule.

The refactor sets us up to fix a few outstanding code coverage bugs and
does away with sad hacks like ProfilerRAII. It also allows us to locally
guarantee that a profile counter increment actually corresponds to the
SILFunction at hand.

That local guarantee causes a bugfix to accidentally fall out of this
refactor: we now set up the profiling state for delayed functions
correctly. Previously, we would set up a ProfilerRAII for the delayed
function, but its counter increment would never be emitted :(. This fix
constitutes the only functional change in this patch -- the rest is NFC.

As a follow-up, I plan on removing some dead code in the profiling
logic and fixing a few naming inconsistencies. I've left that for later
to keep this patch simple.
2018-01-05 17:20:20 -08:00
Vedant Kumar
cccee1df03 Revert "[Coverage] Refactor SIL generation for profiling" 2018-01-03 21:57:49 -08:00
Vedant Kumar
aba9d53736 [Coverage] Refactor SIL generation for profiling
This patch moves the ownership of profiling state from SILGenProfiling
to SILFunction, where it always belonged. Similarly, it moves ownership
of the profile reader from SILGenModule to SILModule.

The refactor sets us up to fix a few outstanding code coverage bugs and
does away with sad hacks like ProfilerRAII. It also allows us to locally
guarantee that a profile counter increment actually corresponds to the
SILFunction at hand.

That local guarantee causes a bugfix to accidentally fall out of this
refactor: we now set up the profiling state for delayed functions
correctly. Previously, we would set up a ProfilerRAII for the delayed
function, but its counter increment would never be emitted :(. This fix
constitutes the only functional change in this patch -- the rest is NFC.

As a follow-up, I plan on removing some dead code in the profiling
logic and fixing a few naming inconsistencies. I've left that for later
to keep this patch simple.
2018-01-03 11:18:40 -08:00
Doug Gregor
cd3c63cbfd [AST] Stop including GenericSignature.h in other headers.
Except GenericEnvironment.h, because you can't meaningfully use a
GenericEnvironment without its signature. Lots less depends on
GenericSignature.h now. NFC
2017-10-12 14:23:46 -07:00
Slava Pestov
7bf3b90b62 SIL: Split off objc_method / objc_super_method from class_method / super_method
This replaces the '[volatile]' flag. Now, class_method and
super_method are only used for vtable dispatch.

The witness_method instruction is still overloaded for use
with both ObjC protocol requirements and Swift protocol
requirements; the next step is to make it only mean the
latter, also using objc_method for ObjC protocol calls.
2017-10-03 22:13:31 -07:00
Michael Gottesman
9d5f28039a [silgen] Update SILGen objc deallocators and enable ownership on objc_dealloc.swift
rdar://33358110
2017-08-29 15:16:38 -07:00
Michael Gottesman
2700fce74f [silgen] Add a "fake" destroy in objc destructors.
In this case, we get in an @owned value but pass it off to the objc destroyer
that takes the @owned value as @unowned. To appease the verifier, this commit
puts in an "end_lifetime" instruction that acts as the implicit -1 associated
with the @owned value.

rdar://33358110
2017-08-29 14:24:21 -07:00