[Draft] Abolish IUO type

What will happen to map()/flatMap() on IUO attributed optional values?

let foo: Int! = 42
let bar = (foo as ImplicitlyUnwrappedOptional).map { $0.UInt($0) }

Replacement would be something like this?

let bar: UInt! = (foo as Int?).map { UInt($0) }

I have never seen code like this in real world,
but it should be covered in "Impact on existing code" section.

···

2016-03-18 13:12 GMT+09:00 Chris Lattner via swift-evolution < swift-evolution@swift.org>:

> On Mar 17, 2016, at 9:08 PM, Chris Lattner via swift-evolution < > swift-evolution@swift.org> wrote:
>
> On Mar 17, 2016, at 5:50 PM, Brent Royal-Gordon <brent@architechies.com> > wrote:
>
>>> It seems like this unnecessarily complicates the surface model of
Swift. To me, it seems like there is no advantage to having two ways to
spell this.
>>
>> @autounwrapped let foo = functionReturningOptional()
>>
>> I *believe* that, without the `@autounwrapped` attribute, there's no
way to go from T? to T! without actually restating T somewhere.
>
> Right, that's part of the feature :-)

Sorry, less snarky answer:

You are right that today it is a regression vs:

let foo : ImplicitlyUnwrappedOptional = ...

However, I have never seen someone actually do that, and if they did, I
would observe that the T is a lot more illuminating than the ! part of the
type. Is there a concrete use case you are concerned about?

-Chris

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

(Come to think of it, is there a cost to converting between `T?` and `T!`, or do they get optimized into the same thing?)

I can't imagine there would be. @autounwrapped (or whatever) is a purely compile-time thing which tells the compiler to automatically insert a `!` operator if it will make the expression typecheck. Other than that compile-time behavior, `!` is an exact synonym for `?`.

···

--
Brent Royal-Gordon
Architechies

One thing I've had bit me is the lack of some sort of confirmation, see
this example.

I have a objective-c method in a library like so:

- (void)observe:(CallbackBlock)block;

The CallbackBlock is a type def-ed block like so:

typedef void (^CallbackBlock)(FDataSnapshot *snapshot);

The parameter in the block gets converted into a IUO, I ended up releasing
an app that crashed due to that IUO being nil.

The code that crashed was something like this

object.observe {
$0.doSomething()
}

There is no way to tell that the $0 was a IUO. The compiler didn't force me
to confirm in it in some way using a ! and unless I remembered to check the
header I would have a crash.

How would this work under your proposal ?

···

*___________________________________*

*James⎥Head Of CEO*

*james@supmenow.com <james@supmenow.com>⎥supmenow.com <http://supmenow.com>*

*Sup*

*Runway East *

*10 Finsbury Square*

*London*

* EC2A 1AF *

On Fri, Mar 18, 2016 at 6:53 AM, Brent Royal-Gordon via swift-evolution < swift-evolution@swift.org> wrote:

> (Come to think of it, is there a cost to converting between `T?` and
`T!`, or do they get optimized into the same thing?)

I can't imagine there would be. @autounwrapped (or whatever) is a purely
compile-time thing which tells the compiler to automatically insert a `!`
operator if it will make the expression typecheck. Other than that
compile-time behavior, `!` is an exact synonym for `?`.

--
Brent Royal-Gordon
Architechies

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Oops, typo in the example code:

let foo: Int! = 42
let bar = (foo as ImplicitlyUnwrappedOptional).map { UInt($0) }

···

2016-03-18 14:05 GMT+09:00 rintaro ishizaki <fs.output@gmail.com>:

What will happen to map()/flatMap() on IUO attributed optional values?

let foo: Int! = 42
let bar = (foo as ImplicitlyUnwrappedOptional).map { $0.UInt($0) }

Replacement would be something like this?

let bar: UInt! = (foo as Int?).map { UInt($0) }

I have never seen code like this in real world,
but it should be covered in "Impact on existing code" section.

2016-03-18 13:12 GMT+09:00 Chris Lattner via swift-evolution <
swift-evolution@swift.org>:

> On Mar 17, 2016, at 9:08 PM, Chris Lattner via swift-evolution < >> swift-evolution@swift.org> wrote:
>
> On Mar 17, 2016, at 5:50 PM, Brent Royal-Gordon <brent@architechies.com> >> wrote:
>
>>> It seems like this unnecessarily complicates the surface model of
Swift. To me, it seems like there is no advantage to having two ways to
spell this.
>>
>> @autounwrapped let foo = functionReturningOptional()
>>
>> I *believe* that, without the `@autounwrapped` attribute, there's no
way to go from T? to T! without actually restating T somewhere.
>
> Right, that's part of the feature :-)

Sorry, less snarky answer:

You are right that today it is a regression vs:

let foo : ImplicitlyUnwrappedOptional = ...

However, I have never seen someone actually do that, and if they did, I
would observe that the T is a lot more illuminating than the ! part of the
type. Is there a concrete use case you are concerned about?

-Chris

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution