Commit Graph

648 Commits

Author SHA1 Message Date
Pavel Yaskevich
6ca3d3fc72 Merge pull request #13138 from xedin/rdar-35702810
[CSSolver/SILGen] Fix solver to support function conversion with collection subtyping
2017-12-04 15:05:37 -08:00
Mark Lacey
6cebc924af [ConstraintSystem] Only record fixes that result in a correct solution.
It's probably harmless to record the ones for failures which later cause
us to back out in the solver, but it means we cannot easily set
breakpoints in places like recordFix and stop only in the places where
the fixes actually cause the solution to make progress.
2017-12-01 17:27:12 -08:00
Mark Lacey
4f7f5d7c09 [ConstraintSystem] Simplify some logic around attempting fixes for Optionals.
Only record the fixes when they have made the solution to this point
successful.
2017-12-01 17:15:37 -08:00
Mark Lacey
fda51bb6b2 [ConstraintSystem] Eliminate the notion of FixKind::None
These purportedly mark that we should stop attempting fixes for a given
constraint, but in fact the only code creating these is clearly
unreachable so these serve no purpose.
2017-12-01 16:18:16 -08:00
Pavel Yaskevich
515520e524 [CSSolver/SILGen] Fix solver to support function conversion with collection subtyping
Fix collection subtyping relation in function argument position
by emiting special re-abstraction thunk with collection upcast.

Resolves: rdar://problem/35702810
2017-11-30 16:47:18 -08:00
Chris Lattner
3f5790fb37 Enhance MemberLookupResult's UnviableCandidates list, NFC.
We now store an entire OverloadChoice in the unviable candidates
list (which is used for error recovery), just like we store them
for viable candidates.

The additional information isn't used, so NFC.
2017-11-26 14:29:00 -08:00
Doug Gregor
e3a5318b97 [Type checker] Teach conformsToProtocol() to check conditional requirements.
conformsToProtocol() is the main way in which we check whether a given type
conforms to a given protocol. Extend it to check conditional requirements by
default, so that an unmodified caller will get the "does not conform" result
(with diagnostics when a location is present) rather than simply ignoring
the conditional requirements.

Some callers take responsibility for conditional requirements, e.g., to
push them into the constraint system. Allow those callers to opt out of
this checking, and do so wherever appropriate.

Fixes rdar://problem/35518088, where we were ignoring the conditional
requirements needed to verify that Equatable synthesis could be performed.
2017-11-21 21:02:00 -08:00
Doug Gregor
33810d9a6a [Constraint solver] Add a constraint locator element for conditional requirements.
Using this constraint locator element, we can check when a failed
constraint is due to an unsatisfied conditional requirement of a
protocol conformance. Unfortunately, it's hard to turn this into
an actionable diagnostic right now.
2017-11-20 21:07:13 -08:00
Doug Gregor
a6913bb2ef [Constraint solver] Check conditional requirements for type erasure.
Rather than wantonly dropping the conditional requirements when checking
for type erasure, add them in the same way we do for (e.g.) conformance
checking for generics. Fixes rdar://problem/35480860.
2017-11-19 22:22:32 -08:00
Doug Gregor
d58a596be1 [Constraint solver] Remove a now-unnecessary hack for conditional conformances.
We added this hack to work around the use of context types within normal
protocol conformances, which created tautological constraint systems.
With the switch to interface types in normal protocol conformances, this
hack is no longer necessary.
2017-11-19 22:07:18 -08:00
Joe Groff
4b401e257a Merge pull request #12835 from jckarter/key-path-type-checking
Sema: Fixes for KeyPath type checking.
2017-11-14 13:10:44 -08:00
Huon Wilson
1339685c5f [CS] Fix conditional conformances in overload ranking.
Resolves rdar://problem/35480952.
2017-11-13 13:14:39 -08:00
Joe Groff
73d2e9a47f Sema: Fixes for KeyPath type checking.
When testing KeyPathApplication constraints, we would keep going after rejecting a concrete KeyPath application by trying PartialKeyPath and AnyKeyPath, even though that's not what we want, since any key path application expression can type check with an AnyKeyPath. We would then miscompile by building the AST such that we applied the mismatched key path expression directly to the base. We also didn't handle expressions where the base was a subtype of the key path's base type correctly—the conversion means the base can't be written through in this situation, and we hardcoded the concrete-to-existential case instead of handling general conversions. Fix these problems, and add an AST verifier for KeyPathApplicationExprs to help catch problems in the future. Fixes SR-6300 | rdar://problem/35368903.
2017-11-09 11:57:23 -08:00
Pavel Yaskevich
66e13bcc85 [ConstraintSolver] Avoid unnecessarily increasing score when matching function types
Remove function-to-function type match score increase, which should only
happen contextually in presence of other restrictions, this used to fix
the case related to matching of arrays of functions with and w/e `throws`
as function parameters which used to be ambigious, and now handled by
collection-upcast conversion score.

