-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IUO: Generate Optional<T> rather than ImplicitlyUnwrappedOptional<T> #14299
Conversation
Rather than comparing function types directly, use the types from the ParamDecls along with the function result type and the IUO attributes to determine whether two function types "match" by our definition.
@swift-ci Please test |
@swift-ci Please test source compatibility |
Build failed |
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.
…ected parameter." This partially reverts commit 8685ee0. The tests are still in place, but the code change is no longer necessary now that IUOs are removed from the type system. Fixes: rdar://problem/37013789
@swift-ci Please test |
Build failed |
Build failed |
@swift-ci Please test Linux platform |
see swiftlang/swift#14299 & swiftlang#129 for motivation
Please test with following PR: @swift-ci Please test source compatibility |
As IUOs types are no longer generated, we don't show them in diagnostics.
As of swiftlang/swift#14299, we should effectively no longer see this decl since we no longer generate IUO types. A follow-on PR actually removes this API completely: swiftlang/swift#14364
As of swiftlang/swift#14299, we should effectively no longer see this decl since we no longer generate IUO types. A follow-on PR actually removes this API completely: swiftlang/swift#14364 (cherry picked from commit 9fac2e9)
@rudkx just a suggestion why don't we get rid of IUO and just have optionals ( ? ) in place. To me IUO sounds pretty confusing especially in the examples section of ( https://github.com/apple/swift-evolution/blob/master/proposals/0054-abolish-iuo.md ) where the type changes automatically depending on what operation is performed which is dangerous. Also for dev what would be the good practice just to get rid of all the forced bang ! and just use ? optional types ? ( exceptions for IBOutlets ). Please can you help. |
Stop creating ImplicitlyUnwrappedOptional so that we can remove it
from the type system.
Enable the code that generates disjunctions for Optional 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:
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:
?
rather than!
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:
rare circumstances be inferred differently. This shows up in
test/ClangImporter/objc_parse.swift
, where we havevar optStr = obj.nsstringProperty
Rather than inferring optStr to be
String!?
, we now infer this tobe
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.
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.
!
was being used where it wasn't supposed to beallowed 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 nolonger 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 implicitlyunwrapped
Optional<T>
!Resolves rdar://problem/33272674.