Commit Graph

649 Commits

Author SHA1 Message Date
Joe Groff
89979137fc Push ArchetypeType's API down to subclasses.
And clean up code that conditionally works only with certain kinds of archetype along the way.
2018-12-12 19:45:40 -08:00
Joe Groff
20a2f3ea9f Merge pull request #21244 from jckarter/archetype-subclasses
Split subclasses out of ArchetypeType.
2018-12-12 11:49:48 -08:00
Joe Groff
f1648a1b3e Split subclasses out of ArchetypeType.
Context archetypes and opened existential archetypes differ in a number of details, and this simplifies the overlapping storage of the kind-specific fields. This should be NFC; for now, this doesn't change the interface of ArchetypeType, but should allow some refinements of how the special handling of certain archetypes are handled.
2018-12-12 08:55:56 -08:00
Doug Gregor
052d4c196c [Type checker] Pull the null check into swift::isSIMDOperator(). 2018-12-11 16:39:10 -08:00
Doug Gregor
88d34a1c7c [Constraint solver] De-priority SIMD operators.
The new SIMD proposal introduced a number of new operators, the presence of
which causes more "expression too complex" failures. Route around the
problem by de-prioritizing those operators, visiting them only if no
other operator could be chosen. This should limit the type checker
performance cost of said operators to only those expressions that need
them OR that already failed to type-check.

Fixes rdar://problem/46541800.
2018-12-11 16:34:37 -08:00
Pavel Yaskevich
b429d5a28a [ConstraintSystem] Erase InOutExpr from member base
Diagnostics could introduce type-checked expressions into AST during
it's bottom up re-typechecking in attempt to find a problem.

To minimize number of AST permutations solver has to handle
let's just strip away implicit `InOutExpr` introduced by previous
successful type-checks, which is not really important anyway.

Resolves: rdar://problem/46459603
2018-12-10 23:23:22 -08:00
Pavel Yaskevich
694c89c090 [ConstraintSystem] Handle InOut base introduced by diagnostic re-typecheck
While trying to lookup member reference on some base type, handle
base being an `InOutType`, which could be a result of previous
sub-expression re-typechecks made by diagnostics.

Resolves: rdar://problem/45771997
2018-12-06 16:02:28 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Pavel Yaskevich
cc780e3292 [ConstraintSystem] Make sure that @autoclosure argument detection works for subscripts/members
Currently logic in `matchCallArguments` could only detect argument
being an @autoclosure parameter for normal calls and operators.

This patch extends it to support subscripts and unresolved member calls.
2018-11-21 12:17:25 -08:00
Pavel Yaskevich
bce1ba5f37 [AST] Remove @autoclosure flag from function type ExtInfo 2018-11-10 11:59:29 -08:00
Mark Lacey
72ba110e5b [ConstraintSystem] Rework new constraint stat as a FRONTEND_STATISTIC.
In the process, remove the old incrementScopeCounter SWIFT_FUNC_STAT.
2018-10-18 07:18:02 -07:00
Mark Lacey
cc0386b461 [ConstraintSystem] Add a new stat to be used for expression type checker performance testing.
This counts the number of leaf scopes we reach while solving the
constraint sytem, and is a much better measure of the growth of
unnecessary work than the total number of scopes opened.

There were two tests where I had a difficult time getting scale-test
to fit the curve even after adjusting some of the parameters, so I've
left those to use the old stat for now.
2018-10-17 07:26:18 -07:00
Pavel Yaskevich
59899a7911 [ConstraintSystem] Make sure that system is returned into its original state after solving
Currently (with or w/o failures) constraint system is not returned
back to its original state after solving, because constraints from
initial "active" list are not returned to the system. To fix that
let's allocate "initial" scope which captures state right before
solving begins, and add "active" list to the solver state to capture
information about "active" constraints at the time of its creation.

This is follow-up to https://github.com/apple/swift/pull/19873
2018-10-15 16:33:57 -07:00
gregomni
dec2f455a8 More thorough retry of constraints which may succeed now that fixes are allowed. 2018-10-14 09:34:43 -07:00
gregomni
b7df1ca1df Re-try a failingConstraint during salvage now that attemptFixes is turned on. This enables better missing conforms-to diagnoses. 2018-10-13 20:06:19 -07:00
Slava Pestov
2d4b25960d Sema: Type variables for opened generic parameters store the generic parameter type and not an archetype
There's no need to instantiate archetypes in the generic environment
of the declaration being opened.

A couple of diagnostics changed. They were already misleading, and the
new diagnostics, while different, are not any more misleading than
before.
2018-09-27 20:49:23 -07:00
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