Commit Graph

197 Commits

Author SHA1 Message Date
Slava Pestov
2d36fcdc80 AST: Split off QueryOverrideSubs and LookUpConformanceInOverrideSubs 2022-07-29 13:33:14 -04:00
Slava Pestov
fcf79485d6 Sema: Tighten up invariants for createDesignatedInitOverride() 2022-07-29 12:01:26 -04:00
Slava Pestov
9bfe02ec3d AST: Refactor getOverrideSubstitutions() to not take derivedSig 2022-07-29 12:01:05 -04:00
Slava Pestov
e7785e14c3 AST: Duplicate combineSubstitutionMaps() inside getOverrideSubstitutions() 2022-07-29 12:01:05 -04:00
Slava Pestov
4538b1bb3e AST: Remove derivedSubs parameter from getOverrideSubstitutions()
We can apply a substitution map afterwards if needed.
2022-07-29 12:01:05 -04:00
Slava Pestov
2686ce37bb AST: Hack around edge case due to broken abstract conformance representation
A substitution map might store an abstract conformance even if the
replacement type is an archetype that conforms concretely via a
superclass requirement.

This is because when we build the substitution map, if the archetype
is represented by a type parameter, we don't have enough information
to know if it will conform abstractly or concretely.
2022-07-29 11:59:17 -04:00
Slava Pestov
665faf5947 AST: Remove unnecessary superclass bound check in SubstitutionMap::lookupConformance() 2022-06-23 17:10:07 -04:00
Slava Pestov
abac60400a AST: Fix SubstitutionMap::getOverrideSubstitutions() for generic protocol requirements
We need a substitution map written in terms of the base requirement's signature;
getProtocolSubstitutions() alone was not enough because it does not include
the extra generic parameters that the base requirement might have if it is
itself generic.
2022-03-02 14:15:06 -05:00
Doug Gregor
209167ae30 Eliminate spurious uses of ArchetypeType::getRoot(). 2022-01-19 09:54:34 -08:00
Doug Gregor
50fd5b5be6 Add ArchetypeType::isRoot() and use it instead of implicit "root" checks 2022-01-14 21:26:11 -08:00
Robert Widmann
e7e11df927 Model Sequence Archetypes 2021-11-16 11:38:57 -08:00
Robert Widmann
22405cefea Plumb the "Is Type Sequence" Bit Through the Surface AST 2021-11-08 13:48:30 -08:00
Robert Widmann
e545d7f760 Lift getCanonicalTypeInContext up to GenericSignature 2021-09-20 15:43:07 -07: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
Robert Widmann
d86551de67 Lift Requirement and Parameter Accessors up to GenericSignature
Start treating the null {Can}GenericSignature as a regular signature
with no requirements and no parameters. This not only makes for a much
safer abstraction, but allows us to simplify a lot of the clients of
GenericSignature that would previously have to check for null before
using the abstraction.
2021-07-22 23:27:05 -07:00
Slava Pestov
53e06d69b5 AST: Factor out a new Requirement::getProtocolDecl() utility method 2021-02-25 17:21:18 -05:00
Philippe Hausler
6e05240426 AsyncSequence and protocol conformance rethrows (#35224)
* Initial draft of async sequences

* Adjust AsyncSequence associated type requirements

* Add a draft implementation of AsyncSequence and associated functionality

* Correct merge damage and rename from GeneratorProtocol to AsyncIteratorProtocol

* Add AsyncSequence types to the cmake lists

* Add cancellation support

* [DRAFT] Implementation of protocol conformance rethrowing

* Account for ASTVerifier passes to ensure throwing and by conformance rethrowing verifies appropriately

* Remove commented out code

* OtherConstructorDeclRefExpr can also be a source of a rethrowing kind function

* Re-order the checkApply logic to account for existing throwing calculations better

* Extract rethrowing calculation into smaller functions

* Allow for closures and protocol conformances to contribute to throwing

* Add unit tests for conformance based rethrowing

* Restrict rethrowing requirements to only protocols marked with @rethrows

* Correct logic for gating of `@rethrows` and adjust the determinates to be based upon throws and not rethrows spelling

* Attempt to unify the async sequence features together

* Reorder try await to latest syntax

* revert back to the inout diagnosis

* House mutations in local scope

* Revert "House mutations in local scope"

This reverts commit d91f1b25b59fff8e4be107c808895ff3f293b394.

* Adjust for inout diagnostics and fall back to original mutation strategy

* Convert async flag to source locations and add initial try support to for await in syntax

* Fix case typo of MinMax.swift

* Adjust rethrowing tests to account for changes associated with @rethrows

* Allow parsing and diagnostics associated with try applied to for await in syntax

* Correct the code-completion for @rethrows

* Additional corrections for the code-completion for @rethrows this time for the last in the list

* Handle throwing cases of iteration of async sequences

* restore building XCTest

* First wave of feedback fixes

* Rework constraints checking for async sequence for-try-await-in checking

* Allow testing of for-await-in parsing and silgen testing and add unit tests for both

* Remove async sequence operators for now

* Back out cancellation of AsyncIteratorProtocols

* Restructure protocol conformance throws checking and cache results

* remove some stray whitespaces

* Correct some merge damage

* Ensure the throwing determinate for applying for-await-in always has a valid value and adjust the for-await-in silgen test to reflect the cancel changes

* Squelch the python linter for line length
2021-01-25 18:48:50 -08:00
Slava Pestov
e675bee26c AST: Split off DependencyCollector.h from EvaluatorDependencies.h
Also remove some unnecessary #includes from DependencyCollector.h,
which necessitated adding #includes in various other files.
2020-12-23 00:00:25 -05:00
Alejandro Alonso
424802fb34 Revert SE-0283 (#34492)
Reverted despite build failures.
2020-10-29 17:32:06 -07:00
Azoy
48ea83723e Manually define _rawHashValue in compatibility libraries, AST fixes for builtin protocol conformance
Remember to use substituted type in builtin conformance substitution
2020-10-22 18:28:38 -04:00
Slava Pestov
94c6bff65d AST: Replace some calls to getDeclaredType() with getDeclaredInterfaceType() 2020-07-31 13:39:01 -04:00
Anthony Latsis
01e6cb35a9 Merge pull request #31812 from AnthonyLatsis/substitution-revolution-pre-1
[NFC] AST: Define SubstitutionMap::getInnermostReplacementTypes
2020-06-20 00:11:07 +03:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Anthony Latsis
b25c4665e4 GenericSignatureImpl, #31712: Plug remaining relevant methods with type param. assertions 2020-05-20 23:49:47 +03:00
Anthony Latsis
eedb335a08 [NFC] AST: Define SubstitutionMap::getInnermostReplacementTypes 2020-05-15 14:09:47 +03:00
Anthony Latsis
44a92a926c [NFC] GenericSignatureImpl: Spell conformsToProtocol & getConformsTo in terms of requirements 2020-05-14 22:51:44 +03:00
Joe Groff
d06b839c03 Add -verify-all-substitution-maps frontend flag 2020-03-11 16:19:30 -07:00
Joe Groff
23f0d8ccbc Create an inherited conformance in SubstitutionMap::lookupConformance when needed.
If the substituted type for a conformance found via a superclass constraint is a subclass of that
superclass, then we should represent that with an InheritedProtocolConformance rather than with
the original root conformance that applies to the superclass. If we don't do this, then we end up
with spurious inequalities in generic signatures that ought to be equivalent, because some
paths use the inherited conformance and some don't, as in SR-12330 | rdar://problem/60174186.
2020-03-11 16:19:26 -07:00
Joe Groff
f0e61d9a38 Fix bug in SubstitutionMap::verify(), and add check that concrete conformances match concrete types 2020-03-11 15:25:06 -07:00
Dan Zheng
1486d6b346 NFC: Add GenericSignature::getCanonicalSignature. (#29105)
Motivation: `GenericSignatureImpl::getCanonicalSignature` crashes for
`GenericSignature` with underlying `nullptr`. This led to verbose workarounds
when computing `CanGenericSignature` from `GenericSignature`.

Solution: `GenericSignature::getCanonicalSignature` is a wrapper around
`GenericSignatureImpl::getCanonicalSignature` that returns the canonical
signature, or `nullptr` if the underlying pointer is `nullptr`.

Rewrite all verbose workarounds using `GenericSignature::getCanonicalSignature`.
2020-01-12 12:17:41 -08:00
Arnold Schwaighofer
f5fe7c1868 Add an API to map substitution map into a type expansion context. 2019-11-11 14:21:52 -08:00
Slava Pestov
559eaf0208 AST: Fix combineSubstitutionMaps() for requirements placed on outer generic parameters
There's an evolution proposal going through that allows
for this in more places, so let's fix a known bug in this
area.

Fixes <https://bugs.swift.org/browse/SR-10073>,
<rdar://problem/48925725>.
2019-11-07 22:59:07 -05:00
Robert Widmann
4f84c2a628 Use the default constructor to clean up some APIs
Use ProtocolConformanceRef::forInvalid() in implementations only as a semantic signal.  In one place, use the default constructor to drop the final use of Optional<ProtocolConformanceRef>.
2019-10-29 16:56:22 -07:00
Robert Widmann
b849e51768 Use operator bool to claw back some readability 2019-10-29 16:56:21 -07:00
Robert Widmann
3e1a61f425 [NFC] Fold The Tri-State In Optional<ProtocolConformanceRef>
ProtocolConformanceRef already has an invalid state.  Drop all of the
uses of Optional<ProtocolConformanceRef> and just use
ProtocolConformanceRef::forInvalid() to represent it.  Mechanically
translate all of the callers and callsites to use this new
representation.
2019-10-29 16:55:56 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Slava Pestov
b3f43680d8 AST: Simplify SubstitutionMap::getProtocolSubstitutions() 2019-09-20 17:59:56 -04:00
Slava Pestov
8fab074bb5 AST: Fix regression from SubstFlags::UseErrorTypes removal
Note that while the original crasher in the radar is gone, my reduced test
case triggers an IRGen crash on both 5.1 and master because of an unrelated
bug that appears to be related to protocol requirement signatures and
declaration ordering.

Fixes <rdar://problem/54952911>.
2019-09-19 15:50:40 -04:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Jordan Rose
8157ccfce5 Teach SubstitutionMap::isIdentity about non-canonical generic params (#25767)
Do a weaker check here that only looks at the canonical generic params
and guarantees that *those* substitute to themselves. There may be
replacement types for other generic params too, to canonicalize them,
but that's not a problem.

This fixes a crash trying to mangle decls with opaque result types
that have generic signatures that canonicalize away a generic
parameter.

rdar://problem/51775857
2019-06-26 13:09:36 -07:00
Slava Pestov
18f216c581 Sema: Fix re-entrant call to ensureRequirementsAreSatisfied() when resolving associated conformances
ConformanceChecker::ensureRequirementsAreSatisfied() modifies the
conformance as it resolves each one of its associated conformances,
so a re-entrant call can end up corrupting state by adding too
many elements to the buffer, or adding elements at the wrong
offsets.

If TypeChecker::checkConformanceRequirements() was called before
ConformanceChecker::resolveTypeWitnesses(), we could re-entrantly call
ConformanceChecker::ensureRequirementsAreSatisfied():

TypeChecker::checkConformanceRequirements()
=> ConformanceChecker::ensureRequirementsAreSatisfied()
   => Type::subst(), etc
      => ConformanceChecker::resolveTypeWitnesses()
         => ConformanceChecker::ensureRequirementsAreSatisfied()

The code in SubstitutionMap::lookupConformance() worked around
this by checking the failure condition and calling
resolveTypeWitness() first, before calling getAssociatedConformance().

Instead, remove this and call resolveTypeWitness() from inside
NormalProtocolConformance::getAssociatedConformance().
2019-05-28 22:08:31 -04:00
Arnold Schwaighofer
60a93467f7 Perform substitution on conformances if we are supposed to substitute opaque archetypes
rdar://50413632
2019-05-02 15:36:37 -07:00
Arnold Schwaighofer
768d1c51a1 Address review feedback 2019-05-01 09:31:07 -07:00
Arnold Schwaighofer
a793dfb451 Respect resilience when specializing opaque type archetypes 2019-05-01 09:31:07 -07:00
Joe Groff
42e1824a30 Mangle opaque result types. 2019-04-17 14:43:32 -07:00
Joe Groff
e3bbd8ce9e Remove ResilienceExpansion from substOpaqueTypes for now.
It's currently meaningless, and it'll require thought to pass the correct value when it becomes
meaningful.
2019-04-17 14:43:32 -07:00
Joe Groff
a419754fe9 Support nested types on opaque archetypes (and maybe opened ones). 2019-04-17 14:43:32 -07:00
Joe Groff
c771a7e71b SILGen: Substitute away opaque types. 2019-04-17 14:43:32 -07:00
Slava Pestov
5062a81e3d AST: Start returning SelfProtocolConformances from ModuleDecl::lookupConformance()
Fixes <rdar://problem/49241923>, <https://bugs.swift.org/browse/SR-10015>.
2019-04-16 23:02:50 -04:00
Doug Gregor
4f5d2d3426 [Substitution map] When the superclass conforms to a protocol directly, use it.
When looking up a conformance in a substitution map, check whether
there is a superclass constraint that satisfies the conformance. If
so, use it directly rather than going through a slower path to find
it.

Addresses rdar://problem/46655186.
2018-12-21 15:29:09 -08:00