Commit Graph

7976 Commits

Author SHA1 Message Date
Slava Pestov
c71395a4c3 Sema: Small cleanup in CSDiag 2016-12-01 13:00:17 -08:00
Bob Wilson
2c21ef586d Update to match llvm r279473: remove ilist_*sentinel_traits.
(cherry picked from commit 391e7d8b60)
2016-12-01 10:46:38 -08:00
Bob Wilson
26a62b912a Update to match llvm r278513: share code for embedded sentinel traits.
Nothing at all should be changing here, this is just rearranging code.

(cherry picked from commit 9964697f22)
2016-12-01 10:42:59 -08:00
Doug Gregor
79812aa073 [Archetype builder] (Almost) decouple PotentialArchetype from generic params.
The root potential archetypes in an archetype builder are associated
with generic parameters. Start decoupling potential archetypes from a
specific GenericTypeParamType and instead work with the abstracted
depth/index. The goal here is to allow the same archetype builder to
be used within different generic environments (which includes both
different generic parameters and different archetypes).

As part of this, boost the archetype builder's GenericTypeParamKey
from a local type to a more generic GenericParamKey that can be used
in other interfaces that want to work with abstracted generic
parameters.
2016-11-30 15:44:14 -08:00
Argyrios Kyrtzidis
482dbc452b [Sema] Fix issue with TypeCaptureWalker holding-on a dangling llvm::function_ref reference. 2016-11-30 11:02:10 -08:00
Mark Lacey
9450713223 Remove some unnecessary setType() from CSGen.cpp.
The visitor sets these types to the type returned, so it is
unnecessary to set these just before returning them.
2016-11-29 14:16:07 -08:00
swift-ci
6a5cf720d3 Merge pull request #5974 from DougGregor/archetype-builder-cleanups 2016-11-29 11:46:24 -08:00
Doug Gregor
581a4de97d [Archetype builder] Eliminate 'builder' parameter to getDependentType(). 2016-11-29 10:45:30 -08:00
Doug Gregor
71b6326021 [Archetype builder] Minor simplifications to constructor, "getType()". NFC 2016-11-29 10:23:18 -08:00
Hugh Bellamy
48109f2a64 Fix errors and warnings building libSwiftSema on Windows using MSVC 2016-11-29 11:24:13 +00:00
Slava Pestov
01bb403e55 AST: Prohibit archetypes in setInterfaceType() 2016-11-29 03:05:36 -07:00
Slava Pestov
835472b14f AST: Remove PolymorphicFunctionType 2016-11-29 03:05:35 -07:00
Slava Pestov
287700631a Sema: configureImplicitSelf() no longer needs to return a type 2016-11-29 03:05:34 -07:00
Slava Pestov
0f7a455d7d AST: Don't call setType() on AbstractFunctionDecls and EnumElementDecls 2016-11-29 03:05:33 -07:00
Slava Pestov
82b764db6a Sema: Tweak a circularity check
Instead of checking if the function has a contextual type, the more
accurate predicate here is if it already has a generic environment.
2016-11-29 03:05:33 -07:00
Slava Pestov
8272fc1530 AST: Assert if getType() called on AbstractFunctionDecl or EnumElementDecl
These can contain PolymorphicFunctionTypes, and should no longer be
accessed.
2016-11-29 03:05:32 -07:00
Slava Pestov
044034cae5 Sema: hasType() => hasInterfaceType() 2016-11-29 03:05:31 -07:00
Slava Pestov
7c556712dd Sema: Fix CSDiag bug noticed by inspection
This triggered with an existing test that was run against
some other changes I was working on, but the current code
does not demonstrate the problem.

However, it's "obviously" more "correct", so here we go.
2016-11-29 03:05:28 -07:00
Slava Pestov
492a8494ad Sema: CSDiag setType() => getInterfaceType()
When collecting callee candidates, get the interface type and map it
into context, rather than calling getType() directly.

This produces almost the same result as getType(), except for two
differences:

1) where getType() would return a PolymorphicFunctionType with
a reference to the original generic parameters, now CSDiag just
sees a simple FunctionType appears with discombobulated archetypes.
This is fine since CSDiag does not do anything specific with
PolymorphicFunctionTypes.

2) substGenericArgs() calls Type::subst(), which produces
SubstitutedType sugar. This would confuse CSDiag, which was not
prepared to see SubstitutedTypes that arise from this particular
call of Type::subst().

As mentioned in a previous commit message, CSDiag should be
refactored to get substitutions via a call to getMemberSubstitutions(),
instead of 'recovering' them from result of getTypeOfMember().

Until this can be fixed, I'm just manually stripping off any
SubstitutedTypes that appear from the call to substGenericArgs().

