Commit Graph

667 Commits

Author SHA1 Message Date
Doug Gregor
949cd57996 This test case is crashing again. Acknowledge the regression. 2017-12-14 16:39:50 -08:00
Doug Gregor
04a9714d9b [Type checker] Short-circuit uses of concrete typealiases in protocols.
Hack to allow IndexDistance to become a deprecated typealias. The actual
fix here involves deeper surgery into the substitution machinery.
2017-12-04 10:05:48 -08:00
Mark Lacey
8b55a0f61b SE-0054: Rework diagnostics for IUOs and revise Swift 3 /4 semantics.
For Swift 3 / 4:

Deprecate the spelling "ImplicitlyUnwrappedOptional", emitting a warning
and suggesting "!" in places where they are allowed according to
SE-0054.

In places where SE-0054 disallowed IUOs but we continued to accept them
in previous compilers, emit a warning suggesting "Optional" or "?"  as
an alternative depending on context and treat the IUO as an Optional,
noting this in the diagnostic.

For Swift 5:

Treat "ImplicitlyUnwrappedOptional" as an error, suggesting
"!" in places where they are allowed by SE-0054.

In places where SE-0054 disallowed IUOs, emit an error suggestion
"Optional" or "?" as an alternative depending on context.
2017-11-18 11:41:53 +09:00
Slava Pestov
afd9903509 Fixed crashers don't require asserts 2017-11-14 12:19:09 -08:00
Slava Pestov
b6200728a6 Sema: Fix crash on invalid openUnboundGenericType()
We can't construct a nominal type with an ErrorType as a
parent, so in the bad circular case, return a Type() instead
to bail out of transform() altogether.
2017-11-14 00:07:56 -08:00
Xi Ge
0d9745f6eb libSyntax: teach parser to parse dictionary and array literals. (#12821)
This commit also adds ArrayExpr and DictionaryExpr to the libSyntax nodes
family. Also, it refactors the original parser code for these two
expressions to better fit to the design of SyntaxParsingContext.

This commit has also fixed two crashers.
2017-11-09 09:00:43 -08:00
Doug Gregor
fe54e70fce [GSB] Don't infer requirements from types in the definitions of protocols.
Previously, we were inferring requirements from types within the definitions
of protocols, e.g., given something like:

    protocol P {
      associatedtype A: Collection
      associatedtype B where A.Element == Set<B>
    }

we would infer that B: Hashable. The code for doing this was actually
incorrect due to its mis-use of requirement sources, causing a few
crashers. Plus, it's not a good idea in general because it hides the
actual requirements on B. Stop doing this.

Also stop trying to infer requirements from conditional
requirements---those have already been canonicalized and minimized, so
there's nothing to infer from.
2017-10-31 15:28:19 -07:00
Doug Gregor
3a3e96cf66 Set the outer generic parameters of a protocol extension properly.
Fixes two compiler crashers.
2017-10-27 23:41:08 -07:00
Doug Gregor
e0aedef88a [AST] Handle superclass and concrete sources in conformance access paths.
If we encounter a superclass or concrete source within a conformance
access path, use the stored conformance to terminate the path. Fixes a
compiler crasher.
2017-10-27 23:41:08 -07:00
Doug Gregor
439bb8cc2b Make sure that TypeChecker::validateExtension() wires up generic environment.
Fixes a crasher.
2017-10-27 23:41:08 -07:00
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