Commit Graph

63 Commits

Author SHA1 Message Date
Slava Pestov
ea15d9f9b2 Stop passing -warn-redundant-requirements in tests 2024-02-02 14:57:19 -05:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Anthony Latsis
bc4a3465a9 Gardening: Migrate test suite to GH issues: Generics 2022-08-30 01:49:59 +03:00
Doug Gregor
904a2ff64c Allow unavailable conformances to non-Sendaable protocols during contraction
Refusing to acknowledge unavailable conformances at this point in the
requirement machine doesn't allow us to make use of unavailable
conformances from unavailable contexts, something which code currently
depends on. Limit the new filtering behavior to `Sendable` conformances
where we need them, as a narrow fix for this regression. We'll revisit
the approach here later.

Fixes rdar://94154905.
2022-06-02 13:24:37 -07:00
Doug Gregor
c9c50b4ae0 [Requirement machine] Ignore unavailable conformances on superclass constraints.
When determining whether a superclass conforms to a particular protocol,
skip unavailable conformances. This way, we don't minimize away a
constraint that might only apply to subclasses of the specified
superclass.

Fixes rdar://91853658.
2022-05-27 13:09:15 -07:00
Slava Pestov
dac8d666ee Stop passing -requirement-machine-{abstract,inferred,protocol}-signatures flags in tests
These flags are now no-ops.
2022-05-10 12:56:17 -04:00
Slava Pestov
f39372b33d RequirementMachine: Turn off redundant requirement warnings by default and add -warn-redundant-requirements frontend flag 2022-05-10 01:49:56 -04:00
Slava Pestov
094130b9c7 RequirementMachine: Diagnose redundant concrete conformance requirements
A conformance requirement on a concrete type parameter is redundant if the
concrete type conforms to the protocol.

The replacement path for the conformance rule is based on a concrete
conformance rule introduced by the property map. Since the concrete
conformance rule is not associated with a requirement ID, this would
normally muffle the redundancy warning, because we don't want to
suggest removing a rule that depends on a non-redundant, non-explicit
rule.

However, concrete conformance rules don't actually appear in the
minimal signature, so skip them when computing the set of non-redundant,
non-explicit rules to ensure that the original conformance requirement
is still diagnosed as redundant.
2022-04-05 21:12:51 -04:00
Slava Pestov
4068c9d707 Pass -requirement-machine-{protocol,inferred}-signatures=verify in remaining tests that fail due to diagnostics 2022-04-01 23:55:34 -04:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Slava Pestov
8e09ba8b45 RequirementMachine: Introduce 'concrete contraction' pre-processing pass before building rewrite system
See the comment at the top of ConcreteContraction.cpp for a detailed explanation.

This can be turned off with the -disable-requirement-machine-concrete-contraction
pass, mostly meant for testing. A few tests now run with this pass both enabled
and disabled, to exercise code paths which are otherwise trivially avoided by
concrete contraction.

Fixes rdar://problem/88135912.
2022-02-25 11:48:38 -05:00
Slava Pestov
e4973158d8 AST: -debug-generic-signatures protocol-qualifies DependentMemberTypes 2022-01-19 22:36:15 -05:00
Slava Pestov
e45b566642 GSB: Try harder to prove derivation via redundant requirements
Consider a signature with a conformance requirement, and two
identical superclass requirements, both of which make the
conformance requirement redundant.

The conformance will have two requirement sources, the explicit
source and a derived source based on one of the two superclass
requirements, whichever one was processed first.

If we end up marking the *other* superclass requirement as
redundant, we would incorrectly conclude that the conformance
was not redundant. Instead, if a derived source is based on a
redundant requirement, we can't just discard it right away;
instead, we have to check if that source could have been
derived some other way.
2021-05-07 18:43:57 -04:00
Slava Pestov
f190e51f8d GSB: Diagnose redundant superclass requirements using the redundant requirement graph 2021-04-03 22:33:14 -04:00
Slava Pestov
1d9b202719 GSB: Fix inconsistent 'redundant conformance' diagnostic 2021-03-27 00:35:19 -04:00
Robert Widmann
dce1e2ea32 [Gardening] Remove unnecessary options and files from tests 2019-09-10 18:15:16 -07:00
fischertony
70f8c84af7 Diag: Correct message for protocols with multiple superclass requirements 2019-04-21 17:04:31 +03:00
Slava Pestov
7566f98a45 Sema: Diagnose enum inheritance clause containing subclass existential
Also, tidy up the code a bit and stop emitting redundant diagnostics for
associated types.

