Commit Graph

757 Commits

Author SHA1 Message Date
Doug Gregor
832a154b08 [GSB] Make sure we wire up same-named type declarations consistently.
Fixes a former crasher that included well-formed code that was rejected
by my previous refactoring. Said crasher now passes, and IRGen's properly
as well. Also, account for three more fixed crashers.
2017-10-27 22:17:45 -07:00
Graydon Hoare
30b6fdce83 Merge pull request #12429 from graydon/named-lazy-member-loading
Named lazy member loading 1/N
2017-10-24 14:27:04 -07:00
Slava Pestov
31176d713a Sema: Only validate all members of a class if we access one of its members
... Or if we subclass it, or define an extension of it.
2017-10-22 20:05:01 -07:00
Graydon Hoare
d538519544 [NamedLazyMemberLoading] Skip some type-member logic for ObjC protocols. 2017-10-20 22:48:44 -07:00
Doug Gregor
1892dbd598 Cope with ill-formed recursion in associated type overrides computation.
Fixes some crasher regressions and accounts for some newly-fixed
crashers.
2017-10-17 22:23:14 -07:00
Huon Wilson
1dee31fe2b [GSB] subst Requirements directly; no need for the extra argument. 2017-10-10 20:17:42 -07:00
Slava Pestov
e96352661b Fix REQUIRES: line in 26725-llvm-smallvectorimpl-swift-diagnosticargument-operator.swift, it was never being run 2017-10-09 19:53:51 -07:00
Doug Gregor
ea1396c364 [GSB] Only build potential archetypes for associated type "anchors".
Use the "override" information in associated type declarations to provide
AST-level access to the associated type "anchor", i.e., the canonical
associated type that will be used in generic signatures, mangling,
etc.

In the Generic Signature Builder, only build potential archetypes for
associated types that are anchors, which reduces the number of
potential archetypes we build when type-checking the standard library
by 14% and type-checking time for the standard library by 16%.

There's a minor regression here in some generic signatures that were
accidentally getting (correct) same-type constraints. There were
existing bugs in this area already (Huon found some of them), while
will be addressed as a follow-up.

Fies SR-5726, where we were failing to type-check due to missed
associated type constraints.
2017-10-07 21:52:40 -07:00
Doug Gregor
5db9b11f2f Address a resolved crasher 2017-10-01 20:18:24 -07:00
Doug Gregor
797df6e8d7 Eliminate the _*Indexable protocols.
The various _*Indexable protocols only exist to work around the lack of
recursive protocol constraints. Eliminate all of the *_Indexable protocols,
collapsing their requirements into the corresponding Collection protocol
(e.g., _MutableIndexable —> Collection).

This introduces a number of extraneous requirements into the various
Collection protocols to work around bugs in associated type
inference. Specifically, to work around the lack of "global" inference
of associated type witnesses. These hacks were implicitly present in
the *Indexable protocols; I've made marked them as ABI FIXMEs here so
we can remove them when associated type inference improves.

Fixes rdar://problem/21935030 and a number of ABI FIXMEs in the library.
2017-10-01 15:08:23 -07:00
Rintaro Ishizaki
cd3bf0341e [Parse] Fix crash case in parseStmtForeach 2017-10-01 10:36:08 +09:00
Doug Gregor
fa0c986c25 [Type checker] Make sure we fully validate ‘where’ clauses in protocols.
Fixes SR-5579 and an existing crash.
2017-09-29 11:23:45 -07:00
Doug Gregor
d93bed5ed1 [GSB] Move a well-formed GenericSignatureBuilder to be the canonical builder.
Once we compute a generic signature from a generic signature builder,
all queries involving that generic signature will go through a separate
(canonicalized) builder, and the original builder can no longer be used.
The canonicalization process then creates a new, effectively identical
generic signature builder. How silly.

Once we’ve computed the signature of a generic signature builder, “register”
it with the ASTContext, allowing us to move the existing generic signature
builder into place as the canonical generic signature builder. The builder
requires minimal patching but is otherwise fully usable.

Thanks to Slava Pestov for the idea!
2017-09-28 16:19:08 -07:00
Doug Gregor
54864f858c [Type checker] Replace a use of GenericSignatureBuilder::resolveArchetype().
The type checker shouldn’t know about potential archetypes. Use
GenericSignatureBuilder::resolveEquivalenceClass() and perform the lookup
into that instead.

The test case change highlights an existing problem with generic signature
minimization.
2017-09-28 14:27:42 -07:00
Doug Gregor
118eb003ed Resolve a fixed crasher 2017-09-28 14:27:09 -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
4b43cbe26b Resolve a fixed crasher 2017-09-25 10:12:27 -07:00
Joe Shajrawi
00f44ce24a Revert "Create fewer generic signature builders" 2017-09-22 21:57:53 -07:00
Doug Gregor
76a532b3af [GSB] Move a well-formed GenericSignatureBuilder to be the canonical builder.
Once we compute a generic signature from a generic signature builder,
all queries involving that generic signature will go through a separate
(canonicalized) builder, and the original builder can no longer be used.
The canonicalization process then creates a new, effectively identical
generic signature builder. How silly.

