Commit Graph

314 Commits

Author SHA1 Message Date
Slava Pestov
244d2afea3 RequirementMachine: New way of propagating failure when building rewrite system for protocol
If we failed to construct a rewrite system for a protocol, either because
the Knuth-Bendix algorithm failed or because of a request cycle while
resolving requirements, we would end up in a situation where the resulting
rewrite system didn't include all conformance requirements and associated
types, so name lookup would find declarations whose interface types are
not valid type parameters.

Fix this by propagating failure better and just doing nothing in
getReducedTypeParameter().

Fixes rdar://147277543.
2025-10-04 09:17:46 -04:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01: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
bf3f4a6d79 AST: Fix lost GenericSignatureErrors in getPlaceholderRequirementSignature() 2025-06-17 17:51:25 -04:00
Joe Groff
22eb7e62d9 SILGen: Emit property descriptors for conditionally Copyable and Escapable types.
Key paths can't reference non-escapable or non-copyable storage declarations,
so we don't need to refer to them resiliently, and can elide their property
descriptors.

However, declarations may still be conditionally Copyable and Escapable, and
if so, then they still need a property descriptor for resilient key path
references. When a property or subscript can be used in a context where it
is fully Copyable and Escapable, emit the property descriptor in a generic
environment constrained by the necessary conditional constraints.

Fixes rdar://151628396.
2025-05-27 09:35:40 -07: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
Hamish Knight
bdd74e717e [AST] Remove redundant logging in validateGenericSignature
We already setup a PrettyStackTrace to include the generic signature
on a crash.
2025-05-19 20:55:01 +01:00
Slava Pestov
fa3d8c520b AST: Compare weight before length in swift::compareDependentTypes() 2025-04-29 13:55:30 -04:00
Doug Gregor
92774e0a3c Move generic signature check for isolated conformances into GenericSignatureImpl
This is going to need a proper implementation in the requirement
machine. For the moment, provide a slightly-less-broken implementation
but leave a test case where we incorrectly accept racey code.
2025-04-13 15:40:02 -07:00
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