Commit Graph

483 Commits

Author SHA1 Message Date
Slava Pestov
f2868dfaac Sema: Don't load unnecessary lazy generic environment in bindArchetypesFromContext() 2018-09-26 23:26:07 -07:00
Slava Pestov
858f4b9562 Sema: Remove AssociatedType constraint locator element kind 2018-09-26 23:26:07 -07:00
gregomni
6deb401cc6 Previously we were sharing a single type variable for a param of a closure's function type and it's paramDecl's type inside the closure itself. With inout parameters this caused vardecls of inout type and some hacks to deal with them.
Instead, create two TVs and constrain them appropriately.
2018-09-23 17:41:18 -07:00
Pavel Yaskevich
baceb68f85 [ConstraintSystem] Rename solveIteratively to solve and start using it
Remove solution filtering from new iterative `solve` method, and
replace all usages of `solveRec` with it.
2018-09-15 20:56:47 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Slava Pestov
83cc9755ed Sema: Refactor matchFunctionTypes() to walk parameter lists directly
This lets us remove a variety of ParenType-preserving hacks.
2018-09-10 12:30:47 -07:00
Pavel Yaskevich
d560b36c5c [ConstraintSystem] NFC: Move allowFreeTypeVariableBindings into SolverState
Currently `allowFreeTypeVariableBindings` flag has to be passed all
the way down from top-level `solve` call to `finalize` that forms
(partial and complete) solutions. Instead of doing that, let's just
make it a part of the solver state, which is already present
throughout whole solver run.
2018-08-31 19:51:11 -07:00
Slava Pestov
765b8844cf Sema: Move removeArgumentLabels() to a method on TypeBase 2018-08-28 14:40:56 -07:00
Pavel Yaskevich
c69097f027 Merge pull request #18980 from xedin/move-salvage-to-cs
[ConstraintSystem] Move `salvage` and related logic away from `CSDiag`
2018-08-25 14:09:48 -07:00
Pavel Yaskevich
7dda51bb81 [Diagnostics] Transform tryDiagnoseTrailingClosureAmbiguity into a failure 2018-08-25 00:19:41 -07:00
Pavel Yaskevich
ea62075766 [ConstraintSystem] NFC: Move diagnoseAmbiguity methods from CSDiag to ConstraintSystem` 2018-08-24 23:18:49 -07:00
Pavel Yaskevich
4692e30c0a [ConstraintSystem] NFC: Move salvage from CSDiag to ConstraintSystem 2018-08-24 17:37:24 -07:00
Robert Widmann
014fd952ef [NFC] Silence a bunch of Wunused-variable diagnostics 2018-08-24 15:16:40 -07:00
Doug Gregor
0eaa00a470 [Type checker] Separate type resolution from the TypeChecker instance. 2018-08-20 22:18:43 -07:00
Doug Gregor
2756377367 [Type checker] Separate more functionality from the TypeChecker instance.
Use the usual bag of tricks to eliminating dependence on the
TypeChecker instance: static functions, LazyResolver callbacks, and
emitting diagnostics on decls/ASTContext.
2018-08-20 21:39:44 -07:00
Doug Gregor
7fa4f1df54 Merge pull request #18859 from DougGregor/type-resolution-stage
[Type Checker] Add TypeResolution(Stage) to describe type computations.
2018-08-20 18:44:31 -07:00
Doug Gregor
79a55895de [Type Checker] Replace GenericTypeResolver with a TypeResolution.
Replace the GenericTypeResolver type hierarchy with TypeResolution,
which more simply encapsulates the information needed to resolve
dependent types and makes explicit those places where we are
using resolution to contextual types.
2018-08-20 16:53:44 -07:00
Slava Pestov
527ff375dc AST: Rename old form of {Generic,}FunctionType::get() to getOld()
This makes it easier to grep for and eventually remove the
remaining usages.

It also allows you to write FunctionType::get({}, ...) to call the
ArrayRef overload empty parameter list, instead of picking the Type
overload and calling it with an empty Type() value.

While I"m at it, in a few places instead of renaming just clean up
usages where it was completely mechanical to do so.
2018-08-17 19:28:17 -04:00
Slava Pestov
a54251074c AST: ExtInfo just wraps an unsigned integer, no need to pass it by reference 2018-08-17 19:27:43 -04:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Pavel Yaskevich
2db0e60275 [ConstraintSystem] Add kind to generic requirement locator
Having requirement kind encoded in the locator helps to identify
what kind of fix to generate (applicable to same-type, superclass)
without retrieving requirement itself.
2018-08-16 01:45:52 -07:00
Slava Pestov
31a570d53c AST: Replace TypeBase::getRValueInstanceType() with getMetatypeInstanceType()
That is, don't look through InOutType anymore, and update callers to
call getInOutObjectType() as well (or not, where it was obvious to me
that InOutType could not appear).

This surfaces more remaining uses of getInOutObjectType() directly.
2018-08-13 21:13:10 -07:00
David Zarzycki
6b6ef5af24 [Sema] NFC: Refactor most TypeResolutionFlags into a traditional enum
TypeResolutionFlags is overly complicated at the moment because the vast
majority of flag combinations are impossible and nonsensical. With this
patch, we create a new TypeResolverContext type that is a classic enum
and far easier to reason about. It also enables "exhaustive enum"
checking, unlike the "flags" based approach.
2018-08-13 08:18:40 -04:00
Doug Gregor
3018becde7 [Type checker] Eliminate type checking from early extension binding.
Use ExtensionDecl::getExtendedNominal() to wire up extensions to their
nominal types early in type checking (the bindExtensions()) operation,
rather than going through type validation to do so.
2018-08-03 11:26:49 -07:00
Mark Lacey
423d2c6139 Merge pull request #18478 from rudkx/getFixedTypeRecursive
[ConstraintSystem] Simplify getFixedTypeRecursive a little.
2018-08-02 19:27:46 -07:00
Mark Lacey
10ea2a59ce [ConstraintSystem] Simplify getFixedTypeRecursive a little.
By making it...recursive.
2018-08-02 15:14:51 -07:00
Slava Pestov
8fc7f7e1e6 Sema: Fix ConstraintSystem::getTypeOfMemberReference() for protocol typealiases 2018-08-01 23:01:56 -07:00
Pavel Yaskevich
16cbc00cbe [ConstraintSystem] Switch to useDC for getUnopenedTypeOfReference while calling from getTypeOfReference 2018-07-28 20:28:42 -07:00
Pavel Yaskevich
f9c6ed54ed [Sema] NFC: Refactor getUnopenedTypeOfReference to accept callback for type 2018-07-28 20:28:41 -07:00
Pavel Yaskevich
d62be440ce [CSSolver] Split `getType(ValueDecl*) into three - getType{OrNull, OrInterfaceType} 2018-07-28 20:28:41 -07:00
Pavel Yaskevich
398abdfb7c [CSSolver] Add closure parameter type caching
While inferring avoid associating type variables with closure
parameters, use cache instead and only set types when everything
is properly type-checked, this avoids multiple problems one of
them - leaking type variables outside of constraint system they
belong to.
2018-07-28 20:28:41 -07:00
Mark Lacey
8f9fcaa275 Merge pull request #18325 from rudkx/minor-refactoring
[ConstraintSystem] Some small clean-ups to getFixedType, getFixedTypeRecursive, and simplifyType
2018-07-28 19:15:12 -07:00
Mark Lacey
a5da413c2a [ConstraintSystem] Simplify getFixedTypeRecursive a bit. 2018-07-27 23:34:03 -07:00
Mark Lacey
4ac4d42b37 [ConstraintSystem] Another small simplification. 2018-07-27 21:08:20 -07:00
Pavel Yaskevich
624c183fe0 [ConstraintGraph] Change gatherConstraints to take SetVector
For stable iteration order, let's switch from `SmallPtrSet`
to `SetVector` which ensures insertion order iteration.
2018-07-27 15:34:15 -07:00
Pavel Yaskevich
48dd1e837b [ConstraintGraph] Add filtering to gatherConstraints per type variable
Most of the use-cases of `gatherConstraints` require filtering
at least based on the constraint kind that caller is interested in,
so instead of returning unrelated results and asking caller to
filter separately, let's add that functionality directly to
`gatherConstraints`.
2018-07-26 22:41:15 -07:00
Pavel Yaskevich
dd798accd8 [ConstraintGraph] Use set to gather constraints for type variables
Since it's possible to find the same constraint through two different
but equivalent type variables, let's use a set to store constraints
instead of a vector to avoid processing the same constraint multiple
times.
2018-07-26 22:41:07 -07:00
Slava Pestov
90cd772228 AST: Remove getParameterLists() and friends from AbstractFunctionDecl subclasses
Now, an AbstractFunctionDecl always stores a single parameter list.