Fixes <https://bugs.swift.org/browse/SR-10232>.
2019-04-01 22:41:16 -04:00
Slava Pestov
c9ae303e2d Sema: Remove TypeChecker::isSuperclassOf()
It's mostly redundant, we already have TypeBase::isExactSuperclassOf().

The only difference between the two is that the TypeChecker method
admitted self-conforming class-constrained existentials (like C & P
where P is an @objc protocol with no static methods) as subclasses
of themselves.

This was actually not sound in the general case, because you can
call static methods and required initializers on the *class* C,
so I'm going to unilaterally ban this, but since the importer
creates such types, I have to allow it if the class is an
imported class.
2018-10-16 00:50:03 -07:00
Doug Gregor
4b80872d48 [Type checker] Introduce stages for inherited type requests.
Extend the inputs to InheritedTypeRequest, SuperclassTypeRequest, and
EnumRawTypeRequest to also take a TypeResolutionStage, describing what
level of type checking is required. The GenericSignatureBuilder relies
only on structural information, while other clients care about the
full interface type.

Only the full interface type will be cached, and the contextual type
(if requested) will depend on that.
2018-08-22 15:29:08 -07:00
Slava Pestov
9ec1926731 Sema: Allow classes in protocol inheritance clauses 2018-07-02 22:06:33 -07:00
Slava Pestov
df9e0a76e0 AST: Fix for name lookup not finding initializers in protocols
If a generic parameter has both a class and protocol constraint,
walking up to the class's superclass would cause us to subsequently
ignore any initializer requirements in the protocol.

Fixes <https://bugs.swift.org/browse/SR-1663>, <rdar://problem/22722738>.
2018-03-16 21:49:02 -07:00
Doug Gregor
fb2b070ab9 [GSB] Don't complain about redundant superclass constraints in derived reqs.
Fixes SR-5862.
2017-10-10 23:06:52 -07:00
Slava Pestov
4ac0aecaef AST: Fix a problem with superclass constraints
If the class itself is generic and we're looking up a nested type
from a conformance, we would pass an interface type to
mapTypeOutOfContext() and crash.
2017-10-06 18:56:13 -07:00
Doug Gregor
b7a511a5ee Stop dumping the full state of the GSB in testing.
The full state of the GSB isn’t all that useful for testing, creates a ton of noise and gets in the way of some cleanups we’d like to make in the interface.
Stop dumping it as part of `-debug-generic-signatures`.
2017-09-28 14:27:15 -07:00
Doug Gregor
8f5d8aa7f9 Revert "[GSB] Centralize, clean up, and cache nested type name lookup" 2017-09-25 13:43:10 -07:00
Doug Gregor
9f063e9657 Stop dumping the full state of the GSB in testing.
The full state of the GSB isn’t all that useful for testing, creates a ton of noise and gets in the way of some cleanups we’d like to make in the interface.
Stop dumping it as part of `-debug-generic-signatures`.
2017-09-25 08:47:40 -07:00
Doug Gregor
9fa2a8bdca Don’t create a new generic signature builder for non-generic members.
When type-checking a function or subscript that itself does not have generic
parameters (but is within a generic context), we were creating a generic
signature builder which will always produce the same generic signature as
the enclosing context. Stop creating that generic signature builder.

Instead, teach the CompleteGenericTypeResolver to use the generic signature
+ the canonical generic signature builder for that signature to resolve
types, which also eliminates some extraneous re-type-checking.

Improves type-checking performance of the standard library by 36%.
2017-09-24 22:23:00 -07:00
Joe Shajrawi
00f44ce24a Revert "Create fewer generic signature builders" 2017-09-22 21:57:53 -07:00
Doug Gregor
fa7801f503 Stop dumping the full state of the GSB in testing.
The full state of the GSB isn’t all that useful for testing, creates a ton of noise and gets in the way of some cleanups we’d like to make in the interface.
Stop dumping it as part of `-debug-generic-signatures`.
2017-09-22 11:32:26 -07:00
Doug Gregor
98a255994d Don’t create a new generic signature builder for non-generic members.
When type-checking a function or subscript that itself does not have generic
parameters (but is within a generic context), we were creating a generic
signature builder which will always produce the same generic signature as
the enclosing context. Stop creating that generic signature builder.

Instead, teach the CompleteGenericTypeResolver to use the generic signature
+ the canonical generic signature builder for that signature to resolve
types, which also eliminates some extraneous re-type-checking.

Improves type-checking performance of the standard library by 36%.
2017-09-22 11:32:25 -07:00
Doug Gregor
a4e35ed151 [GSB] Remove unused form of addSameTypeRequirementDirect() 2017-06-23 10:00:11 -07:00
Doug Gregor
ffea1b35ca [GSB] Separate out a "structurally derived" requirement source kind.
Rather than abusing the "superclass" requirement source with a null
protocol conformance, introduce a separate "structurally derived"
requirement source kind for structurally-derived requirements that
don't need any additional information, e.g., the class layout
requirement derived from a superclass requirement.
2017-06-23 09:32:03 -07:00
Doug Gregor
610ffd5680 [GSB] Fall back to "abstract" requirements when we don't find a match.
The previous commit tightened up our choice of requirement sources for
superclass and layout constraints, but always assumed a match
existed. In cases where it does not, don't fail; rather, use an
abstract source, which we do elsewhere when we're synthesizing
requirements.

This is a defensive approach to cope with cases where we might not
have precisely the same value within one of our recorded
constraints. This currently only occurs when there are errors (hence
the elimination of the odd "hasError()"), but will come up more often
when we're deriving information from a combination of constraints.
2017-06-09 15:23:06 -07:00
Doug Gregor
969163f6ea [GSB] Only use matching superclass constraints in enumerated requirements.
Fixes SR-5165 / rdar://problem/32658705.
2017-06-09 00:00:17 -07:00
Doug Gregor
4fbb3ec611 [GSB] Resolve nested types by looking into superclass constraints.
This was previously handled very late, by the type checker, which led
to weird ordering dependencies and meant that we could end up with
well-formed code where the GSB was left with unresolved types. We want
such states to never exist, so make sure we can resolve everything in
the GSB.
2017-06-01 22:29:46 -07:00
Slava Pestov
95e28023a9 Sema: Test inheritance clause references to nested type of class-constrained archetype
This hits the FIXME case in CompleteGenericTypeResolver's
resolveDependentMemberType() method I thought was dead, but
it's actually not.
2017-04-10 17:04:37 -07:00
Roman Levenstein
e1403c6dc2 [GSB] Improve handling of layout constraints
This PR addresses TODOs from #8241.

- It supports merging for layout constraints, e.g., if both a _Trivial constraint and a _Trivial(64) constraint appear on a type parameter, we keep only _Trivial(64) as a more specific layout constraint. We do a similar thing for ref-counted/native-ref-counted. The overall idea is to keep the more specific of two compatible layout constraints.
- The presence of a superclass constraint implies a layout constraint, e.g., a superclass constraint implies _Class or _NativeClass
2017-03-22 16:39:02 -07:00
Doug Gregor
9385849dc0 [GSB] Don't emit redundant superclass constraints.
We were emitting a superclass constraint for each connected component
of derived same-type constraints within an equivalence class, when in
fact we only need one superclass constraint for the entire equivalence
class.
2017-03-21 07:25:35 -07:00
Doug Gregor
eaee4add8a [GSB] Track all conformance constraint sources.
Move the storage for the protocols to which a particular potential
archetype conforms into EquivalenceClass, so that it is more easily
shared. More importantly, keep track of *all* of the constraint
sources that produced a particular conformance requirement, so we can
revisit them later, which provides a number of improvements:

* We can drop self-derived requirements at the end, once we've
  established all of the equivalence classes
* We diagnose redundant conformance requirements, e.g., "T: Sequence"
  is redundant if "T: Collection" is already specified.
* We can choose the best path when forming the conformance access
  path.
2017-03-16 23:15:37 -10:00
Doug Gregor
84c5d3ee28 [GSB] Start tracking source locations for requirements within protocols.
Start reshuffling RequirementSource to store more information about
requirements in protocols. As a small step, track the source locations
for requirements written within the protocols themselves.

Note: there's a QoI regression here where we get duplicated
diagnostics (due to multiple generic signature builders being built
from a bad signature).
2017-03-06 10:11:18 -08:00
Doug Gregor
cdb38c1e97 [GSB] Check all superclass constraints during finalization.
Use the same infrastructure we have for same-type-to-concrete
constraints to check superclass constraints. Specifically,

* Track all superclass constraints; never "update" a requirement source
* Remove self-derived superclass constraints
* Pick the best superclass constraint within each connected component
  of an equivalence class and use that for requirement generation.
