Commit Graph

305 Commits

Author SHA1 Message Date
Slava Pestov
69e3aaf6fe AST: Add workaround for incorrect mangling of conditional conformances with pack requirements
I added commit 7eecf97132 a while ago
to fix a newly-added assertion failure that came up, however this
had the inadvertent side effect of changing symbol mangling and
ASTPrinter behavior.

The problem in both instances was that we would incorrectly return
certain requirements as unsatisfied when really they are satisfied.

There is nothing to fix in the ASTPrinter, because printing redundant
requirements does not change the generic signature of the extension;
they are simply dropped. I added a test to exercise the new behavior
showing that the requirements are dropped.

As for the mangler, the fix introduced an ABI break, because the
symbol name of a conformance descriptor includes its conditional
requirements, so we must preserve the redundant requirements forever.
The IRGen test has some examples of manglings that are incorrect but
must be preserved.

I'm plumbing down a flag to isRequirementSatified() to preserve
compatibility with the old behavior where we would mangle these
redundant requirements. No other callers should pass this flag,
except for the mangler.

Fixes rdar://139089004.
2024-11-07 16:28:26 -05:00
Slava Pestov
e95ff011b3 AST: Fix invariant violation in swift::validateGenericSignature()
This is a silly "extended" verification check that we only exercise
in test/Generics/validate_stdlib_generic_signatures.swift.

We were taking a requirement containing unbound dependent member types
and applying a substitution map to it, which would result in an
ErrorType, so the requirement was always considered unsatisfied here
and the check was not as useful as it should have been.

