Proposal: Allow #if to guard switch case clauses


#1

Hi evolution community,

This proposal allows you to enclose switch cases with #if directive.
Implementation: https://github.com/apple/swift/pull/9457
This is one of the oldest SR issue:
https://bugs.swift.org/browse/SR-2
https://bugs.swift.org/browse/SR-4196

Thanks!
Rintaro

Allow #if to guard switch case clauses

   - Proposal: SE-NNNN <https://gist.github.com/rintaro/NNNN-filename.md>
   - Authors: Rintaro Ishziaki <https://github.com/rintaro>
   - Review Manager: TBD
   - Status: Awaiting review

<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#introduction>
Introduction

This proposal adds ability to guard switch case clauses with #if directives.

Swift-evolution thread: Not yet
<https://lists.swift.org/pipermail/swift-evolution/>
<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#motivation>
Motivation

When you want to switch cases only for certain compilation condition, say
switching #if os(Linux) guarded enum cases, right now you have to write
switch twice:

enum Operation {
  case output(String)
#if os(Linux)
  case syscall(Syscall)
#endif
}
func execute(operation: Operation) {
#if !os(Linux)
   switch operation {
   case .output(let str):
       print(str)
   }
#else
   switch operation {
   case .output(let str):
       print(str)
   case .syscall(let call):
       call.execute()
   }
#endif
}

This is annoying and error prone.
<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#proposed-solution>Proposed
solution

This proposal allows #if to guard switch case clauses.

func execute(operation: Operation) {
    switch operation {
    case .output(let str):
        print(str)
#if os(Linux)
    case .syscall(let call):
        call.execute()
#endif
    }
}

<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#detailed-design>Detailed
design

This change shouldn't affect existing #if directives *within* case clauses.
This code should works as expected:

func foo(x: MyEnum) {
    switch x {
    case .some(let str):
        doSomething(str)
#if PRINT_SOME
        print(str)
#endif
    case .other:
        doOther()
    }
}

Only if the next token after #if is case or default, the Parser treat it as
guarding case clauses.

func foo(x: MyEnum) {
    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHER
    case .other:
        doOther()
    }
#endif
}

func foo(x: MyEnum) {
    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHER
    default:
        break
#endif
}

Error cases:

    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHER
    case .other:
        doOther()
#else
        doMore() // error: all statements inside a switch must be
covered by a 'case' or 'default'#endif
    }

    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHER
        doMore()
    case .other:
        doOther() // error: 'case' label can only appear inside a
'switch' statement#else
    }

You can guard multiple cases as long as it is guarding whole clauses:

    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHERS
    case .other:
        doOther()
    case .more:
        doMore()
#else
    }

<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#source-compatibility>


(Rien) #2

I hope this makes it through without generating a lot of extra discussion. I would love to have this in Swift 4, or the next regular update of xcode.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: http://github.com/Balancingrock
Project: http://swiftfire.nl - A server for websites build in Swift

···

On 10 May 2017, at 10:32, rintaro ishizaki via swift-evolution <swift-evolution@swift.org> wrote:

Hi evolution community,

This proposal allows you to enclose switch cases with #if directive.
Implementation: https://github.com/apple/swift/pull/9457
This is one of the oldest SR issue:
https://bugs.swift.org/browse/SR-2
https://bugs.swift.org/browse/SR-4196

Thanks!
Rintaro

Allow #if to guard switch case clauses

  • Proposal: SE-NNNN
  • Authors: Rintaro Ishziaki
  • Review Manager: TBD
  • Status: Awaiting review
Introduction

This proposal adds ability to guard switch case clauses with #if directives.

Swift-evolution thread: Not yet

Motivation

When you want to switch cases only for certain compilation condition, say switching #if os(Linux) guarded enum cases, right now you have to write switch twice:

enum Operation
{
  
case output(String
)
#
if os(Linux
)
  
case syscall
(Syscall)
#
endif

}

func execute(operation
: Operation) {
#
if !os(Linux
)
   
switch
operation {
   
case .output(let str):

print
(str)
   }
#
else

switch
operation {
   
case .output(let str):

print
(str)
   
case .syscall(let call):

       call.
execute
()
   }
#
endif

}

This is annoying and error prone.

Proposed solution

This proposal allows #if to guard switch case clauses.

func execute(operation
: Operation) {
    
switch
operation {
    
case .output(let str):

print
(str)
#
if os(Linux
)
    
case .syscall(let call):

        call.
execute
()
#
endif

    }
}

Detailed design

This change shouldn't affect existing #if directives within case clauses. This code should works as expected:

func foo(x
: MyEnum) {
    
switch
x {
    
case .some(let str):

doSomething
(str)
#
if
PRINT_SOME
        
print
(str)
#
endif

case .other:

doOther
()
    }
}

Only if the next token after #if is case or default, the Parser treat it as guarding case clauses.

func foo(x
: MyEnum) {
    
switch
x {
    
case .some(let str):

doSomething
(str)
#
if
HAS_OTHER
    
case .other:

doOther
()
    }
#
endif

}

func foo(x
: MyEnum) {
    
switch
x {
    
case .some(let str):

doSomething
(str)
#
if
HAS_OTHER
    
default:

break

#
endif

}

Error cases:

    switch
x {
    
case .some(let str):

doSomething
(str)
#
if
HAS_OTHER
    
case .other:

doOther
()
#
else

doMore() // error: all statements inside a switch must be covered by a 'case' or 'default'
#endif

    }

    switch
x {
    
case .some(let str):

doSomething
(str)
#
if
HAS_OTHER
        
doMore
()
    
case .other:

doOther() // error: 'case' label can only appear inside a 'switch' statement
#else

    }

You can guard multiple cases as long as it is guarding whole clauses:

    switch
x {
    
case .some(let str):

doSomething
(str)
#
if
HAS_OTHERS
    
case .other:

doOther
()
    
case .more:

doMore
()
#
else

    }

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


(Joe Groff) #3

Seems reasonable to me.

···

On May 10, 2017, at 1:32 AM, rintaro ishizaki via swift-evolution <swift-evolution@swift.org> wrote:

Hi evolution community,

This proposal allows you to enclose switch cases with #if directive.
Implementation: https://github.com/apple/swift/pull/9457
This is one of the oldest SR issue:
https://bugs.swift.org/browse/SR-2
https://bugs.swift.org/browse/SR-4196

Thanks!
Rintaro

Allow #if to guard switch case clauses

  • Proposal: SE-NNNN
  • Authors: Rintaro Ishziaki
  • Review Manager: TBD
  • Status: Awaiting review
Introduction

This proposal adds ability to guard switch case clauses with #if directives.

Swift-evolution thread: Not yet

Motivation

When you want to switch cases only for certain compilation condition, say switching #if os(Linux) guarded enum cases, right now you have to write switch twice:

enum Operation
{
  
case output(String
)
#
if os(Linux
)
  
case syscall
(Syscall)
#
endif

}

func execute(operation
: Operation) {
#
if !os(Linux
)
   
switch
operation {
   
case .output(let str):

print
(str)
   }
#
else

switch
operation {
   
case .output(let str):

print
(str)
   
case .syscall(let call):

       call.
execute
()
   }
#
endif

}

This is annoying and error prone.

Proposed solution

This proposal allows #if to guard switch case clauses.

func execute(operation
: Operation) {
    
switch
operation {
    
case .output(let str):

print
(str)
#
if os(Linux
)
    
case .syscall(let call):

        call.
execute
()
#
endif

    }
}

Detailed design

This change shouldn't affect existing #if directives within case clauses. This code should works as expected:

func foo(x
: MyEnum) {
    
switch
x {
    
case .some(let str):

doSomething
(str)
#
if
PRINT_SOME
        
print
(str)
#
endif

case .other:

doOther
()
    }
}

Only if the next token after #if is case or default, the Parser treat it as guarding case clauses.

func foo(x
: MyEnum) {
    
switch
x {
    
case .some(let str):

doSomething
(str)
#
if
HAS_OTHER
    
case .other:

doOther
()
    }
#
endif

}

func foo(x
: MyEnum) {
    
switch
x {
    
case .some(let str):

doSomething
(str)
#
if
HAS_OTHER
    
default:

break

#
endif

}

Error cases:

    switch
x {
    
case .some(let str):

doSomething
(str)
#
if
HAS_OTHER
    
case .other:

doOther
()
#
else

doMore() // error: all statements inside a switch must be covered by a 'case' or 'default'
#endif

    }

    switch
x {
    
case .some(let str):

doSomething
(str)
#
if
HAS_OTHER
        
doMore
()
    
case .other:

doOther() // error: 'case' label can only appear inside a 'switch' statement
#else

    }

You can guard multiple cases as long as it is guarding whole clauses:

    switch
x {
    
case .some(let str):

doSomething
(str)
#
if
HAS_OTHERS
    
case .other:

doOther
()
    
case .more:

doMore
()
#
else

    }

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


(Jordan Rose) #4

I'm in favor, certainly. I'd personally say this wouldn't even need to go through the full evolution process, but I'm not a core team member.

Jordan

···

On May 10, 2017, at 01:32, rintaro ishizaki via swift-evolution <swift-evolution@swift.org> wrote:

Hi evolution community,

This proposal allows you to enclose switch cases with #if directive.
Implementation: https://github.com/apple/swift/pull/9457
This is one of the oldest SR issue:
https://bugs.swift.org/browse/SR-2
https://bugs.swift.org/browse/SR-4196

Thanks!
Rintaro


#5

Here's proposal link:
https://github.com/rintaro/swift-evolution/blob/conditional-switch-case/proposals/NNNN-conditional-switch-case.md

Fixed some typos, including my name :slight_smile:

···

2017-05-10 17:32 GMT+09:00 rintaro ishizaki <fs.output@gmail.com>:

Hi evolution community,

This proposal allows you to enclose switch cases with #if directive.
Implementation: https://github.com/apple/swift/pull/9457
This is one of the oldest SR issue:
https://bugs.swift.org/browse/SR-2
https://bugs.swift.org/browse/SR-4196

Thanks!
Rintaro

Allow #if to guard switch case clauses

   - Proposal: SE-NNNN <https://gist.github.com/rintaro/NNNN-filename.md>
   - Authors: Rintaro Ishziaki <https://github.com/rintaro>
   - Review Manager: TBD
   - Status: Awaiting review

<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#introduction>
Introduction

This proposal adds ability to guard switch case clauses with #if
directives.

Swift-evolution thread: Not yet
<https://lists.swift.org/pipermail/swift-evolution/>

<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#motivation>
Motivation

When you want to switch cases only for certain compilation condition, say
switching #if os(Linux) guarded enum cases, right now you have to write
switch twice:

enum Operation {
  case output(String)
#if os(Linux)
  case syscall(Syscall)
#endif
}
func execute(operation: Operation) {
#if !os(Linux)
   switch operation {
   case .output(let str):
       print(str)
   }
#else
   switch operation {
   case .output(let str):
       print(str)
   case .syscall(let call):
       call.execute()
   }
#endif
}

This is annoying and error prone.

<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#proposed-solution>Proposed
solution

This proposal allows #if to guard switch case clauses.

func execute(operation: Operation) {
    switch operation {
    case .output(let str):
        print(str)
#if os(Linux)
    case .syscall(let call):
        call.execute()
#endif
    }
}

<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#detailed-design>Detailed
design

This change shouldn't affect existing #if directives *within* case clauses.
This code should works as expected:

func foo(x: MyEnum) {
    switch x {
    case .some(let str):
        doSomething(str)
#if PRINT_SOME
        print(str)
#endif
    case .other:
        doOther()
    }
}

Only if the next token after #if is case or default, the Parser treat it
as guarding case clauses.

func foo(x: MyEnum) {
    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHER
    case .other:
        doOther()
    }
#endif
}

func foo(x: MyEnum) {
    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHER
    default:
        break
#endif
}

Error cases:

    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHER
    case .other:
        doOther()
#else
        doMore() // error: all statements inside a switch must be covered by a 'case' or 'default'#endif
    }

    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHER
        doMore()
    case .other:
        doOther() // error: 'case' label can only appear inside a 'switch' statement#else
    }

You can guard multiple cases as long as it is guarding whole clauses:

    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHERS
    case .other:
        doOther()
    case .more:
        doMore()
#else
    }

<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#source-compatibility>


(Chris Lattner) #6

I agree with Jordan.

-Chris

···

On May 10, 2017, at 11:47 AM, Jordan Rose via swift-evolution <swift-evolution@swift.org> wrote:

I'm in favor, certainly. I'd personally say this wouldn't even need to go through the full evolution process, but I'm not a core team member.

Jordan

On May 10, 2017, at 01:32, rintaro ishizaki via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Hi evolution community,

This proposal allows you to enclose switch cases with #if directive.
Implementation: https://github.com/apple/swift/pull/9457
This is one of the oldest SR issue:
https://bugs.swift.org/browse/SR-2
https://bugs.swift.org/browse/SR-4196

Thanks!
Rintaro

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


(Kevin Nattinger) #7

I support this proposal 100%. In fact, I just ran into this use case.

I’d support extending it to allow partial-case coverage (as long as it doesn’t cross a case: boundary, obviously), e.g.

switch result {
case .success(let object):
    doSomething(with: object)
case .error(let error):
    #if debug
    alertUser(error)
    #endif
    handleError(error)
}

I don’t see a reason to prevent that, but if we can just get the current proposal (full cases only) in Swift 4 I’ll be satisfied and just put this on my (large and growing) list of things to bring up for 5.