Resolves: rdar://problem/35142121
2017-10-31 23:14:35 -07:00
Robert Widmann
ebdd126a2c [NFC] Remove more uses of <InOutType> 2017-10-22 02:00:07 -04:00
Huon Wilson
f6729f17d6 [Sema] Add conditional requirements as CS constraints.
This tries to feed through the constraint system all the constraints
implied by a concrete type satisfying a conformance requirement.
2017-10-10 20:17:41 -07:00
Huon Wilson
96172048d3 [Sema/CS] Convenience function for adding a Requirement as a constraint. 2017-10-10 20:17:40 -07:00
Pavel Yaskevich
f95c979cbf [ConstraintSolver] Remove hack related to single parameter handling 2017-10-03 15:15:57 -07:00
Pavel Yaskevich
4317074a9a [ConstraintSolver] Prioritize certain type variables while looking for bindings
Presence of some constraints (Subtype at least) requires a certain
contextual ranking of the type variables associated with them when
it comes to picking bindings, otherwise it might lead to no or
invalid solutions, because only a set of the bindings for the best
type variable is attempted.

Resolves: rdar://problem/22898292
2017-10-03 10:41:35 -07:00
Pavel Yaskevich
695baccc3e Revert "[ConstraintSolver] Prioritize certain type variables while looking for bindings"
This reverts commit 001b09747a.
2017-10-02 17:30:18 -07:00
Pavel Yaskevich
001b09747a [ConstraintSolver] Prioritize certain type variables while looking for bindings
Presence of some constraints (Subtype at least) requires a certain
contextual ranking of the type variables associated with them when
it comes to picking bindings, otherwise it might lead to no or
invalid solutions, because only a set of the bindings for the best
type variable is attempted.

Resolves: rdar://problem/22898292
2017-09-30 14:36:16 -07:00
Pavel Yaskevich
3b06f2e897 Merge pull request #12072 from xedin/rdar-33429010
[ConstraintGraph] Don't try to contract edge of parameter bindings with `inout` attribute
2017-09-26 11:51:09 -07:00
Pavel Yaskevich
80e4a2226b [ConstraintGraph] Don't try to contract edge of parameter bindings with inout attribute
Currently edge related to the parameter bindings is contracted
without properly checking if newly created equivalence class has
the same inout & l-value requirements. This patch improves the
situation by disallowing contraction of the edges related to parameter
binding constraint where left-hand side has `inout` attribute set.

Such guarantees that parameter can get `inout` type assigned when
argument gets `l-value` type.

Resolves: rdar://problem/33429010
2017-09-22 17:23:12 -07:00
David Zarzycki
e02d4c5afa [Sema] NFC: Ensure that closures are not subtypes of auto-closures
Right now, the sole caller ensures this, but that is just a hack.
2017-09-21 14:16:26 -04:00
David Zarzycki
03a48b076f [Sema] NFC: Simplify matchFunctionTypes()
In this scope, if func1->throws() is false, then func2->throws() must be true.
2017-09-21 14:16:26 -04:00
Pavel Yaskevich
84790d8c31 Merge pull request #11907 from xedin/cleanup-subtype-workaround
[ConstraintSolver] NFC: Cleanup dead-code related to contraction of s…
2017-09-13 17:32:57 -07:00
Pavel Yaskevich
d5fb892515 [ConstraintSolver] NFC: Cleanup dead-code related to contraction of subtype constraints in matchTypes
Since we no longer allow constraction of subtype constraints, workaround
which exists in `matchTypes`, for situations where left-hand side of such
constraint is going to be wrapped in `inout` type, is no longer required.