Furthermore, ConstructorDecl and DestructorDecl always store a
ParamDecl for 'self'.

FuncDecl only has a 'self' if it is a member of a nominal type or
extension, so we tail-allocate the storage for it.
2018-07-22 20:56:56 -07:00
Slava Pestov
e1da265873 Sema: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 21:21:17 -07:00
Slava Pestov
acc494e3ff Sema: Simplify simplifyTypeImpl() a bit 2018-07-16 16:44:27 -07:00
Mark Lacey
aa30cc5adc Merge branch 'master' into remove-swift-3-in-expr-typechecking 2018-07-11 20:55:32 -07:00
Slava Pestov
4878889c1e Sema: Better fix for <rdar://problem/36449760> 2018-07-10 17:01:12 -07:00
Mark Lacey
28f759c8b0 Remove support for -swift-version 3 from the expression type checker.
This is the obvious stuff. There will probably be more fallout.
2018-07-06 16:10:08 -07:00
Mark Lacey
1a2d7f5e99 [ConstraintSystem] Reinstate favoring more specialized of two generic overloads.
This was originally commited in
3d32e89e33, and then backed out in
c40fd3966c due to concern over
behavioral changes.

This version avoids the optimization when there are any optional types
involved in the signatures of the functions.

For these cases, compareDeclarations can return the wrong order at the
moment.

