Commit Graph

481 Commits

Author SHA1 Message Date
Joe Groff
89979137fc Push ArchetypeType's API down to subclasses.
And clean up code that conditionally works only with certain kinds of archetype along the way.
2018-12-12 19:45:40 -08:00
Slava Pestov
bc4aa75b35 AST: Simplify GenericSignatureBuilder::computeRequirementSignature() 2018-12-11 23:55:41 -05:00
Pavel Yaskevich
d2d8f705c7 Merge pull request #20646 from xedin/rdar-45957015
[GSB] When adding same-type requirements pick representative based on…
2018-11-26 18:04:35 -08:00
Jordan Rose
1f25ea51d7 Fix two issues with typealiases in protocol extensions (#20654)
- The GenericSignatureBuilder assumed it didn't have to look in
  protocol extensions to resolve member types.

- Serialization was incorrectly filtering out such typealiases when
  trying to resolve a cross-module reference to one.

rdar://problem/46103190
2018-11-26 11:31:12 -08:00
Pavel Yaskevich
439784d54a [GSB/Diagnostics] Use llvm::array_pod_sort to sort "as written" edges
Instead of using `std::sort`, transform source-ordered edge vector
to reference `IntercomponentEdge *` instead of their indices in
`intercomponentEdges` vector and use `llvm::array_pod_sort` to sort them.
2018-11-26 11:20:54 -08:00
Pavel Yaskevich
ab3d1f54e1 [GSB/Diagnostics] Improve redundant same-type constraint diagnostics 2018-11-24 00:19:34 -08:00
Pavel Yaskevich
c725660cc9 [GSB] When adding same-type requirements pick representative based on canonical order
Instead of trying to order based on the "nested depth", let's
always prefer canonical ordering of type parameters when it comes
to picking representative equivalence class.

Resolves: rdar://problem/45957015
2018-11-23 00:08:14 -08:00
Slava Pestov
7ffe361709 Sema: Clean up generic signature checking 2018-11-16 01:18:18 -05:00
Pavel Yaskevich
a21990f3f6 [GSB] NFC: Couple of minor cleanups
- getOrCreateRewriteTreeRoot can't fail (unless it fails to allocate memory)
- mark `equivClass2` as modified as per original comment
2018-11-15 00:33:57 -08:00
Slava Pestov
add4185b83 AST: Fix infinite recursion with recursive same-type constraints
We diagnose and flag these in finalize(), but we can encounter one
even earlier through resolveDependentMemberTypes(). Do the same
thing there that we already do in EquivalenceClass::getTypeInContext().

Fixes <rdar://problem/45328122>, <https://bugs.swift.org/browse/SR-9022>.
2018-10-28 23:30:19 -04:00
Slava Pestov
7edbbae5c7 GSB: When merging two equivalence classes, don't forget to re-process delayed requirements
Fixes <rdar://problem/45307061>.
2018-10-16 17:01:02 -07:00
Slava Pestov
8acc11f80c Sema: Fix ambiguity resolution when doing unqualified lookup of associated types and type aliases
In structural lookup mode, let's resolve protocol typealiases to
dependent member types also. This is because areSameType() has
no way to see if a type alias is going to be equal to another
associated type with the same name, and so it would return false,
which produced ambiguity errors when there should not be any.

This exposes a deficiency in how we diagnose same-type constraints
where both sides are concrete. Instead of performing the check on
the requirement types, which might be dependent member types that
later on resolve to concrete types, do the check on the actual
equivalence classes further down in the GSB instead.

However, this in turn produces bogus diagnostics in some recursive
cases where we add same-type constraints twice for some reason,
resulting in a warning the second time around. Refine the check by
adding a new predicate to FloatingRequirementSource for requirements
that are explicitly written in source... which is not what
isExplicit() currently means.
2018-10-15 01:52:11 -07:00
Slava Pestov
9d131fd5f1 Merge pull request #18999 from hamishknight/location-by-association
[GSB] Avoid emitting associated type diagnostics on the protocol decl
2018-10-13 15:16:40 -07:00
Slava Pestov
b0009b6f7b GenericSignatureBuilder: Remove unnecessary null check 2018-10-12 03:06:52 -07:00
Slava Pestov
a8688b55e0 AST: Don't load unnecessary lazy generic environment in GenericSignatureBuilder::inferRequirements() 2018-09-26 23:24:14 -07:00
Graydon Hoare
14db5d2285 [AST] Add and use NominalTypeDecl::LookupDirectFlags rather than booleans. 2018-09-21 14:34:26 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Hamish Knight
42dc4ca342 [GSB] Remove getColonLoc() and getEqualLoc() in favour of getSeparatorLoc()
Most callers aren't concerned about the difference between the two (and those that are are already exercising the appropriate assertions with e.g the use of `getFirstType()`).
2018-09-06 16:40:07 +01:00
Doug Gregor
fafa9ed2d5 [GSB] ‘override’ keyword suppresses redeclaration warnings for assoc types. 2018-09-05 13:51:26 -07:00
Doug Gregor
e670ac42d9 Add command-line option -warn-implicit-overrides.
When provided, this flag warns about implicit overrides, where a
declaration overrides another declaration but is not marked with the
‘override’ keyword. The warning can be suppressed by either providing
‘override’ or ‘@_nonoverride’.

At present, this only happens with overrides in protocols.
2018-09-04 16:42:06 -07:00
Hamish Knight
819a13e880 [GSB] Avoid emitting associated type diagnostics on the protocol decl
For explicit abstract protocol floating requirement sources, get the source location from the protocol requirement rather than delegating to the parent `RequirementSource`.
2018-08-27 18:39:04 +01:00
Hamish Knight
7c5fbf2710 NFC: Remove a few unnecessary TypeLoc::withoutLoc()s 2018-08-27 13:23:42 +01:00
Robert Widmann
014fd952ef [NFC] Silence a bunch of Wunused-variable diagnostics 2018-08-24 15:16:40 -07:00
Doug Gregor
3c54886c4d [Type checker] Use RequirementRequest::visitRequirements() more intentionally.
Rather than using RequirementRequest::visitRequirements() for its side
effects, then reading from the TypeLocs left behind, start eliminating
TypeLoc-based APIs so we pass Type and TypeRepr separately.

Add some utilities to dig into a possibly-null RequirementRepr* and dig
out the appropriate TypeReprs.
2018-08-23 15:14:19 -07:00
Doug Gregor
868f763406 [GSB] Ensure that we don’t pick a self-recursive requirement source.
When computing the conformance access path, make sure that we don’t pick
a self-recursive requirement source.
2018-08-23 14:20:25 -07:00
Doug Gregor
fcfd4c8a8c [Type checker] Introduce a request to evaluate “where” clause requirements.
Introduce a new form of request that produces the ith Requirement of the
where clause of a given entity, which could be a protocol, associated type,
or anything with generic parameters. The requirement can be evaluated
at any type resolution stage; the “interface” type stage will be cached
in the existing RequirementReprs.

Fixes SR-8119 / rdar://problem/41498944.
2018-08-23 09:25:58 -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
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Doug Gregor
fa183b3639 [GenericSignatureBuilder] Rewrite sanity check to avoid warning in no-asserts builds. 2018-08-15 13:08:50 -07:00
swift-ci
be0e1643d6 Merge pull request #18720 from DougGregor/kill-type-resolver-context-generic-signature 2018-08-15 10:55:08 -07:00
Doug Gregor
7f759145c7 [GSB] Make requirement-signature computation more robust for nested protocols.
Add all of the generic parameters from outer contexts as well. This only
occurs in ill-formed code, but maintains a GenericSignatureBuilder
invariant that it knows about all of the generic parameters in play.
2018-08-15 09:26:23 -07:00
Doug Gregor
0a26e333bb Switch two simple callers over to decl-based lookupQualified. 2018-08-14 02:39:24 -07:00
Doug Gregor
b947a47a5d [AST] Reimplement ProtocolDecl::getInheritedProtocols() on decl name lookup.
Use the declaration-based name lookup facilities to re-implement
ProtocolDecl::getInheritedProtocols(), rather than dynamically selecting
between the requirement signature and the inherited types. This reduces
dependencies for this computation down to basic name lookup (no semantic
analysis) and gives us a stable result.
2018-08-06 16:12:09 -07:00
Doug Gregor
b421d08955 [GSB] Use resolved type when looking for a representative constraint.
When looking for a representative superclass constraint, take into
account other same-type constraints by comparing against the resolved
superclass constraint type rather than the type as spelled.

Fixes SR-8179 / rdar://problem/41851224.
2018-07-26 12:42:29 -07:00
Huon Wilson
c12bb46145 Merge pull request #18004 from huonw/sr8240
[AST] Member lookup in the GSB needs to understand equivalence classes with concrete types.
2018-07-18 12:46:08 +10:00
Huon Wilson
4faa0da99b [AST] Fix a few incorrectly indented lines. NFC. 2018-07-17 23:01:21 +10:00
Huon Wilson
ea1560f43b [AST] Member lookup in the GSB needs to understand equivalence classes with concrete types.
A constraint like `Parameter == SomethingConcrete` means references to
`Parameter` in that context behave like `SomethingConcrete`, including for name
resolution. Handling the parameter as just a parameter type means that it won't
find any non-protocol nested types (i.e. things other than associated types and
protocol typealiases are invisible).

Fixes rdar://problem/42136457 and SR-8240.
2018-07-17 22:54:22 +10:00
Slava Pestov
45fb11ce3c AST: Add ExistentialLayout::getSuperclass(), rename superclass to explicitSuperclass
More groundwork for protocols with superclass constraints.
In several places we need to distinguish between existential
types that have a superclass term (MyClass & Proto) and
existential types containing a protocol with a superclass
constraint.

This is similar to how I can write 'AnyObject & Proto', or
write 'Proto1 & Proto2' where Proto1 has an ': AnyObject'
in its inheritance clause.

Note that some of the usages will be revisited later as
I do more refactoring and testing. This is just a first pass.
2018-07-02 22:06:33 -07:00
Huon Wilson
92189c6079 Merge pull request #17356 from huonw/lazier-conditional-requirements
More errors instead of crashes for conditional conformances that are invalid or involve hard-to-resolve recursion
2018-06-21 11:59:49 +10:00
Huon Wilson
10b30fef78 [GSB] Explicit error on unsupported conditional conformance recursion.
This doesn't fix the fundamental problem of correctly handling such cases, but
it is better than the "error message" that occurred previously:

    Assertion failed: ((bool)typeSig == (bool)extensionSig && "unexpected generic-ness mismatch on conformance").

Fixes the crash rdar://problem/41281406 (that in
https://bugs.swift.org/browse/SR-6569 (rdar://problem/36068136)),
https://bugs.swift.org/browse/SR-8019 (rdar://problem/41216423) and
https://bugs.swift.org/browse/SR-7989 (rdar://problem/41126254).
2018-06-21 10:53:30 +10:00
Huon Wilson
1ba49949f9 [NFC]/[GSB] Move addConditionalRequirements to be a method. 2018-06-20 18:30:27 +10:00
Huon Wilson
175192fd7b [NFC] 'static Type' is more conventional than 'Type static'. 2018-06-20 11:32:11 +10:00
Doug Gregor
2b2e143f59 [Request-Evaluator] Introduce a request for getting an "inherited type". 2018-06-14 15:29:57 -07:00
Doug Gregor
d9c0ca951a Merge pull request #16997 from DougGregor/resolve-fewer-decl-signatures
[AST] Resolve fewer decl signatures
2018-06-06 13:08:55 -07:00
Doug Gregor
bc0445d1f7 Narrow a few LazyResolver::resolveDeclSignature() calls to what they really need.
Specifically, introduce entrypoints for "resolve overridden decl" and "is @objc". These can
be computed cheaply in many more cases.
2018-06-04 18:15:39 -07:00
Huon Wilson
ec1ed4ca57 Merge pull request #16893 from huonw/errors-are-unresolved-equivalence-class
[GSB] Error types end up as unresolved equivalence classes.
2018-06-04 16:27:48 -07:00
Huon Wilson
10c3e6cea9 [GSB] Error types end up as unresolved equivalence classes.
We need to make sure they don't end up as "concrete" equivalence
classes, because they behave more like unresolved ones.

Fixes rdar://problem/40009245.
2018-05-29 16:21:31 -07:00
Slava Pestov
a1c6f069c5 AST: Don't infer requirements from existential types 2018-05-28 19:09:33 -07:00
Doug Gregor
5ed639fec6 [GSB] Canonicalize types when checking concrete and superclass constraints.
Concrete and superclass constraints may be written involving type parameters
that are later resolved to concrete types. Perform the substitution to
ensure that type equality within constraint checking accounts for other
same-type constraints.

Fixes assertion in rdar://problem/40428709.
2018-05-23 14:49:58 -07:00
Slava Pestov
bd6281c558 AST: Change SubstitutionMap conformance lookup callbacks to take ProtocolDecl and not ProtocolType 2018-05-19 01:09:17 -07:00