···

On May 10, 2017, at 6:28 AM, rintaro ishizaki via swift-evolution <swift-evolution@swift.org> wrote:

Here's proposal link:
https://github.com/rintaro/swift-evolution/blob/conditional-switch-case/proposals/NNNN-conditional-switch-case.md

Fixed some typos, including my name :slight_smile:

2017-05-10 17:32 GMT+09:00 rintaro ishizaki <fs.output@gmail.com <mailto:fs.output@gmail.com>>:
Hi evolution community,

This proposal allows you to enclose switch cases with #if directive.
Implementation: https://github.com/apple/swift/pull/9457
This is one of the oldest SR issue:
https://bugs.swift.org/browse/SR-2
https://bugs.swift.org/browse/SR-4196

Thanks!
Rintaro

Allow #if to guard switch case clauses

Proposal: SE-NNNN <https://gist.github.com/rintaro/NNNN-filename.md>
Authors: Rintaro Ishziaki <https://github.com/rintaro>
Review Manager: TBD
Status: Awaiting review
<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#introduction>Introduction

This proposal adds ability to guard switch case clauses with #if directives.

Swift-evolution thread: Not yet <https://lists.swift.org/pipermail/swift-evolution/>
<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#motivation>Motivation

When you want to switch cases only for certain compilation condition, say switching #if os(Linux) guarded enum cases, right now you have to write switch twice:

enum Operation {
  case output(String)
#if os(Linux)
  case syscall(Syscall)
#endif
}

func execute(operation: Operation) {
#if !os(Linux)
   switch operation {
   case .output(let str):
       print(str)
   }
#else
   switch operation {
   case .output(let str):
       print(str)
   case .syscall(let call):
       call.execute()
   }
#endif
}
This is annoying and error prone.

<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#proposed-solution>Proposed solution