A better approach here would be to redo the callee diagnostics
stuff to look at interface types, plumbing through the correct
generic signatures. Then questions like 'what protocols does this
generic parameter conform to' can be asked of the signature and
interface type, instead of looking at archetypes.
2016-11-29 03:05:28 -07:00
Slava Pestov
fa9d66c70f Sema: Small refactoring for findGenericSubstitutions()
When matching a potential callee type against the actual argument
types in a call expression, CSDiag would walk both types in parallel,
noting differences and recording archetype substitutions in a map.

We would also walk the callee type and attempt to recover substitutions
that came from a 'self.foo' method application where self is a generic
nominal type. This relied on the fact that Type::subst() leaves behind
the old types in the form of SubstitutedType sugar.

Only one of the two call sites of findGenericSubstitutions() used the
second feature, so move the SubstitutedType walk over to that call site
instead of doing it for both.

Unfortunately the SubstitutedType walk is somewhat fragile, because
multiple subst() calls with different generic contexts will leave behind
an unpredictable structure of SubstitutedTypes. The code in CSDiag has
some heuristics to bail out when things don't make sense, but I think it
would be simpler to just call getMemberSubstitutions() and pass around
the substitution map together with the substituted type and original decl.

Notably, the only other place we rely on SubstitutedType showing up in
the result of Type::subst() is accessibility and availability checking
for nested typealiases, like 'Foo<T>.Bar', so it might be wise to redo
these passes to operate on the types of decls before we apply generic
parameters. Then we could remove SubstitutedType altogether.
2016-11-29 03:05:27 -07:00
Slava Pestov
7cfe0e6401 Sema: getType() => getInterfaceType() 2016-11-29 03:05:27 -07:00
Slava Pestov
6cbb494ad2 AST: Give all ValueDecls an interface type
Previously, getInterfaceType() would return getType() if no
interface type was set. Instead, always set an interface type
explicitly.

Eventually we want to remove getType() altogether, and this
brings us one step closer to this goal.

