Skip to content
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

Merged
merged 3 commits into from
Feb 2, 2018
Merged

IUO: Generate Optional<T> rather than ImplicitlyUnwrappedOptional<T> #14299

merged 3 commits into from
Feb 2, 2018

Conversation

rudkx
Copy link
Contributor

@rudkx rudkx commented Jan 31, 2018

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:

  • 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.

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.
@rudkx
Copy link
Contributor Author

rudkx commented Jan 31, 2018

@swift-ci Please test

@rudkx
Copy link
Contributor Author

rudkx commented Jan 31, 2018

@swift-ci Please test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - e456784841b147b7deff266fd16bd04c19748aa6

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
@rudkx
Copy link
Contributor Author

rudkx commented Jan 31, 2018

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - e456784841b147b7deff266fd16bd04c19748aa6

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - e456784841b147b7deff266fd16bd04c19748aa6

@rudkx
Copy link
Contributor Author

rudkx commented Jan 31, 2018

@swift-ci Please test Linux platform

@rudkx
Copy link
Contributor Author

rudkx commented Feb 2, 2018

Please test with following PR:
swiftlang/swift-source-compat-suite#127

@swift-ci Please test source compatibility

@rudkx rudkx merged commit e43ff71 into swiftlang:master Feb 2, 2018
@rudkx rudkx deleted the iuo-remove-the-type branch February 2, 2018 05:58
hamishknight added a commit to hamishknight/swift that referenced this pull request Feb 2, 2018
As IUOs types are no longer generated, we don't show them in diagnostics.
adrian-prantl pushed a commit to apple/swift-lldb that referenced this pull request Feb 10, 2018
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
adrian-prantl pushed a commit to apple/swift-lldb that referenced this pull request Feb 10, 2018
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)
@deepeshwp
Copy link

deepeshwp commented Oct 1, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants