Commit Graph

115 Commits

Author SHA1 Message Date
Andrew Trick
22646bd07c Fix AbstractionPattern::isNoncopyable to handle archetypes.
This fixes TypeLowering for ~Copyable generics, such as:

struct S<T: ~Copyable>: ~Copyable {
  var x: T
}

extension S: Copyable where T: Copyable  {}

func foo<T>(s: S<T>) -> ()

Previously, TypeLowering would ignore the implicit Copyable
requirement on the archetype 'T'.
2024-04-07 20:31:55 -07:00
Doug Gregor
f54782eab5 [SILGen] Correctly determine the thrown error type for closures
When a closure throws a generic error type, we were retrieving the
substituted error type (involving archetypes) when we needed to be
working with the interface type.

Fixes rdar://124484012.
2024-03-13 12:51:48 -07:00
Joe Groff
fe7049ed13 SIL: More accurate for type lowering whether a type is trivial based on conditional Copyable requirements.
We want a conditionally-copyable type to still be classified as trivial in cases
where it's bitwise-copyable, has a trivial deinit, and is Copyable. The previous
implementation here only checked at the declaration level whether a type was
Copyable or not; get a more accurate answer by consulting the combination
of information in the substituted type and abstraction pattern we have
available during type lowering so that we classify definitely-copyable substitutions
of a conditionally-copyable type as trivial. Should fix rdar://123654553 and
rdar://123658878.
2024-02-27 15:01:20 -08:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
John McCall
868fc6ad46 Basic SILGen for @isolated(any).
The main piece that's still missing here is support for closures;
they actually mostly work, but they infer the wrong isolation for
actor-isolated closures (it's not expressed in the type, so obviously
they're non-isolated), so it's not really functional.  We also have
a significant problem where reabstraction thunks collide incorrectly
because we don't mangle (or represent!) formal isolation into
SILFunctionType; that's another follow-up.  Otherwise, I think SILGen
is working.
2024-02-19 21:21:03 -05:00
Slava Pestov
af50d7e6b8 AST: Add allowInverses flag to AbstractGenericSignatureRequest 2024-02-05 18:43:06 -05:00
Slava Pestov
81027cff23 SIL: Drop conformances to Copyable and Escapable from substitution signature 2024-02-05 18:43:06 -05:00
Slava Pestov
af3ab14986 SILGen: Clean up substitution map construction to deal with Copyable 2024-01-31 21:55:52 -05:00
Doug Gregor
2cef4b97b0 [Abstraction pattern] Eliminate unnecessary assertion for typed throws
Abstraction patterns can handle conversions involving typed throws
nowdays. Remove the assertion, fixing rdar://121617307.
2024-01-29 12:04:19 -08:00
Doug Gregor
ad75dae2ba [SIL] Fix thrown error computation for lowering of witnesses 2023-12-26 21:25:27 -08:00
Dario Rexin
36dd2c9450 [SilOpt] Add new layout type _TrivialStride and add pre-specialization suppport for it (#70308)
rdar://119329771

This layout allows adding pre-specializations for trivial types that have a different size, but the same stride. This is especially useful for collections, where the stride is the important factor.
2023-12-09 08:13:50 -08:00
Dario Rexin
df35f3327d [SilOpt] Add new layout _BridgeObject and add pre-specialization support for it (#70239)
rdar://119048001
2023-12-08 14:34:16 -08:00
Doug Gregor
42d77df648 [SIL] Fix computation of substituted error type against an abstraction pattern
We were attempting to perform substitution against the original pattern
even when it didn't have a substitution map, and then trying to cover
for the resulting errors by adjusting to `any Error`... which isn't
always correct. Do the substitution only when it makes sense.

Fixes rdar://119217570 & rdar://119219214.
2023-12-07 10:05:38 -08:00
Doug Gregor
927e2420a0 [Typed throws] Handle closure reabstraction
This peephole optimization in SILGen requires us to use the thrown
error for the context of a closure type rather than the thrown error
for the closure AST node itself.
2023-11-08 12:08:01 -08:00
Slava Pestov
d430d12b2c SIL: Don't destructure tuples in AbstractionPattern::getErrorConvention()
Tuples don't conform to Error anyway so it's moot, but if they ever do
we won't be destructuring them into multiple indirect error results.
2023-10-27 21:15:06 -04:00
Slava Pestov
b84df92b70 SIL: Type lowering support for indirect error results 2023-10-27 17:37:43 -04:00
Slava Pestov
1d05c356c4 SIL: AbstractionPattern support for typed throws 2023-10-27 17:37:43 -04:00
Slava Pestov
04fe8f4bc6 SIL: Add forEachExpandedPackElement() and use it in type lowering
Probably there's no way to hit this right now, but there will be if
concrete formal PackTypes start showing up in AST.
2023-07-19 16:24:38 -04:00
Slava Pestov
8a07466938 SIL: Fix SubstFunctionTypePatternVisitor handling of pack types
The included test case also covers the previous commit.
2023-07-19 16:24:27 -04:00
Slava Pestov
76c90f6024 Merge pull request #67362 from slavapestov/sil-pattern-count-abstraction
SIL: Fix substituted function type visitor for PackExpansionType with concrete pattern type
2023-07-19 07:49:27 -04:00
John McCall
1a7d44a11d Diagnose attempts to reabstract variadic function types in unimplementable ways. 2023-07-18 13:22:35 -04:00
Slava Pestov
e0a1a11a6b SIL: Fix substituted function type visitor for PackExpansionType with concrete pattern type
If the pattern doesn't have any pack parameters in it anymore,
we need to recover the substituted count type from the original
count type.

Fixes rdar://problem/112065340.
2023-07-18 12:19:22 -04:00
John McCall
e14f2bc0c7 [NFC] Add a method to just ask if a tuple AP vanishes under substitution 2023-06-29 19:39:51 -04:00
Erik Eckstein
6b1697eb06 use new llvm::Optional APIs to fix deprecation warnings 2023-06-28 14:28:38 +02: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
Michael Gottesman
29672c503a Merge pull request #66381 from gottesmm/noimplicitcopy-borrow-consuming
[borrowing/consuming] Make borrowing and consuming parameters no implicit copy.
2023-06-06 21:41:18 -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
ec3aa5c9d7 SIL: Preliminary AbstractionPattern support for PackElementType 2023-06-06 14:18:37 -04:00
Slava Pestov
a3e13610be SIL: Use walkPackReferences() instead of bespoke logic 2023-06-06 14:18:37 -04:00
Slava Pestov
b2bc2c72ec AST: Introduce PackElementType 2023-05-25 11:17:30 -04:00
John McCall
30817b11dd Support vanishing tuples in the the general abstraction pattern routines. 2023-04-03 23:14:47 -04: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
8421669a59 Pass down the substitutions of the original pattern when extracting
a subst abstraction pattern from a generic nominal type.
2023-03-27 18:31:08 -04:00
John McCall
280c91a54f Fix the dumping of AbstractionPatterns with substitutions 2023-03-27 18:31:08 -04:00
Nate Chandler
adb21a373a [TypeLowering] Fix lexicality check for packs.
In asserts builds, the lexicality of packs is verified via an
alternative code-path that walks into aggregates.  That walk needs to
proceed through packs.

rdar://107283101
2023-03-27 14:03:30 -07:00
John McCall
debc8d9ebd [NFC] Move forEachTupleElement to use a generator 2023-03-22 22:04:36 -04:00
John McCall
0c3c62bd73 [NFC] Rename isPackExpansion -> isOrigPackExpansion for clarity 2023-03-22 15:40:02 -04:00
John McCall
f99efc2f94 Fix unsafeGetSubstFieldType to propagate a substitution map in
whichever case it happens to be in.

This is a basic fix so that parallel walks on tuples and function
types in the substituted type will work .  Separately, though, I
do not think the places that use this really need to be passed an
orig type; this is used for computing type properties, and I am
not aware of any reason we should need an orig type to compute
type properties.  Additionally, the orig types computed by this
function are not really correct because of the substitution being
done in some cases, so it'd be very nice to rip this all out.
I'm not good to look into that right now, though.
2023-03-22 15:40:02 -04:00
John McCall
bbc682822a [NFC] Change the printing of AbstractionPattern to include the sub map 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
5f1a669f2f [NFC] Change the existing client of forEachFunctionParam
Yeah, this is much cleaner.
2023-03-20 16:01:54 -04:00
John McCall
2e4ad65889 [NFC] Change forEachFunctionParam to only ignore the final orig parameter
and not also drop a subst parameter.

This turned out to be more convenient for certain clients (e.g. SILGenPoly)
than requiring the full subst param list to be passed in.  These clients
want to process the subst param list separately, and dropping self early
can be convenient for that.  The only fundamental reason we need this
flag is for working with the orig type, so just use it for that; clients
that need to use this feature can reasonably be expected to cooperate.
2023-03-20 13:36:40 -04:00
John McCall
2172c0ae52 [NFC] Provide a more generator-like interface for traversing orig+subst function parameters
This is necessary because the use patterns in SILGenPoly require
walking two orig+subst sequences in parallel, which poses problems
for a callback-centric design like the one I addded before.  An
inversion of control is necessary; this is basically a manual
coroutine.  But frankly it's a nicer interface than the callback
design, too; I switched the implementation of forEachFunctionParam
to use the generator just to avoid code duplication, but I might
try to remove it and switch all the clients over to the generator.
The main problems with the callback design are that (1) I wasn't
sure which values clients would want, and the result is that there
are a *lot* of parameters and (2) (relatedly) the types of those
parameters have to be written out explicitly, and some of them
are quite large.  The generator code is just much nicer.  Maybe
I can still give the generator a little unparameterized callback
to keep lexical loops simple.

I'll need to do this same thing for tuples.  One at a time.
2023-03-20 13:36:40 -04:00
John McCall
3342d67161 Fix the creation of substituted abstraction patterns for expansions 2023-03-17 22:07:10 -04:00
John McCall
72cc8dcb1e [NFC] Rewrite the subst-type extracttor to be a CanTypeVisitor 2023-03-16 15:56:46 -04:00
John McCall
f3e7daf478 [NFC] Remove the now-dead PackExpanded accessors from AbstractionPattern 2023-03-16 01:38:46 -04:00
John McCall
4499e3d055 [NFC] Introduce new APIs for traversing orig/subst parameters in parallel 2023-03-16 01:38:46 -04:00