Commit Graph

255 Commits

Author SHA1 Message Date
Doug Gregor
d9095b1079 [Conformance checking] Don't suppress substitution failures during checking.
When checking whether a particular protocol conformance satisfies all of
the protocol's requirements, we were suppressing substitution failures.
In some cases, this would mean that we marked a conformance "invalid"
without ever emitting a diagnostic, which would lead to downstream crashes.

Instead, treat substitution failures somewhat more lazily. If we encounter
one while performing the checking, put the conformance into a "delayed" list
rather than failing immediately. Teach the top-level type checking
loop to re-check these conformances, emitting a diagnostic if they
fail the second time around.

Fixes rdar://problem/35082483 and likely other issues that slipped
through the type checker or blew up in unpredictable ways.
2017-12-18 16:43:59 -08:00
Doug Gregor
40207e8c60 Add test case for rdar://problem/26140749, a fixed crasher 2017-12-18 16:43:46 -08:00
Joe Shajrawi
1bb1b5de68 Add CHECK lines to 0134-rdar35947198 validation-test 2017-12-14 13:33:25 -08:00
Joe Shajrawi
027057f5d6 hasValidLinkageForFragileRef: Add a test that checks if the containing module is serialized
Commit 53754a7a69 added a module pass that serializes the entire module.
Part of that pass is a method called removeSerializedFlagFromAllFunctions that removes the serialized flag from all functions within the module, which allows for more optimizations and for a better dead function elimination.
The problem is that this might break the Devirtualizer: If we run Devirtualization after “SerializeSILPass”, and we do LinkAll after Devirtualizing a function, SIL Verifier will fail: a public_external [serialized] function might be calling a [serialized] function for which we removed the [serialized] flag and added said flag to the module itself.
The verifier thinks that a function_ref inside fragile function is referencing private or hidden symbol.
2017-12-13 19:08:13 -08:00
Ben Cohen
4ddac3fbbd [stdlib] Eradicate IndexDistance associated type (#12641)
* Eradicate IndexDistance associated type, replacing with Int everywhere

* Consistently use Int for ExistentialCollection’s IndexDistance type.

* Fix test for IndexDistance removal

* Remove a handful of no-longer-needed explicit types

* Add compatibility shims for non-Int index distances

* Test compatibility shim

* Move IndexDistance typealias into the Collection protocol
2017-12-08 12:00:23 -08:00
Doug Gregor
25fc87ded0 Fix whitespace in a test 2017-12-06 16:35:59 -08:00
Doug Gregor
6eec137374 [Type checker] Don't check near-miss candidates of the wrong kind.
Fixes rdar://problem/35832679.
2017-12-06 14:01:47 -08:00
Pavel Yaskevich
f5d9c2eb79 [Diagnostics] Fix crash related to diagnostics of trailing closures
While trying to diagnose a problem related to contextual result type
of the trailing closure, don't assume that declaration context is properly
set, instead directly set it to correct one before running type-check.

Resolves: rdar://problem/35699666
2017-11-28 13:12:25 -08:00
Doug Gregor
9554e61705 [AST] Fix a crash when conformance lookup fails during substitution.
The enclosing conformance-lookup operation can fail (i.e., it returns
Optional), but the nested call was force-unwrapping the optional from
an inner call for no particular reason. Stop doing that, which fixes
SR-6466.

Note that the offending code is still something that should go away in
time, so this is merely polishing the band-aid to avoid a crash that
occurs often with conditional conformances.
2017-11-24 23:18:11 -08:00
Doug Gregor
41e0648336 [AST] Properly adjust substitution type for inherited conformances.
When we substitute into an inherited conformance, make sure that we
follow the superclass chain from the new conforming type up to the
matching superclass *before* doing the substitution.

Fixes rdar://problem/35632543.
2017-11-19 21:50:24 -08:00
Doug Gregor
a8cd86f811 Add no-longer-crashing test case from rdar://problem/35441779. 2017-11-16 11:36:52 -08: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
Doug Gregor
3681cdc7a1 Add fixed crasher from rdar://problem/35019075 2017-10-26 14:08:07 -07:00
Slava Pestov
c5182e8b6b Add a regression test for rdar://problem/35088384 2017-10-24 22:47:07 -07:00
Doug Gregor
c999f621a7 Add fixed crasher from SR-5905. 2017-10-04 10:59:16 -07:00
Doug Gregor
d12dbf99ea [Type checker] Diagnose failed attempts to resolve associated type witnesses.
If unqualified name lookup finds an associated type, but resolution to
the type witness fails, produce a diagnostic rather than silently
failing. Fixes the crash in SR-5825, SR-5881, and SR-5905.

It's conceivable that we could resolve this with suitably global
associated type inference... but that's far off and it's best not to
crash until then.
2017-10-03 21:59:14 -07:00
Doug Gregor
7e6b564bf5 Add fixed crasher from rdar://problem/33575781 2017-10-03 13:47:19 -07:00
Doug Gregor
2b54380e7d Add now-passing test for rdar://problem/30965000. 2017-10-03 08:32:13 -07:00
Doug Gregor
0f30f5e7de [AST] Don't try to compute substitutions for a missing generic signature.
Eliminates the crash in rdar://problem/34184392, but we still don't handle
this pattern.
2017-10-02 13:30:43 -07:00
Doug Gregor
5426fe2b16 Resolve another fixed crasher. It also doesn't need to be a long test 2017-10-01 21:42:42 -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
Slava Pestov
044af751f3 Sema: Fix a failure to emit a diagnostic
CSDiag was misinterpreting the result of checkGenericArguments().

A result of SubstitutionFailure does not mean a diagnostic was
emitted, only a result of Failure means that. This fixes a case
where we did not emit a diagnostic, result in a crash on invalid.

The diagnostic is still poor, but that's better than crashing.

Fixes <https://bugs.swift.org/browse/SR-5932>,
<rdar://problem/34522739>.
2017-09-27 16:39:06 -07:00
Pavel Yaskevich
9d9a6c6231 [Diagnostics] Restore inout ParamDecl types properly after type-check
We are currently in process of removing `InOutType`
so `VarDecl::get{Interface}Type` is going to wrap base
type into `InOutType` if its flag indicates that it's
an `inout` parameter declaration. But such type can't
be restored directly using `VarDecl::set{Interface}Type`
caller needs additional logic to extract base type.

Resolves: rdar://problem/33613329
2017-09-25 17:38:28 -07:00
Mark Lacey
84caa59e26 Merge pull request #11771 from rudkx/fix-test-for-rdar33433087
Switch test from 'not ...' to positive test with the correct verify c…
2017-09-05 14:25:00 -07:00
swift-ci
2195b73f07 Merge pull request #11772 from rudkx/test-for-rdar31529413 2017-09-05 14:04:22 -07:00
Mark Lacey
86e2bdab92 Add a test case for rdar://problem/31529413.
This crasher was fixed at some point but I don't know what change it
was.
2017-09-05 12:40:06 -07:00
Mark Lacey
f566d8d295 Switch test from 'not ...' to positive test with the correct verify check. 2017-09-05 12:38:17 -07:00
Max Moiseev
4c0368a02a [test] Cleaning up tests 2017-08-29 10:04:39 -07:00
Pavel Yaskevich
2d49d1202c [QoI] Fix crash while trying to compute default parameters
Arguments and parameters are not guaranteed to line-up perfectly,
because failure diagnostics sometimes has to match one argument
to different "candidate" parameters to see which one is closer,
so let's teach `computeDefaultMap` to respect that.

Resolves: rdar://problem/33433087.
2017-08-22 17:23:17 -07:00
Slava Pestov
bf8add0c01 Add regression test for rdar://33365139, which was fixed at some point 2017-08-14 00:31:57 -04:00
Doug Gregor
bebac49cee [GSB] Form minimal requirement sources by removing redundant subpaths.
When we detect that a requirement source is self-derived, identify the
redundant subpath and remove it to produce a new, smaller requirement
source that computes the same result. We were doing this form the
limited case where the redundant subpath ended at the end of the
requirement source; generalize that notion.

Fixes SR-5601.
2017-08-10 17:00:07 -07:00
Slava Pestov
1221bd8f60 Sema/AST: Fix a couple of protocol typealias validation order bugs
We break name lookup circularities by special-casing validation of
type aliases, resolving the underlying type of the type alias before
building the generic environment of the protocol that contains the
type alias.

However doing this gives the type alias an underlying type written
in terms of unresolved DependentMemberTypes which do not map to
associated types.

Attempting to substitute such a type fails.

We worked around this by re-validating type alias members of
protocols when we finally got around to building the protocol's
generic environment. Force this to happen earlier in
substMemberTypeWithBase(), because we need the fully resolved
underlying type in order to perform the substitution.

Also, fix TypeAliasDecl::setUnderlyingType() to only create a new
NameAliasType the first time it is called. In this special case
where it can be called twice with a resolved underlying type the
second time, we should not be creating a new NameAliasType.

There are better fixes possible here, requiring various levels
of refactoring. I'll investigate this soon, but for now this narrow
fix should address the problem with minimal risk.

Fixes <rdar://problem/33189068>.
2017-07-23 17:34:38 -07:00
Pavel Yaskevich
481401f6c3 [QoI] Don't try to lookup members on incorrect type during Objective-C KeyPath validation
While trying to validate Objective-C keypath components
don't assume that type of the component is always correct, check
before trying to see if it's bridged type or has members.

Resolves: rdar://problem/33044867
2017-07-12 14:04:10 -07:00
Mark Lacey
8d9f97cdc5 Fix another subtle SE-0110-related break.
The change to roll back a part of SE-0110 to allow multi-argument
functions to be passed in places where functions taking a tuple are
expected resulted in a regression in some cases where the fix would
strip off the last ParenType from single-argument functions.

Instead of stripping off parens from both function types we're trying to
match when they both have them, strip off none. This ensures that we
don't get summarily rejected in the nested matchTypes call by other
SE-0110-related code that bails if the two types do not have the same
"parenness".

Fixes rdar://problem/33043106 / SR-5387.
2017-07-10 17:36:53 -07:00
Mark Lacey
b89b5707b2 Revert "[QoI] Add a fixed crasher which triggers closure return diagnostics related to rdar://problem/33067102"
This reverts commit 70deaa89e2.

My next commit already added the same test case, but this reverted
commit added it in a way that the test will fail with my fix in place.
2017-07-10 17:36:37 -07:00
Pavel Yaskevich
70deaa89e2 [QoI] Add a fixed crasher which triggers closure return diagnostics related to rdar://problem/33067102 2017-07-10 16:08:14 -07:00
Pavel Yaskevich
be204f27d2 Merge pull request #10779 from xedin/rdar-33135487
[QoI] Don't try to lookup members on incorrect type while diagnosing keypath components
2017-07-06 10:04:42 -07:00
swift-ci
9fb11c5dd0 Merge pull request #10787 from DougGregor/gsb-nested-in-concrete 2017-07-05 23:32:31 -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
Pavel Yaskevich
c45073efd1 [QoI] Don't try to lookup members on incorrect type while diagnosing keypath components
While trying to diagnose problems related to keypath components
don't assume that type of the component is always correct, check
before trying to see if it's bridged type or has members.

Resolves: rdar://problem/33135487
2017-07-05 17:19:05 -07:00
Jordan Rose
88556eec94 Avoid building conformance lookup tables when we don't have to.
- Deinitializers never get a custom Objective-C name.
- Classes and protocols are never bridged themselves; that only matters
  for structs and enums.

This avoids another circularity issue like the one in a8bc132565,
where the Clang importer ends up importing a class and hands it to the
type checker, which then asks about conformances. The conformance
lookup table goes to add the extension from the Swift module, except
that the Swift module is what asked for the import in the first place.

It's possible there's a more general solution here, but this
particular change is good even in the non-crashy cases, and definitely
safe for Swift 4.0. Even if the test case is even more idiosyncratic
than the last one.

The test case change for SourceKit is probably due to the first
category not triggering the import of the other two
categories. Changes in import order have been known to affect source
compatibility, though not frequently. However, categories are not
intended to be ordered in the first place. There's still more we can
do in this space, and implicitly depending on these calls /outside/ of
the importer to control category import order was quite brittle
anyway.

SR-5330 / rdar://problem/32677610
2017-07-05 11:23:27 -07:00
swift-ci
c063d4939f Merge pull request #10714 from DougGregor/gsb-no-unresolved-potential-archetypes 2017-06-30 09:51:18 -07:00
Pavel Yaskevich
a82b16fb2d [QoI] Don't assume that contextual type is always present for trailing closure diagnostics
Fixes crasher in diagnostics related to the fact that contextual type
is not always available when trying to diagnose problems related to
calls with trailing closures.

Resolves: rdar://problem/33067102
2017-06-29 23:09:55 -07:00
Doug Gregor
ac8e8aa1b3 [GSB] Stop creating unresolved potential archetypes; rework typo correction.
The small-but-significant change to the generic signature builder is
to refuse to create unresolved potential archetypes. Instead, delay
any requirement that depends on such type, to be reprocessed once
we've seen all of the other requirements. If the type can be resolved
later, it will be; Otherwise, the type checker will complain when it
sees an unresolvable type. By itself, this fixes the crash in SR-2796.

Doing this by itself regresses diagnostics because typo correction in
the generic signature builder no longer kicks in. Therefore, implement
typo correction for these cases in the type checker proper, using its
existing facilities for typo correction. The result is more consistent
code with a better result.

Fixes SR-2796 / rdar://problem/28544316.
2017-06-29 16:52:46 -07:00
Doug Gregor
c1cb8eb9a2 Reinstate crasher from SR-4737 / rdar://problem/31905232.
It was failing to crash for the wrong reasons; this needs more work
(and a proper reduction).
2017-06-28 09:41:06 -07:00
Doug Gregor
6862ef10ac Add recently-fixed test case from SR-4737 / rdar://problem/31905232. 2017-06-23 22:29:47 -07:00
Doug Gregor
dd3869739e [GSB] Don't add invalid concrete requirements.
When a concrete requirement is invalid due to the concrete type
lacking a conformance to a particular, required protocol, don't emit
that incorrect requirement---it causes invalid states further down the
line.

Fixes SR-5014 / rdar://problem/32402482.

While here, fix a comment that Huon noticed trailed off into oblivion.
2017-06-23 22:23:46 -07:00
Doug Gregor
2f00a08b85 Add formerly-crashing test case for SR-4786 / rdar://problem/31955862. 2017-06-23 22:17:58 -07:00
Doug Gregor
c47aea7150 [GSB] Cope with typealiases within protocol hierarchies.
When we see two type(aliase)s with the same name in a protocol
hierarchy, make them equal with an implied same-type requirement. This
detects inconstencies in typealiases across different protocols, and
eliminates the need for ad hoc consistency checking. This is a step
toward simplifying away the need for direct-diagnosis operations
involving concrete type mismatches.

While here, warn when we see an associated type with the same as a
typealias from an inherited protocol; in this case, the associated
type is basically useless, because it's going to be equivalent to the
typealias.
2017-06-23 17:25:45 -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