Instead, re-implement a version of isRequirementSatisfied() that only
uses generic signature queries instead of substitution here.
2024-09-20 10:06:29 -04:00
Slava Pestov
7eecf97132 AST: Fix latent bug with GenericSignatureImpl::isRequirementSatisfied() 2024-09-19 14:18:34 -04:00
Slava Pestov
08bb0017f5 AST: Add GenericSignatureImpl::getReducedTypeParameter()
This avoids a bit of indirection when the input is already known to be
a type parameter, and not just a type that contains type parameters.
2024-09-13 15:19:48 -04:00
Slava Pestov
be9d999e64 AST: Simplify GenericSignature::getLocalRequirements() 2024-09-13 15:19:48 -04:00
Slava Pestov
2c1297e5a2 AST: Simplify GenericSignatureImpl::isRequirementSatisfied() 2024-09-12 11:49:01 -04: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
b601c294ac AST: Replace remaining uses of Type::transform() with transformRec() 2024-08-12 16:05:43 -04:00
Sima Nerush
1ba38c54f2 [Requirement Machine] When forming requirements from same-element rewrite rules, swap the sides depending on which one is longer once the [element] symbol is dropped.
This change fixes the "out-of-order" type parameters error in `GenericSignature::verify`
2024-07-15 10:19:32 -07:00
Holly Borla
0b6f8c8bd0 [Requirement Machine] Fix the order of requirements that involve pack elements. 2024-07-15 10:19:32 -07:00
Holly Borla
2ea4586580 [Requirement Machine] Implement same-element requirements. 2024-07-15 10:19:32 -07:00
Slava Pestov
1901862afc AST: Remove LookUpConformanceInSignature 2024-07-06 12:05:46 -04:00
Joe Groff
179a1253a7 Merge pull request #74604 from jckarter/conformance-descriptor-invertible-conditional-requirements
IRGen: Don't encode conditional requirements to Copyable as normal conformance requirements.
2024-06-24 07:37:33 -07:00
Joe Groff
73e4c6fecd IRGen: Don't encode conditional requirements to Copyable as normal conformance requirements.
For new runtimes, this is redundant with the invertible requirement encoding, and for
old runtimes, this breaks dynamic conformance checking because Copyable and Escapable
aren't real protocols on those older runtimes. Fixes rdar://129857284.
2024-06-20 19:01:03 -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
Slava Pestov
818f47918c AST: Use getNextDepth()/getMaxDepth() 2024-05-01 12:09:01 -04:00
Slava Pestov
cb66dabc8c AST: Add getNextDepth() and getMaxDepth() methods to GenericSignature 2024-05-01 12:08:40 -04:00
Doug Gregor
79b78acdf6 Use SuppressibleProtocolSet as InvertibleProtocolSet
Collapse the representations of "suppressible" and "invertible"
protocol sets. Only minor adjustments were required.
2024-03-29 11:31:48 -07:00
Kavon Farvardin
149c052ec5 use new noncopyable types infrastructure
The infrastructure underpinning the new feature NoncopyableGenerics is
mature enough to be used.
2024-03-14 23:10:44 -07:00
Slava Pestov
4a1b0c80cd RequirementMachine: Install placeholder requirement signature if completion fails
I did this if there was a request cycle but forgot the other obvious case.
2024-02-29 18:13:28 -05:00
Slava Pestov
0e31d41072 AST: Move GenericSignature::typeErased() to SIL
This is used by the specializer and belongs at the SIL level.
2024-02-24 07:25:59 -05:00
Slava Pestov
f9ed50ebac AST: More detailed error message from GenericSignature::verify() 2024-02-24 07:25:59 -05:00
Kavon Farvardin
08b71e0136 NCGenerics: rebuild stdlib from its interface
When a NoncopyableGenericsMismatch happens between the compiler and
stdlib, allow the compiler to rebuild the stdlib from its interface
instead of exiting with an error.
2024-02-15 18:08:54 -08:00
Kavon Farvardin
485a7822b3 NFC: improve GeneriSignature::verify error output 2024-02-15 10:45:18 -08:00
Slava Pestov
af50d7e6b8 AST: Add allowInverses flag to AbstractGenericSignatureRequest 2024-02-05 18:43:06 -05:00
Slava Pestov
8092f18772 AST: Generalize GenericSignatureImpl::getUpperBound()
Handle inverses, and add a couple of flags (yuck!) to allow its
usage in diagnostics and code completion.
2024-02-01 23:35:33 -05:00
Slava Pestov
23b1690f6b ASTPrinter: Refactor printing of RequirementSignatures 2024-01-31 21:55:52 -05:00
Slava Pestov
6ed553da59 AST: Introduce GenericSignature::getRequirementsWithInverses() 2024-01-31 18:40:35 -05:00
Dario Rexin
06b92719c1 [SILOpt] Represent _TrivialStride pre-specializations with vector types (#70938)
rdar://121071710

Currently it uses builtin integers, which round up to the next power of 2, which is not what we want here. Instead it should use builtin vectors of uint8 and a number of elements equal to the stride in bytes.
2024-01-16 16:13:19 -08:00
Dario Rexin
36dd2c9450 [SilOpt] Add new layout type _TrivialStride and add pre-specialization suppport for it (#70308)
rdar://119329771

This layout allows adding pre-specializations for trivial types that have a different size, but the same stride. This is especially useful for collections, where the stride is the important factor.
2023-12-09 08:13:50 -08:00
Dario Rexin
406fe3eed2 [SILOpt] Allow pre-specializations for _Trivial of known size (#70256)
* [SILOpt] Allow pre-specializations for _Trivial of known size

rdar://119224542

This allows pre-specializations to be generated and applied for trivial types of a shared size.
2023-12-08 19:42:49 -08:00
Dario Rexin
df35f3327d [SilOpt] Add new layout _BridgeObject and add pre-specialization support for it (#70239)
rdar://119048001
2023-12-08 14:34:16 -08:00
Sima Nerush
b6d0afba1f Merge pull request #67594 from simanerush/simanerush/pack-iteration-impl
[SE-0408] Enable Pack Iteration
2023-12-07 17:09:48 -08:00
Dario Rexin
564d284d40 [AST] Use buildGenericSignature in GenericSignature::typeErased (#70276)
Previously this used GenericSignature::get, which is not appropriate to use here.
2023-12-06 20:59:48 -08:00
Holly Borla
48cb3309bd [Constraint System] Fix the shape class and context substitiutions for
opened element generic environments containing same-element requirements.
2023-12-03 21:51:41 -08:00
Slava Pestov
f5e250551d AST: Merge GenericSignature::get{Non,}DependentUpperBounds() 2023-11-27 14:05:36 -05:00
Evan Wilde
309aed4925 Add SmallSetVector replacement
llvm::SmallSetVector changed semantics
(https://reviews.llvm.org/D152497) resulting in build failures in Swift.
The old semantics allowed usage of types that did not have an
`operator==` because `SmallDenseSet` uses `DenseSetInfo<T>::isEqual` to
determine equality. The new implementation switched to using
`std::find`, which internally uses `operator==`. This type is used
pretty frequently with `swift::Type`, which intentionally deletes
`operator==` as it is not the canonical type and therefore cannot be
compared in normal circumstances.

This patch adds a new type-alias to the Swift namespace that provides
the old semantic behavior for `SmallSetVector`. I've also gone through
and replaced usages of `llvm::SmallSetVector` with the
`Swift::SmallSetVector` in places where we're storing a type that
doesn't implement or explicitly deletes `operator==`. The changes to
`llvm::SmallSetVector` should improve compile-time performance, so I
left the `llvm::SmallSetVector` where possible.
2023-07-25 12:28:27 -07:00
Holly Borla
79c4cfbf8b [NFC] Replace a few calls to TypeBase::isParameterPack() with isRootParameterPack(). 2023-07-20 15:29:53 -07:00
Slava Pestov
8afff61699 AST: Replace TypeArrayView<GenericTypeParamType> with ArrayRef<GenericTypeParamType *>
This basically undoes 3da6fe9c0d, which in hindsight was wrong.

There were no other usages of TypeArrayView anywhere else except for
GenericSignature::getGenericParams(), and it was almost never what
you want, so callers had to convert back and forth to an ArrayRef.
Remove it.
2023-06-29 19:23:44 -04:00
Angela Laar
a92deb070d [GenericSignature] Exclude GenericParam Constraints
Only preserve primary associated types during type erasure if the
generic context does not contain outer generic prameters.

i.e.

  Given `func foo {  ... any P <Int> ... }` getNonDependentUpperBounds()
  should produce any P<Int>

  However, given `func foo<T> { ... any P<T> ... }` getNonDependentUpperBounds()
  should produce any P

Fixes rdar://110262754
2023-06-22 14:15:41 -07:00
Angela Laar
a9f1096839 [Generic Signature] Unify generic upper bound functions
Opened existentials should be erased to the dependent upper bound
if the dependent member can be reduced to a concrete type. This
allows the generic signature to support parameterized protocol types
and bound generic class types by producing a more specific constraint
instead of just a plain protocol or class.
2023-05-17 15:33:50 -07:00
Angela Laar
5c818b3fd4 [Constraint System] Fix covariant erasure for constrained existentials
Constrained existentials should be type erased to an upper bound that is dependent on other type parameters.
2023-05-15 16:17:59 -07:00
Alex Hoppen
1eadffcc00 [CodeCompletion] Don’t crash when completing in a parameter position that only constraints one of two primary associated protocol types
When completing, we call `getExistentialType` on the contextual type to get a nice and concise description of the contextual parameter’s type that doesn’t contain archetypes and which we can also serialize into a USR so we are able to calculate type relations for code completion results from the code completion cache.

When completing in a position that has a contextual type which only constrains one of two primary associated protocol types, this fails because `getExistentialType` (which calls `getDependentUpperBounds`) tries to form a `ParameterizedProtocolType`, which fails since not all primary associated types have been constrained.

AFAICT the fix here is to just fall back to the default behavior of returning the plain protocol type instead of `abort`ing.

rdar://108835466
2023-05-10 16:38:30 -07:00
Slava Pestov
b6b51cf4cf AST: Checking of pack requirements 2023-03-17 22:18:55 -04:00
Slava Pestov
d27231a91c AST: Generalize Requirement::isSatisfied() to Requirement::checkRequirement() 2023-03-17 22:18:55 -04:00
Slava Pestov
a5cf7d3298 RequirementMachine: The reduced type of a PackExpansionType has a reduced *shape* for the count type
I don't have a test case for this but it was bound to
come up eventually.
2023-03-15 23:04:50 -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
Slava Pestov
8af5bbedc3 AST: Factor out GenericSignatureImpl::getShapeClasses() 2023-03-03 14:16:54 -05:00
Slava Pestov
70dec2b909 AST: Split off Requirement.cpp from GenericSignature.cpp 2022-11-12 02:13:54 -05:00