This proposal allows #if to guard switch case clauses.

func execute(operation: Operation) {
    switch operation {
    case .output(let str):
        print(str)
#if os(Linux)
    case .syscall(let call):
        call.execute()
#endif
    }
}
<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#detailed-design>Detailed design

This change shouldn't affect existing #if directives within case clauses. This code should works as expected:

func foo(x: MyEnum) {
    switch x {
    case .some(let str):
        doSomething(str)
#if PRINT_SOME
        print(str)
#endif
    case .other:
        doOther()
    }
}
Only if the next token after #if is case or default, the Parser treat it as guarding case clauses.

func foo(x: MyEnum) {
    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHER
    case .other:
        doOther()
    }
#endif
}
func foo(x: MyEnum) {
    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHER
    default:
        break
#endif
}
Error cases:

    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHER
    case .other:
        doOther()
#else
        doMore() // error: all statements inside a switch must be covered by a 'case' or 'default'
#endif
    }
    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHER
        doMore()
    case .other:
        doOther() // error: 'case' label can only appear inside a 'switch' statement
#else
    }
You can guard multiple cases as long as it is guarding whole clauses:

    switch x {
    case .some(let str):
        doSomething(str)
#if HAS_OTHERS
    case .other:
        doOther()
    case .more:
        doMore()
#else
    }

<https://gist.github.com/rintaro/a5a9d9836027d7df7a5326a3a8cf9d89#source-compatibility>
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Nicholas Maccharoli) #8

I also strongly agree.

I can think of no strong argument against this, was this intentional at one
point or a compiler bug?

- Nick

···

On Thu, May 11, 2017 at 2:37 PM, Chris Lattner via swift-evolution < swift-evolution@swift.org> wrote:

I agree with Jordan.

-Chris

On May 10, 2017, at 11:47 AM, Jordan Rose via swift-evolution < > swift-evolution@swift.org> wrote:

I'm in favor, certainly. I'd personally say this wouldn't even need to go
through the full evolution process, but I'm not a core team member.

Jordan

On May 10, 2017, at 01:32, rintaro ishizaki via swift-evolution < > swift-evolution@swift.org> wrote:

Hi evolution community,

This proposal allows you to enclose switch cases with #if directive.
Implementation: https://github.com/apple/swift/pull/9457
This is one of the oldest SR issue:
https://bugs.swift.org/browse/SR-2
https://bugs.swift.org/browse/SR-4196

Thanks!
Rintaro

_______________________________________________
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


(John McCall) #9

I also strongly agree.

I can think of no strong argument against this, was this intentional at one point or a compiler bug?

The language design of #if is more complex than it is in C: it is part of the language grammar, not a separate phase of pre-processing, and must be specifically supported in every position it appears.

That said, I agree with Chris and Jordan that supporting #if in any simple, sequential position in the grammar is an obvious extension of the existing design and can reasonably be fast-tracked.

Grammatically similar positions where it's hard to dispute the consistency argument for #if: get-set clauses, precedencegroup declarations.

A position which would definitely be more useful to prioritize but where both the language design and the implementation are trickier: attribute lists.

John.

···

On May 11, 2017, at 1:45 AM, Nicholas Maccharoli via swift-evolution <swift-evolution@swift.org> wrote:

- Nick

On Thu, May 11, 2017 at 2:37 PM, Chris Lattner via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
I agree with Jordan.

-Chris

On May 10, 2017, at 11:47 AM, Jordan Rose via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

I'm in favor, certainly. I'd personally say this wouldn't even need to go through the full evolution process, but I'm not a core team member.

Jordan

On May 10, 2017, at 01:32, rintaro ishizaki via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Hi evolution community,

This proposal allows you to enclose switch cases with #if directive.
Implementation: https://github.com/apple/swift/pull/9457
This is one of the oldest SR issue:
https://bugs.swift.org/browse/SR-2
https://bugs.swift.org/browse/SR-4196

