Commit Graph

566 Commits

Author SHA1 Message Date
John McCall
444e770175 [NFC] Generalize createOpenedElementValueEnvironment to also be able
to map formal types into the new environment.
2024-01-03 16:25:16 -05:00
John McCall
b11af8854a [NFC] Abstract over the inner slot type 2024-01-03 16:09:22 -05:00
Doug Gregor
504329545f [SILGen] Handle indirect error results in allocating class initializers 2023-11-12 03:20:39 -08:00
Doug Gregor
76a89500d6 [SILGen] Handle indirect errors in other thunk kinds 2023-11-10 15:30:17 -08:00
Doug Gregor
fc19b8e1f4 [Typed throws] Handle error conversions in witness thunks 2023-11-10 15:30:17 -08:00
Doug Gregor
0ba605a4b9 [Typed throws] Implement reabstraction thunks that change the error
Introduce SILGen support for reabstractions thunks that change the
error, between indirect and direct errors as well as conversions
amongst error types (e.g., from concrete to `any Error`).
2023-11-07 11:39:56 -08:00
Slava Pestov
d2f1dedd35 Merge pull request #68220 from slavapestov/remove-get-protocol-self-type
Remove DeclContext::getSelfProtocolType()
2023-08-31 11:39:17 -04:00
Slava Pestov
361d49a843 AST: Remove DeclContext::getSelfProtocolType() 2023-08-30 15:15:08 -04:00
John McCall
acece4c35f [NFC] Push cleanup management through a few reabstraction utilities 2023-08-29 18:11:08 -04:00
John McCall
60d2a93209 [NFC] result -> inner, for consistency 2023-08-28 12:27:36 -04:00
John McCall
c1f110c8e8 Generalize the handling of pack cleanups in reabstraction thunks
The result-reabstraction code doesn't need to handle cleanups properly
during the planning phase because of course we don't have any values
yet.  That is not true of argument reabstraction, so we need to make
sure that the recursive emitters can produce values with cleanups
so that we can collect and forward those cleanups correctly when
emitting the call.

As part of this, I've changed the code so that it should forward
outer addresses to inner address more consistently; it wouldn't
have done this before if we were breaking apart or assembling
a pack.  I'm not sure I can directly test this without figuring
out a way to get SILGen to reabstract both sides of a function,
though.

I'm not sure this is really doing borrowed vs owned arguments
correctly, if e.g. we need to rebstract one component of a tuple
that's otherwise borrowed.
2023-08-28 12:27:36 -04:00
John McCall
6dc298a80f [NFC] Split the inner/outer vanishing tuple handling
I'm going to change the type signature for inner tuples,
so this isn't going to work.
2023-08-28 12:25:17 -04:00
John McCall
8a5bfd5701 [NFC] Be more precise in some parameter types 2023-08-28 12:25:17 -04:00
John McCall
fb6a811fe9 [NFC] Allow the pack input value to be "written back" to the generator
This will be necessary in order to adopt this in TranslateArguments.
2023-08-28 12:25:17 -04: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
104379adab [silgen] Rename SILGenFunction::emitManagedRetain -> emitManagedCopy.
This is an old API that should have been renamed a long time ago. It just kept
its early name due to inertia.
2023-08-19 14:11:44 -07:00
John McCall
66ea1f1ddd [NFC] Fix an oversight in my previous NFC patches
This is starting to feel a little spaghetti-ish.  This kind of
existential stuff is hard to do in C++.
2023-08-14 22:29:27 -04:00
John McCall
127acfa686 [NFC] Share argument order and names between the arguments and results code
This was an annoying change, but mostly mechanical.  The goal here is
to create parallel structure between the two paths so that it isn't
utterly confusing to share common CRTP paths between them.  The renaming
of translate->process is just to make sure that all of the call sites
get correctly rewritten.
2023-08-14 21:48:13 -04:00
John McCall
bcb6230302 [NFC] Extract a lot of common expansion logic out of ResultPlanner 2023-08-14 19:06:49 -04:00
John McCall
939270c573 [NFC] More prep work for sharing code between param and result reabstraction 2023-08-14 19:06:49 -04:00
John McCall
c2207c6608 [NFC] Fold PlanData into the main ResultBuilder in SILGenPoly
I'm trying to create more parallel structure between the param
and result reabstraction code so that, hopefully, some of the
basic explosion reasoning can be shared.
2023-08-14 19:06:49 -04: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
Michael Gottesman
7dbcdfb126 [silgen] Rename forTrivialObjectRValue -> forObjectRValueWithoutOwnership.
The reason to do this rename is that this is also used for objects that while
non-trivial have .none ownership. Example: enum instance without a case.
2023-08-07 13:36:02 -07:00
Allan Shortlidge
ca8bf981a4 NFC: Hoist queries for unavailable decl optimizations into the AST library.
Moving the query implementation up to the AST library from SIL will allow
conveniences to be written on specific AST element classes. For instance, this
will allow `EnumDecl` to expose a convenience that enumerates element decls
that are available during lowering.

