Commit Graph

335 Commits

Author SHA1 Message Date
Slava Pestov
ad5697778e Merge pull request #69430 from slavapestov/silgen-typed-throws-wip
Preliminary SILGen support for address-only typed throws
2023-10-27 21:00:51 -04:00
Slava Pestov
581776b997 SILGen: Emit indirect error result argument 2023-10-27 17:37:43 -04:00
Slava Pestov
4ed2dc4428 SILGen: Don't use CanType() on a type that might be a sugared type 2023-10-27 17:37:43 -04:00
Sophia Poirier
4c9a726183 nonisolated(unsafe) to opt out of strict concurrency static checking for global variables 2023-10-26 16:22:28 -07:00
Doug Gregor
ef642098f2 [Typed throws] Parsing and AST representation for typed errors
Parse typed throw specifiers as `throws(X)` in every place where there
are effects specified, and record the resulting thrown error type in
the AST except the type system. This includes:
* `FunctionTypeRepr`, for the parsed representation of types
* `AbstractFunctionDecl`, for various function-like declarations
* `ClosureExpr`, for closures
* `ArrowExpr`, for parsing of types within expression context

This also introduces some serialization logic for the thrown error
type of function-like declarations, along with an API to extract the
thrown interface type from one of those declarations, although right
now it will either be `Error` or empty.
2023-09-29 10:51:51 -07:00
Kavon Farvardin
f1142d5da4 [nfc] rename or eliminate isPureMoveOnly APIs
I think from SIL's perspective, it should only worry about whether the
type is move-only. That includes MoveOnlyWrapped SILTypes and regular
types that cannot be copied.

Most of the code querying `SILType::isPureMoveOnly` is in SILGen, where
it's very likely that the original AST type is sitting around already.
In such cases, I think it's fine to ask the AST type if it is
noncopyable. The clarity of only asking the ASTType if it's noncopyable
is beneficial, I think.
2023-09-20 15:23:17 -07:00
Holly Borla
549b45250f [Concurrency] Remove ClosureActorIsolation. 2023-09-16 12:22:38 -07:00
Holly Borla
97f1e617fd [Concurrency] Replace ClosureActorIsolation with ActorIsolation throughout
the isolation query APIs.
2023-09-16 12:21:36 -07:00
Holly Borla
4b23564711 [Concurrency] Rename AbstractClosureExpr::getActorIsolation to
getClosureActorIsolation.

This is preparation for changing AbstractClosureExpr to store
ActorIsolation instead of ClosureActorIsolation, and convert to
ClosureActorIsolation when needed to allow incrementally updating
callers. This change is NFC.
2023-09-16 12:20:53 -07:00
Holly Borla
a6d078b820 [Concurrency] Use the 'nonisolated' terminology instead of 'independent'.
This commit is NFC; it's mostly renames.
2023-09-08 13:28:55 -07:00
Manu
02b5fa2c8e Fix some typos in the codebase 2023-08-31 18:50:10 -03:00
Michael Gottesman
37d60a08bb [move-only] Rename mark_must_check -> mark_unresolved_non_copyable_value.
I was originally hoping to reuse mark_must_check for multiple types of checkers.
In practice, this is not what happened... so giving it a name specifically to do
with non copyable types makes more sense and makes the code clearer.

Just a pure rename.
2023-08-30 22:29:30 -07:00
Nate Chandler
ff302212a0 [OpaqueValues] Fix closure handling.
Rewrote and tested all currently emittable variations of closure
handling for opaque values.
2023-08-22 07:48:39 -07:00
Michael Gottesman
543063ef0e [silgen] Make ManagedValue::forUnmanaged private and change users to use other more specific APIs.
I have been doing this over the past couple of days in preparation for changing
ManagedValue to specify the type of scope its cleanup is connected to.
2023-08-19 14:11:44 -07:00
Michael Gottesman
85e38afbac Merge pull request #67780 from gottesmm/pr-d9b586775f6ea84fe9868857eb8dd2eeaeb39f6f
[silgen] Rename forTrivialObjectRValue -> forObjectRValueWithoutOwnership and change a bunch of forUnmanaged to use this API
2023-08-08 09:58:33 -07:00
Michael Gottesman
2208caac32 [silgen] Convert a bunch of forUnmanaged -> forObjectRValueWithoutOwnership.
NFCI.
2023-08-07 13:36:02 -07:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Michael Gottesman
b060e5ba60 [move-only] Make sure we mark local function inout parameters with mark_must_check.
Originally, we were relying on capture info to determine if we needed to insert
this mark_must_check. This ignored that the way that we are handling
escaping/non-escaping is something that is approximated in the AST but actually
determined at SIL level. With that in mind, rather than relying on the capture
info here, just rely on us having an inout argument. The later SIL level
checking for inout escapes is able to handle mark_must_check and knows how to
turn off noncopyable errors in the closure where we detect the error to prevent
us from emitting further errors due to the mark_must_check here.

