218 Commits

Author SHA1 Message Date
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
12ce32ef09 AST: Early return from substOpaqueTypesWithUnderlyingTypes() overloads if nothing to do 2025-10-23 15:36:53 -04:00
Hamish Knight
954b08cae5 [AST] Remove UnresolvedType
We have now removed all uses of this type.
2025-10-03 09:50:42 +01:00
Slava Pestov
672135b053 AST: Remove old hack that appears to be obsolete
The FIXME was originally introduced in 2017 by commit c0805a2bc8.

Good riddance!
2025-08-28 16:51:49 -04:00
Slava Pestov
bf95643dca AST: Add a FIXME 2025-07-24 12:55:47 -04:00
Slava Pestov
8d05d79fad AST: Cache substituted substitution maps inside the InFlightSubstitution
A substitution map contains conformances, and a conformance can contain
a substitution map. This will always be a DAG, but not a tree, and to
avoid exponential blowup in certain edge cases, let's cache the work to
avoid visiting the same substitution map repeatedly, if multiple
conformances refer to the same substitution map.
2025-07-18 20:03:03 -04:00
Slava Pestov
103428fe80 AST: More robust recursion check for opaque types with infinite underlying types
Tracking seen declarations and substitution maps only detects the
situation where the opaque type's underlying type contains itself
with the same substitution map. However, it is also possible to
recurse with a different substitution map.

In general termination is undecidable with a problem like this,
so instead of trying to catch cycles, just impose a termination
limit.

This converts a stack overflow into an assertion, which is still
not ideal; we should really diagnose something instead. But this
is a first step.
2025-07-18 20:03:03 -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
Hamish Knight
edca7c85ad Adopt ABORT throughout the compiler
Convert a bunch of places where we're dumping to stderr and calling
`abort` over to using `ABORT` such that the message gets printed to
the pretty stack trace. This ensures it gets picked up by
CrashReporter.
2025-05-19 20:55:01 +01:00
Slava Pestov
52afa15a74 AST: Fix two bugs with SelfProtocolConformance
There were two problems that have been there for years:

- SubstitutionMap::lookupConformance() assumes that every concrete conformance
  in the path has a root normal conformance. But calling getRootNormalConformance()
  on a self conformance would assert.

- SelfProtocolConformance::getAssociatedConformance() was not implemented. While
  self-conforming protocols do not have associated types, they can inherit from
  other protocols, and we model this with an associated conformance requirement
  having a subject type of `Self`.

Both problems were hidden by the fact that ProtocolConformanceRef::subst()
directly handled self-conforming existentials without calling into the
substitution map. But that is the wrong place for other reasons. The refactoring
in a209ff8869 exposed both of the above issues.

Fixes rdar://problem/151162470.
2025-05-14 23:34:53 -04:00
Slava Pestov
e3c8f423bc AST: Clean up SubstitutionMap::lookupConformance() a bit
The abstract conformance hack is no longer necessary, so now all of the
cases can all be handled by ProtocolConformanceRef::getAssociatedConformance(),
without having to dispatch on the conformance kind.
2025-04-30 13:42:20 -04:00
Slava Pestov
6ffa8fd489 AST: Change signature of LookupConformanceFn
Instead of passing in the substituted type, we pass in the
InFlightSubstitution. This allows the substituted type to be
recovered if needed, but we can now skip computing it for
the common case of LookUpConformanceInSubstitutionMap.
2025-04-30 13:42:20 -04:00
Slava Pestov
2746a83109 Merge pull request #81181 from slavapestov/fix-issue-79763
AST: Fix existential erasure of long member types
2025-04-30 13:33:56 -04:00
Slava Pestov
6b4710ed22 Merge pull request #81142 from slavapestov/more-type-subst-cleanup
Clean up duplicated opened existential archetype handling in SIL and more
2025-04-30 02:42:57 -04:00
Slava Pestov
d2b0bf002a AST: Fix existential erasure of long member types
Suppose protocol P has a primary associated type A, and we have
a `any P<S>` value. We form the generalization signature <T>
with substitution map {T := S}, and the existential signature
<T, Self where T == Self.A>.

Now, if we call a protocol requirement that takes Self.A.A.A,
we see this is fixed concrete type, because the reduced type of
Self.A.A.A is T.A.A in the existential signature.

However, this type parameter is not formed from the
conformance requirements of the generalization signature
(there aren't any), so we cannot directly apply the outer
substitution map.

Instead, change the outer substitution conformance lookup
callback to check if the reduced type parameter is valid
in the generalization signature, and not just rooted in a
generic parameter of the generalization signature.

If it isn't, fall back to global conformance lookup.

A better fix would introduce new requirements into the
generalization signature to handle this, or store them
separately in the generic environment itself. But this is fine
for now.

- Fixes https://github.com/swiftlang/swift/issues/79763.
- Fixes rdar://problem/146111083.
2025-04-29 18:58:58 -04:00
Slava Pestov
115ba5c54f AST: Factor out GenericTypeParamType::withDepth() 2025-04-29 13:55:29 -04:00
Slava Pestov
2fa49b0458 AST: SubstitutionMap overload of substOpaqueTypesWithUnderlyingTypes()
This replaces the oddly-named mapIntoTypeExpansionContext() method
on SubstitutionMap itself in favor of a global function, just like
the ones that take Type and ProtocolConformanceRef.
2025-04-28 13:48:35 -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
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