Commit Graph

1005 Commits

Author SHA1 Message Date
Doug Gregor
4acbf586eb [AST] Optimize collection upcasts of array literals.
When we form a collection upcast of an array literal, upcast the
individual elements directly so we avoid a call through the
runtime. This both improves code generation and sidesteps a regression
involving the inability to dynamically cast function types.

Fixes SR-7362 / rdar://problem/39218656.
2018-04-17 14:08:14 -07:00
Mark Lacey
9a7497aa17 Opportunistic fix to allow \Derived.property to be inferred as \Base.property.
Noticed this opportunity while reading through the keypath type checking code.
2018-04-12 09:55:40 -07:00
Joe Groff
6d053f5a9c Sema: Fix setter visibility computation when checking key path literals.
`AbstractStorageDecl::isSettable` by itself doesn't account for access control, so we need to check `isSetterAccessibleFrom` as well. Furthermore, key paths should not get the special context-sensitive privileges direct accesses do, such as initializers being able to assign into `let` properties. Fix the type checking logic here to only create a statically writable KeyPath value when the referenced declaration has a setter visible independent of current context. Fixes SR-6667 | rdar://problem/36257266.
2018-04-09 11:06:29 -07:00
David Zarzycki
67710606e6 [Parse] Move tok::amp_prefix closer to parameter list logic
The amp_prefix token is currently tolerated in any unary expression
context and then diagnosed later by Sema. This patch changes parsing to
only accept tok::amp_prefix in its allowed position: parameter lists.

This also fixes two "compiler crasher" tests.
2018-03-30 17:56:36 -04:00
David Zarzycki
94a540db4b [Sema] NFC: More TVO_CanBindToInOut removal
If we're willing to tolerate less specific diagnostics, then we can
remove more instances of TVO_CanBindToInOut. After this change, there is
only one client of TVO_CanBindToInOut.
2018-03-30 09:22:37 -04:00
David Zarzycki
01ca5f0b05 [Tests] Ensure that nontrivial inout exprs cause errors 2018-03-29 16:40:57 -04:00
Pavel Yaskevich
5f222ec36d [Diagnostics] Improve diagnostics for type parameter requirements
Detect and diagnose failures in constraints representing
type parameter requirements generated by `openGeneric`.

Resolves: rdar://problem/35890334
2018-03-27 00:11:57 -07:00
Doug Gregor
e82e7ee908 [Type checker] Use BoundNameAliasType for all typealiases.
Rather than relying on the NameAliasType we get by default for references
to non-generic typealiases, use BoundNameAliasType consistently to handle
references to typealiases that are formed by the type checker.
2018-03-25 21:35:16 -07:00
Rintaro Ishizaki
5baf106c20 [test][gardening] move test files to appropriate directory
`#selector` and `#keyPath` are parsed in parseExprPrimary
2018-03-15 17:45:32 +09:00
Rintaro Ishizaki
0a26e287ba [Parse] Diagnose unknown pound expressions
Implemented diagnostics for `'#' identifier arguments?` at expression
position.
Also, added back diagnostics (and fix-it) for legacy object literals.
2018-03-15 15:36:51 +09:00
Pavel Yaskevich
d8b355dbae Revert "[CSSolver] Use correct locator when matching function result types re…" 2018-03-07 23:19:30 -08:00
Slava Pestov
26e69d9667 Sema: Diagnose self.init and super.init inside closures
Fixes <rdar://problem/27420414>.
2018-03-06 18:20:07 -08:00
Pavel Yaskevich
20019be9d3 [CSSolver] Use correct locator when matching function result types related to closures
Currently we always use 'FunctionResult' as a path element when matching
function result types, but closure result type is allowed to be implicitly
converted to Void, which means we need to be careful when to use
'FunctionResult' and 'ClosureResult'.

