Commit Graph

923 Commits

Author SHA1 Message Date
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
Doug Gregor
138b0361d2 [Type checker] Don't allow type variables to bind to dependent members.
When a type variable binds to an (unresolved) dependent member type,
it prevents us from inferring the type variable and adds no useful
information to the system. Refuse to bind type variables to dependent
member types.

Fixes rdar://problem/32697033.
2017-07-11 13:03:16 -07:00
Mark Lacey
8605b29951 [Constraint system] Improve SE-0110 exception by allowing optional injection.
There was an oversight in the exception that was added to SE-0110 to
maintain compatibility for closure arguments. We were not allowing
optional injection to happen for the closure being passed in, so things
like:
  func test(_ fn: ((Int, Int))->()) {}
  test { x, y in }
worked, but
  func test(_ fn: (((Int, Int))->())?) {}
  test { x, y in }
did not.

Fixes SR-5433 (rdar://problem/33239714).
2017-07-11 11:19:28 -07:00
Alex Hoppen
f8c2692f79 Introduce special decl names
Special DeclNames represent names that do not have an identifier in the
surface language. This implies serializing the information about whether
a name is special together with its identifier (if it is not special)
in both the module file and the swift lookup table.
2017-07-11 19:04:13 +02:00
Joe Groff
7a92acbc37 Merge pull request #10870 from jckarter/key-path-failure-diagnosis-with-resolved-components
Sema: Allow KeyPath and KeyPathApplicationExprs to re-type-check during failure diagnosis.
2017-07-11 08:17:01 -07:00
Mark Lacey
8d9f97cdc5 Fix another subtle SE-0110-related break.
The change to roll back a part of SE-0110 to allow multi-argument
functions to be passed in places where functions taking a tuple are
expected resulted in a regression in some cases where the fix would
strip off the last ParenType from single-argument functions.

Instead of stripping off parens from both function types we're trying to
match when they both have them, strip off none. This ensures that we
don't get summarily rejected in the nested matchTypes call by other
SE-0110-related code that bails if the two types do not have the same
"parenness".

Fixes rdar://problem/33043106 / SR-5387.
2017-07-10 17:36:53 -07:00
Joe Groff
51672d3bbf Sema: Allow KeyPath and KeyPathApplicationExprs to re-type-check during failure diagnosis.
Fixes SR-5034 | rdar://problem/32488872.
2017-07-10 16:43:34 -07:00
Joe Groff
6ad01d63f6 Sema: Feed argument label and constraint locator info from key path subscript components into getCalleeDeclAndArgs.
Fixes SR-5189 | rdar://problem/32713662.
2017-07-10 14:55:08 -07:00
Joe Groff
2bb827340b Sema: Simplifying a KeyPathExpr's type should *bind* to the specific type, not accept a subtype constraint.
We want the type of a KeyPathExpr to be the specific *KeyPath<T, U> subclass appropriate for the literal, with upcasts to a more general contextual type, since we rely on that invariant elsewhere to extract the base and projected value types. Fixes SR-5008 | rdar://problem/32395076.
2017-07-05 19:15:45 -07:00
David Rönnqvist
00833a2343 [QoI] Improve the fix-it for out-of-order arguments.
Change the fix-it to move the argument to its correct location in one go. This happens by removing it from one location and inserting it in the other (as opposed to the original implementation which swapped one argument with the preceding one). The commas separating the arguments are adjusted to match the moved argument.

Add new tests for reordering regular arguments, variadic arguments, and function arguments.

Resolves: SR-4715 rdar://problem/31849281
2017-07-02 10:15:18 +02:00
practicalswift
d39719ec3f [gardening] Fix typos 2017-06-29 23:09:22 +02:00
Robert Widmann
da35f11486 Merge pull request #10453 from CodaFi/high-and-DRY
Unify CallArgParam and AnyFunctionType::Param
2017-06-21 14:11:26 -07:00
Robert Widmann
0795c9946c Unify CallArgParam and AnyFunctionType::Param 2017-06-21 11:31:51 -07:00
Doug Gregor
a570a5a15e [Type checker] Check type equality even for argument tuples in Swift 4.
Replace a where Type-pointer-equality check with what it intended,
i.e., match up ParenTypes at the top level and perform a deeper
equality comparison of the underlying types.

Fixes SR-5166 / rdar://problem/32666189.
2017-06-20 23:49:47 -07:00
Mark Lacey
0ba4a312af Roll back a portion of SE-0110
As described in:
  https://lists.swift.org/pipermail/swift-evolution-announce/2017-June/000386.html

Specifically allow an N-ary argument function to be passed as an
argument in a place where a function of a single N-tuple is expected.

Fixes: rdar://problem/32875953
2017-06-20 11:05:28 -07:00
Robert Widmann
9fa8341540 Only decompose function types for info about default arguments
AnyFunctionType::Param carries around information about decomposed
parameters now.  Information about default arguments must be computed
separately with swift::computeDefaultMap.
2017-06-19 23:05:44 -07:00
Doug Gregor
7b56977eff [Type checker] Consistently mark used protocol conformances as "used".
Keep track of the protocol conformances required to form a particular
solution. At the point where we apply a solution, mark each of those
conformances as "used" so we're sure they are complete for later
phases (SILGen, SIL optimizer, IRGen). This general mechanism makes
sure we don't miss any cases in CSApply, such as the multi-case
illustrated in the new test where CSApply doesn't form any AST notes
describing the type erasure in a function conversion, so it otherwise
wouldn't see the conformance to mark it "used".

Pavel went most of the way down this path to track conformances last
month for unrelated reasons (that didn't really pan out). Resurrect
his work to track conformances, but only use them to mark as "used".

Fixes rdar://problem/32111710.
2017-06-15 14:40:04 -07:00
Pavel Yaskevich
3781877b93 [ConstraintSystem] Track conformance checking done while solving to validate solution
Track outcomes of `conformsToProtocol` calls in `simplifyConformanceConstraints`
to be able to validate conformances when solution is formed to avoid returning
solutions with nominal types with invalid conformances to protocols.
2017-06-15 14:18:36 -07:00
Robert Widmann
abd5aa8e6d Rename some X-Value-related entities
* Rename coerceToMaterializableValue to coerceToRValue

* Rename isLValueType to hasLValueType to better match the
intended semantics of the member.
2017-06-14 13:18:45 -07:00
swift-ci
af2aca0165 Merge pull request #10092 from xedin/pointer-conversions 2017-06-06 23:14:05 -07:00
Mark Lacey
65e338ea4a [Constraint solver] Do not allow unavailable decls to be favored.
There is a short-circuiting hack in the constraint solver that speeds up
solving, but isn't generally sound. If we allow unavailable decls to be
considered "favored", this can fire and result in our choosing a
solution that involves the unavailable decl where other solutions exist.

Fixes rdar://problem/32570734.
2017-06-06 13:38:36 -07:00
Pavel Yaskevich
3559047340 [ConstraintSolver] Unify value-to-pointer conversion scoring
Instead of having three different scores for - string, array, inout,
let's unify them under a single value-to-pointer score and use
it in appropriate places when simplifying restricted constraints.
2017-06-02 23:42:32 -07:00
Pavel Yaskevich
5998cd645f [ConstraintSolver] Penalize conversions from String to UnsafePointer
There are possible situations when we find solutions with String
and String -> UnsafePointer conversions at the same time for
expressions with default string literals. In order to disambiguite
such situations let's prefer solutions without String -> UnsafePointer
conversions if possible.
2017-06-01 14:43:43 -07:00
Slava Pestov
6526d513c0 Sema: Remove the 'extraFunctionAttrs' hack 2017-05-31 17:31:37 -07:00
Slava Pestov
7af399fd51 Sema: Change a getInterfaceType() to hasInterfaceType() in a couple of places
ValueDecl::getInterfaceType() asserts if the decl has no interface
type; to check if the declaration has been type checked yet, use
hasInterfaceType().

Fixes <https://bugs.swift.org/browse/SR-4743>.
2017-05-29 00:06:55 -07:00
Jordan Rose
c0ccdb1626 Change getBaseName to return DeclBaseName instead of Identifier (#9968)
This changes `getBaseName()` on `DeclName` to return a `DeclBaseName`
instead of an `Identifier`. All places that will continue to be
expecting an `Identifier` are changed to call `getBaseIdentifier` which
will later assert that the `DeclName` is actually backed by an
identifier and not a special name.

For transitional purposes, a conversion operator from `DeclBaseName` to
`Identifier` has been added that will be removed again once migration
to DeclBaseName has been completed in other parts of the compiler.

Unify approach to printing declaration names

Printing a declaration's name using `<<` and `getBaseName()` is be
independent of the return type of `getBaseName()` which will change in
the future from `Identifier` to `DeclBaseName`
2017-05-28 17:55:03 -07:00