Once we’ve computed the signature of a generic signature builder, “register”
it with the ASTContext, allowing us to move the existing generic signature
builder into place as the canonical generic signature builder. The builder
requires minimal patching but is otherwise fully usable.

Thanks to Slava Pestov for the idea!
2017-09-22 17:11:05 -07:00
Doug Gregor
ca4c5253d0 [GSB] Don’t record invalid concrete types via parent conformances. 2017-09-14 09:16:13 -07:00
Slava Pestov
3e2acb8ab0 Parse: Allow protocol compositions in all inheritance clauses
We allowed them for generic parameter inheritance clauses but
not anywhere else. While arguably this has stylistic benefits,
the restriction was not enforced consistently and was mostly a
result of implementation limitations.

Lift the restriction and fix things up where needed to make them
work. This brings us closer to allowing protocols to constrain
the 'Self' type to a subclass of a class by listing the class in
the protocol's inheritance clause, which was a feature from SE-0156,
but this doesn't quite work.

Fixes <https://bugs.swift.org/browse/SR-4678> and
<rdar://problem/31785092>.
2017-09-05 21:53:52 -07:00
Slava Pestov
50e7c066f7 Parse: Simpler handling of 'class' in protocol inheritance list
Instead of treating this as its own thing, just parse it as if
the user wrote 'AnyObject'.
2017-09-04 17:52:34 -05:00
Robert Widmann
f479f27420 Turn on circularity checks for ProtocolCompositions
When resolving protocol composition types, using the
old type checker to resolve the type manually instead
of the iterative type checker submits a recursive-but-
satisfiable request to the ITC.  This way we directly
resolve through TypeCheckType and can catch the
circularity before it takes down the compiler.
2017-08-14 03:55:22 -07:00
Slava Pestov
2c61ed5c99 Sema: Fix pre-check expression folding nested types of generic parameters
This allows [Foo.Bar](), [Foo.Bar?]() etc to type check if Bar is
an associated type of a generic parameter Foo.

Fixes <rdar://problem/27631137>.
2017-08-06 20:27:47 -07:00
Slava Pestov
edfaf7f724 Sema: Fix name lookup of nominal types nested inside a class from a protocol 2017-08-06 00:21:49 -07:00
Slava Pestov
8c98b7a306 AST: Fix a crasher with unqualified lookup
If the DeclContext's Self type-in-context is an ErrorType,
we should still resolve generic parameters to interface types.
2017-08-06 00:21:49 -07:00
Robert Widmann
d033648c21 Merge pull request #11208 from CodaFi/paren-de-la-paren
Report nested inout paren types as non-materializable
2017-07-26 15:19:24 -07:00
Robert Widmann
43beb80480 Report nested inout paren types as non-materializable 2017-07-26 13:56:33 -07:00
Robert Widmann
04e4c8c9ce Update CSDiag to use the proper InOutType convention 2017-07-26 13:15:19 -07:00
Slava Pestov
ee68ff4170 Sema: Use foundDC in resolveTypeInContext()
Now that we remember the DeclContext of lookup results when
doing unqualified lookup, we don't have to walk parent contexts
again to find this DeclContext.

This means that unqualified lookup is now the "single source of
truth" for what names are visible and why.
2017-07-18 22:11:29 -07:00
Robert Widmann
296492e4d1 Merge pull request #10941 from CodaFi/im-in-ur-member-base
Never Bind to ErrorType
2017-07-18 14:14:19 -07:00
Slava Pestov
a39b5eb53b Sema: Move preCheckExpression() out of solveForExpression()
There are two "RAII cleaners" here:

- CleanupIllFormedExpressionRAII cleans up the Expr in its final state
- ExprCleanser walks the Expr before it is mutated and collects
  sub-expressions, then cleans those up after

The subtle difference comes into play if we started to apply the
solution (which can fail, leaving the AST in an inconsistent state)
or if preCheckExpression() modified the AST.

The latter case was causing an ASan failure because we were not
cleaning up type variables in new nodes introduced by
preCheckExpression().

Fix this by moving the preCheckExpression() call out of
solveForExpression(), so that if solveForExpression() is called
with TypeCheckExprFlags::SkipApplyingSolution, we don't mutate the
AST at all.

Sigh...