* Diagnose conflicting superclass requirements during finalization
* Diagnose redundant superclass requirements (during finalization)
2017-02-28 16:14:30 -08:00
Doug Gregor
c2da97172b [GSB] Store the root potential archetype in RequirementSource.
Use TrailingObjects to help us efficiently store the root potential
archetype within requirement sources, so we can reconstruct the
complete path from the point where a requirement was created to the
potential archetype it affects.

The test changes are because we are now dumping the root potential
archetype as part of -debug-generic-signatures.
2017-02-28 09:47:11 -08:00
Slava Pestov
ea0f271786 Sema: Remove unnecessary function signature typecheck pass
This was necessary when we would 'adopt' archetypes from outer
contexts, but that is long gone, and the only thing it accomplished
was emitting duplicate diagnostics.
2017-02-18 23:12:21 -08:00
Doug Gregor
d017fe3ab4 [GenericSigBuilder] Clean up handling of "inheritance" clauses.
Unify the handling of the "inheritance" clauses of a generic type
parameter, associated type, or protocol, walking them in a
TypeRepr-preserving manner and adding requirements as they are
discovered. This sets the stage for providing better source-location
information [*].

This eliminates a redundant-but-different code path for protocol
"inheritance" clauses, which was using
ProtocolDecl::getInheritedProtocols() rather than looking at the
actual TypeReprs, and unifies the logic with that of associated types
and type parameters. This eliminates a near-DRY violation, sets us up
for simplifying the "inherited protocols" part of ProtocolDecl, and
sets us up better for the soon-to-be-proposed

  class C { }
  protocol P: C { }

[*] We still drop it, but now we have a FIXME!
2017-02-17 17:39:10 -08:00
Doug Gregor
da39d9b17b [GenericSig Builder] Rework RequirementSource to describe requirement path.
Reimplement the RequirementSource class, which captures how
a particular requirement is satisfied by a generic signature. The
primary goal of this rework is to keep the complete path one follows
in a generic signature to get from some explicit requirement in the
generic signature to some derived requirement or type, e.g.,

1) Start at an explicit requirement "C: Collection"
2) Go to the inherited protocol Sequence,
3) Get the "Iterator" associated type
4) Get its conformance to "IteratorProtocol"
5) Get the "Element" associated type

We don't currently capture all of the information we want in the path,
but the basic structure is there, and should also allow us to capture
more source-location information, find the "optimal" path, etc. There are
are a number of potential uses:

* IRGen could eventually use this to dig out the witness tables and
  type metadata it needs, instead of using its own fulfillment
  strategy
* SubstitutionMap could use this to lookup conformances, rather than
  it's egregious hacks
* The canonical generic signature builder could use this to lookup
  conformances as needed, e.g., for the recursive-conformances case.

... and probably more simplifications, once we get this right.
2017-02-17 13:50:51 -08:00
Huon Wilson
51da51dfc0 [AST] Use the requirement signature in the ArchetypeBuilder.
The requirement signature is far more compact than looking at all the members.
2017-02-08 13:09:36 -08:00
Doug Gregor
0c76a9d828 [Archetype builder] Clean up PotentialArchetype a bit.
Clean up the representation of PotentialArchetype in a few small ways:

* Eliminate the GenericTypeParamType* at the root, and instead just
  store a GenericParamKey. That makes the potential archetypes
  independent of a particular set of generic parameters.

* Give potential archetypes a link back to their owning
  ArchetypeBuilder, so we can get contextual information (etc.) when
  needed. We can remove the "builder" arguments as a separate step.

Also, collapse getName()/getDebugName()/getFullName() into
getNestedName() and getDebugName(). Generic parameters don't have
"names" per se, so they should only show up in debug dumps.

In support of the former, clean up some of the diagnostics emitted by
the archetype builder that were using 'Identifier' or 'StringRef'
where they should have been using a 'Type' (i.e., the type behind the
dependent archetype).
2017-02-07 11:15:11 -08:00
Doug Gregor
def14bfb70 [Archetype builder] Move checking for recursive constraints to finalize().
Rather than waiting until we try to form a contextual type to diagnose
recursion, perform the check while finalizing the archetype builder
itself.
2017-02-06 22:58:44 -08:00
Doug Gregor
bf2a75e784 [Archetype builder] Lazily form context types for generic parameters.
Teach GenericEnvironment to lazily populate its mapping from generic
parameters to context types when queried (e.g., during
substitutition) rather than assuming that will be pre-populated before
any queries occur.

We're still forcing all of the archetypes when the generic environment
is created by the archetype builder; baby steps!
2016-12-01 10:35:18 -08:00