Commit Graph

11023 Commits

Author SHA1 Message Date
Doug Gregor
cc9ac43f22 [AST] Use declaration-based name lookup in the conformance lookup table.
This avoids a call into the lazy resolver simply to figure out which
protocols a type conforms to.
2018-08-13 19:03:35 -07:00
Doug Gregor
a1fe426866 [Name lookup] Use decl-based name lookup for unqualified lookup.
Within unqualified name lookup, replace uses of Type-based lookup
(formed from calls to getSelfTypeInContext()) with declaration-based
name lookup, so that name lookup doesn't depend directly on the type
checker.

The main oddity here is that we need to consider "Self: Foo"
requirements within a protocol extension during name lookup, so that
we will also look into "Foo". This is handled via the basic
name-lookup facilities that allow us to resolve TypeReprs to
declarations without going through the type checker.
2018-08-13 19:03:35 -07:00
Rintaro Ishizaki
67f691503d Merge pull request #18665 from rintaro/rdar42639255
[ConstraintSystem] Remove any semantic expression in SanitizeExpr
2018-08-14 11:00:01 +09:00
Pavel Yaskevich
dd9c28b456 [ConstraintSystem] Add proper printing (name + locator) for fixes 2018-08-13 18:10:50 -07:00
Pavel Yaskevich
ebb9f86bee [ConstraintSystem] NFC: Remove obsolete Fix struct
Also clean up `ConstraintSystem` interface from the storage
supporing `Fix` such as missing types, decl names, conformances etc.
2018-08-13 18:10:40 -07:00
Pavel Yaskevich
e631a37ef6 [ConstraintSystem] Replace Fix with ConstraintFix throughout solver 2018-08-13 18:10:27 -07:00
Pavel Yaskevich
1983431591 [ConstraintSystem] Make it so re-labeling fix holds correct labels as trailing objects 2018-08-13 18:09:01 -07:00
Pavel Yaskevich
3c7d7782db [Diagnostics] Don't try to diagnose missing conformance for any type of operator call
My original diagnostic changes included only `BinaryExpr` but there
are also postfix/prefix that I missed.
2018-08-13 18:06:49 -07:00
swift-ci
4237bd3af1 Merge pull request #18546 from davezarzycki/more_type_resolution_clean_up 2018-08-13 09:41:41 -07:00
David Zarzycki
3f2fdd8943 [Sema] NFC/perf - avoid double hashing during inheritance checking
Replace `find()` followed by "insert" with actual `insert()`. This also
consolidates some std::pair ugliness.
2018-08-13 11:01:49 -04:00
David Zarzycki
6fc21fe0a2 [Sema] NFC: Remove dead code: TypeResolverContext::InheritanceClause 2018-08-13 08:18:46 -04: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
Rintaro Ishizaki
7532da4e37 [ConstraintSystem] Remove any semantic expression in SanitizeExpr
Existence of semantic expr (`getSemanticExpr()`) prevents ASTWalker
walking into the *original* sub expressions which may cause
re-typechecking failure. For example,
`ConstraintGenerator::visitArrayExpr()` assumes we already visited its
elements, but that's not the case if the semantic expr exists.