Fixes <rdar://problem/33277279>.
2017-07-14 16:46:51 -07:00
Robert Widmann
6a47d02ca5 Don't add ErrorType-containing substitutions to the map
As a side-effect, resolves compiler crasher 28815
2017-07-13 13:22:23 -07:00
Doug Gregor
138b0361d2 [Type checker] Don't allow type variables to bind to dependent members.
When a type variable binds to an (unresolved) dependent member type,
it prevents us from inferring the type variable and adds no useful
information to the system. Refuse to bind type variables to dependent
member types.

Fixes rdar://problem/32697033.
2017-07-11 13:03:16 -07:00
Doug Gregor
1c6c51d137 [GSB] Cope with elided conformance requirements in concrete nested types.
If we encounter an associated type reference within a concrete type, but
haven't seen a specific protocol requirement, add the protocol
conformance.

Fixes rdar://problem/33139928 and another crasher.
2017-07-05 23:08:41 -07:00
Doug Gregor
158c048149 [Type checker] Always compute protocol requirement signature first.
The protocol requirement signature is key to conformance access paths
and other queries related to protocols. Make sure we create it first.
2017-06-28 13:55:46 -07:00
Doug Gregor
be5bc3fd07 [GSB] Eliminate two more uses of ArchetypeResolutionKind::AlwaysPartial.
We don't need to force the creation of potential archetypes when
finding anchors, because new potential archetypes will only be created
by this process in ill-formed generic signatures. Tolerate failure
whenever this happens (for now) and the failure paths will become dead
once AlwaysPartial is eliminated fully.
2017-06-28 06:23:52 -07:00
Doug Gregor
deef22fc7f [GSB] Don't crash when substitution fails to produce a type.
Fixes two more recently-found GSB crashers.
2017-06-26 09:43:13 -07:00
Doug Gregor
239a0f5f4c [GSB] Ensure that we have superclass constraints from merged equiv class.
Fixes one recently-found crasher.
2017-06-26 08:40:40 -07:00
Doug Gregor
a72a2bf730 [GSB] Avoid recursively growing increasingly-nested potential archetypes.
In some circumstances, we could end up growing increasingly-nested
potential archetypes due to a poor choice of representatives and
anchors. Address this in two places:

* Always prefer to use the potential archetype with a lower nesting
  depth (== number of nested types) to one with a greater nesting
  depth, so we don't accumulate more nested types onto the
  already-longer potential archetypes, and

* Prefer archetype anchors with a lower nesting depth *except* that we
  always prefer archetype anchors comprised of a sequence of
  associated types (i.e., no concrete type declarations), which is
  important for canonicalization.

Fixes SR-4757 / rdar://problem/31912838, as well as a regression
involving infinitely-recursive potential archetypes caused by the
previous commit.
2017-06-23 16:58:56 -07:00
Doug Gregor
a4e35ed151 [GSB] Remove unused form of addSameTypeRequirementDirect() 2017-06-23 10:00:11 -07:00
Doug Gregor
52e52b564b [GSB] Improve handling of conformances resolved by concrete types.
Centralize and simplify the handling of conformance requirements
resolved by same-type-to-concrete requirements in a few ways:

* Always store a ProtocolConformanceRef in via-superclass and
  via-concrete requirement sources, so we never lose this information.

* When concretizing a nested type based on its parent, use the
  via-concrete conformance information rather than performing lookup
  again, simplifying this operation considerably and avoiding
  redundant lookups.

* When adding a conformance requirement to a potential archetype that
  is equivalent to a concrete type, attempt to find and record the
  conformance.

Fixes SR-4295 / rdar://problem/31372308.
2017-06-23 09:34:57 -07:00
Slava Pestov
151f38630b AST: Fix DeclContext::getAsTypeOrTypeExtensionContext() for extensions of typealiases 2017-06-21 00:44:32 -07:00
Slava Pestov
773d7b3225 Sema: Remove more methods from GenericTypeResolver
resolveGenericTypeParamType(), resolveTypeOfDecl() and
resolveTypeOfContext() would all take the type of a
declaration, and optionally map it into context.

Replace them with a mapTypeIntoContext() that takes a
type and either returns it verbatim or maps it into
context.
2017-06-15 21:31:35 -07:00
Slava Pestov
d1610a5536 Sema: Kill GenericTypeResolver::resolveSelfAssociatedType() 2017-06-15 18:37:16 -07:00
Doug Gregor
622e3a6342 Fixed a compiler crasher 2017-06-14 23:23:53 -07:00
Slava Pestov
c4df92aef3 Sema: Clean up 'dynamic' inference a bit 2017-06-07 17:55:42 -07:00
Slava Pestov
c152fee9f8 Sema: A couple of recursion-breaking hacks 2017-06-07 17:19:09 -07:00
Slava Pestov
00997138b5 Sema: Fix crash with associated type <=> typealias circularity 2017-06-06 23:56:34 -07:00
Slava Pestov
ec60c88412 Sema: Use requirement signature to check type witnesses 2017-06-06 23:56:33 -07:00