[Accepted] SE-0115: Rename Literal Syntax Protocols


(Chris Lattner) #1

Proposal Link: https://github.com/apple/swift-evolution/blob/master/proposals/0115-literal-syntax-protocols.md

The review of "SE-0115: Rename Literal Syntax Protocols " ran from Active review July 1...7. The proposal has been *accepted*:

The community and core team agree that this proposal is a better set of names for these protocols. The core team agrees with the community sentiment that “By” is better than “As” in the protocol names, and has accepted the proposal with this revision.

Thank you to Matthew Johnson and many others for driving this discussion forward!

-Chris Lattner
Review Manager


(Beta) #2

Does this one have an SR number yet? It would make for a fantastic starter bug.

···

On Jul 11, 2016, at 4:16 PM, Chris Lattner <clattner@apple.com> wrote:

Proposal Link: https://github.com/apple/swift-evolution/blob/master/proposals/0115-literal-syntax-protocols.md

The review of "SE-0115: Rename Literal Syntax Protocols " ran from Active review July 1...7. The proposal has been *accepted*:

The community and core team agree that this proposal is a better set of names for these protocols. The core team agrees with the community sentiment that “By” is better than “As” in the protocol names, and has accepted the proposal with this revision.

Thank you to Matthew Johnson and many others for driving this discussion forward!

-Chris Lattner
Review Manager

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


(Jacob Bandes-Storch) #3

Tangential: Is there any way to make it impossible to call these
literal-initializers explicitly, instead requiring "<literal> as T" or just
"<literal>" in a typed context?

I have seen several explicit calls of these initializers where literals
would have been more appropriate, such as "Set(arrayLiteral: foo, bar)",
and I think this only happens because folks find these initializers via
code completion. I can't think of any reason why you'd want to invoke one
by name rather than by using a literal.

Jacob

···

On Mon, Jul 11, 2016 at 4:16 PM, Chris Lattner via swift-evolution < swift-evolution@swift.org> wrote:

Proposal Link:
https://github.com/apple/swift-evolution/blob/master/proposals/0115-literal-syntax-protocols.md

The review of "SE-0115: Rename Literal Syntax Protocols " ran from Active
review July 1...7. The proposal has been *accepted*:

The community and core team agree that this proposal is a better set of
names for these protocols. The core team agrees with the community
sentiment that “By” is better than “As” in the protocol names, and has
accepted the proposal with this revision.

Thank you to Matthew Johnson and many others for driving this discussion
forward!

-Chris Lattner
Review Manager

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


(Xiaodi Wu) #4

Maybe just a warning + fix-it would be sufficient?

···

On Mon, Jul 11, 2016 at 19:02 Jacob Bandes-Storch via swift-evolution < swift-evolution@swift.org> wrote:

Tangential: Is there any way to make it impossible to call these
literal-initializers explicitly, instead requiring "<literal> as T" or just
"<literal>" in a typed context?

I have seen several explicit calls of these initializers where literals
would have been more appropriate, such as "Set(arrayLiteral: foo, bar)",
and I think this only happens because folks find these initializers via
code completion. I can't think of any reason why you'd want to invoke one
by name rather than by using a literal.

Jacob

On Mon, Jul 11, 2016 at 4:16 PM, Chris Lattner via swift-evolution < > swift-evolution@swift.org> wrote:

Proposal Link:
https://github.com/apple/swift-evolution/blob/master/proposals/0115-literal-syntax-protocols.md

The review of "SE-0115: Rename Literal Syntax Protocols " ran from Active
review July 1...7. The proposal has been *accepted*:

The community and core team agree that this proposal is a better set of
names for these protocols. The core team agrees with the community
sentiment that “By” is better than “As” in the protocol names, and has
accepted the proposal with this revision.

Thank you to Matthew Johnson and many others for driving this discussion
forward!

-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


(Dave Abrahams) #5

Does this one have an SR number yet? It would make for a fantastic starter bug.

Not that I know of.

···

on Mon Jul 11 2016, Robert Widmann <swift-evolution@swift.org> wrote:

On Jul 11, 2016, at 4:16 PM, Chris Lattner <clattner@apple.com> wrote:

Proposal Link: https://github.com/apple/swift-evolution/blob/master/proposals/0115-literal-syntax-protocols.md

The review of "SE-0115: Rename Literal Syntax Protocols " ran from Active review July 1...7. The proposal has been *accepted*:

The community and core team agree that this proposal is a better set
of names for these protocols. The core team agrees with the
community sentiment that “By” is better than “As” in the protocol
names, and has accepted the proposal with this revision.

Thank you to Matthew Johnson and many others for driving this discussion forward!

-Chris Lattner
Review Manager

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

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

--
Dave


(Jacob Bandes-Storch) #6

I'd be happy with a warning + fix-it too.

What's the right way to do this? An attribute like "@implicit" on the
initializers? Perhaps a special case in the compiler, since these are
already "known protocol kinds"
<https://github.com/apple/swift/blob/778a4ee136503574e75742ad9a5b3ad1677f382c/lib/Sema/CSSolver.cpp#L582-L584>
?

If someone can offer guidance on the right direction, I'd be happy to write
up a proposal.

Jacob

···

On Mon, Jul 11, 2016 at 5:05 PM, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

Maybe just a warning + fix-it would be sufficient?

On Mon, Jul 11, 2016 at 19:02 Jacob Bandes-Storch via swift-evolution < > swift-evolution@swift.org> wrote:

Tangential: Is there any way to make it impossible to call these
literal-initializers explicitly, instead requiring "<literal> as T" or just
"<literal>" in a typed context?

I have seen several explicit calls of these initializers where literals
would have been more appropriate, such as "Set(arrayLiteral: foo, bar)",
and I think this only happens because folks find these initializers via
code completion. I can't think of any reason why you'd want to invoke one
by name rather than by using a literal.

Jacob

On Mon, Jul 11, 2016 at 4:16 PM, Chris Lattner via swift-evolution < >> swift-evolution@swift.org> wrote:

Proposal Link:
https://github.com/apple/swift-evolution/blob/master/proposals/0115-literal-syntax-protocols.md

The review of "SE-0115: Rename Literal Syntax Protocols " ran from
Active review July 1...7. The proposal has been *accepted*:

The community and core team agree that this proposal is a better set of
names for these protocols. The core team agrees with the community
sentiment that “By” is better than “As” in the protocol names, and has
accepted the proposal with this revision.

Thank you to Matthew Johnson and many others for driving this discussion
forward!

-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


(Jacob Bandes-Storch) #7

I'd call it an antipattern: it pretty much defeats the purpose of having
the ExpressibleBy*Literal protocols.

If you just want a type to be constructible from a value of some other type
(literal or not), that's what regular initializers are for. For example, in
addition to its ArrayLiteralConvertible conformance, Set provides init<S:
Sequence where S.Iterator.Element == Element>(_ seq: S), so you can write
Set([1, 2, 3]). The literal protocols are different because they're invoked
*implicitly*: doSomethingWithASet([1, 2, 3]).

They're also awkward, because the argument labels (integerLiteral:,
arrayLiteral:, nilLiteral:) provide only type information, and not "role"
information — and if you're invoking one of these inits explicitly, there's
no way the compiler can enforce that you're actually passing a *literal* in
for those parameters (in fact, you *can't* pass an array literal to
init(arrayLiteral:), because it's a variadic parameter rather than an array
parameter).

Jacob

···

On Mon, Jul 11, 2016 at 5:22 PM, David Sweeris <davesweeris@mac.com> wrote:

On Jul 11, 2016, at 19:13, Jacob Bandes-Storch via swift-evolution < > swift-evolution@swift.org> wrote:

I'd be happy with a warning + fix-it too.

On Mon, Jul 11, 2016 at 5:05 PM, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

Maybe just a warning + fix-it would be sufficient?

On Mon, Jul 11, 2016 at 19:02 Jacob Bandes-Storch via swift-evolution < >> swift-evolution@swift.org> wrote:

