Commit Graph

52 Commits

Author SHA1 Message Date
Elsa Keirouz 16f5b6cf00 BorrowingForLoop: check availability of Protocol and Conformance 2026-03-25 09:51:53 +00:00
Elsa Keirouz 0c2fa1f2c2 DesugarForEachStmt: custom error for unavailable sequence conformance 2026-03-17 11:27:21 +00:00
Slava Pestov 64f2d1acce AST: Rename mapConformanceOutOfContext() => mapConformanceOutOfEnvironment(), mapReplacementTypesOutOfContext() => subs.mapReplacementTypesOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Slava Pestov 819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Slava Pestov 1731b09a88 AST: Don't return null Type() from getTypeWitness() 2025-10-03 14:24:10 -04:00
Slava Pestov ee440f3c91 AST: Remove MakeAbstractConformanceForGenericType
While the intent behind this functor was noble, it has grown in complexity
considerably over the years, and it seems to be nothing but a source of
crashes in practice. I don't want to deal with it anymore, so I've decided
to just subsume all usages with LookUpConformanceInModule instead.
2025-07-15 16:34:11 -04:00
Slava Pestov 0b961c6139 AST: Clean up InFlightSubstitution::lookupConformance()
The special handling of DynamicSelfType should no longer be necessary
so I'm removing it.
2025-04-28 13:48:24 -04:00
Slava Pestov cea72e35a9 AST: Remove ProtocolConformanceRef::getAssociatedType() 2025-04-03 17:35:34 -04:00
Slava Pestov ec0dfc8716 AST: Add new form of SubstitutionMap::getProtocolSubstitutions() 2025-04-03 17:35:33 -04:00
Slava Pestov 0616333129 AST: Remove origType parameter from ProtocolConformanceRef::getAssociatedType() 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 7399eeb602 AST: Remove type parameter from ProtocolConformanceRef::getWitnessByName() 2025-04-03 17:35:33 -04:00
Slava Pestov 00766f7deb AST: Remove type parameter from ProtocolConformanceRef::getTypeWitnessByName() 2025-04-03 17:35:32 -04:00
Slava Pestov 91503710bc AST: Remove origType parameter from ProtocolConformanceRef::getTypeWitness() 2025-04-03 17:35:32 -04:00
Slava Pestov 8b1514cfd7 AST: Remove origType parameter from ProtocolConformanceRef::getAssociatedConformance() 2025-04-03 17:35:32 -04:00
Allan Shortlidge b6cf794bb8 AST: Fix some -Wunused-but-set-variable warnings. 2025-04-01 13:11:36 -07:00
Slava Pestov b53b770a2f AST: Fix wrong subject type in ProtocolConformanceRef::getAssociatedConformance() 2025-03-31 17:36:16 -04:00
Slava Pestov 4433fe38da AST: Handle new abstract conformances in ProtocolConformanceRef::mapConformanceOutOfContext() 2025-03-31 17:35:44 -04:00
Slava Pestov ce3f6e00e8 AST: Use correct functor in ProtocolConformanceRef::mapConformanceOutOfContext() 2025-03-31 17:35:44 -04:00
Slava Pestov 151b1f1873 AST: Handle new abstract conformances in ProtocolConformanceRef::subst() 2025-03-31 17:35:44 -04:00
Slava Pestov cc05e1e79a AST: Check subject type in ProtocolConformanceRef::forAbstract() 2025-03-26 12:29:35 -04:00
Doug Gregor 731f58443c Address review feedback on AbstractConformance in ProtocolConformanceRef 2025-03-23 20:54:39 -07:00
Doug Gregor 2a7de1b559 Store the conforming type within an abstract ProtocolConformanceRef
An "abstract" ProtocolConformanceRef is a conformance of a type
parameter or archetype to a given protocol. Previously, we would only
store the protocol requirement itself---but not track the actual
conforming type, requiring clients of ProtocolConformanceRef to keep
track of this information separately.

Record the conforming type as part of an abstract ProtocolConformanceRef,
so that clients will be able to recover it later. This is handled by a uniqued
AbstractConformance structure, so that ProtocolConformanceRef itself stays one
pointer.

