Commit Graph

67 Commits

Author SHA1 Message Date
Nate Chandler
a2a4d22042 [NFC] IRGen: Typed this flag. 2025-10-22 13:00:38 -07:00
Slava Pestov
0d90b62491 AST: Clean up in preparation for non-canonical archetypes 2025-10-08 15:15:43 -04:00
Anthony Latsis
f8577a2731 IRGen: Address llvm::Type::getPointerTo deprecation
See https://github.com/llvm/llvm-project/pull/113331.
2025-07-21 12:37:15 +01:00
Doug Gregor
731f58443c Address review feedback on AbstractConformance in ProtocolConformanceRef 2025-03-23 20:54:39 -07:00
Nate Chandler
1102752604 [IRGen] Pack: Scope recursive pack allocations.
While materializing one metadata pack, another pack may need to be
materialized. When that happens, the inner pack's dynamically sized
allocation must be deallocated within the same dominance scope.

The CFG within which the inner dynamically sized pack is allocated isn't
visible from SIL; that explains why the existing infrastructure around
`de`/`alloc_pack_metadata` instructions fails to produce a deallocation
at the appropriate point.

In the fullness of time, this emitted code should be optimized such that
the inner loop is hoisted out of its current outer loop.

rdar://141718098
2025-02-13 12:11:27 -08:00
Nate Chandler
65bae742df [IRGen] Pack: Fix phi source block.
Rather than the block that we _think_ we're emitting into, use the block
we're actually emitting into.  These aren't the same because callees
can and do introduce control flow.
2025-02-12 15:26:39 -08:00
Slava Pestov
47156e006b AST: Introduce ProtocolConformanceRef::forAbstract() 2024-11-16 16:16:06 -05:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Slava Pestov
5577f27661 AST: Opened existential environments store outer substitutions 2024-08-20 16:54:51 -04:00
Slava Pestov
375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
Slava Pestov
1901862afc AST: Remove LookUpConformanceInSignature 2024-07-06 12:05:46 -04:00
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
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
Slava Pestov
b2ffac54d3 IRGen: Fulfill pack metadata from tuple metadata
When the SelfMetadata in a witness thunk is the tuple type (repeat each Self),
we can fulfill the pack shape and type metadata for Pack{repeat each Self}
from tuple metadata.

The length is trivially projected; the type metadata pack is slightly more
involved, because tuple metadata stores a list of element/offset pairs, so
we must stack allocate a pack and fill it in.
2023-08-24 17:57:10 -04:00
Slava Pestov
d09fd91826 IRGen: Remove unused parameter from emitPackExpansionPack() 2023-08-24 17:57:10 -04:00
Slava Pestov
59fd29551e IRGen: Emitting metadata for function types containing pack expansion parameters 2023-08-03 22:12:05 -04:00
Slava Pestov
8dfeeebeb5 IRGen: Support tuple labels in emitDynamicTupleTypeMetadataRef() 2023-07-27 13:39:52 -04:00
Slava Pestov
0ca01ccd61 IRGen: Replace some usages of mapPackTypeIntoElementContext() with mapContextualPackTypeIntoElementContext() 2023-07-12 18:02:14 -04: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
Nate Chandler
d1ec1e6693 [IRGen] Dealloc metadata packs on dom frontier.
Deallocate dynamic allocas done for metadata/wtable packs.  These
stackrestore calls are inserted on the dominance frontier and then stack
nesting is fixed up.  That was achieved as follows:

Added a new IRGen pass PackMetadataMarkerInserter; it
- determines if there are any instructions which might allocate on-stack
  pack metadata
- if there aren't, no changes are made
- if there are, alloc_pack_metadata just before instructions that could
  allocate pack metadata on the stack and dealloc_pack_metadata on the
  dominance frontier of those instructions
- fixup stack nesting

During IRGen, the allocations done for metadata/wtable packs are
recorded and IRGenSILFunction associates them with the instruction that
lowered.  It must be the instruction after some alloc_pack_metadata
instruction.  Then, when visiting the dealloc_pack_metadata instructions
corresponding to that alloc_pack_metadata, deallocate those packs.
2023-06-05 08:11:28 -07:00
Nate Chandler
db13477ec2 [IRGen] Skip metadata heapification on flag.
If the -enable-pack-metadata-stack-promotion[=true] flag is passed, skip
eager heapification.
2023-06-05 08:11:27 -07:00
Nate Chandler
0b5a233d73 [GenPack] Always heapify metadata packs.
Until the optimization to leave packs on-stack is in place.  Even then,
we'll want to keep this as a fallback.

rdar://110123679
2023-06-03 07:30:09 -07:00
Nate Chandler
c9f79861f1 [GenPack] NFC: Stack de/alloc traffics in shapes.
When allocating, the shape is computed, and it (its constant value if
any) is needed when deallocating, so return the shape along with the
address.  And when deallocating, accept the shape, which the client
received during allocation, rather than requiring that the caller
compute the fixed size.
2023-06-03 07:30:09 -07:00
Nate Chandler
6e7952b4ad [IRGen] Mask off metadata pack passed to DebugInfo
When a metadata pack is heap allocated, the pointer's LSB is set.
But lldb is expecting a real pointer.  So mask it off.