Resolves: rdar://problem/37790062
2018-03-01 11:41:36 -08:00
Mark Lacey
e43ff7164c Merge pull request #14299 from rudkx/iuo-remove-the-type
IUO: Generate Optional<T> rather than ImplicitlyUnwrappedOptional<T>
2018-02-01 21:58:37 -08:00
Ben Cohen
9ee856f386 [stdlib][WIP] Eliminate (Closed)CountableRange using conditional conformance (#13342)
* Make Range conditionally a Collection

* Convert ClosedRange to conditionally a collection

* De-gyb Range/ClosedRange, refactoring some methods.

* Remove use of Countable{Closed}Range from stdlib

* Remove Countable use from Foundation

* Fix test errors and warnings resulting from Range/CountableRange collapse

* fix prespecialize test for new mangling

* Update CoreAudio use of CountableRange

* Update SwiftSyntax use of CountableRange

* Restore ClosedRange.Index: Hashable conformance

* Move fixed typechecker slowness test for array-of-ranges from slow to fast, yay

* Apply Doug's patch to loosen test to just check for error
2018-02-01 20:59:28 -08:00
Mark Lacey
f08823757a IUO: Generate Optional<T> rather than ImplicitlyUnwrappedOptional<T>.
Stop creating ImplicitlyUnwrappedOptional<T> so that we can remove it
from the type system.

Enable the code that generates disjunctions for Optional<T> and
rewrites expressions based on the original declared type being 'T!'.

Most of the changes supporting this were previously merged to master,
but some things were difficult to merge to master without actually
removing IUOs from the type system:
- Dynamic member lookup and dynamic subscripting
- Changes to ensure the bridging peephole still works

Past commits have attempted to retain as much fidelity with how we
were printing things as possible. There are some cases where we still
are not printing things the same way:
- In diagnostics we will print '?' rather than '!'
- Some SourceKit and Code Completion output where we print a Type
  rather than Decl.

Things like module printing via swift-ide-test attempt to print '!'
any place that we now have Optional types that were declared as IUOs.

There are some diagnostics regressions related to the fact that we can
no longer "look through" IUOs. For the same reason some output and
functionality changes in Code Completion. I have an idea of how we can
restore these, and have opened a bug to investigate doing so.

There are some small source compatibility breaks that result from
this change:
- Results of dynamic lookup that are themselves declared IUO can in
  rare circumstances be inferred differently. This shows up in
  test/ClangImporter/objc_parse.swift, where we have
    var optStr = obj.nsstringProperty
  Rather than inferring optStr to be 'String!?', we now infer this to
  be 'String??', which is in line with the expectations of SE-0054.
  The fact that we were only inferring the outermost IUO to be an
  Optional in Swift 4 was a result of the incomplete implementation of
  SE-0054 as opposed to a particular design. This should rarely cause
  problems since in the common-case of actually using the property rather
  than just assigning it to a value with inferred type, we will behave
  the same way.
- Overloading functions with inout parameters strictly by a difference
  in optionality (i.e. Optional<T> vs. ImplicitlyUnwrappedOptional<T>)
  will result in an error rather than the diagnostic that was added
  in Swift 4.1.
- Any place where '!' was being used where it wasn't supposed to be
  allowed by SE-0054 will now treat the '!' as if it were '?'.
  Swift 4.1 generates warnings for these saying that putting '!'
  in that location is deprecated. These locations include for example
  typealiases or any place where '!' is nested in another type like
  `Int!?` or `[Int!]`.

This commit effectively means ImplicitlyUnwrappedOptional<T> is no
longer part of the type system, although I haven't actually removed
all of the code dealing with it yet.

ImplicitlyUnwrappedOptional<T> is is dead, long live implicitly
unwrapped Optional<T>!

Resolves rdar://problem/33272674.
2018-01-31 12:15:58 -08:00
gregomni
68141a0388 Remove the terminology "l-value" from the diagnostic by being more exact about what sort of lvalue it is. 2018-01-28 12:55:25 -08:00
gregomni
90f0edc009 Need to check that the keypath decl is an AbstractStorageDecl instead of assuming it. 2018-01-14 15:05:44 -08:00
Yasser Deceukelier
fa2c9b97fd Added test for fix 2018-01-09 23:28:34 +01:00
Slava Pestov
fbab72bd81 Sema: Fix crash when coercing a closure literal returning one uninhabited type to another
Silly corner case. Fixes <https://bugs.swift.org/browse/SR-4963>.
2018-01-05 23:41:41 -08:00
Slava Pestov
d843b10bcc Sema: Fix crash with unresolved dot expression with optional protocol metatype base
Mostly fixes <rdar://problem/35945827>, but there is a case that should
work that does not type check. At least we don't crash though.
2018-01-05 20:33:12 -08:00
Slava Pestov
3502102f00 Add test case for trailing closure with self/super.init
It looks like rdar://18426302 is already fixed, but I couldn't
find any tests that cover it. Add some just in case.
2017-12-07 13:50:57 -08:00
Doug Gregor
ba6f605d47 Fix some tests due to Equatable Optional/Array/Dictionary change. 2017-11-27 21:09:50 -08:00
Doug Gregor
9f1cd0bf6b [Stdlib] Move _OptionalNilComparisonType operators into an extension on Optional.
Because global operators are “meh”.
2017-11-17 20:41:43 -08:00
Greg Parker
e8475cc130 Revert "Use conditional conformances to implement Equatable for Optional, Array and Dictionary" 2017-11-15 14:17:22 -08:00
Doug Gregor
e9b7336d44 [Stdlib] Move _OptionalNilComparisonType operators into an extension on Optional.
Because global operators are “meh”.
2017-11-14 16:23:20 -08:00
Doug Gregor
9f68fdae80 [Conditional conformances] Fix up test cases that changed for the better. 2017-11-14 16:23:20 -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
gregomni
a76d74b6d4 When subscripting with a keypath, check for the path being an IUO. 2017-10-21 16:12:28 -07:00
gregomni
0188e1cb65 Incorrect condition here resulted in incorrectly trying to optional-wrap for an optional chain to optional lvalue. 2017-10-15 15:31:06 -07:00
Joe Groff
d3a2a0ff82 Sema: Coerce the type of the index expression in a key path component to match the subscript decl's index type.
Fixes SR-6062 | rdar://problem/34835322.
2017-10-05 14:33:21 -07:00
Robert Widmann
e310ab3e3c Coerce the base of existential keypath applies
We can wind up in a situation where the base of a keypath
application is concrete but is being applied to a keypath
with an existential source type.  Coerce the base to the
intended type if necessary when building the final subscript
expression.

Resolves SR-5878.
2017-09-17 16:52:49 -04:00
Joe Groff
2ba8f57514 Remove staging flag for unimplemented key path components.
All the originally-planned component kinds are now implemented.
2017-09-15 11:55:35 -07:00
Joe Groff
a67f9ca3e5 Sema: Require indexes in key path subscript components to be Hashable.
And save the conformance to be captured when we form the KeyPath object.
2017-09-15 09:59:51 -07:00
Slava Pestov
a102341c9c Merge pull request #11640 from gibachan/fixit-nested-static-value
[Qol]Fixit nested static value
2017-09-14 22:56:19 -07:00
gibachan
182faa72bd Use Swift4 2017-09-07 18:44:18 +09:00
gibachan
2310bbf98a Fix the position of fixit 2017-09-05 18:10:12 +09:00
Max Moiseev
4c0368a02a [test] Cleaning up tests 2017-08-29 10:04:39 -07:00
gibachan
64704f3537 Add a test for protocol with static member 2017-08-27 19:14:08 +09:00
gibachan
596463f34a Fix spaces 2017-08-27 19:00:44 +09:00
gibachan
8d99ccd574 [Qol]Add a test for nested static value
Variable name in nested static value should be fixed to have complete declarelation
2017-08-27 07:31:31 +09:00
Joe Groff
90377199cf Sema: Track ReferenceWritableKeyPath applications as reads of their base.
Fixes SR-5673 | rdar://problem/33881533.
2017-08-21 15:06:18 -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
Joe Groff
a689b34945 Merge pull request #11061 from jckarter/static-key-path-error
Sema: Don't allow key path literals to refer to static members.
2017-07-19 16:14:50 -07:00
Joe Groff
605804cd17 Sema: Don't allow key path literals to refer to static members.
This is theoretically supportable some day, but isn't implemented today. Fixes rdar://problem/33318422 | SR-5453.
2017-07-19 15:27:43 -07:00
Robert Widmann
5dfe3364a2 Redo a hack in CSDiag
Turns out keeping the "mutability classifier" only affects one diagnostic.
2017-07-19 09:49:32 -07:00
John McCall
847bc86638 Upgrade the warning about non-escaping parameter exclusivity to an error
now that Dispatch has fixed its violations.
2017-07-15 15:42:30 -04:00
Huon Wilson
f813cd00a7 Merge pull request #10796 from d-ronnqvist/SR-5263
[QoI] [Parse] Improve error message when parsing integer literal
2017-07-11 14:01:40 -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
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