Commit Graph

631 Commits

Author SHA1 Message Date
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
Doug Gregor
a4e35ed151 [GSB] Remove unused form of addSameTypeRequirementDirect() 2017-06-23 10:00:11 -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
Slava Pestov
151f38630b AST: Fix DeclContext::getAsTypeOrTypeExtensionContext() for extensions of typealiases 2017-06-21 00:44:32 -07:00
Slava Pestov
773d7b3225 Sema: Remove more methods from GenericTypeResolver
resolveGenericTypeParamType(), resolveTypeOfDecl() and
resolveTypeOfContext() would all take the type of a
declaration, and optionally map it into context.

Replace them with a mapTypeIntoContext() that takes a
type and either returns it verbatim or maps it into
context.
2017-06-15 21:31:35 -07:00
Slava Pestov
d1610a5536 Sema: Kill GenericTypeResolver::resolveSelfAssociatedType() 2017-06-15 18:37:16 -07:00
Doug Gregor
622e3a6342 Fixed a compiler crasher 2017-06-14 23:23:53 -07:00
Slava Pestov
c4df92aef3 Sema: Clean up 'dynamic' inference a bit 2017-06-07 17:55:42 -07:00
Slava Pestov
c152fee9f8 Sema: A couple of recursion-breaking hacks 2017-06-07 17:19:09 -07:00
Slava Pestov
00997138b5 Sema: Fix crash with associated type <=> typealias circularity 2017-06-06 23:56:34 -07:00
Slava Pestov
ec60c88412 Sema: Use requirement signature to check type witnesses 2017-06-06 23:56:33 -07:00
Slava Pestov
18082b1b3f Sema: Don't set "validation started" bit on typealiases in the ITC
This appears to do nothing except cause a crash.
2017-06-06 23:56:33 -07:00
Slava Pestov
c49a1d77d2 AST: Stricter DeclContext::getParentForLookup() 2017-06-06 23:56:32 -07:00
Slava Pestov
9e1f60d751 Sema: Skip an invalid kind of nested type in name lookup 2017-06-06 23:56:31 -07:00
Slava Pestov
55ffbe8cce AST: Fix Type::transform() for protocol compositions
There was undefined behavior here; we were calling
members.append(members.begin(), members.begin() + index),
which is invalid because 'members' is the new array of
members being built, which is empty at this point!
2017-06-06 23:27:54 -07:00
Slava Pestov
1bd91dee5c Sema: Fix crash with unbound generic types in patterns 2017-06-06 00:35:02 -07:00
Slava Pestov
e5becab4ac Sema: Fix crashes when applying solution with error types or unresolved types 2017-06-05 23:50:30 -07:00
Slava Pestov
433b7f276e Sema: Fix bug with name lookup from initializers 2017-06-05 23:11:53 -07:00
Robert Widmann
25901cc467 Merge pull request #10065 from CodaFi/shame-on-you-shame-on-your-cow
Change an assertion to an ad-hoc circularity check
2017-06-02 11:40:06 -07:00
Robert Widmann
12f81163b1 Change an assertion to an ad-hoc circularity check 2017-06-02 10:23:02 -07:00
swift-ci
032c18c426 Merge pull request #10064 from CodaFi/thats-not-my-name 2017-06-02 00:37:12 -07:00
Robert Widmann
72ee26a52f Resolve a crasher 2017-06-01 23:58:14 -07:00
Jordan Rose
63bc717963 Error when one associated type is constrained to another. (#10053)
(...is constrained to be a subtype of another)

Previously the compiler would just mark the entry in the inheritance
clause invalid and move on without emitting any errors; in certain
circumstances in no-asserts builds this could actually lead to
everything working "correctly" if all conforming types happened to
pick the same concrete type for both associated types. In Swift 4 this
can actually be enforced with a same-type requirement, which will
guarantee that the two associated types are the same even in generic
contexts.

This fix avoids assertions and crashes, but the diagnostic is still
incorrect, and in the simple case of the inheritance clause it's
redundant. Doing something better and possibly even downgrading it to
a warning in Swift 3 mode is tracked by rdar://problem/32409449.

Initial patch by Slava, fixed up by me.
2017-06-01 19:45:34 -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
da4232e546 [Diagnostics] Fix checking for presence of type variables in closure return expression
Instead of validating sub-expressions included in the closure's result
`diagnoseAmbiguousMultiStatementClosure` was only checking parent expression
by mistake.
2017-05-30 02:42:56 -07:00
Jacob Bandes-Storch
b7fe4e2355 [Parse] Fix InFlightDiagnostic lifetime (#9961)
Fixes @practicalswift's crasher 28759 (#9907), which seems to have been introduced in #9294.
2017-05-27 13:38:05 -07:00
Jacob Bandes-Storch
035179331b [CSDiag] Fix crasher in KeyPathExpr diagnosis (#9962)
New KeyPathExpr diagnosis recently added in #9845 did not work for Obj-C key paths.
2017-05-27 13:36:56 -07:00
Slava Pestov
39d0385e10 Sema: Fix a crasher by removing TVO_CanBindToInOut in a couple of spots 2017-05-26 23:47:10 -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
1c7428666a Sema: Update isExtensionApplied() for primitive AnyObject 2017-05-24 22:09:23 -07:00
Slava Pestov
d8234bace6 Sema: Fix double type checking of lazy initializer expressions
If a lazy var has no declared type, we have to type check the
initializer to get a type before we can build the getter.

Then, the initializer is type checked as part of the getter
again.

Use the new SkipApplyingSolution flag when type checking for
the first time. We still end up doing redundant work, but by
not applying the solution we avoid feeding invalid AST nodes
back into the constraint solver.

This fixes some bad diagnostics and crashes.

Fixes <https://bugs.swift.org/browse/SR-2616> and
<rdar://problem/28313602>.
2017-05-24 17:21:28 -07:00
Slava Pestov
fa155bf1d1 Sema: Rework typeCheckBinding() to use the new foundSolution() callback
Record the initializer type as soon as we have a solution, before
it is applied, and get the type from the constriant system instead
of from the final type checked expression.

Note that the coerceToMaterializable() was unnecessary, since we
always coerce the value to an rvalue type with coerceToType().

Eventually coerceToMaterializable() should go away.

This is mostly NFC, except using the result of simplifyType() rather
than the type of the final expression changes some diagnostics where it
appears we were previously losing sugar.

Also this accidentally fixes a crasher. Unfortunately the underlying
issue is still there (applying a solution has bugs with opened
existentials "leaking" out) -- this merely masks the problem by
getting the initializer type directly from the constriant system.
2017-05-24 17:21:28 -07:00
Joe Groff
2e04e24ad8 Merge pull request #9760 from jckarter/sibling-nested-generic-call
Sema: Bind context generic params using the current ConstraintSystem's generic environment instead of the decl's DC.
2017-05-19 13:14:26 -07:00
Joe Groff
d16eb33477 Sema: Bind context generic params using the current ConstraintSystem's generic environment instead of the decl's DC.
Fixes SR-4833.
2017-05-19 10:47:57 -07:00
Dave Abrahams
4660a77816 Patch up tests per https://github.com/apple/swift/pull/9689 2017-05-17 17:17:49 -07:00
Dave Abrahams
9f37da8bb6 Merge branch 'master' into string-init-from-character-speedup 2017-05-17 12:23:56 -07:00
Dave Abrahams
4db3509ad6 [stdlib] A Character's buffer should only contain 1 grapheme
This speeds up construction of a String from large Character representations,
and various other operations that would otherwise require additional grapheme
breaking just to interpret the Character.
2017-05-17 10:06:35 -07:00