Commit Graph

209 Commits

Author SHA1 Message Date
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
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