[Review] SE-0123: Disallow coercion to optionals in operator arguments


(Chris Lattner) #1

Hello Swift community,

The review of "SE-0123: Disallow coercion to optionals in operator arguments" begins now and runs through July 19. The proposal is available here:

  https://github.com/apple/swift-evolution/blob/master/proposals/0123-disallow-value-to-optional-coercion-in-operator-arguments.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

  https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

  * What is your evaluation of the proposal?
  * Is the problem being addressed significant enough to warrant a change to Swift?
  * Does this proposal fit well with the feel and direction of Swift?
  * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
  * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

  https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,

-Chris Lattner
Review Manager


(Robert Widmann) #2

Whoops. +swift-evolution

~Robert Widmann

2016/07/12 22:34、Chris Lattner <clattner@apple.com> のメッセージ:

···

You can respond on list as part of the swift team if you’d like :slight_smile:

-Chris

On Jul 12, 2016, at 10:33 PM, Robert Widmann <devteam.codafi@gmail.com> wrote:

* What is your evaluation of the proposal?

+1. The less optional promotion the better.

* Is the problem being addressed significant enough to warrant a change to Swift?

Yes. Removing this kind of coercion has, as I understand it, long been a goal. It doesn't serve much purpose outside of being slightly more convenient at the expensive of being terribly unreadable and downright confusing to reason about.

* Does this proposal fit well with the feel and direction of Swift?

Yes.

* If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

Nothing comes to mind.

* How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Attempted an implementation last night.

On Tue, Jul 12, 2016 at 10:25 PM, Chris Lattner via swift-evolution <swift-evolution@swift.org> wrote:
Hello Swift community,

The review of "SE-0123: Disallow coercion to optionals in operator arguments" begins now and runs through July 19. The proposal is available here:

        https://github.com/apple/swift-evolution/blob/master/proposals/0123-disallow-value-to-optional-coercion-in-operator-arguments.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

        https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

        * What is your evaluation of the proposal?
        * Is the problem being addressed significant enough to warrant a change to Swift?
        * Does this proposal fit well with the feel and direction of Swift?
        * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
        * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

        https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,

-Chris Lattner
Review Manager

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


(Joe Groff) #3

-1. This feels like a band-aid rather than a well-considered fix to the issues raised in the proposal. I don't see what makes operators as a class of functions more or less susceptible to these surprising optional upcasts. Removing the comparison operators for optionals will resolve the issue with '<', and if we're concerned about '??', an unavailable overload for ??(T, T) could address that specific issue. Optional promotion in operators is clearly useful in many cases, as the proposal itself concedes by special-case exempting the assignment operator from the restriction and proposing the addition of more than a dozen overloads to restore the equivalent of explicit promotion behavior for specific operators, and that doing so accepts other undesirable formulations like 'nonOptional == nil'. This proposal doesn't make a compelling case that being an operator is the correct criterion to disable optional promotion.

-Joe

···

On Jul 12, 2016, at 10:25 PM, Chris Lattner via swift-evolution <swift-evolution@swift.org> wrote:

Hello Swift community,

The review of "SE-0123: Disallow coercion to optionals in operator arguments" begins now and runs through July 19. The proposal is available here:

  https://github.com/apple/swift-evolution/blob/master/proposals/0123-disallow-value-to-optional-coercion-in-operator-arguments.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

  https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

  * What is your evaluation of the proposal?
  * Is the problem being addressed significant enough to warrant a change to Swift?
  * Does this proposal fit well with the feel and direction of Swift?
  * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
  * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

  https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,

-Chris Lattner
Review Manager

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


(Fabian Ehrentraud) #4

* What is your evaluation of the proposal?

Given SE-0121 would get accepted, this proposal does only add small additional value, and might even make code unnecessary complicated.

BUT the nil-coalescing operator (??) really should not allow a non-optional on its left hand side.

* Is the problem being addressed significant enough to warrant a change to Swift?

No, not really once SE-0121 is accepted.

* Does this proposal fit well with the feel and direction of Swift?

No, too much boilerplate needed in some cases where the coercion is obvious

···

* If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

-

* How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Working with optionals for some while now, and a few minutes thinking through the implications of the proposal.


(Brent Royal-Gordon) #5

  * What is your evaluation of the proposal?

I'm not in favor.

Briefly: I may soon propose an overload of `..<` like so:

  func ..< <Bound: Comparable>(lhs: Bound?, rhs: Bound?) -> IncompleteRange<Bound> {…}

This operator is one which ought to lift its parameters to greater optionality. I can only assume there will be other operators like this too.

There may be a place for making the lifting behavior more explicit, either only in operators, or in all functions. But I don't think disabling lifting always in operators and never in functions is the best solution.