Also, improve naming and documentation for these queries.
2023-08-04 17:39:26 -07:00
Nate Chandler
cc3038dcf6 [OpaqueValues] Transforms emit addr-only loads.
In opaque values mode, when transforming, load address even when their
type is address-only.
2023-08-02 20:16:58 -07:00
nate-chandler
d13348c074 Merge pull request #62494 from nate-chandler/opaque-values/2/20221209
[OpaqueValues] Initial support for AD.
2023-07-19 07:12:37 -07:00
Nate Chandler
c8bce4ac04 [OpaqueValues] Initial support for AD.
Just enough to build _Differentiation.
2023-07-18 14:09:36 -07:00
John McCall
1a7d44a11d Diagnose attempts to reabstract variadic function types in unimplementable ways. 2023-07-18 13:22:35 -04:00
Anton Korobeynikov
eb82df6bc6 [AutoDiff] Support differentiable functions with multiple semantic results (#66873)
Add support for differentiable functions having multiple semantic results

Co-authored-by: Brad Larson <larson@sunsetlakesoftware.com>
2023-07-06 16:31:39 -07:00
John McCall
c0777e611d Handle vanishing and variadic tuple results in reabstraction thunks.
Fixes rdar://110391963
2023-06-30 02:08:57 -04: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
Allan Shortlidge
235922d5ae SILGen: Stub unavailable protocol witness thunks.
Part of rdar://107388493
2023-05-03 15:19:31 -07:00
John McCall
0c3c62bd73 [NFC] Rename isPackExpansion -> isOrigPackExpansion for clarity 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
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
d25a8aec8b Add explicit lowering for value packs and pack expansions.
- SILPackType carries whether the elements are stored directly
  in the pack, which we're not currently using in the lowering,
  but it's probably something we'll want in the final ABI.
  Having this also makes it clear that we're doing the right
  thing with substitution and element lowering.  I also toyed
  with making this a scalar type, which made it necessary in
  various places, although eventually I pulled back to the
  design where we always use packs as addresses.

- Pack boundaries are a core ABI concept, so the lowering has
  to wrap parameter pack expansions up as packs.  There are huge
  unimplemented holes here where the abstraction pattern will
  need to tell us how many elements to gather into the pack,
  but a naive approach is good enough to get things off the
  ground.

- Pack conventions are related to the existing parameter and
  result conventions, but they're different on enough grounds
  that they deserve to be separated.
2023-01-29 03:29:06 -05:00
Pavel Yaskevich
3fb69b3c3c [SIL] SILFunction: Add runtime accessible function attribute
This attribute indicates that the given SILFunction has to be
added to "accessible functions" section and could be looked up
at runtime using a special API.
2022-12-20 09:33:44 -08:00
Doug Gregor
0e8d4c470e [SILGen] Fix formal type of global actor metatype.
Fixes a crash reported in rdar://103255322 .
2022-12-16 12:33:09 -08:00
Nate Chandler
626e708c41 [OpaqueValues] Fix @in_guaranteed loadable yields.
When opaque values are enabled, when yielding a value with an indirect
convention, a value whose type's category is "object" must be yielded.
Previously, if a value's type was loadable, an attempt was made to yield
a value whose type's category was "address".  Here, that's fixed.
Additionally, handling for trivial types yielded via @in_guaranteed is
added.
2022-12-13 18:07:52 -08:00
Nate Chandler
8d8577e5b0 [SIL] Removed Indirect_In_Constant convention.
It is no different from @in.

Continue parse @in_constant in textual and serialized SIL, but just as
an alias for @in.
2022-12-09 21:54:00 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Slava Pestov
87844648ba SILGen: Add a couple of assertions 2022-11-11 23:31:06 -05:00
swift-ci
fd6fd76dae Merge pull request #42513 from jsoref/spelling-silgen
Spelling silgen
2022-11-09 23:28:43 -08:00