There remain a small number of places where we create an abstract
ProtocolConformanceRef with a null type. We'll want to chip away at
those and establish some stronger invariants on the abstract conformance
in the future.
2025-03-23 20:53:48 -07:00
Slava Pestov efbeaea969 AST: Always-on ASSERTs for ProtocolConformanceRef
If any of the get*() methods are called on the wrong kind of
ProtocolConformanceRef, we immediately cast a pointer to an
incorrect type, which will most likely cause a crash.
2025-03-18 19:38:20 -04:00
Doug Gregor ffca6968ed [Isolated conformances] Diagnose conflict with isolated conformances and Sendable 2025-02-28 13:08:35 -08:00
Allan Shortlidge d0f63a0753 AST: Split Availability.h into multiple headers.
Put AvailabilityRange into its own header with very few dependencies so that it
can be included freely in other headers that need to use it as a complete type.

NFC.
2025-01-03 18:36:04 -08:00
Allan Shortlidge 1dc7aa5b7b AST: Introduce Decl::isUnavailable().
Replace calls to `AvailableAttr::isUnavailable()` with `Decl::isUnavailable()`.
2024-12-02 07:35:58 -08:00
Slava Pestov 47156e006b AST: Introduce ProtocolConformanceRef::forAbstract() 2024-11-16 16:16:06 -05:00
Slava Pestov 9afff03a1a AST: Re-implement ProtocolConformanceRef::getAssociatedConformance() as a primitive 2024-09-19 14:18:34 -04:00
Slava Pestov a911693c8c AST: PackConformance::getAssociatedType() => getTypeWitness() 2024-09-19 14:18:34 -04:00
Slava Pestov 6928588dba AST: Gut ProtocolConformanceRef::getAssociatedType() 2024-09-19 14:18:34 -04:00
Slava Pestov afbd81a599 AST/Sema: Use ProtocolConformanceRef::getTypeWitness() 2024-09-19 14:18:33 -04:00
Slava Pestov 508dacc3a2 AST: Add ProtocolConformanceRef::getTypeWitness() 2024-09-19 14:18:33 -04:00
Slava Pestov a8ed7ba61d AST: Allow ProtocolConformanceRef::getAssociatedType() with invalid conformance 2024-09-19 14:18:32 -04:00
Slava Pestov da4d076f02 AST: Introduce SubstFlags::SubstitutePrimaryArchetypes 2024-08-22 18:41:14 -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 c321b337ba SIL: Fix crash with missing existential Sendable conformance
If a protocol does not inherit Sendable, we still say that the
existential type is Sendable in Swift 5 mode. Make sure this
doesn't crash the SIL specializer.

Fixes https://github.com/swiftlang/swift/issues/75728
2024-08-08 16:17:16 -04:00
Holly Borla e2ddc6c6c2 [ProtocolConformance] Compute the correct un-availability for inherited
conformances.
2024-07-12 14:58:49 -07: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
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
Slava Pestov e9bdadef74 AST: Remove unused method 2024-01-20 17:43:01 -05:00
Kavon Farvardin bb78171767 [NFC] forEachMissingConformance doesn't use module 2024-01-10 19:39:07 -08:00
Kavon Farvardin e0412269fd [NCGenerics] infinite substitution hack
Workaround for rdar://119950540 when dealing with invertible protocols.

This should be sound because "its an invariant that subst() on a
conformance returns the same thing as a global lookup with subst() of
the conforming type, assuming you don't have overlapping conformances."
2024-01-10 19:37:21 -08:00
Slava Pestov eefa409656 AST: Change return type of ProtocolConformance::subst() to ProtocolConformanceRef 2023-09-08 15:56:30 -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
Slava Pestov be218f5e16 AST: Use PackElementType to model references to pack elements of outer expansions 2023-06-06 14:18:37 -04:00
Pavel Yaskevich fe8fd91307 [AST] NFC: Fold PackConformance::isInvalid into ProtocolConformanceRef::isInvalid
Instead of making callers responsible for that (like in other cases),
let's fold the code check `isInvalid` to make mistakes less likely.
2023-05-26 08:53:11 -07: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
Slava Pestov a355c38a34 AST: Rename ProtocolConformance::getSubstitutions() to getSubstitutionMap() and remove ModuleDecl parameter 2023-03-21 16:16:34 -04:00