Commit Graph

6754 Commits

Author SHA1 Message Date
John McCall
5942049c83 Set substitutions on storage abstraction patterns in l-value access.
Fixes a host of problems with stored type members with types dependent
on a type parameter pack; I ran into it specifically with vanishing
tuples.

Test to follow.
2023-04-03 23:09:36 -04:00
John McCall
df82443138 Count lowered parameters for a formal parameter using just the
AbstractionPattern.

The old logic was wrong for vanishing tuples: a non-tuple substituted
type might correspond to multiple lowered parameters if it's the result
of substituting into a vanishing tuple that also contains empty pack
expansions.

Test to follow later in this PR.
2023-04-03 23:04:19 -04:00
Adrian Prantl
0337ea94f2 Remove uses of SGF.CurrentSILLoc from SILGenPattern 2023-04-03 16:08:20 -07:00
Joe Groff
736242d394 Merge pull request #64850 from jckarter/move-only-escape-di
MoveOnlyAddressChecker: Confine analysis to current formal access.
2023-04-03 09:27:56 -07: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
Saleem Abdulrasool
c8f88175d8 IRGen: attribute correct linkage to Windows DSO handle
Partially address the incorrect handling for the `#dsohandle` on
Windows.

We were previously emitting a local definition for this external
constant, and worse yet, not marking the definition for COMDAT.  It is
unclear what definition would win ultimately (implementation defined),
as we had a definition as well as the linker synthesized value. We can
change the SIL linkage for this type to `DefaultForDeclaration` which
will give it `available_externally` and default visibility and storage
which is closer to what we desire.  However, because we do not track the
LLVM variables and apply heuristics for lowering the
`SILGlobalVariable`, we would attribute it with imported DLL Storage.
This would then cause us to fail at link time (amusingly enough link.exe
will report a LNK1000).  Special case the variable and track that we are
targeting a windows environment in the `UniversalLinkageInfo` so that we
do not special case this on other platforms.

This also has the nice side effect of allowing us to remove the special
case in the TBD handling.

Fixes: #64741
2023-04-02 10:08:16 -07:00
Saleem Abdulrasool
07efa25c01 Merge pull request #64754 from compnerd/reuse
SILGen: refactor `#dsohandle` handling
2023-04-01 08:18:27 -07:00
Nate Chandler
1126561733 [NFC] SILGen: Added comment.
Explained why lexical borrow scopes are only created for boxes whose
contents have lexical lifetimes.
2023-03-31 16:52:03 -07:00
Saleem Abdulrasool
1e7bccbfdb SILGen: refactor #dsohandle handling
Refactor the shared code for the construction of the DSO handle variable
to share some of the SILGen.
2023-03-29 19:06:07 -07:00
John McCall
03f4e5629e Merge pull request #64681 from rjmccall/more-variadic-fixes
More fixes for generating SIL for variadic generics
2023-03-28 19:25:31 -04:00
John McCall
74420994d4 Teach ResultPlan to handle packs correctly when we're not emitting
into an Initialization.