Tangential: Is there any way to make it impossible to call these
literal-initializers explicitly, instead requiring "<literal> as T" or just
"<literal>" in a typed context?

I have seen several explicit calls of these initializers where literals
would have been more appropriate, such as "Set(arrayLiteral: foo, bar)",
and I think this only happens because folks find these initializers via
code completion. I can't think of any reason why you'd want to invoke one
by name rather than by using a literal.

I don't see how this is a problem.

- Dave Sweeris


(David Sweeris) #8

I don't see how this is a problem.

- Dave Sweeris

···

On Jul 11, 2016, at 19:13, Jacob Bandes-Storch via swift-evolution <swift-evolution@swift.org> wrote:

I'd be happy with a warning + fix-it too.

On Mon, Jul 11, 2016 at 5:05 PM, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:
Maybe just a warning + fix-it would be sufficient?

On Mon, Jul 11, 2016 at 19:02 Jacob Bandes-Storch via swift-evolution <swift-evolution@swift.org> wrote:
Tangential: Is there any way to make it impossible to call these literal-initializers explicitly, instead requiring "<literal> as T" or just "<literal>" in a typed context?

I have seen several explicit calls of these initializers where literals would have been more appropriate, such as "Set(arrayLiteral: foo, bar)", and I think this only happens because folks find these initializers via code completion. I can't think of any reason why you'd want to invoke one by name rather than by using a literal.


(David Sweeris) #9

Agreed... I don’t see the harm in letting someone use them if they want to.

To be clear, I’m only pointing out that, IMHO, there’s not really a need to do the work of specifically disallowing this “antipattern”. If others think it’s important enough to bother with, I won’t complain. If we weren’t in the Swift 3 crunch, I might not have raised it at all.

- Dave Sweeris

···

On Jul 11, 2016, at 7:34 PM, Jacob Bandes-Storch <jtbandes@gmail.com> wrote:

I'd call it an antipattern: it pretty much defeats the purpose of having the ExpressibleBy*Literal protocols.

If you just want a type to be constructible from a value of some other type (literal or not), that's what regular initializers are for. For example, in addition to its ArrayLiteralConvertible conformance, Set provides init<S: Sequence where S.Iterator.Element == Element>(_ seq: S), so you can write Set([1, 2, 3]). The literal protocols are different because they're invoked *implicitly*: doSomethingWithASet([1, 2, 3]).

They're also awkward, because the argument labels (integerLiteral:, arrayLiteral:, nilLiteral:) provide only type information, and not "role" information — and if you're invoking one of these inits explicitly, there's no way the compiler can enforce that you're actually passing a *literal* in for those parameters (in fact, you *can't* pass an array literal to init(arrayLiteral:), because it's a variadic parameter rather than an array parameter).


(Xiaodi Wu) #10

...I'll go ahead and file one.

···

On Tue, Jul 12, 2016 at 12:17 PM, Dave Abrahams via swift-evolution < swift-evolution@swift.org> wrote:

on Mon Jul 11 2016, Robert Widmann <swift-evolution@swift.org> wrote:

> Does this one have an SR number yet? It would make for a fantastic
starter bug.

Not that I know of.

>> On Jul 11, 2016, at 4:16 PM, Chris Lattner <clattner@apple.com> wrote:
>>
>> Proposal Link:
https://github.com/apple/swift-evolution/blob/master/proposals/0115-literal-syntax-protocols.md
>>
>> The review of "SE-0115: Rename Literal Syntax Protocols " ran from
Active review July 1...7. The proposal has been *accepted*:
>>
>> The community and core team agree that this proposal is a better set
>> of names for these protocols. The core team agrees with the
>> community sentiment that “By” is better than “As” in the protocol
>> names, and has accepted the proposal with this revision.
>>
>> Thank you to Matthew Johnson and many others for driving this
discussion forward!
>>
>> -Chris Lattner
>> Review Manager
>>
>>
>> _______________________________________________
>> swift-evolution-announce mailing list
>> swift-evolution-announce@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution-announce
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

--
Dave

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