Resolves: rdar://problem/34137342, rdar://problem/34136625
2017-09-13 15:43:50 -07:00
Mark Lacey
12587fd845 [Constraint system] Hoist some common code in matchTypes.
This may not quite be NFC since the path for Subtype bindings checked
other conditions before this, but I believe this is the right thing to
do in all cases where we have two identical type vars.
2017-09-12 17:56:37 -07:00
John McCall
965e95c41c Merge pull request #11831 from rjmccall/accessor-validation
Improve the validation of storage accessors
2017-09-10 13:38:00 -04:00
John McCall
2d3d6addc0 Delay the validaton of storage accessors until finalization.
The base mutability of storage is part of the signature, so be sure
to compute that during validation.  Also, serialize it as part of
the storage declaration, and fix some places that synthesize
declarations to set it correctly.
2017-09-10 04:56:02 -04:00
Mark Lacey
23c677ff52 [Constraint system] Hoist some code into a separate function.
The naming here might not be perfect as it's not the only place that we
bind types to typevars in matchTypes, but it is a step towards cleaning
things up a bit. I'll revisit naming after I get a better idea what
other common code there may be that can get factored out.
2017-09-10 01:32:13 -07:00
Mark Lacey
343f3583a3 [Constraint system] Eliminate some code duplication in matchTypes. 2017-09-10 00:52:07 -07:00
Mark Lacey
53218c887c [Constraint system] Add some code that was missing.
This code was added above but not to this duplicated code path. Once I
know this doesn't expose any issues I'll unduplicate this.
2017-09-09 10:40:05 -07:00
Jordan Rose
449cd98997 Excise "Accessibility" from the compiler (3/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

Rename AccessibilityAttr to AccessControlAttr and
SetterAccessibilityAttr to SetterAccessAttr, then track down the last
few uses of "accessibility" that don't have to do with
NSAccessibility. (I left the SourceKit XPC API alone because that's
supposed to be more stable.)
2017-08-28 13:27:59 -07:00
Jordan Rose
5f30eac288 Excise "Accessibility" from the compiler (1/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the names of methods, fields, a few local
variables, and even a swift-ide-test flag. The full list is below.

accessibilityForDiagnostics -> accessLevelForDiagnostics
checkAccessibility -> checkAccess
checkGenericParamAccessibility -> checkGenericParamAccess
checkTypeAccessibility -> checkTypeAccess
checkWitnessAccessibility -> checkWitnessAccessibility
computeAccessibility -> computeAccessLevel
computeDefaultAccessibility -> computeDefaultAccessLevel
fixItAccessibility -> fixItAccess
getAccessibilityString -> getAccessLevelString
getAccessibilityStrictly -> getAccessLevelStrictly
getAccessibilityUID -> getAccessLevelUID
getActualAccessibility -> getActualAccessLevel
getDefaultAccessibility -> getDefaultAccessLevel
getMaxAccessibility -> getMaxAccessLevel
getOverridableAccessibility -> getOverridableAccessLevel
getRawStableAccessibility -> getRawStableAccessLevel
getSetterAccessibility -> getSetterFormalAccess
hasAccessibility -> hasAccess
hasDefaultAccessibility -> hasDefaultAccessLevel
inferAccessibility -> inferAccessLevel
inferDefaultAccessibility -> inferDefaultAccessLevel
inferSetterAccessibility -> inferSetterAccessLevel
overwriteAccessibility -> overwriteAccess
overwriteSetterAccessibility -> overwriteSetterAccess
printAccessibility -> printAccess
requiredAccessibilityForDiagnostics -> requiredAccessForDiagnostics
resolveAccessibility -> resolveAccessControl
setAccessibility -> setAccess
setSetterAccessibility -> setSetterAccess
setDefaultAndMaxAccessibility -> setDefaultAndMaxAccess
validateAccessibility -> validateAccessControl

Accessibility -> AccessLevel
AccessibilityFilter -> AccessFilter
IgnoreAccessibility -> IgnoreAccessControl
NL_IgnoreAccessibility -> NL_IgnoreAccessControl
PrintAccessibility -> PrintAccess
PrintInternalAccessibilityKeyword -> PrintInternalAccessKeyword
SetterAccessibility -> SetterAccessLevel

setterAccessibility -> setterAccess
storedPropertyAccessibility -> storedPropertyAccess

-print-accessibility -> -print-access
2017-08-28 11:11:57 -07:00
Robert Widmann
3c1a6ab6d3 Reject member lookups that require bridging metatypes
We can only coerce metatypes covariantly but bridging
always requires an unrelated metatype cast.  When
performing member lookup, especially unqualified member
lookup, disregard static members from bridged types entirely.

See SR-5670 and rdar://problem/33830526
2017-08-13 12:39:33 -07:00
David Zarzycki
78298c8d2a [Sema] Remove vestigial member lookup path
The normal lookup path can handle all constructors just fine.
2017-08-09 20:25:09 -04:00
Arnold Schwaighofer
8146104b7e Revert "Simplify performMemberLookup()" 2017-08-09 10:56:38 -07:00
David Zarzycki
823e3e16c0 [Sema] Remove vestigial member lookup path
The normal lookup path can handle all constructors just fine.
2017-08-08 21:26:55 -04:00
swift-ci
17ddc5802f Merge pull request #10965 from ahoppen/deinit-special-name 2017-08-01 07:50:00 -07:00
Alex Hoppen
ebd701c4b7 Represent the name of destructors by a special DeclBaseName
No longer use the known identifier `deinit` for destructors. This allows
classes to have functions called `deinit`.
2017-07-28 19:20:02 +02:00
Kosuke Ogawa
2a18723b55 [gardening] Fix typos (#11245)
* [Gardening] Fix typo: getTopLeveDecls -> getTopLevelDecls

* [Gardening] Fix typo: silModue -> silModule

* [Gardening] Fix typo: Evaludate -> Evaluate

* [Gardening] Fix typo: OptioanlPayload -> OptionalPayload

* [Gardening] Fix typo: confromance -> conformance

* [Gardening] Fix typos

* [Gardening] Fix typo: tpye -> type

* [Gardening] Fix typo: resoved -> resolved

* [Gardening] Fix typo: ahve -> have

* Revert "[Gardening] Fix typo: silModue -> silModule"

This reverts commit ed8c4d0b71.
2017-07-28 10:14:21 -07:00
Slava Pestov
f51a9d022c Sema: Simplify behavior of NameLookupFlags::PerformConformanceCheck flag
I'd like to remove this eventually, but for now I want
to remove this special case check.
2017-07-27 23:44:45 -07:00
Slava Pestov
c8cf0a05cf Sema: Simplify matchSuperclassTypes() 2017-07-24 22:58:04 -07:00
Slava Pestov
83684eb08a Sema: Remove LookupResult::Entry in favor of AST's LookupResultEntry
Both types store a base declaration and a result declaration;
we can remove one. Soon, it will change to store a base
declaration context, instead.
2017-07-18 22:09:19 -07:00
Robert Widmann
6ee20e59ab Merge pull request #10488 from CodaFi/a-parametric-equation
Switch over function input matching to use Params
2017-07-11 18:32:36 -07:00
Doug Gregor
8def4d8759 [Type checker] Factor out "isBindable" check for matchTypes. NFC
Thanks to Pavel (@xedin) for the feedback.
2017-07-11 15:41:19 -07:00
Doug Gregor
1e043ab179 Merge pull request #10883 from DougGregor/dont-bind-dependent-member-types
[Type checker] Don't allow type variables to bind to dependent members.
2017-07-11 15:38:58 -07:00
Robert Widmann
d5328ea3cb Switch over function input matching to use Params
Currently handles non-constructor-based applies and function
parameter comparisons.
2017-07-11 15:17:31 -07:00
Mark Lacey
2e9dc6b6b4 Merge pull request #10881 from rudkx/fix-rdar33239714
[Constraint system] Improve SE-0110 exception by allowing optional in…
2017-07-11 13:58:45 -07:00