I discovered this while playing with the previous commit.

rdar://112555589
2023-07-19 15:02:04 -07:00
Joe Groff
9d2735ea46 SILGen: Provide a reabstracted writeback for inout parameters emitted in a more abstract closure literal context.
When we emit closure literals in the context of a generic parameter, the parameters of the
closure may be more abstract than they would normally be for the closure's abstract type.
We handled this by reabstracting value parameters to their usual substituted representation
in the prolog, but neglected to do so for `inout` parameters too. In this case, we need to take
the initial value, reabstract it to provide a local variable with the substituted representation,
and then take the final value, reabstract it back, and write back to the original inout parameter
on function exit.

Fixes rdar://111563642.
2023-07-11 18:30:01 -07:00
Kuba (Brecka) Mracek
d427696bf9 Allow @_silgen_name to be used on globals and add a @_silgen_name(raw: ...) version that skips mangling (#66540)
Attribute @_silgen_name is today only allowed to be used on functions, this change allows usage on globals as well. The motivation for that is to be able to "forward declare" globals just like it's today possible to do with functions (for the cases where it's not practical or convenient to use a bridging header).

Separately, this change also adds a @_silgen_name(raw: ...) syntax, which simply avoids mangling the name (by using the \01 name prefix that LLVM uses). The motivation for that is to be able to reference the "magic Darwin linker symbols" that can be used to look up section bounds (in the current dylib/module) -- those symbols don't use the underscore prefix in their mangled names.
2023-06-29 08:37:51 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
John McCall
acbd4a6022 Fix the emission of closures into reabstracted contexts with
variadic-tuple results.  There are three parts to this.

First, fix the emission of indirect result parameters to do a
proper abstraction-pattern-aware traversal of tuple patterns.
There was a FIXME here and everything.

Second, fix the computation of substituted abstraction
patterns to properly handle vanishing tuples.  The previous code
was recursively destructuring tuples, but only when it saw a
tuple as the substituted type, which of course breaks on vanishing
tuples.

Finally, fix the emission of returns into vanishing tuple
patterns by allowing the code to not produce a TupleInitialization
when the tuple pattern vanishes.  We should always get a singleton
element initializer in this case.

Fixes rdar://109843932, plus a closely-related test case for
vanishing tuples that I added myself.
2023-06-14 21:29:22 -04:00
John McCall
3332ce7d1e [NFC] Add a utility for this load take/borrow dance 2023-06-14 21:29:21 -04:00
Michael Gottesman
59c8cff917 [borrowing] Add support for borrowing/consuming copyable types to be a noimplicitcopy type.
rdar://108383660
2023-06-06 18:12:29 -04:00
Slava Pestov
8a6fddfc74 Merge pull request #66290 from slavapestov/class-allocating-init-with-pack
SILGen: Fix emission of class allocating init with pack expansion parameters
2023-06-01 22:42:42 -04:00
Slava Pestov
a1582341a5 SILGen: Fix emission of class allocating init with pack expansion parameters
Fixes rdar://110099644.
2023-06-01 19:20:11 -04:00
Michael Gottesman
42b4b9a652 [move-only] Fix class setters of address only move only types.
We were not properly propagating along cleanups in SILGenProlog. I went through
SILGenProlog and fixed this.

rdar://109287977
2023-05-31 14:24:40 -07:00
Joe Groff
9db359985d Emit updated debug info when inout parameters are consumed and reinitialized.
Change SILGen to emit the `debug_value` instruction using the original inout
parameter address, instead of the `mark_must_check` inserted for move-only
parameters, because code in the MoveOnlyAddressChecker did not expect to
find the debug_value anywhere but on the original address. Update move-only
diagnostics so that they pick up the declaration name for a memory location
from any debug_value instruction if there are more than one. rdar://109740281
2023-05-24 12:15:53 -07:00
Michael Gottesman
82c645db21 [move-only] Fix emission of addressonly noncopyable setter new values.
NOTE: This does not affect normal parameters since normal parameters that are
noncopyable never have default access semantics since the user is forced to
specify either borrow or consume. This is incontrast to implicit parameters like
the newValue of a setter.

rdar://109726282
2023-05-23 10:56:45 -07:00
Michael Gottesman
12e1db4f1e [move-only] Ensure that resilient deinits take their self argument as an address argument instead of an object.
The signature was already correct, just the logic in the deinit code assumed
that we would always have an object.

rdar://109170069
2023-05-10 14:11:55 -07:00
Slava Pestov
ebb99e5e84 SILGen: Wrap captures of parameter packs inside tuples
Fixes rdar://problem/108481933.
2023-05-05 22:45:03 -04:00
Michael Gottesman
e1f2a207bd Merge pull request #65604 from gottesmm/address-only-stuff
[move-only] Address Only Patches
2023-05-03 18:39:25 -07:00
Michael Gottesman
20958c90b5 [move-only] Add initial support for address only types.
Specifically, I changed emitRValueForDecl and SILGenProlog to do the right
thing. I also added some tests.

