Commit Graph

805 Commits

Author SHA1 Message Date
Slava Pestov
a2181092fb AST: Tweak a concrete-nested-type-of-archetype hack slightly
When an archetype conforms to a protocol abstractly (ie, it is
not class-constrained and we don't have any further information
other than that it conforms), we can recover nested types,
but we cannot recover the conformance of those nested types
to protocols if those conformances are concrete (the nested
type might be concrete, or it might be a class-constrained
archetype).

To work around this, we added a hack where if the conformance
lookup in the SubstitutionMap fails, we fall back to the module.

This is horrible and unprincipled, but has to remain in place
until more infrastructure is plumbed through.

Commit 620db5f74c made this
workaround apply in fewer cases, so that we could still catch
cases where the SubstitutionMap was constructed with missing
conformances.

Unfortunately this workaround didn't handle the case where the
nested type was an archetype with a superclass constraint.

This will all go away soon, but for now tweak the logic a bit,
since I really want to keep the "narrow" workaround in place
and not the general fallback, otherwise we run the risk of
SubstitutionMap conformance lookup bitrotting completely.

Fixes <https://bugs.swift.org/browse/SR-4088> and
<rdar://problem/32773028>.
2017-06-20 22:18:50 -07:00
Doug Gregor
fe7ba8b79b [GSB] Pull typo correction for nested types into delayed reqs handling.
Rather than performing typo correction at the very end of finalize(),
do it as part of delayed requirement handling when we cannot otherwise
make progress. This is a cleaner way to cope with typo correction that
gives us a better chance of getting to a sane result.

Fixes rdar://problem/31048352 by eliminating the need for tracking the
number of unresolved potential archetypes altogether. Fixes
rdar://problem/32077627.
2017-06-19 22:47:33 -07:00
Doug Gregor
b44f24dc2d [Type checker] Re-validate typealiases in protocols after protocol validation.
Validation for typealiases in protocols is... odd. It needs to avoid
depending on the whole protocol being validated, so it does an initial
validation that can leave nested types of Self (and other associated
types) somewhat unresolved. In these cases, do something icky but
partially effective: when we resolve the protocol, go back and clean
up the types of these typealiases.

A better solution would allow us to use the types of these typealiases
within the Generic Signature Builder without recording them in the AST
as "the interface type", so there's no way unresolved nested types
could be found (and, therefore, nothing to "fix up" later). Howwever,
that's a more significant undertaking.

Fixes rdar://problem/32287795.
2017-06-15 22:51:30 -07:00
Doug Gregor
01b45a245c Fold ConstraintSolver::coerceToRValue() into TypeChecker::coerceToRValue()
ConstraintSolver::coerceToRValue() missed a bunch of cases where we
should be dealing with lvalues, e.g., tuples, "try" expressions, and
so on. Extend TypeChecker::coerceToRValue() to deal with the
expression type side-tables and ConstraintSolver::coerceToRValue() to
it.

Fixes rdar://problem/32700180, a crash-on-valid.
2017-06-14 22:44:32 -07:00
Slava Pestov
65c3565c2d Sema: Fix failure to produce diagnostics when 'is' casts are involved
When re-typechecking an expression during diagnostics, we begin by
erasing all the types in the expression. However, any expressions
created as part of applying the solution will remain.

CSGen was doing the wrong thing when it encountered EnumIsCaseExpr,
which can only appear in already-type checked ASTs.

Returning expr->getType() is not correct, because the type is not
yet set; returning a null type is intended to signal that a
diagnostic was already emitted, which causes Sema to stop
type checking.

The end result is that certain combinations of invalid code with
an 'is' cast nested inside would crash either the AST verifier
(with asserts on) or in SILGen (with asserts off), because we
would stop trying to diagnose the issue prematurely, and possibly
not emit a diagnostic at all.

Fixes <https://bugs.swift.org/browse/SR-5050> and
<rdar://problem/32487948>.
2017-06-13 20:19:43 -07:00
Slava Pestov
632fdf5dbd Sema: Add a SE-0110-related test case that used to crash 2017-06-05 23:11:53 -07:00
Robert Widmann
71bf312a25 Migrate the rest of the tests to %empty-directory 2017-06-04 11:08:39 -07:00
Slava Pestov
945f6cfeb1 Add a fixed crasher and an unfixed one 2017-06-02 20:43:27 -07:00
Doug Gregor
a9733cb8db [GSB] Resolve dependent member types in same-type and superclass constraints.
Once we're finalizing same-type-to-concrete and superclass
constraints, replace any unresolved DependentMemberTypes with their
resolved counterpairs. This allows us to simplify
DependentGenericTypeResolver, which only builds unresolved
DependentMemberTypes now, and eliminates the penultimate use of
ArchetypeResolutionKind::AlwaysPartial.
2017-05-30 11:43:53 -07:00
Pavel Yaskevich
9c1e9756e4 Merge pull request #9971 from xedin/sr-4301
[QoI] Fix crash when constructing existential metatype without '.init'
2017-05-29 23:16:45 -07:00
Pavel Yaskevich
29b8f5615d [QoI] Fix crash when constructing existential metatype without '.init'
Resolves: SR-4301.
2017-05-29 22:08:50 -07:00
Slava Pestov
7af399fd51 Sema: Change a getInterfaceType() to hasInterfaceType() in a couple of places
ValueDecl::getInterfaceType() asserts if the decl has no interface
type; to check if the declaration has been type checked yet, use
hasInterfaceType().