Note that ParamDecls are excempt from this treatment, because
they don't have a proper interface type yet. Cleaning this up
requires more effort.
2016-11-29 03:05:25 -07:00
Slava Pestov
f803d8f12c AST: Remove AbstractFunctionDecl::getBodyResultType()
This is made redundant by the existing getResultInterfaceType()
accessor.
2016-11-29 03:05:23 -07:00
Slava Pestov
f6e692198c AST: Remove FuncDecl::getResultType() 2016-11-29 03:05:23 -07:00
Slava Pestov
55ad1800a1 AST: Remove ConstructorDecl::getArgumentType() 2016-11-29 03:05:23 -07:00
Slava Pestov
69e7cca64f AST: Remove ConstructorDecl::getResultType() 2016-11-29 03:05:22 -07:00
xedin
2f3b5ad318 [QoI] Handle coercions involving ImplicitlyUnwrappedOptional<T> as 'from' type (#5900)
Add a case to ExprRewriter.coerceToType which tries to look through
ImplicitlyUnwrappedOptional<T> and apply 'to-value' transformation
before coercing to required 'to' type.

Resolves: <rdar://problem/28023899>.
2016-11-29 16:08:34 +09:00
swift-ci
9c5c28a0ad Merge pull request #5947 from rintaro/sema-diag-valueofmeta 2016-11-28 22:53:01 -08:00
Rintaro Ishizaki
cdcbc2d2e0 [QoI] When adding '.self' for metatype expressions, enclose with parenthesis if the typerepr is not Simple 2016-11-29 15:28:48 +09:00
Rintaro Ishizaki
af19a0bd50 [Diag] Suggest adding '()' only if it has accessible initializers 2016-11-29 15:28:48 +09:00
Pavel Yaskevich
d111e9b4be [Diagnostics] When building a subscript don't assume that overload is always present
This handles situation when overload for the subscript hasn't been resolved
by constraint solver, such might happen, for example, if solver was allowed to
produce solutions with free or unresolved type variables (e.g. when running diagnostics).

Resolves: <rdar://problem/27329076>, <rdar://problem/28619118>, <rdar://problem/2778734>.
2016-11-28 19:18:44 -08:00
swift-ci
fe1cd74221 Merge pull request #5808 from xedin/r28051973 2016-11-28 17:01:38 -08:00
Pavel Yaskevich
2707a9c585 [Diagnostics] Improve diagnostics of overloaded mutating methods
Add special logic to FailureDiagnosis::visitApplyExpr to
handle situation like following:

struct S {
  mutating func f(_ i: Int) {}
  func f(_ f: Float) {}
}

Given struct has an overloaded method "f" with a single argument of
multiple different types, one of the overloads is marked as
"mutating", which means it can only be applied on LValue base type.
So when struct is used like this:

let answer: Int = 42
S().f(answer)

Constraint system generator is going to pick `f(_ f: Float)` as
only possible overload candidate because "base" of the call is immutable
and contextual information about argument type is not available yet.
Such leads to incorrect contextual conversion failure diagnostic because
type of the argument is going to resolved as (Int) no matter what.
To workaround that fact and improve diagnostic of such cases we are going
to try and collect all unviable candidates for a given call and check if
at least one of them matches established argument type before even trying
to re-check argument expression.

Resolves: <rdar://problem/28051973>.
2016-11-28 14:23:14 -08:00
practicalswift
7d412572e6 [gardening] Use proper doxygen comments (///) 2016-11-28 21:25:30 +01:00
Rintaro Ishizaki
da36a13474 Merge pull request #5926 from rintaro/ast-tupletyperepr-tail
[AST] Tail allocate TupleTypeRepr elements and names. Eliminate NamedTypeRepr
2016-11-26 16:30:15 +09:00
Slava Pestov
ea28765ced Sema: Resolve invalid generic parameters to error types
When a generic parameter list fails to parse, we don't call
DeclContext::setGenericParams(), even though the generic
parameters are still available for name lookup.

This causes various crashes, which this patch fixes by
mapping the generic parameters to ErrorTypes.
2016-11-26 01:31:59 -05:00
Rintaro Ishizaki
264be984b5 [AST] Eliminate NamedTypeRepr
Now that, TupleTypeRepr holds all information needed.
2016-11-26 14:17:57 +09:00
Rintaro Ishizaki
9b243526b8 [AST] Hold element name information in TupleTypeRepr
For now, only 'TupleTypeRepr::isParentType()' is using this informations.
Next commit will eliminate NamedTypeRepr.
2016-11-26 14:15:29 +09:00
Rintaro Ishizaki
6702d5d3fd [AST] Tail allocate TupleTypeRepr elements 2016-11-26 14:14:11 +09:00
Graydon Hoare
7c1dc18b64 Revert "Give all declarations an explicit interface type" 2016-11-24 09:55:27 -08:00
Slava Pestov
e8a7eabc97 Merge pull request #5910 from slavapestov/give-all-decls-interface-type
Give all declarations an explicit interface type
2016-11-24 02:53:19 -05:00
Slava Pestov
dbf3e682ee Merge pull request #5893 from xedin/r27575060
[QoI] Coerce tuple type elements to RValue before erasure
2016-11-24 02:39:46 -05:00
Slava Pestov
5b8524a9d1 AST: Remove FuncDecl::getResultType() 2016-11-24 02:35:35 -05:00
Slava Pestov
1dc14e2ec6 AST: Remove ConstructorDecl::getArgumentType() 2016-11-24 02:35:35 -05:00
Slava Pestov
6db43138fa AST: Remove ConstructorDecl::getResultType() 2016-11-24 02:35:30 -05:00
Slava Pestov
ee56292808 AST: Give all ValueDecls an interface type
Previously, getInterfaceType() would return getType() if no
interface type was set. Instead, always set an interface type
explicitly.

Eventually we want to remove getType() altogether, and this
brings us one step closer to this goal.

Note that ParamDecls are excempt from this treatment, because
they don't have a proper interface type yet. Cleaning this up
requires more effort.
2016-11-24 02:35:21 -05:00
Rintaro Ishizaki
8d4ed3219e [Sema] Recusively preCheckExpression() for folded sequence expression
Since 'try' or '=' can be folded with type expression at the same time,
Shallow simplifyTypeExpr() results '->' being escaped from TypeChecker.

For instance:
  try () -> Int
Used to crash the compiler.

Also, never return nullptr for ArrowExpr. `1 -> Int` is invalid anyway.
Instead of leave ArrowExpr as is, construct ErrorTypeRepr for '1' part.
2016-11-24 10:46:36 +09:00
Rintaro Ishizaki
b92f769932 [Sema] Handle 'P1 & P2 -> P3 & P4' expression
_ = (P1 & P2 -> P3 & P4).self

This expression is parsed as a single SequenceExpr, thus folded the same time.
We have to rescusively simplifyTypeExpr() both LHS and RHS.
2016-11-24 10:46:36 +09:00
Slava Pestov
241abfaaee Merge pull request #5869 from jtbandes/diag-inaccessible-init
[QoI] Improve diagnostics when accessing .init on a non-metatype
2016-11-23 18:25:36 -05:00
Slava Pestov
bbb869415f Merge pull request #5880 from jtbandes/there-can-be-only-one
[Sema] Disallow multiple overrides of the same base declaration
2016-11-23 18:24:44 -05:00