Some notes:

1. We currently consider using a copyable field of a move only address type to
be a consume of that type. I am going to fix that in the next commit to make it
easier to understand.

2. I am going to need to write more tests/flesh out the behavior more. I am sure
there is more here.

rdar://105106470
2023-05-02 16:30:24 -07:00
Andrew Trick
ea7b8055bc Rewrite some isPlusOne calls to isPlusOneOrTrivial.
Whenever we want to forward to a +1 value but don't need to destroy
the original memory, use isPlusOneOrTrivial.

This follows the existing naming scheme.

Fixes rdar://108001491 (SIL verification failed: Found mutating or
consuming use of an in_guaranteed parameter?!:
!ImmutableAddressUseVerifier().isMutatingOrConsuming(fArg))
2023-05-01 23:24:29 -07:00
Erik Eckstein
c4ae7fe9e6 move-only: support deinits which get the self argument as indirect argument
This happens for address-only move-only types.
2023-04-11 10:25:49 +02:00
John McCall
9c9671b349 Merge pull request #64887 from rjmccall/vanishing-tuple-silgen
SILGen and SIL type lowering support for vanishing tuples
2023-04-04 12:41:29 -04:00
John McCall
cbf8519084 Fix an indexing bug when binding tuple parameters with non-initial
parameter packs.
2023-04-03 23:12:18 -04:00
Joe Groff
8e21bfcc47 MoveOnlyAddressChecker: Confine analysis to current formal access.
Code can only locally interact with a mutable memory location within a
formal access, and is only responsible for maintaining its invariants
during that access, so the move-only address checker does not need to,
and should not, observe operations that occur outside of the access
marked with the `mark_must_check` instruction. And for immutable
memory locations, although there are no explicit formal accesses, that's
because every access must be read-only, so although individual
accesses are not delimited, they are all compatible as far as
move-only checking is concerned. So we can back out the changes to SILGen
to re-project a memory location from its origin on every access, a
change which breaks invariants assumed by other SIL passes.
2023-04-02 16:33:57 -07:00
John McCall
debc8d9ebd [NFC] Move forEachTupleElement to use a generator 2023-03-22 22:04:36 -04:00
John McCall
5cf05f501b Implement arity reabstraction for closures 2023-03-21 22:23:45 -04:00
John McCall
4a8a3ac454 [NFC] Use a generator in prolog emission to generate parameters.
This adds an assertion that we're using all of the parameters, so
pass prolog emission the number of lowered parameters to ignore.
That's easy for the callers to provide, since they do actually
still need to add function arguments for those parameters.
2023-03-20 20:06:08 -04:00
Allan Shortlidge
fb03b4aa04 Sema: Relax availability checking for @MainActor.
The `@MainActor` global actor constraint on a declaration does not carry an
inherent ABI impact and therefore use of this constraint should not be limited
to OS versions where Swift concurrency is available.

Resolves rdar://105610970
2023-03-16 14:23:36 -07:00
John McCall
9ab4dc494c [NFC] Add better APIs for parallel destructuring of orig+subst types
As I've been iterating on this work, I've been gradually mulling these
over, and I think this is the way to go for now.  These should make it
a lot less cumbersome to write these kinds of traversals correctly.

The intent is to the sunset the existing expanded-components stuff
after I do a similar pass for function parameters.
2023-03-16 00:19:30 -04:00
John McCall
239777aacb Fix parameter binding for tuples containing pack expansions
More missing infrastructure.  In this case, it's really *existing*
missing infrastructure, though; we should have been imploding tuples
this way all along, given that we're doing it in the first place.

I don't like that we're doing all these extra tuple copies.  I'm not
sure yet if they're just coming out of SILGen and eliminated immediately
after in practice; maybe so.  Still, it should be obvious that they're
unnecessary.
2023-03-09 02:28:29 -05:00
Joe Groff
643efd0d43 SILGen: Don't DI the box for consuming parameters.
It's always immediately initialized, so there's no need. This also sidesteps
an issue with DI and escaped move-only boxes (rdar://106049211).
2023-03-03 12:02:52 -08:00
Joe Groff
4bb68a36cf Update for rebase 2023-02-28 11:02:16 -08:00
Joe Groff
2a187f2606 SILGen: Support mutable consuming parameters.
Emit a box like we would for a local variable, and move the parameter value into the box, as
part of the prolog.
2023-02-28 09:16:45 -08:00
Joe Groff
655e9e681d Add ParamSpecifier cases for Borrowing and Consuming.
And do a first pass of auditing existing uses of the parameter specifiers to
make sure that we look at the ValueOwnership mapping in most cases instead of
individual modifiers.
2023-02-28 09:16:44 -08:00
Michael Gottesman
799dba1184 [move-only] Suppress moveonly errors when an inout is captured by an escaping closure since we will already emit a more specific capture error. 2023-02-20 13:54:23 -08:00