Commit Graph

310 Commits

Author SHA1 Message Date
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
Slava Pestov
532d097779 AST: Implement Requirement::isSatisfied() for SameShape requirements 2022-11-12 02:13:54 -05:00
Slava Pestov
f632363a18 AST: Clean up GenericSignatureImpl::getNonDependentUpperBounds() 2022-11-07 18:38:03 -05:00
Slava Pestov
7ffbf58c55 AST: Add GenericSignatureImpl::getDependentUpperBounds() 2022-11-07 18:38:00 -05:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Holly Borla
be619c62c9 [RequirementMachine] Add a generic signature query that determines whether
two type parameter packs have the same shape.
2022-10-07 10:35:49 -07:00
Holly Borla
38a2c8218b [Requirement] Rename RequirementKind::SameCount to SameShape. 2022-10-06 20:48:40 -07:00
Holly Borla
fab5b7d364 [RequirementMachine] Add a generic signature query that returns the
reduced shape of a given type parameter pack.
2022-10-06 20:38:31 -07:00
Dario Rexin
210c68d8aa [SILOptimizer] Add prespecialization for arbitray reference types (#58846)
* [SILOptimizer] Add prespecialization for arbitray reference types

* Fix benchmark Package.swift

* Move SimpleArray to utils

* Fix multiple indirect result case

* Remove leftover code from previous attempt

* Fix test after rebase

* Move code to compute type replacements to SpecializedFunction

* Fix ownership when OSSA is enabled

* Fixes after rebase

* Changes after rebasing

* Add feature flag for layout pre-specialization

* Fix pre_specialize-macos.swift

* Add compiler flag to benchmark build

* Fix benchmark SwiftPM flags
2022-09-22 16:29:01 -07:00
Slava Pestov
5c32f2136e AST: Introduce RequirementKind::SameCount 2022-08-23 11:12:00 -04:00
Slava Pestov
7a970367fd AST: Rename GenericEnvironment::Kind::Normal to ::Primary, ::getIncomplete() to ::forPrimary() 2022-08-15 13:59:12 -04:00
Slava Pestov
7d8f3e6b63 AST: Change return type of Requirement::subst() to Requirement
Instead of returning None, let callers check hasError() if they need to.

Fixes rdar://problem/98565072.
2022-08-12 14:03:57 -04:00
Slava Pestov
4a041c57d0 AST: Rename ConformanceAccessPath to ConformancePath 2022-08-09 13:34:27 -04:00
Slava Pestov
9d96ed940f AST: Rename 'canonical wrt. generic signature' to 'reduced'
We had two notions of canonical types, one is the structural property
where it doesn't contain sugared types, the other one where it does
not contain reducible type parameters with respect to a generic
signature.

Rename the second one to a 'reduced type'.
2022-08-09 12:46:31 -04:00
Slava Pestov
d8393bc287 AST: Add Requirement::hasError() utility method 2022-04-01 21:40:40 -04:00
Slava Pestov
4d097da73c RequirementMachine: Re-use requirement machines constructed by minimization for queries
Fixes rdar://problem/88135641.
2022-03-26 00:56:41 -04:00
Pavel Yaskevich
2b6379de24 [AST] GenericSignature: Add a way to drop marker protocol requirements 2022-03-17 15:02:14 -07:00
Slava Pestov
cfdb937fed AST: Stricter invariants in GenericSignature::verify() 2022-03-08 23:21:58 -05:00
Robert Widmann
ab44a07045 Convert DeclContext Parameters to their Associated Generic Signatures Instead 2022-03-07 22:54:23 -08:00
Slava Pestov
628af191e2 AST: Fix -verify-generic-signatures mode to not violate requirement machine invariants
We can't feed resolved DependentMemberTypes into the Requirement Machine
since that will trigger an assertion if there is a missing conformance.

Instead, copy and paste some logic from GenericSignatureBuilder.cpp to
'erase' resolved DependentMemberTypes into unresolved DependentMemberTypes.
2022-02-28 18:44:38 -05:00
Slava Pestov
f5212e7173 AST: Better assertion output in Requirement::compare() 2022-02-09 00:26:04 -05:00
Anthony Latsis
b3ee4b0718 AST, Sema: Use the opened archetype's generic signature to determine existential member availability 2022-02-02 02:09:59 +03:00
Doug Gregor
2dbaab98b9 Adopt GenericSignature::isValidTypeInContext for nested archetypes 2022-01-14 21:25:32 -08:00
Slava Pestov
0ffd11c558 RequirementMachine: New GenericSignature::isValidTypeInContext() query 2022-01-14 21:25:32 -08:00
Slava Pestov
3a92d2fc53 AST: Remove legacy GSB-based GenericSignature query implementation 2022-01-12 12:33:34 -05:00
Slava Pestov
f5545bbd00 AST: Relax a GenericSignature assertion
A type in a same-type requirement can have a non-canonical type if
its parent is a concrete type.
2021-12-16 21:42:20 -05:00
Slava Pestov
589fc40d5a AST: Use RequirementMachine to verify protocol requirement signatures 2021-12-08 23:07:48 -05:00
Slava Pestov
24bdecdca5 AST: Remove ASTContext::getOrCreateRequirementMachine() in favor of getRewriteContext() 2021-11-11 22:39:20 -05:00
Slava Pestov
0d167a435c AST: Move GenericSignatureBuilder.h from include/swift/AST/ to lib/AST/ 2021-10-30 00:35:59 -04:00
Slava Pestov
0eb66222e2 AST: Move expensive generic signature checks to GenericSignature.cpp
This removes the final dependency on GenericSignatureBuilder.h.
2021-10-30 00:35:59 -04:00
Slava Pestov
ee5a3fe9af AST: AbstractGenericSignatureRequest and InferredGenericSignatureRequest return the HadAnyError bit
For now I'm going to use this in -verify-generic-signatures, but
it could be useful in other places too.
2021-10-30 00:35:59 -04:00
Slava Pestov
f38f25a3de AST: Factor out AbstractGenericSignatureRequest into a new buildGenericSignature() function
This is slightly cleaner.
2021-10-30 00:35:59 -04:00
Slava Pestov
74d944d511 RequirementMachine: Use llvm::array_pod_sort() to sort requirements 2021-10-27 00:38:26 -04:00
Slava Pestov
f81e4c9da4 AST: Fix Requirement::compare() for self-comparison
std::sort() will sometimes compare an element with itself (?)
so remove the assert here. Duplicate conformance requirements
should be already caught by checkGenericSignature() anyway.
2021-10-08 19:38:48 -04:00
Slava Pestov
3f8ef30185 RequirementMachine: Preserve sugared generic params in getSuperclassBound() and getConcreteType()
This was manifesting as module interfaces printing generic parameters
as `τ_0_0` in some cases.

Note that the GSB has the same bug, so this test case will fail with
-requirement-machine=off. I don't plan on fixing the bug in the GSB
unless we need to.

Fixes rdar://problem/78977127.
2021-09-29 14:39:38 -04:00
Slava Pestov
47ab4a9f28 AST: GenericSignatures point directly to their RequirementMachine
This avoids a hashtable lookup when performing queries.
2021-09-27 21:36:45 -04:00
Robert Widmann
e545d7f760 Lift getCanonicalTypeInContext up to GenericSignature 2021-09-20 15:43:07 -07:00
Robert Widmann
980fde2ede Lift requirementsNotSatisfiedBy Into GenericSignature 2021-09-20 15:29:51 -07:00
Slava Pestov
26fa4b354b GSB: Use RequirementMachine (when enabled) to verify newly-built generic signatures 2021-09-07 13:31:17 -04:00
Slava Pestov
22facd357c AST: Use source location instead of memory address to tie break associated types
If two associated types in an (invalid) protocol have the same name, use their
source location to order them instead of their memory address. This fixes a
non-deterministic test failure with the requirement machine enabled.
2021-09-06 23:35:19 -04:00
Slava Pestov
fb097aed60 RequirementMachine: Relax cross-check assert for areSameTypeParameterInContext()
The GSB and RequirementMachine sometimes disagree on whether two
type parameters that have both been equated to the same concrete
type belong to the same equivalence class or not.

Since in practice, this distinction does not matter, relax the
assert here.
2021-08-26 02:07:18 -04:00
Doug Gregor
d54abea922 Implement customizable Sendable conformance diagnostics.
Rework Sendable checking to be completely based on "missing"
conformances, so that we can individually diagnose missing Sendable
conformances based on both the module in which the conformance check
happened as well as where the type was declared. The basic rules here
are to only diagnose if either the module where the non-Sendable type
was declared or the module where it was checked was compiled with a
mode that consistently diagnoses `Sendable`, either by virtue of
being Swift 6 or because `-warn-concurrency` was provided on the
command line. And have that diagnostic be an error in Swift 6 or
warning in Swift 5.x.

There is much tuning to be done here.
2021-08-14 08:13:10 -07:00
Slava Pestov
fd7759ff68 AST: Move Requirement::compare() to GenericSignature.cpp 2021-08-11 12:01:07 -04:00
Slava Pestov
8f8b02c114 AST: Move compareDependentTypes() to GenericSignature.cpp 2021-08-11 12:01:07 -04:00
Slava Pestov
b3deddb68d AST: Factor out duplicated definition of compareAssociatedTypes() 2021-08-11 12:01:07 -04:00
Slava Pestov
6dc9ef88d7 AST: GenericSignatures don't contain type variables 2021-08-05 14:39:07 -04:00