rdar://107161241
2023-03-28 14:34:06 -04:00
Allan Shortlidge
9a1a2c3b9d Merge pull request #64644 from tshortli/strip-unavailable-code
Introduce `-unavailable-decl-optimization`
2023-03-28 08:53:48 -07:00
Konrad `ktoso` Malawski
0586c14b60 [Concurrency] SerialExecutor.isSameExclusiveExecutionContext (#64604) 2023-03-28 15:56:28 +09:00
John McCall
de283f8053 Make BlackHoleInitialization support pack initialization
Fixes rdar://107151145
2023-03-27 18:31:08 -04:00
Allan Shortlidge
ada0f09615 SILGen: Implement 'complete' unavailable decl optimization.
Avoid SIL lowering for declarations marked unavailable when
`-unavailable-decl-optimiation=complete` is specified.

Part of rdar://106674022
2023-03-27 11:40:54 -07:00
John McCall
a3c5e1664f Merge pull request #64575 from rjmccall/variadic-memberwise-initializers
Fixed memberwise initializers for structs with variadic-tuple properties
2023-03-24 12:24:38 -04:00
nate-chandler
21701ace65 Merge pull request #64584 from apple/revert-64494-dihole-assertion
Revert "Add a verify-di-hole assertion to SILBuilder."
2023-03-23 20:32:50 -07:00
nate-chandler
af5d611962 Merge pull request #64583 from nate-chandler/rdar79508092
[SILGen] Use decl location for main's functions.
2023-03-23 18:47:24 -07:00
nate-chandler
4ea51cfe33 Revert "Add a verify-di-hole assertion to SILBuilder." 2023-03-23 13:27:06 -07:00
Nate Chandler
8c4a0aed53 [SILGen] Use decl location for main's functions.
Previously, the location used for functions corresponding to @main was
just RegularLocation::getModuleLocation().  Make that more specific by
using the annotated type's location instead.

rdar://79508092
2023-03-23 13:14:39 -07:00
John McCall
a3b195bd6d Merge pull request #64529 from rjmccall/variadic-tuples-in-structs
A bunch of fixes for variadic tuple properties in structs
2023-03-23 14:42:13 -04:00
John McCall
481f9c7362 Fix memberwise initializers for structs with variadic-tuple fields 2023-03-22 22:04:37 -04:00
John McCall
debc8d9ebd [NFC] Move forEachTupleElement to use a generator 2023-03-22 22:04:36 -04:00
Adrian Prantl
88b071bf9f Merge pull request #64494 from adrian-prantl/dihole-assertion
Add a verify-di-hole assertion to SILBuilder.
2023-03-22 12:50:17 -07:00
John McCall
0c3c62bd73 [NFC] Rename isPackExpansion -> isOrigPackExpansion for clarity 2023-03-22 15:40:02 -04:00
John McCall
d18b914fc3 Do a proper orig+subst walk of tuple expression elements in call
argument emission.
2023-03-22 15:40:02 -04:00
John McCall
5cf05f501b Implement arity reabstraction for closures 2023-03-21 22:23:45 -04:00
John McCall
3fe46464c7 Allow a SILFunctionArgument to be a parameter pack.
We might want to record the *sequence* of parameter decls associated
with a parameter pack, but currently we're not doing that.
2023-03-21 17:36:05 -04:00
Adrian Prantl
5129aea296 Add a verify-di-hole assertion to SILBuilder.
The verify-di-hole SILVerifier pass is very useful in catching incorrectly set
SILDebugScopes, but it can be very tedious to track down the root cause of a
verification failure. This patch replicates much of its functionality inside an
assertion in SILBuilder, which will result in a backtrace pointing directly to
where the offending scope is being set.
2023-03-21 09:40:11 -07: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
John McCall
0b3b0d84d7 [NFC] Use the generators library in SILGenPoly 2023-03-20 20:06:08 -04:00
John McCall
a05fef5122 Implement parameter arity reabstraction.
This is largely a matter of changing the main loop over subst
params in TranslateArguments to use the generators I added,
then plugging back into the general reabstraction infrastructure.

Because we don't have pack coroutines, we're kind of stuck in
the code generation for pack reabstraction: we have to write
+1 r-values into a temporary tuple and then write those tuple
element addresses into the output pack.  It's not great.  We
also have lifetime problems with things like non-escaping
closures --- we have that problem outside of reabstraction
thunks, too.

Other than that glaring problem, I'm feeling relatively good
about the code here.  It's missing some peepholes, but it should
work.  But that that's not to say that arity reabstraction works
in general; my attempts to test it have been exposing some
problems elsewhere, and in particular the closure case crashes,
which is really bad.  But this gets a few more things working,
and this PR is quite large already.
2023-03-20 20:06:08 -04:00
John McCall
a37146c731 [NFC] Return a result from all the single-result translators
We'll be using these results with packs.
2023-03-20 13:36:40 -04:00
John McCall
23ccbfde99 [NFC] Factor out the tuple-to-scalar path into a method 2023-03-19 23:31:27 -04:00
John McCall
7190ac4a50 [NFC] Add a detailed explanatory comment 2023-03-19 23:31:27 -04:00
John McCall
1f1aa3eee6 [NFC] Unindent these helper classes 2023-03-19 23:30:51 -04:00
John McCall
999dbecf25 Merge pull request #64464 from rjmccall/pack-argument-reabstraction
A myriad of fixes, including the reabstraction of pack argument values
2023-03-18 04:22:32 -04:00
John McCall
cd3765c9fa Reabstract pack values when passing them as arguments 2023-03-17 22:07:11 -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
4499e3d055 [NFC] Introduce new APIs for traversing orig/subst parameters in parallel 2023-03-16 01:38:46 -04: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
Kavon Farvardin
a8a44ebb17 Merge pull request #64106 from kavon/enable-moveonly-by-default
Enable moveonly / noncopyable types by default
2023-03-15 09:59:29 -07:00
Konrad `ktoso` Malawski
41f99fc2ae [Executors][Distributed] custom executors for distributed actor (#64237)
* [Executors][Distributed] custom executors for distributed actor

* harden ordering guarantees of synthesised fields

* the issue was that a non-default actor must implement the is remote check differently

* NonDefaultDistributedActor to complete support and remote flag handling

* invoke nonDefaultDistributedActorInitialize when necessary in SILGen

* refactor inline assertion into method

* cleanup

* [Executors][Distributed] Update module version for NonDefaultDistributedActor

* Minor docs cleanup

* we solved those fixme's

* add mangling test for non-def-dist-actor
2023-03-15 23:42:55 +09:00
Michael Gottesman
02a12d4142 [move-only] Make sure to treat ref_element_addr mutable address accesses similar to inout.
I also slightly changed the codegen around where we insert the mark_must_check.
Specifically, before we would emit the mark_must_check directly on the
ref_element_addr and then insert the access. This had the unfortunate effect
that we would hoist any destroy_addr that were actually needed out of the access
scope. Rather than do that, I now insert the mark_must_check on the access
itself. This results in the destroy_addr being within the scope (like the
mark_must_check itself).

rdar://105910066
2023-03-14 14:03:20 -07:00
Kavon Farvardin
76107ed931 expose more of SILGen to move-only types by default
Also removes some redundant checks in SILGen for
the flag in order to process `_move` and `_borrow`
that are already checked for in Sema. We will keep
those behind the feature flag for now.
2023-03-13 22:39:31 -07:00
Holly Borla
8862b1bfb5 Merge pull request #64272 from hborla/emit-materialize-pack-expr
[SILGen] Emit `MaterializePackExpr`s.
2023-03-11 13:30:52 -08:00
John McCall
3bdee8c215 Fix an ownership bug when splitting an opaque tuple value into
a pack expansion.
2023-03-10 19:02:38 -05:00
Holly Borla
dce70f373f [SILGen] Emit MaterializePackExprs.
The subexpression of a MaterializePackExpr (which is always a tuple value
currently) is emitted while preparing to emit a pack expansion expr, and its
elements are projected from within the dynamic pack loop. This means that a
materialized pack is only evaluated once, rather than being evaluated on
every iteration over the pack elements.
2023-03-09 21:44:03 -08: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
John McCall
3faee07bbe Teach RValue to not recursively expand tuples with pack expansions
Arguably, it would be more consistent with the current design to
figure out a representation for pack-expansion components so that
we can keep them around in whatever storage.  But honestly, I
don't like the current design; I think the eager explosion is an
over-complicated mistake.  So this is partly just me finding an
excuse to not extend that to more cases.
2023-03-09 02:22:24 -05:00