Commit Graph

289 Commits

Author SHA1 Message Date
Doug Gregor
7177b23f93 Merge pull request #16069 from DougGregor/sr-7364
[Conformance checking] Diagnose missing witnesses along "lazy" paths.
2018-04-20 13:27:38 -07:00
Doug Gregor
8146d25641 [Conformance checking] Diagnose missing witnesses along "lazy" paths.
When lazily resolving witnesses, we would fail to diagnose missing
witnesses for which we had no specific diagnostic to give, leading to
AST verifier errors and crashes later on. Make sure we call the
operation to diagnose missing witnesses along these paths, too.

Fixes SR-7364 / rdar://problem/39239629 as well as the older
rdar://problem/36278079.
2018-04-20 11:17:21 -07:00
Doug Gregor
8d2ca387ef The test case from rdar://problem/31164540 is also fixed. 2018-04-20 11:15:22 -07:00
Doug Gregor
bb04d87cd8 [AST] Make TypeBase::adjustSuperclassMemberDeclType() more robust.
When performing substitutions in this function, allow them to fail
more gracefully by producing error types. Fixes SR-7457 /
rdar://problem/39492060.
2018-04-20 11:14:50 -07:00
Pavel Yaskevich
e1fab0559c [Serialization] Always serialize requirement substitutions
Absence of synthetic generic environment should not affect
serialization of the required substitutions because they can
come from outer requirement context for static members.

Resolves: rdar://problem/36497404
2018-04-19 17:58:13 -07:00
Huon Wilson
db8b98bbc9 Merge pull request #15842 from huonw/generic-class-objc-protocol-extension
[Sema] Explicit error for "extension GenericClass : ObjcProtocol".
2018-04-13 09:11:38 +10:00
Huon Wilson
d33a5c16f2 [Sema] Explicit error for "extension GenericClass : ObjcProtocol".
If there was any requirements in the @objc protocol, the user got an error in
some form (a complaint about those requirements), but giving the direct error is
better, and handles @objc protocol with no requirements.

Also, fix a hole in that existing @objc method check: in `class Outer<T> { class
Inner {} }`, Inner should be considered generic, but the loop that was checking
for this didn't consider it.

Fixes https://bugs.swift.org/browse/SR-7370 and rdar://problem/39239512.
2018-04-13 08:09:02 +10:00
Huon Wilson
7c435adc94 [GSB] withoutRedundantSubpath should leave Concrete RequirementSource as Concrete.
Fixes rdar://problem/39316039 and https://bugs.swift.org/browse/SR-7397.
2018-04-12 17:09:10 +10:00
Pavel Yaskevich
3ba6ad654b [TypeChecker] Fix lookup of the dependent type through typealias
While trying to resolve nested type component with type parameter
as a parent, try to resolve it as dependent member directly but
if that fails go through longer resolution path which is required
in case member type is accessed using `typealias`.

Resolves: rdar://problem/39253925
2018-04-09 16:01:37 -07:00
Pavel Yaskevich
7f314d1a2f [TypeChecker] NFC: add test-case for rdar://problem/39040593 2018-04-05 14:15:24 -07:00
Nathan Hawes
d367dfc3ff Merge pull request #15627 from nathawes/reachable-unreachables
[CSGen] Mark visitDynamicMemberRefExpr as unreachable to match ExprRewriter and update SanitizeExpr to handle them
2018-04-02 12:32:44 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Nathan Hawes
0145439a2b [CSGen] Mark visitDynamicMemberRefExpr as unreachable to match ExprRewriter and update SanitizeExpr to handle them
We were hitting an unreachable in visitDynamicMemberExpr in ExprRewriter when
re-typechecking during a salvage. Check for these earlier (in CSGen) and update
SanitizeExpr to handle them.