(I hope to have this ready for a second look in the next couple days. It's at the top of my to-do list.)

···

--
Brent Royal-Gordon
Architechies


(David Rönnqvist) #6

   * What is your evaluation of the proposal?

-1. I agree that there is a problem with optional coercion for the ?? operator (and have on occasion encountered the type of bugs/mistakes that the proposal mentions). However, I'm against the proposed solution to that a problem.

Some operators (like +) already have a way of not allowing coercion to optionals. For other operators (including custom operators) allowing coercion to optionals can still be useful (for the same arguments as it is useful for functions).

I feel that a more appropriate solution to this problem is to disallow coercion to optionals for only the ?? operator (similar to SE-0121 or the various comparison operators).

···

---

Since this proposal wants to change the behavior of all operators it would nice be if it included a list of other operators, pointing out which ones already don't permit optional coercion, for which ones optional coercion is problematic, and for which ones it is convenient.

   * Is the problem being addressed significant enough to warrant a change to Swift?

If SE-0121 is accepted, then the optional coercion for the comparison operators will already be dealt with.

I feel that the ?? operator is problematic enough to warrant a change, but am not convinced that the same is true for operators in general.

   * Does this proposal fit well with the feel and direction of Swift?

-

   * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

-

   * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Read the proposal and experimented with optional coercion for some other operators in a playground.

- David


(John McCall) #7

-1. This feels like a band-aid rather than a well-considered fix to the issues raised in the proposal. I don't see what makes operators as a class of functions more or less susceptible to these surprising optional upcasts. Removing the comparison operators for optionals will resolve the issue with '<', and if we're concerned about '??', an unavailable overload for ??(T, T) could address that specific issue. Optional promotion in operators is clearly useful in many cases, as the proposal itself concedes by special-case exempting the assignment operator from the restriction and proposing the addition of more than a dozen overloads to restore the equivalent of explicit promotion behavior for specific operators, and that doing so accepts other undesirable formulations like 'nonOptional == nil'. This proposal doesn't make a compelling case that being an operator is the correct criterion to disable optional promotion.

Agreed. To me, the right solution is some attribute to suppress promotion for specific arguments.

When we get to decl-based overload resolution, this will become straightforward to implement.

John.

···

On Jul 13, 2016, at 10:06 AM, Joe Groff via swift-evolution <swift-evolution@swift.org> wrote:

-Joe

On Jul 12, 2016, at 10:25 PM, Chris Lattner via swift-evolution <swift-evolution@swift.org> wrote:

Hello Swift community,

The review of "SE-0123: Disallow coercion to optionals in operator arguments" begins now and runs through July 19. The proposal is available here:

  https://github.com/apple/swift-evolution/blob/master/proposals/0123-disallow-value-to-optional-coercion-in-operator-arguments.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

  https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

  * What is your evaluation of the proposal?
  * Is the problem being addressed significant enough to warrant a change to Swift?
  * Does this proposal fit well with the feel and direction of Swift?
  * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
  * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

  https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,

-Chris Lattner
Review Manager

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

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


#8

I concur with Joe Groff and John McCall, this proposal does not seem to be
the right approach.

What I would really like is the complete elimination of implicit coercion
to Optional (implicit type conversions are not Swifty!) and the
simultaneous introduction of a simple notation for doing so explicitly.

If we can make it play nice with optional chaining, then a postfix `?`
operator is the natural choice: `(42?, "babel fish"?, mattressSwamp?)`
would be a tuple of optionals, and `(1, 2, 3)?` an optional tuple.

Nevin

···

On Wed, Jul 13, 2016 at 1:16 PM, John McCall via swift-evolution < swift-evolution@swift.org> wrote:

> On Jul 13, 2016, at 10:06 AM, Joe Groff via swift-evolution < > swift-evolution@swift.org> wrote:
> -1. This feels like a band-aid rather than a well-considered fix to the
issues raised in the proposal. I don't see what makes operators as a class
of functions more or less susceptible to these surprising optional upcasts.
Removing the comparison operators for optionals will resolve the issue with
'<', and if we're concerned about '??', an unavailable overload for ??(T,
T) could address that specific issue. Optional promotion in operators is
clearly useful in many cases, as the proposal itself concedes by
special-case exempting the assignment operator from the restriction and
proposing the addition of more than a dozen overloads to restore the
equivalent of explicit promotion behavior for specific operators, and that
doing so accepts other undesirable formulations like 'nonOptional == nil'.
This proposal doesn't make a compelling case that being an operator is the
correct criterion to disable optional promotion.

Agreed. To me, the right solution is some attribute to suppress promotion
for specific arguments.

When we get to decl-based overload resolution, this will become
straightforward to implement.

John.

>
> -Joe
>
>> On Jul 12, 2016, at 10:25 PM, Chris Lattner via swift-evolution < > swift-evolution@swift.org> wrote:
>>
>> Hello Swift community,
>>
>> The review of "SE-0123: Disallow coercion to optionals in operator
arguments" begins now and runs through July 19. The proposal is available
here:
>>
>>
https://github.com/apple/swift-evolution/blob/master/proposals/0123-disallow-value-to-optional-coercion-in-operator-arguments.md
>>
>> Reviews are an important part of the Swift evolution process. All
reviews should be sent to the swift-evolution mailing list at
>>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>> or, if you would like to keep your feedback private, directly to the
review manager.
>>
>> What goes into a review?
>>
>> The goal of the review process is to improve the proposal under review
through constructive criticism and contribute to the direction of Swift.
When writing your review, here are some questions you might want to answer
in your review:
>>
>> * What is your evaluation of the proposal?
>> * Is the problem being addressed significant enough to warrant a
change to Swift?
>> * Does this proposal fit well with the feel and direction of Swift?
>> * If you have used other languages or libraries with a similar
feature, how do you feel that this proposal compares to those?
>> * How much effort did you put into your review? A glance, a quick
reading, or an in-depth study?
>>
>> More information about the Swift evolution process is available at
>>
>> https://github.com/apple/swift-evolution/blob/master/process.md
>>
>> Thank you,
>>
>> -Chris Lattner
>> Review Manager
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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