Commit Graph

22 Commits

Author SHA1 Message Date
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Hamish Knight
16cfca4186 [ASTWalker] NFC: Rename SkipChildren -> SkipNode
This better describes what the action currently
does, and allows us to re-introduce `SkipChildren`
with the correct behavior.
2024-02-05 15:27:25 +00:00
Sima Nerush
0beffe79df [SILGen] In emitDynamicPackLoop, branch to the loop latch only if
there's a valid insertion point.
2024-01-24 13:55:42 -08:00
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
Sima Nerush
af56beb60e Add for case support and tests 2023-12-03 21:51:40 -08: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
Michael Gottesman
8cfb3d238f [silgen] Cleanup a few Cleanups dump output. 2023-08-19 14:11:44 -07:00
Michael Gottesman
7c5c548968 [silgen] Fix PartialDestroyPackCleanup dumping output to handle LimitWithinComponent to be nullptr. 2023-08-19 14:11:44 -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
Slava Pestov
ebb99e5e84 SILGen: Wrap captures of parameter packs inside tuples
Fixes rdar://problem/108481933.
2023-05-05 22:45:03 -04: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
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
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
2d72da3942 Add a few convenience functions for inducing pack types from tuples
and lowered pack types.

The "approximate" thing is kindof a representational/testing wart.
Really, all that we care about is that we have a formal pack type
with the right shape.  (We don't *really* need a formal pack type ---
we could use anything that can represent the shape --- but we seem
to be standardizing on `PackType` for that.)  We could just use the
reduced shape for that, but for some reason I've been resisting that.
Not sure I have a compelling reason, though, and if we decide to
use reduced shapes, we can eliminate the approximate formal packs
stuff.

Inducing packs from tuple slices is a more permanently-useful thing.
2023-03-09 02:08:37 -05:00
John McCall
81f11c19ab Implement the caller side of return types containing variadic packs
This is all relatively nicely abstracted, which is not to say that
it didn't take an awful lot of plumbing to get it to work.  The basic
problem here is inherent: we need to do component-specific setup and
teardown, and unfortunately in the current representation we have to
do that with separate loops and without any dominance relationships.
(This is the same thing preventing us from doing borrows in the
general case.)  The result is that the general case of result emission
is to emit every element of the expansion into a temporary tuple
(requiring a pack loop before the call to initialize the pack), then
process those elements in the body of a second pack loop after the
call.  And that's terrible enough that we really have to do the work
to try to avoid it, which makes all the APIs more complicated.

Anyway, most of the way through the basic plumbing for variadic
generics now.  Next is reabstraction, I think, which I hope will
mostly mean fixing bugs in the infrastructure I've already written.
2023-03-07 03:15:31 -05:00
John McCall
6b57f73139 Fix a copy-and-paste mistake blocking some other code from working
I hadn't bothered testing that code yet, but Holly had, and she
found this; oops.
2023-03-07 03:15:31 -05:00
John McCall
8bfc18bd31 Generalize the operation to get an opened environment for value
operations on a type
2023-03-07 03:15:31 -05:00
John McCall
6c066502a2 Add an API to map contextual types from the pack to element environment
I'm not really convinced that the existing implementation here is
correct in general; it might work for the type checker's use cases,
but I don't think we can rely on not seeing opened element archetypes
from other expansions in the type we're processing here.  But we can
at least tread water while offering a more convenient API.
2023-03-07 03:15:31 -05:00
John McCall
157be3420c Implement the callee side of returning a tuple containing a pack expansion.
This required quite a bit of infrastructure for emitting this kind of
tuple expression, although I'm not going to claim they really work yet;
in particular, I know the RValue constructor is going to try to explode
them, which it really shouldn't.

It also doesn't include the caller side of returns, for which I'll need
to teach ResultPlan to do the new abstraction-pattern walk.  But that's
next.
2023-03-06 04:26:18 -05:00
John McCall
06a7468e4f Implement the emission of pack expansion arguments in SILGen
Mostly fixing some existing code.
2023-03-03 02:52:32 -05:00
John McCall
fb9578133b Steps towards supporting pack expansions properly in signature
lowering and argument emission.

Pack expansions in argument emission don't work yet, but I wanted
to land this bit of incremental progress.
2023-02-24 18:34:52 -05:00