Fixes <https://bugs.swift.org/browse/SR-4743>.
2017-05-29 00:06:55 -07:00
Slava Pestov
fc21ecce68 AST: Don't return hasTypeParameter() for DependentMemberTypes with an ErrorType base
Instead, introduce a new hasDependentMember() recursive property.

The only place that cares about this is associated type inference,
where I changed all existing hasTypeParameter() checks to instead
check (hasTypeParameter() || hasDependentMember()). We could
probably refine this over time and remove some of the
hasTypeParameter() checks, but I'm being conservative for now.

Fixes <https://bugs.swift.org/browse/SR-4575> and
<rdar://problem/31603113>.
2017-05-26 18:10:13 -07:00
Slava Pestov
a3ff37c1ad Add an unfixed crasher and two fixed ones 2017-05-23 23:14:10 -07:00
Slava Pestov
e4b08e00a2 Add a regression test 2017-05-22 18:35:52 -07:00
Slava Pestov
e58ae766a3 Fix and un-XFAIL regressed crashers from recent stdlib change 2017-05-17 05:51:51 -07:00
Ben Cohen
ea2f64cad2 [stdlib] Add Sequence.Element, change ExpressibleByArrayLiteral.Element to ArrayLiteralElement (#8990)
* Give Sequence a top-level Element, constrain Iterator to match

* Remove many instances of Iterator.

* Fixed various hard-coded tests

* XFAIL a few tests that need further investigation

* Change assoc type for arrayLiteralConvertible

* Mop up remaining "better expressed as a where clause" warnings

* Fix UnicodeDecoders prototype test

* Fix UIntBuffer

* Fix hard-coded Element identifier in CSDiag

* Fix up more tests

* Account for flatMap changes
2017-05-14 06:33:25 -07:00
Doug Gregor
fd4bcdc007 Add fixed crasher for rdar://problem/30154791. 2017-05-11 09:31:58 -07:00
Slava Pestov
a21053d5d2 Add a regression test 2017-05-07 01:57:38 -07:00
Slava Pestov
bf23ed2d18 Add a regression test 2017-05-03 22:31:52 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Doug Gregor
93435d17d6 [Substitution Map] Handle substitutions of generic parameters made concrete.
If SubstitutionMap is asked to form a substitution for a generic
parameter that has been made concrete by the generic signature,
substitute into the concrete type. This allows us to better deal with
non-canonical types.
2017-04-28 16:22:07 -07:00
Doug Gregor
29a15ce402 [Stdlib] Apply SE-0142 to fix ABI FIXME #92, part of ABI FIXME #99. 2017-04-19 23:15:33 -07:00
Slava Pestov
60998cbb50 Merge pull request #8842 from slavapestov/new-test
Add a regression test
2017-04-18 14:58:47 -07:00
Slava Pestov
b450552c26 Add a regression test 2017-04-18 14:10:56 -07:00
Doug Gregor
d21d6f1585 [Generic environment] Only substitute top-level archetypes.
The core substitution routine for the archetypes-to-interface types
substitution was attempting to provide mappings for nested archetypes,
when in fact these archetypes would (1) always be resolvable via their
parent, and (2) could in fact cause infinite recursion, as with the
new test case. Fixes SR-4617 / rdar://problem/31673819.
2017-04-18 13:19:21 -07:00
Max Moiseev
9b53efd72c Merge branch 'master' into new-integer-protocols 2017-04-17 09:53:44 -07:00
Doug Gregor
4ed8bf5532 New test requires ObjC support 2017-04-17 06:15:25 -07:00
Doug Gregor
a892e89922 [GSB] Simplify and clean up RequirementSource::isSelfDerivedSource().
Reimplement isSelfDerivedSource() in terms of the new
visitPotentialArchetypesAlongPath(). Aside from being clearer and
shorter, this formulation eliminates some hackery (the direct
"NestedType" lookup) that was mostly masking a bug in
updateNestedTypeForConformance() where we created a
nested-type-name-match source with an incorrect source for the
purposes of concretizing the nested type.

Fixes SR-4458 / rdar://problem/31375569.
2017-04-16 23:05:28 -07:00
Doug Gregor
8dfc25edc7 [GSB] Filter out conformance constraints derived from concrete conformance.
When an otherwise abstract conformance constraint is derived from a
concrete conformance, retain the abstract conformance by removing the
requirement source that involves the concrete conformance. This
eliminates our reliance on the concrete conformance, which is not
retained as part of the generic signature.

Fixes rdar://problem/31163470 and rdar://problem/31520386.
2017-04-16 23:05:23 -07:00
Max Moiseev
022665547b Merge branch 'master' into new-integer-protocols 2017-04-07 14:42:53 -07:00
Slava Pestov
51d7723640 Add regression test for a bug that's already fixed 2017-04-06 15:56:41 -07:00
Max Moiseev
8fe28b4e32 Merge branch 'master' into new-integer-protocols 2017-04-06 10:22:37 -07:00
Doug Gregor
44c2f849d6 [Type checker] Continue validating requirements after an error.
We want to validate both type in same-type or conformance constraints,
even when the first type is ill-formed, so we don't leave null types
around for later phases to crash on.

Fixes rdar://problem/31093854.
2017-04-05 14:05:59 -07:00
Max Moiseev
52882c47b4 Merge branch 'master' into new-integer-protocols 2017-04-05 11:26:13 -07:00
Roman Levenstein
75c8274fd9 Fix tests 2017-04-04 13:10:43 -07:00
Max Moiseev
42095bfbaa Merge branch 'master' into new-integer-protocols 2017-04-04 11:00:47 -07:00
Slava Pestov
9db6b10059 AST: Targeted fix for conformance lookup issue
When substituting a type like T.A.B where A and B are
associated types and the conformance requirement on T.A
is implied by conformance requirements on T, we would
crash.

The problem is that we have no way of representing an
abstract conformance with nested concrete types.

This patch adds a workaround that we can live with until
ConformanceAccessPaths are plumbed through all the way.

Fixes <rdar://problem/30737546> and
<https://bugs.swift.org/browse/SR-3500>.

Possibly fixes <rdar://problem/31334245>.
2017-04-03 15:35:10 -07:00
Max Moiseev
969b4814e2 Merge branch 'master' into new-integer-protocols 2017-03-27 20:40:15 -07:00
Slava Pestov
19b12aa3b1 Sema: Fix convenience init delegation to a convenience init in a generic base class
While in the constraint system, the delegation is modeled as
returning an instance of the derived class, in the AST we type
the reference as returning an instance of the base class, and
insert a downcast, because in SILGen we're calling the base
class initializer which is typed as returning the base class.

This bit of fixup logic wasn't happening if the base class was
generic, and so we were not inserting the cast, which would
crash in SILGen with an assert.

Fixes <rdar://problem/31000248>.
2017-03-26 00:00:53 -07:00
Max Moiseev
ec8e286b5c Merge branch 'master' into new-integer-protocols 2017-03-24 14:14:00 -07:00
Doug Gregor
c4735314d1 Add test for SR-4016 / rdar://problem/30677848, which is now fixed. 2017-03-24 11:36:45 -07:00
Max Moiseev
b9fb3badc8 Merge remote-tracking branch 'origin/master' into new-integer-protocols 2017-03-22 12:30:24 -07:00
Slava Pestov
a3a290eb60 Mangling: Fix bug in the logic for dropping same-type constraints
It's not correct to drop a constraint if one of the two types
structurally contains generic parameters at the method depth.
2017-03-21 00:15:18 -07:00
Doug Gregor
87dab47d5d [HACK] XFAIL a crasher that was passing due to bogus canonicalization
This test was passing for the wrong reasons before. We need to
correctly model cases where a nested type of an abstract conformance is
in fact concrete and, therefore, has concrete conformances. XFAIL for now.
2017-03-16 23:16:32 -10:00
John McCall
22382f7e15 Reimplement associated conformance IRGen using Doug's conformance
access path work.

Having done so, simplify archetype TypeInfos by removing a now-
unnecessary layer of abstraction.
2017-03-14 03:48:10 -04:00
Max Moiseev
7d73b2e1ca Arithmetic => Numeric 2017-03-13 11:50:02 -07:00
Slava Pestov
068f3a18da Sema: Fix crash if we try to look up constructors while validating a constructor
addImplicitConstructors() will crash if validateDecl() does not produce
a valid signature for one of the class's constructors because the
constructor is already being validated.

This was triggered during associated type inference in the test case
in the radar.

Fixes <rdar://problem/30751491>.
2017-03-13 01:50:41 -07:00
Slava Pestov
3ab7c7283d Sema: Allow protocol typealiases to witness associated type requirements
When resolving a type witness by lookup, also consider protocol members.

Fixes <rdar://problem/30442622>.
2017-03-13 01:19:45 -07:00
Max Moiseev
8ffbc81239 Fixing some validation tests 2017-03-10 17:09:28 -08:00