Commit Graph

266 Commits

Author SHA1 Message Date
Pavel Yaskevich
38e305cfdc [DeclChecker] Don't try to derive conformances for invalid enums
If one of the cases is invalid, let's mark parent enum as invalid
as well, and avoid trying to derive any conformances related to it.

Resolves: rdar://problem/36989792
2018-02-05 14:12:55 -08:00
Doug Gregor
e0c39396cc Merge pull request #14154 from DougGregor/sr-6746-test-case
Add now-fixed test case for SR-6746 / rdar://problem/36483751.
2018-01-25 09:37:18 -08:00
Pavel Yaskevich
261ffe4d5c Merge pull request #14100 from xedin/rdar-36449760
[ConstraintSystem] Bind Self to correct contextual type for nested types in protocol
2018-01-25 00:57:41 -08:00
Doug Gregor
3806d56fb7 Add now-fixed test case for SR-6746 / rdar://problem/36483751. 2018-01-24 23:46:57 -08:00
Doug Gregor
597c955948 [Associated type inference] Find tentative type witnesses across protocol hierarchy.
As a minor step toward more global associated type inference,
allow tentative type witnesses to be found across a protocol
hierarchy, eliminating some recursion through associated type
inference. Fixes a recent regression in validation-test/stdlib/CollectionTypes.swift, as well as rdar://problem/36453271.
2018-01-24 23:01:21 -08:00
Pavel Yaskevich
a11263b156 [ConstraintSystem] Bind Self to correct contextual type for nested types in protocol
If something that we are trying to contextually bind is a nested type inside
protocol or protocol extension, let's try to find the innermost conforming type
from the current declaration context and map Self parameter of the protocol
to that nominal type. Since nested types in protocols aren't yet implemented this
is going to result in failure, but that's better than crashing.

Resolves: rdar://problem/36449760
2018-01-24 18:21:26 -08:00
Michael Gottesman
13d19e5a23 %swift-target-frontend => %target-swift-frontend.
Looks like it was a typo.
2018-01-16 10:48:04 -08:00
Ben Cohen
ca6c6b1d36 [stdlib] Cleanup DefaultIndices, delete dead code (#13952)
* Remove a bunch of Default(Bidirectional|RandomAccess)Indices usage from stdlib and test

* Remove some DefaultRandomAccessIndices and IndexDistance usage from Foundation

* Remove no-longer-used internal type in Existentials.swift

* Get rid of indicesForTraversal
2018-01-15 13:48:08 -08:00
Slava Pestov
3717aa41cc Add regression test for https://bugs.swift.org/browse/SR-6730 2018-01-12 00:06:02 -08:00
Erik Eckstein
cd3d50a5d9 ABI: Change the mangling prefix from _T0 to $S 2018-01-06 13:55:59 -08:00
Doug Gregor
8b58b0dbb4 [Type checker] Make redeclaration checking validate fewer declarations.
Redeclaration checking was validating all declarations with the same
base name as the given declaration (and in the same general nominal
type), even when it was trivial to determine that the declarations
could not be conflicting. Separate out the easy structural checks
(based on kind, full name, instance vs. non-instance member, etc.) and
perform those first, before validation.

Fixes SR-6558, a case where redeclaration checking caused some
unnecessary recursion in the type checker.
2017-12-30 23:27:04 -08:00
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