Commit Graph

199 Commits

Author SHA1 Message Date
Slava Pestov
ec0dfc8716 AST: Add new form of SubstitutionMap::getProtocolSubstitutions() 2025-04-03 17:35:33 -04:00
Slava Pestov
a209ff8869 AST: Remove origType parameter from ProtocolConformanceRef::subst() 2025-04-03 17:35:33 -04:00
Slava Pestov
26543d1242 AST: Preserve sugar in getIdentitySubstitutionMap()
We implement getIdentitySubstitutionMap() by passing in
a no-op substitution callback. Remove the unnecessary
getCanonicalType() call, to ensure that the abstract
conformance in the identity substitution map uses the
sugared form of the subject type.
2025-04-03 17:35:33 -04:00
Slava Pestov
75c8a16bce AST: Don't need to pass down the options here 2025-03-31 23:11:21 -04:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Slava Pestov
b70c76233e AST: Workaround for rdar://139469939
This unconditional assert was added recently so it started failing in
noassert toolchains. I'll have a proper fix soon.
2024-11-21 15:24:35 -05:00
Slava Pestov
47156e006b AST: Introduce ProtocolConformanceRef::forAbstract() 2024-11-16 16:16:06 -05:00
Slava Pestov
8d05362f89 AST: Simplify some lookupConformance() callers 2024-11-16 16:16:06 -05:00
Slava Pestov
080f3d2950 AST: Fix up SubstitutionMap::verify() 2024-11-15 17:27:25 -05:00
Alejandro Alonso
45d7ea39a5 Merge pull request #75518 from Azoy/integer-generics
Implement Value generics
2024-09-05 15:33:46 -07:00
Alejandro Alonso
f4f60f4344 Remove Value requirement Add GenericTypeParamKind 2024-09-04 15:13:43 -07: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
b1e0e776b4 AST: Simplify SubstitutionMap::lookupConformance() 2024-09-04 14:57:38 -04:00
Slava Pestov
7e4e79c69f AST: Simplify SubstitutionMap::get() 2024-09-04 14:57:38 -04:00
Slava Pestov
e520a325bb AST: Generalize GenericEnvironment::maybeApplyOuterSubstitutions() 2024-09-02 22:50:44 -04:00
Slava Pestov
43c7310288 SILOptimizer: Move combineSubstitutionMaps() to Devirtualize.cpp 2024-08-29 16:18:14 -04:00
Slava Pestov
a275780bdb AST: Simplify SubstitutionMap::lookupSubstitution() 2024-08-23 16:45:03 -04:00
Slava Pestov
da4d076f02 AST: Introduce SubstFlags::SubstitutePrimaryArchetypes 2024-08-22 18:41:14 -04:00
Slava Pestov
ae77d6f0c1 AST: Replace one-off predicates with SubstitutionMap::getRecursiveProperties() 2024-08-21 13:19:10 -04:00
Slava Pestov
b601c294ac AST: Replace remaining uses of Type::transform() with transformRec() 2024-08-12 16:05:43 -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
eca5a1c342 AST: Optimize getContextSubstitutionMap() 2024-07-10 13:28:26 -04:00
Slava Pestov
26fffae30a AST: Simplify SubstitutionMap representation
There was a bunch of logic to lazily populate replacement types
corresponding to reducible generic parameters. This didn't seem
to have a clear purpose so let's remove it.
2024-07-10 13:28:26 -04:00
Slava Pestov
86d567f95a AST: ModuleDecl::lookupConformance() is a static method 2024-07-06 12:05:47 -04:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 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
Slava Pestov
77f948671c AST: Add SubstitutionMap::hasOpaqueArchetypes() 2024-05-14 13:50:35 -04:00
Slava Pestov
818f47918c AST: Use getNextDepth()/getMaxDepth() 2024-05-01 12:09:01 -04:00
Slava Pestov
69f71129b7 AST: Fix latent bug in SubstitutionMap::lookupConformance()
We should check if the type parameter actually conforms to our
protocol before we do the global lookup, otherwise we might
return an abstract conformance instead of an invalid conformance.

I don't know if there's any way to exercise this today though.
2024-04-02 19:55:02 -04:00
Kavon Farvardin
6cd5468cce adjust infinite type substitution workaround
resolves rdar://124697829