Thanks!
Rintaro

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

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto: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


#10

Thank you all!

I also strongly agree.

I can think of no strong argument against this, was this intentional at
one point or a compiler bug?

The language design of #if is more complex than it is in C: it is part of
the language grammar, not a separate phase of pre-processing, and must be
specifically supported in every position it appears.

That said, I agree with Chris and Jordan that supporting #if in any
simple, sequential position in the grammar is an obvious extension of the
existing design and can reasonably be fast-tracked.

So, can I withdraw my proposal PR on swift-evolution repository now?

Grammatically similar positions where it's hard to dispute the consistency
argument for #if: get-set clauses, precedencegroup declarations.

A position which would definitely be more useful to prioritize but where
both the language design and the implementation are trickier: attribute
lists.

John.

···

2017-05-11 16:18 GMT+09:00 John McCall via swift-evolution < swift-evolution@swift.org>:

On May 11, 2017, at 1:45 AM, Nicholas Maccharoli via swift-evolution < > swift-evolution@swift.org> wrote:

- Nick

On Thu, May 11, 2017 at 2:37 PM, Chris Lattner via swift-evolution < > swift-evolution@swift.org> wrote:

I agree with Jordan.

-Chris

On May 10, 2017, at 11:47 AM, Jordan Rose via swift-evolution < >> swift-evolution@swift.org> wrote:

I'm in favor, certainly. I'd personally say this wouldn't even need to go
through the full evolution process, but I'm not a core team member.

Jordan

On May 10, 2017, at 01:32, rintaro ishizaki via swift-evolution < >> swift-evolution@swift.org> wrote:

Hi evolution community,

This proposal allows you to enclose switch cases with #if directive.
Implementation: https://github.com/apple/swift/pull/9457
This is one of the oldest SR issue:
https://bugs.swift.org/browse/SR-2
https://bugs.swift.org/browse/SR-4196

Thanks!
Rintaro

_______________________________________________
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

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


(Jon Shier) #11

Just wanted to add that I ran into the #if limitations when trying to port Alamofire to Linux, so any enhancements would be most welcome. There was a point where I had to duplicate an entire class because I couldn't use #if for just the parts I needed.

Jon

···

On May 11, 2017, at 11:57 AM, rintaro ishizaki via swift-evolution <swift-evolution@swift.org> wrote:

Thank you all!

2017-05-11 16:18 GMT+09:00 John McCall via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>>:

On May 11, 2017, at 1:45 AM, Nicholas Maccharoli via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
I also strongly agree.

I can think of no strong argument against this, was this intentional at one point or a compiler bug?

The language design of #if is more complex than it is in C: it is part of the language grammar, not a separate phase of pre-processing, and must be specifically supported in every position it appears.

That said, I agree with Chris and Jordan that supporting #if in any simple, sequential position in the grammar is an obvious extension of the existing design and can reasonably be fast-tracked.

So, can I withdraw my proposal PR on swift-evolution repository now?

Grammatically similar positions where it's hard to dispute the consistency argument for #if: get-set clauses, precedencegroup declarations.

A position which would definitely be more useful to prioritize but where both the language design and the implementation are trickier: attribute lists.

John.

- Nick

On Thu, May 11, 2017 at 2:37 PM, Chris Lattner via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
I agree with Jordan.

-Chris

On May 10, 2017, at 11:47 AM, Jordan Rose via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

I'm in favor, certainly. I'd personally say this wouldn't even need to go through the full evolution process, but I'm not a core team member.

Jordan

On May 10, 2017, at 01:32, rintaro ishizaki via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Hi evolution community,

This proposal allows you to enclose switch cases with #if directive.
Implementation: https://github.com/apple/swift/pull/9457
This is one of the oldest SR issue:
https://bugs.swift.org/browse/SR-2
https://bugs.swift.org/browse/SR-4196

Thanks!
Rintaro

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

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

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

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

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