rdar://problem/42639255
2018-08-13 20:36:07 +09:00
Pavel Yaskevich
8f9631bf6c [ConstraintSystem] Add unwrap optional base with optional result fix kind 2018-08-13 01:23:28 -07:00
Pavel Yaskevich
c3ac038a66 [ConstraintSystem] Add anchor expression accessor to ConstraintFix 2018-08-13 01:23:28 -07:00
Pavel Yaskevich
c005e0084d [ConstraintSystem] Allocate constraint fixes using constraint system
Since constraint fix life span is tightly coupled with particular
constraint system, it makes sense to allocate fixes using the same
allocator as used for constraints.
2018-08-13 01:23:28 -07:00
Pavel Yaskevich
d00d73aff4 [ConstraintSystem] Move FixKind to new abstraction
Make is so `FixKind` lives in the new `CSFix` header and
all new `ConstraintFix` classes get a kind. That's useful
when trying to identify if locator has multiple fixes of
the same kind attached to it.
2018-08-13 01:23:28 -07:00
Pavel Yaskevich
df9614177a [ConstraintSystem] Add 'missing conformance' fix 2018-08-13 01:23:28 -07:00
Pavel Yaskevich
8221354ce5 [ConstraintSystem] Add 're-label arguments' fix 2018-08-13 01:23:27 -07:00
Pavel Yaskevich
a1651f9b3c [ConstraintSystem] Add 'mark explicitly @escaping' fix 2018-08-13 01:23:27 -07:00
Pavel Yaskevich
2ced603bc3 [ConstraintSystem] Add 'replace as with as!' fix 2018-08-13 01:23:27 -07:00
Pavel Yaskevich
48c4eb4539 [ConstraintSystem] Add 'add address-of' fix 2018-08-13 01:23:27 -07:00
Pavel Yaskevich
a17c1cb409 [ConstraintSystem] Add 'unwrap optional base' fix 2018-08-13 01:23:27 -07:00
Pavel Yaskevich
6fc5ce36fd [ConstraintSystem] Add 'force optional' fix 2018-08-13 01:23:27 -07:00
Pavel Yaskevich
428e9b5926 [ConstraintSystem] Add 'force downcast' fix 2018-08-13 01:23:27 -07:00
Pavel Yaskevich
ac0509729a [ConstraintSystem] Introduce ConstraintFix abstraction
A fix is related to one of the constraints through its locator,
and contains information required to "fix" a failure associated with
given constraint, each of the fixes also includes diagnostic.
2018-08-13 01:23:27 -07:00
gregomni
ba96db66de Conflict resolution. 2018-08-12 12:57:20 -07:00
gregomni
36cf24fb9e When we diagnose an unwrap, if the expression being unwrapped is a sole reference to a local let/var, and the local's type is inferred, offer fixits on the initializer as well. In this position we can also reasonably offer 'guard let'. Since we're identifying the implicitly typed initializer now, we can give a specific explanation of how IUOs get turned into optional types with the new IUO implementation.
Pass constraint system down into offering force unwrap fixits so that we can identify the type of the last member chosen for an optional chain. If there's a chain and the last member's return type isn't optional, then it's cleaner to offer to change that last '?' into a '!' to perform the force, rather than parenthesize the whole expression and force the result.
2018-08-12 12:57:20 -07:00
Slava Pestov
432924018c Sema: Remove TupleType::getVarArgsBaseType()
Or, actually, now that there's only one usage left move it to CSDiag.
Hopefully, both vararg tuple types and CSDiag are going away
eventually.
2018-08-11 22:28:36 -07:00
Slava Pestov
06392abaee Sema: Clean up 'tuple splat' code in coerceParameterListToType() 2018-08-11 22:28:36 -07:00
Slava Pestov
f2ae23a2ab AST: Remove TupleType::getElementForScalarInit()
This is a legacy holdover from when tuple types had default
arguments, and also the constraint solver's matching of function
types pre-SE-0110.