Resolves rdar://problem/39055736
2018-03-30 17:17:21 -07:00
Pavel Yaskevich
48e71f7325 Merge pull request #15559 from xedin/rdar-38144674
[Sema] Fix `PreCheckExpression` to avoid walking into capture lists
2018-03-28 00:01:35 -07:00
Pavel Yaskevich
e8cd3f94ee [Sema] Fix PreCheckExpression to avoid walking into capture lists
`PreCheckExpression` should only walk into associated closure if
it's a single statement, and should avoid list itself since it should
already be properly type-checked by `typeCheckDecl`.

Resolves: rdar://problem/34852808
2018-03-27 17:18:20 -07:00
Doug Gregor
7e01e54329 [AST] Remove a bogus assertion from the NameAliasType creation function.
Fixes SR-7282.
2018-03-27 09:41:02 -07:00
Pavel Yaskevich
134f4e5611 [Diagnostics] Fix a crash when using withoutActuallyEscaping incorrectly
Teach `eraseOpenedExistentials` how to handle `OpaqueValueExpr`
associated with `MakeTemporarilyEscapableExpr`.

Resolves: rdar://problem/35773761
2018-03-23 14:41:30 -07:00
Pavel Yaskevich
9f7d91323b [Sema] Don't allow member type lookup on existential types
Existential types don't support nested types so let's not
allow the lookup to make such access, with only exception
for typealias or associated types without type parameters,
they are currently allowed.

Resolves: rdar://problem/38505436
2018-03-16 13:53:09 -07:00
Pavel Yaskevich
cdf6cb3f2c [CSApply] Don't try to force propagate l-value access in "shallow" mode
Some of the expressions call into `typeCheckExpressionShallow` while trying to
apply solutions, we need to respect the fact that sub-expressions might be
already properly type-checked while propagating l-value access kind.

Resolves: rdar://problem/38309176
2018-03-15 18:07:51 -07:00
Doug Gregor
823d2a990b [GSB] Always ensure that we wire up typealiases in protocol extensions.
During "expansion" of the requirements of a protocol, we check all of
the inherited associated types against definitions within the
protocol. Also look for concrete types within extensions of that
protocol, so we can identify more places where developers have used
typealiases in inheriting protocols to effect a same-type constraint
on an inherited associated type.

Fixes SR-7097 / rdar://problem/38001269.
2018-03-05 17:10:39 -08:00
Doug Gregor
46e623a089 [SubstitutionMap] Handle conformance lookup via superclass requirements.
Conformances that discoverably for a type parameter via a superclass
requirement occupy a bit of a gray area in the type checker and
generic signature handling right now: we have a type parameter (so the
paths that handle concrete conformances don't kick in), but the
conformance itself isn't modeled as a requirement because it is
available via lookup. Teach SubstitutionMap's conformance lookup to
detect this case and perform conformance lookup in the generic
signature (i.e., falling back to global lookup) in this case,
replicating the hack that IRGen uses to address the same issue when
accessing the conformance (see GenArchetype.cpp's TODO where we lookup
a conformance on the superclass). The removal of that hack (as well as
this one) are tracked by rdar://problem/34609744.

For now, fixes SR-7072 / rdar://problem/37904576.
2018-02-26 23:31:46 -08:00
Pavel Yaskevich
ea0427e9f9 [TypeChecker] Fix crash related to chained optionals in case statements
Type checker didn't handle the safe of disjoint optional chaining when trying
to convert such chaining into `.Some` cases, which leads to dangling
`BindOptionalExpr` in the AST.

Resolves: rdar://problem/35870863
2018-02-22 19:33:48 -08:00
Doug Gregor
8b04dd3dbe [GSB] Avoid unresolved dependent member types in generic signatures.
The GenericSignatureBuilder is allowing unresolved dependent member
types to creep into generic signatures, which eventually blows up in
name mangling. Prefer to pick dependent member types that are
fully-resolved when choosing anchors.

This is a spot fix; a better approach would eliminate the notion of
unresolved dependent member types entirely from
PotentialArchetype. That's tracked by rdar://problem/35839277.

Fixes rdar://problem/36549499.
2018-02-13 15:40:53 -08:00
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