Companion PR has a test: https://github.com/apple/llvm-project/pull/6961

rdar://110195273
2023-06-03 07:30:09 -07:00
Slava Pestov
75cea742a5 IRGen: Unwrap one-element tuple metadata in emitDynamicTupleTypeMetadataRef()
This matches the static behavior of Type::subst() and the SIL optimizer.
2023-05-01 14:46:04 -04:00
Slava Pestov
a892b9196b IRGen: bindOpenedElementArchetypesAtIndex() should use bindGenericRequirement()
Fixes rdar://problem/107852985.
2023-04-20 22:05:34 -04:00
Slava Pestov
7ad2365278 AST: Introduce PackType::unwrapSingletonPackExpansion() 2023-04-02 23:04:00 -04:00
Slava Pestov
8563229c4a IRGen: Fix binding element archetypes when we have concrete pack conformances 2023-03-31 22:18:09 -04:00
Slava Pestov
fd6ff412c5 IRGen: Fix indexing into on-heap packs from emitTypeMetadataPackElementRef() 2023-03-24 13:05:37 -04:00
Slava Pestov
837075c9d5 IRGen: Use ConditionalDominanceScope in IRGen-generated control flow for pack iteration 2023-03-21 14:59:22 -04:00
John McCall
b5881d9c7d Merge pull request #64191 from rjmccall/bitcast-alloc-pack
Bitcast fixed-sized packs after allocating them.
2023-03-08 17:24:04 -05:00
John McCall
7236ece430 Bitcast fixed-sized packs after allocating them.
Clients expect a %swift.opaque**; without the cast, local GEPs will
go off into the weeds.
2023-03-08 11:26:19 -05:00
Slava Pestov
71e40317b3 AST: Remove PackArchetypeType::getSingletonPackType() 2023-03-07 23:19:25 -05:00
Slava Pestov
ec89cdff63 IRGen: Handle on-heap packs in bindMetadataAtIndex() and bindWitnessTableAtIndex() 2023-03-07 23:19:25 -05:00
Slava Pestov
f0ebda0018 IRGen: Add DynamicTupleTypeInfo to model TupleTypes with PackExpansionType elements
For now these are completely resilient blobs, which is wrong
because it prevents us from being able to model something like
(Int, repeat each T, String).

But one step at a time...
2023-03-07 23:19:25 -05:00
John McCall
dc477a0fd2 Merge pull request #64167 from rjmccall/variadic-results
Implement the caller side of return types containing variadic packs
2023-03-07 11:20:46 -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
db4b16e3dd [WIP] Always use PackTypes as the substitutions for type parameter packs
This simplifies the representation and allows clients to handle fewer
cases.  It also removes an ambiguity in the representation which could
lead us to have two canonical types for the same type.

This is definitely not working yet, but I'm not making progress on
it quickly enough to unblock what we need to unblock; it'll have to
be fixed in parallel.
2023-03-06 17:08:35 -08:00
Slava Pestov
37ceeb3981 IRGen: Cast fixed-size metadata and witness table packs to the correct pointer type 2023-03-04 10:42:42 -05:00
Slava Pestov
aa8f87a768 IRGen: Fix emitPackShapeExpression() with empty pack 2023-02-25 16:19:07 -05:00
John McCall
68df7e80b1 [NFC] Move this helper for opening pack expansions into the AST 2023-02-24 15:02:09 -05:00
Nate Chandler
8eb305883b [NFC] Pass calculated metadata along.
Don't make the witness table emission look up the cached metadata again.
2023-02-16 15:29:45 -08:00
Nate Chandler
6378efee04 [IRGen] Bound all reqs of open_pack_element.
Previously, only the element archetypes that corresponded to the
relevant pack generic parameters were bound, and the wtables that were
bound for them were based on looking up what they conform to.  Here, the
requirements of the generic signature are used to find which archetypes
must be bound to metadata and which conformances must be bound to
wtables.
2023-02-16 15:29:45 -08:00
Nate Chandler
c8d57c86fe [NFC] Simplified transient helper type.
Just use the opened element environment for all substitutions rather
than keeping the outer environment around.
2023-02-16 13:32:04 -08:00
Nate Chandler
29a62aabe6 [Gardening] Fixed comment grammar. 2023-02-16 13:30:09 -08:00
Nate Chandler
befd0bc17e [GenPack] Emit all element signature requirements.
Enumerate the requirements of opened element signature and emit metadata
and witness tables for each *Pack requirement.
2023-02-14 20:54:05 -08:00
Nate Chandler
f707f70c93 [NFC] Tweaked GenPack organization.
Moved a few static helpers to the top.
2023-02-10 18:13:23 -08:00
Nate Chandler
5cb91af1c0 [IRGen] Forwarded wtable packs when possible.
Previously wtable packs were never forwarded because pack types
consisting of a single element which was itself a pack archetype were
never canonicalized into that.

In the forwarding scenario, gepped and loaded from wtable when lowering
open_pack_element.
2023-02-10 18:13:21 -08:00
Nate Chandler
da5b5c1ea5 [IRGen] Lowered de/alloc_pack. 2023-02-09 07:24:01 -08:00
Nate Chandler
58954ab405 [IRGen] Added getPackElementSize. 2023-02-07 20:51:03 -08:00