I have another PR in the works that attempts to begin unraveling some
of the issues around fixing the overload comparisons.
2018-06-19 23:42:51 -07:00
Doug Gregor
d098b3e571 [Sema] Remove the IterativeTypeChecker. 2018-06-15 22:46:55 -07:00
Huon Wilson
e4d306f499 Merge pull request #17168 from huonw/validate-conditional-type-in-expr
[Sema] More aggressive consideration of conditionally defined types in expressions
2018-06-15 08:58:24 +10:00
Huon Wilson
5f585a12b4 [Sema] Generalize checking of conditional nested typealiases to all types.
One can have arbitrary types defined in a constrained extension, not just
typealiases, e.g.

struct Foo<T> {}
extension Foo where T == Int {
    struct X {}
}

A mention of `Foo<String>.X` should be flagged, since String != Int. Previously
this worked (in expressions) only if `X` was a typealias, and with this patch
the above example is flagged too.

Part of https://bugs.swift.org/browse/SR-5440 and
https://bugs.swift.org/browse/SR-7976 and rdar://problem/41063870.
2018-06-14 17:34:16 +10:00
Mark Lacey
197593b4aa Merge pull request #17136 from rudkx/rdar40868990
[ConstraintSystem] Allow LValues for the bindings of an IUO @optional…
2018-06-12 12:20:23 -07:00
Mark Lacey
803fbee0dd [ConstraintSystem] Allow LValues for the bindings of an IUO @optional requirement.
We were failing to bind the alternatives for an IUO @optional
requirement because we forgot to set the appropriate type variable option.

Fixes: rdar://problem/40868990
2018-06-11 23:44:00 -07:00
Joe Groff
711984234d Sema: Pass the useDC down to getTypeOfReference.
This fixes a subtle issue where, during single-expression closure type inference, we would ask for the settability of local variables from the outer function's context, leading us to mistakenly consider them mutable inside single-expression closure contexts. DI would catch some but not all violations of the expected semantics here.
2018-06-11 10:53:00 -07:00