Well, move the last live usage to CSDiag, where it can die a slow
painful death over time. The other usages were not doing anything.
2018-08-11 22:26:44 -07:00
Slava Pestov
5b918ff4c9 Sema: Convert REPL printing to use ParameterList::getParams() 2018-08-11 03:29:16 -07:00
Slava Pestov
1deb075d93 Sema: Convert closure constraint generation to use ParameterList::getParams() 2018-08-11 03:29:16 -07:00
Pavel Yaskevich
cd4909bfa8 Merge pull request #18640 from xedin/improve-simplify-locator
[Diagnostics] Improve `simplifyLocator` to extract arguments from unr…
2018-08-10 21:41:21 -07:00
John McCall
ba965ecc56 Merge pull request #18610 from rjmccall/generic-subscript-accessor-signatures
Just use a generic subscript's generic context in its accessors (NFC)
2018-08-10 23:47:12 -04:00
Slava Pestov
a728305345 Merge pull request #18647 from slavapestov/inout-in-parens-is-still-inout
Easy InOutType removals and bug fix
2018-08-10 20:46:32 -07:00
Slava Pestov
de58075467 Merge pull request #18646 from slavapestov/fix-sema-warning
Sema: Remove unused function
2018-08-10 20:36:48 -07:00
Robert Widmann
fe8873a5d0 Merge pull request #18641 from hamishknight/objc-subscript-cleanup
[AST] NFC: Remove ObjCSubscriptKind::None
2018-08-10 18:43:13 -07:00
Slava Pestov
1226049747 Sema: Remove uses of InOutType from TypeChecker::coerceParameterListToType() 2018-08-10 18:42:04 -07:00
Slava Pestov
5be9d60c96 Sema: Remove dead diagnostics about mis-placed InOutType
These are now diagnosed immediately as part of resolveType(), so
replace them with assertions since we should never be building such
types at all.
2018-08-10 18:42:02 -07:00
Slava Pestov
39f8c425db Sema: resolveType() no longer produces InOutType
We would always just strip it off and look at the TypeRepr instead
to compute parameter flags anyway.
2018-08-10 18:41:58 -07:00
Slava Pestov
f0e72290d4 Sema: Fix handling of parentheses around 'inout T'
In Swift, wrapping the type of a function parameter in parentheses
never changes its meaning. By this logic,

  func foo(x: (inout Int))

should be equivalent to

  func foo(x: inout Int)

This worked in Swift 4.1 but regressed when the new function type
representation was introduced.
2018-08-10 18:41:52 -07:00
Slava Pestov
f4dd148859 Sema: Remove unused function 2018-08-10 18:23:31 -07:00
John McCall
9f7c5f5642 Just use a generic subscript's generic context in its accessors. NFC.
The main purpose of doing this is to eliminate the need for some special
cases for materializeForSet (and read and modify) in the requirements-
gathering code, but it should also be a small performance improvement
for code that's heavy in generic subscripts.
2018-08-10 21:00:19 -04:00
Rintaro Ishizaki
5e001f1913 Merge pull request #18626 from rintaro/ide-completion-unresolved-refactor
[CodeCompletion] Completion for UnresolvedMember via CodeCompletionExpr
2018-08-11 09:10:28 +09:00
Pavel Yaskevich
538e5e89b3 [Diagnostics] Improve simplifyLocator to extract arguments from unresolved member calls
Unresolved member calls e.g. `.foo(1, 2)` are unique in a way that
they don't form regular application expressions. So let's teach
`simplifyLocator` how to extract arguments from such calls
based on locators like:
`[UnresolvedMemberExpr -> apply argument -> comparing call argument # to parameter #]`.

This helps to diagnose more failures via diagnostics attached to
constraint system fixes.
2018-08-10 16:31:13 -07:00
Rintaro Ishizaki
3bff834f22 Merge pull request #18625 from rintaro/rdar43057058
[CSGen] Rework SanitizeExpr
2018-08-11 08:23:09 +09:00
Pavel Yaskevich
2707807596 Merge pull request #18620 from xedin/port-rest-of-fixes-to-new-diags
[Diagnostics] NFC: Port the rest of "fix" diagnostics to new abstraction
2018-08-10 15:51:21 -07:00
Hamish Knight
523992c848 [AST] NFC: Remove ObjCSubscriptKind::None
This enum case, and associated diagnostic hasn't been used since id-as-Any.
2018-08-10 23:10:52 +01:00
Slava Pestov
4b258e86e6 AST: Stop setting contextual types on ParamDecls
VarDecl::getType() lazily maps the interface type into context if needed.
2018-08-10 13:33:12 -07:00