Co-authored-by: Slava Pestov <spestov@apple.com>
2024-03-25 20:20:22 -07: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
Slava Pestov
af3ab14986 SILGen: Clean up substitution map construction to deal with Copyable 2024-01-31 21:55:52 -05:00
Slava Pestov
979fc28461 AST: Remove ProtocolConformanceState::CheckingTypeWitnesses 2024-01-24 21:45:34 -05:00
Slava Pestov
28d1455373 AST: Re-implement associated conformance storage in preparation for AssociatedConformanceRequest 2023-10-11 15:04:09 -04:00
Slava Pestov
1646085ba7 AST: Replace SubstitutionMap::hasOpenedExistential() with SubstitutionMap::hasLocalArchetypes() and actually use it 2023-06-29 14:54:27 -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
Slava Pestov
36b3d3a5ca AST: Handle PackConformance in SubstitutionMap::lookupConformance() 2023-06-07 15:17:54 -04:00
Slava Pestov
be218f5e16 AST: Use PackElementType to model references to pack elements of outer expansions 2023-06-06 14:18:37 -04:00
Slava Pestov
4f42c553cd AST: Fix two problems in SubstitutionMap::get(GenericSignature, SubstitutionMap)
It's fine to have the empty generic signature and non-empty
substitution map here. Also, correctly handle an input
generic signature with non-canonical generic parameter types.
2023-06-01 22:36:24 -04:00
Slava Pestov
2705ecaa06 AST: More accurate SubstitutionMap::isIdentity() 2023-04-12 15:44:54 -04:00
John McCall
4edfd79fc9 [NFC] Add a convenience function to IFS 2023-03-25 18:54:14 -04:00
John McCall
80551ce8ad [NFC] Thread a common type through all the AST substitution code.
There are a lot of problems caused by our highly-abstract substitution
subsystem.  Most of them would be solved by a more semantic / holistic
understanding of the active transformation, but that's difficult to do
because we just pass around function_refs.  The first step in fixing
that is to pass around a better currency type.  For now, it can just
hold the function_refs (and the SubstOptions).

I've set it up so that the places that just apply SubstitutionMaps
are constructing the IFS in a standard way; that should make it easy
to change those places in the future.
2023-03-25 18:54:14 -04:00
John McCall
91acf1dd2e Assert if SubstitutionMap::subst tries to replace a non-pack with a pack 2023-03-17 15:35:41 -04: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
John McCall
2169743c65 Test that SIL inlining works for the new variadic generics instructions
I had a fix a bunch of bugs in this, which isn't very surprising.

I changed remapSubstitutionMap to preserve the non-canonical signature
of the substitutions because otherwise it messes up printing
open_pack_element pretty badly --- we end up printing a sugared shape
class but a desugared generic signature.  I'd rather not eagerly
canonicalize everything there because the sugar is quite nice.
Still, I don't feel great about this approach, and this is the
second time I've found myself doing something a little gross in order
to preserve sugar for printing this instruction.

Canonicalizing the replacement types is important for test stability,
and I think it's good downstream.

The most interesting part of this is that I implemented a rule which
handles tuple types becoming scalar as part of the substitution of
tuple_pack_element_addr.  We talked about having this rule in the
formal type system, and I thought we were going to do it, but it
looks like we haven't actually implemented that yet.  I added it to
SIL substitution because (1) I anticipate we'll be doing this
eventually in the formal type system, and that will have consequences
for SIL, and (2) we don't actually have a way to parse these singleton
tuple types, and I didn't want expanding singleton packs into tuples
to become this weird untestable corner case.  I did have to poke a
hole in this rule to preserve types that were singleton tuples before
substitution, since apparently AutoDiff makes a lot of those.

I think adding a type_refine_addr that statically asserts a type
match is the right way to go in the long term for rewriting
singleton tuple_pack_element_addr, but I'm a little sick of adding
SIL instructions, so we just rewrite to unchecked_addr_cast for now.
2023-02-10 14:58:37 -05:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Holly Borla
9bb837a241 [AST] Rename SequenceArchetype to PackArchetype. 2022-10-10 16:25:26 -07:00
Slava Pestov
3b03a5ed9d AST: Work around shortcoming in abstract conformance representation when computing override substitutions
Fixes rdar://problem/98404650.
2022-08-29 21:57:01 -04:00