Simple question about ParameterTypeFlags

Hello! I’m trying to test which ParameterTypeFlags flag combinations are valid. I wrote the following test case. Are the results “as expected”, or are some of the failures incorrect?

// RUN: %target-typecheck-verify-swift

//
// isVariadic is NOT compatible with any flag combinations
//
// expected-error@+1 {{@autoclosure must not be used on variadic parameters}}
func v_and_autoclosure(arg : @autoclosure ()->()...) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func v_and_escaping(arg : @escaping ()->()...) {}
// expected-error@+1 {{'inout' must not be used on variadic parameters}}
func v_and_inout(arg : inout Int...) {}
// expected-error@+1 {{'__shared' must not be used on variadic parameters}}
func v_and_shared(arg : __shared Int...) {}

//
// 'inout' is NOT compatible with remaining parameter flag combinations
//
// expected-error@+1 {{parameter must not have multiple '__owned', 'inout', '__shared', 'var', or 'let' specifiers}}
func inout_and_shared(arg : inout __shared Int) {}
// expected-error@+1 {{'inout' may only be used on parameters}}
func inout_and_escaping(arg : @escaping inout ()->()) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func escaping_and_inout(arg : inout @escaping ()->()) {}
// expected-error@+1 {{@autoclosure may only be used on parameters}}
func inout_and_autoclosure(arg : inout @autoclosure ()->()) {}
// expected-error@+1 {{'inout' may only be used on parameters}}
func autoclosure_and_inout(arg : @autoclosure inout ()->()) {}

//
// '__shared' is NOT compatible with remaining parameter flag combinations
//
// expected-error@+1 {{'__shared' may only be used on parameters}}
func autoclosure_and_shared(arg : @autoclosure __shared ()->()) {}
// expected-error@+1 {{@autoclosure may only be used on parameters}}
func shared_and_autoclosure(arg : __shared @autoclosure ()->()) {}
// expected-error@+1 {{'__shared' may only be used on parameters}}
func escaping_and_shared(arg : @escaping __shared ()->()) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func shared_and_escaping(arg : __shared @escaping ()->()) {}

//
// @autoclosure and @escaping are the only valid parameter flag combinations
//
func autoclosure_and_escaping(arg : @autoclosure @escaping ()->()) {}
func escaping_and_autoclosure(arg : @escaping @autoclosure ()->()) {}

I think perhaps __shared @escaping and __shared @autoclosure should be OK. You’re just passing the context as a +0 value instead of +1. Also __shared varargs make sense for the same reason. But it’s not important to get that working right now.

The others look OK.

Slava

···

On Dec 11, 2017, at 1:15 PM, David Zarzycki via swift-dev <swift-dev@swift.org> wrote:

Hello! I’m trying to test which ParameterTypeFlags flag combinations are valid. I wrote the following test case. Are the results “as expected”, or are some of the failures incorrect?

// RUN: %target-typecheck-verify-swift

//
// isVariadic is NOT compatible with any flag combinations
//
// expected-error@+1 {{@autoclosure must not be used on variadic parameters}}
func v_and_autoclosure(arg : @autoclosure ()->()...) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func v_and_escaping(arg : @escaping ()->()...) {}
// expected-error@+1 {{'inout' must not be used on variadic parameters}}
func v_and_inout(arg : inout Int...) {}
// expected-error@+1 {{'__shared' must not be used on variadic parameters}}
func v_and_shared(arg : __shared Int...) {}

//
// 'inout' is NOT compatible with remaining parameter flag combinations
//
// expected-error@+1 {{parameter must not have multiple '__owned', 'inout', '__shared', 'var', or 'let' specifiers}}
func inout_and_shared(arg : inout __shared Int) {}
// expected-error@+1 {{'inout' may only be used on parameters}}
func inout_and_escaping(arg : @escaping inout ()->()) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func escaping_and_inout(arg : inout @escaping ()->()) {}
// expected-error@+1 {{@autoclosure may only be used on parameters}}
func inout_and_autoclosure(arg : inout @autoclosure ()->()) {}
// expected-error@+1 {{'inout' may only be used on parameters}}
func autoclosure_and_inout(arg : @autoclosure inout ()->()) {}

//
// '__shared' is NOT compatible with remaining parameter flag combinations
//
// expected-error@+1 {{'__shared' may only be used on parameters}}
func autoclosure_and_shared(arg : @autoclosure __shared ()->()) {}
// expected-error@+1 {{@autoclosure may only be used on parameters}}
func shared_and_autoclosure(arg : __shared @autoclosure ()->()) {}
// expected-error@+1 {{'__shared' may only be used on parameters}}
func escaping_and_shared(arg : @escaping __shared ()->()) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func shared_and_escaping(arg : __shared @escaping ()->()) {}

//
// @autoclosure and @escaping are the only valid parameter flag combinations
//
func autoclosure_and_escaping(arg : @autoclosure @escaping ()->()) {}
func escaping_and_autoclosure(arg : @escaping @autoclosure ()->()) {}
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

Hi Slava,

Interesting. Did I make a mistake in my test then? Both __shared @escaping and __shared @autoclosure are failing below.

Dave

···

On Dec 11, 2017, at 16:58, Slava Pestov via swift-dev <swift-dev@swift.org> wrote:

I think perhaps __shared @escaping and __shared @autoclosure should be OK. You’re just passing the context as a +0 value instead of +1. Also __shared varargs make sense for the same reason. But it’s not important to get that working right now.

The others look OK.

Slava

On Dec 11, 2017, at 1:15 PM, David Zarzycki via swift-dev <swift-dev@swift.org> wrote:

Hello! I’m trying to test which ParameterTypeFlags flag combinations are valid. I wrote the following test case. Are the results “as expected”, or are some of the failures incorrect?

// RUN: %target-typecheck-verify-swift

//
// isVariadic is NOT compatible with any flag combinations
//
// expected-error@+1 {{@autoclosure must not be used on variadic parameters}}
func v_and_autoclosure(arg : @autoclosure ()->()...) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func v_and_escaping(arg : @escaping ()->()...) {}
// expected-error@+1 {{'inout' must not be used on variadic parameters}}
func v_and_inout(arg : inout Int...) {}
// expected-error@+1 {{'__shared' must not be used on variadic parameters}}
func v_and_shared(arg : __shared Int...) {}

//
// 'inout' is NOT compatible with remaining parameter flag combinations
//
// expected-error@+1 {{parameter must not have multiple '__owned', 'inout', '__shared', 'var', or 'let' specifiers}}
func inout_and_shared(arg : inout __shared Int) {}
// expected-error@+1 {{'inout' may only be used on parameters}}
func inout_and_escaping(arg : @escaping inout ()->()) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func escaping_and_inout(arg : inout @escaping ()->()) {}
// expected-error@+1 {{@autoclosure may only be used on parameters}}
func inout_and_autoclosure(arg : inout @autoclosure ()->()) {}
// expected-error@+1 {{'inout' may only be used on parameters}}
func autoclosure_and_inout(arg : @autoclosure inout ()->()) {}

//
// '__shared' is NOT compatible with remaining parameter flag combinations
//
// expected-error@+1 {{'__shared' may only be used on parameters}}
func autoclosure_and_shared(arg : @autoclosure __shared ()->()) {}
// expected-error@+1 {{@autoclosure may only be used on parameters}}
func shared_and_autoclosure(arg : __shared @autoclosure ()->()) {}
// expected-error@+1 {{'__shared' may only be used on parameters}}
func escaping_and_shared(arg : @escaping __shared ()->()) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func shared_and_escaping(arg : __shared @escaping ()->()) {}

//
// @autoclosure and @escaping are the only valid parameter flag combinations
//
func autoclosure_and_escaping(arg : @autoclosure @escaping ()->()) {}
func escaping_and_autoclosure(arg : @escaping @autoclosure ()->()) {}
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

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

Sorry, what I meant is that they make sense with our language model, but it’s not surprising that it doesn’t work today. In any case, __shared is not yet completely implemented or even designed, so it doesn’t matter.

Slava

···

On Dec 11, 2017, at 2:05 PM, David Zarzycki <dave@znu.io> wrote:

Hi Slava,

Interesting. Did I make a mistake in my test then? Both __shared @escaping and __shared @autoclosure are failing below.

Dave

On Dec 11, 2017, at 16:58, Slava Pestov via swift-dev <swift-dev@swift.org> wrote:

I think perhaps __shared @escaping and __shared @autoclosure should be OK. You’re just passing the context as a +0 value instead of +1. Also __shared varargs make sense for the same reason. But it’s not important to get that working right now.

The others look OK.

Slava

On Dec 11, 2017, at 1:15 PM, David Zarzycki via swift-dev <swift-dev@swift.org> wrote:

Hello! I’m trying to test which ParameterTypeFlags flag combinations are valid. I wrote the following test case. Are the results “as expected”, or are some of the failures incorrect?

// RUN: %target-typecheck-verify-swift

//
// isVariadic is NOT compatible with any flag combinations
//
// expected-error@+1 {{@autoclosure must not be used on variadic parameters}}
func v_and_autoclosure(arg : @autoclosure ()->()...) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func v_and_escaping(arg : @escaping ()->()...) {}
// expected-error@+1 {{'inout' must not be used on variadic parameters}}
func v_and_inout(arg : inout Int...) {}
// expected-error@+1 {{'__shared' must not be used on variadic parameters}}
func v_and_shared(arg : __shared Int...) {}

//
// 'inout' is NOT compatible with remaining parameter flag combinations
//
// expected-error@+1 {{parameter must not have multiple '__owned', 'inout', '__shared', 'var', or 'let' specifiers}}
func inout_and_shared(arg : inout __shared Int) {}
// expected-error@+1 {{'inout' may only be used on parameters}}
func inout_and_escaping(arg : @escaping inout ()->()) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func escaping_and_inout(arg : inout @escaping ()->()) {}
// expected-error@+1 {{@autoclosure may only be used on parameters}}
func inout_and_autoclosure(arg : inout @autoclosure ()->()) {}
// expected-error@+1 {{'inout' may only be used on parameters}}
func autoclosure_and_inout(arg : @autoclosure inout ()->()) {}

//
// '__shared' is NOT compatible with remaining parameter flag combinations
//
// expected-error@+1 {{'__shared' may only be used on parameters}}
func autoclosure_and_shared(arg : @autoclosure __shared ()->()) {}
// expected-error@+1 {{@autoclosure may only be used on parameters}}
func shared_and_autoclosure(arg : __shared @autoclosure ()->()) {}
// expected-error@+1 {{'__shared' may only be used on parameters}}
func escaping_and_shared(arg : @escaping __shared ()->()) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func shared_and_escaping(arg : __shared @escaping ()->()) {}

//
// @autoclosure and @escaping are the only valid parameter flag combinations
//
func autoclosure_and_escaping(arg : @autoclosure @escaping ()->()) {}
func escaping_and_autoclosure(arg : @escaping @autoclosure ()->()) {}
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

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

This is a tangent from the original question, but is __shared a planned feature? Or just experimental work?

Dave

···

On Dec 11, 2017, at 17:12, Slava Pestov <spestov@apple.com> wrote:

Sorry, what I meant is that they make sense with our language model, but it’s not surprising that it doesn’t work today. In any case, __shared is not yet completely implemented or even designed, so it doesn’t matter.

Slava

On Dec 11, 2017, at 2:05 PM, David Zarzycki <dave@znu.io> wrote:

Hi Slava,

Interesting. Did I make a mistake in my test then? Both __shared @escaping and __shared @autoclosure are failing below.

Dave

On Dec 11, 2017, at 16:58, Slava Pestov via swift-dev <swift-dev@swift.org> wrote:

I think perhaps __shared @escaping and __shared @autoclosure should be OK. You’re just passing the context as a +0 value instead of +1. Also __shared varargs make sense for the same reason. But it’s not important to get that working right now.

The others look OK.

Slava

On Dec 11, 2017, at 1:15 PM, David Zarzycki via swift-dev <swift-dev@swift.org> wrote:

Hello! I’m trying to test which ParameterTypeFlags flag combinations are valid. I wrote the following test case. Are the results “as expected”, or are some of the failures incorrect?

// RUN: %target-typecheck-verify-swift

//
// isVariadic is NOT compatible with any flag combinations
//
// expected-error@+1 {{@autoclosure must not be used on variadic parameters}}
func v_and_autoclosure(arg : @autoclosure ()->()...) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func v_and_escaping(arg : @escaping ()->()...) {}
// expected-error@+1 {{'inout' must not be used on variadic parameters}}
func v_and_inout(arg : inout Int...) {}
// expected-error@+1 {{'__shared' must not be used on variadic parameters}}
func v_and_shared(arg : __shared Int...) {}

//
// 'inout' is NOT compatible with remaining parameter flag combinations
//
// expected-error@+1 {{parameter must not have multiple '__owned', 'inout', '__shared', 'var', or 'let' specifiers}}
func inout_and_shared(arg : inout __shared Int) {}
// expected-error@+1 {{'inout' may only be used on parameters}}
func inout_and_escaping(arg : @escaping inout ()->()) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func escaping_and_inout(arg : inout @escaping ()->()) {}
// expected-error@+1 {{@autoclosure may only be used on parameters}}
func inout_and_autoclosure(arg : inout @autoclosure ()->()) {}
// expected-error@+1 {{'inout' may only be used on parameters}}
func autoclosure_and_inout(arg : @autoclosure inout ()->()) {}

//
// '__shared' is NOT compatible with remaining parameter flag combinations
//
// expected-error@+1 {{'__shared' may only be used on parameters}}
func autoclosure_and_shared(arg : @autoclosure __shared ()->()) {}
// expected-error@+1 {{@autoclosure may only be used on parameters}}
func shared_and_autoclosure(arg : __shared @autoclosure ()->()) {}
// expected-error@+1 {{'__shared' may only be used on parameters}}
func escaping_and_shared(arg : @escaping __shared ()->()) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func shared_and_escaping(arg : __shared @escaping ()->()) {}

//
// @autoclosure and @escaping are the only valid parameter flag combinations
//
func autoclosure_and_escaping(arg : @autoclosure @escaping ()->()) {}
func escaping_and_autoclosure(arg : @escaping @autoclosure ()->()) {}
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

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

It is one of the user-facing features from John McCall’s ownership manifesto.

Slava

···

On Dec 11, 2017, at 3:33 PM, David Zarzycki <dave@znu.io> wrote:

This is a tangent from the original question, but is __shared a planned feature? Or just experimental work?

Dave

On Dec 11, 2017, at 17:12, Slava Pestov <spestov@apple.com> wrote:

Sorry, what I meant is that they make sense with our language model, but it’s not surprising that it doesn’t work today. In any case, __shared is not yet completely implemented or even designed, so it doesn’t matter.

Slava

On Dec 11, 2017, at 2:05 PM, David Zarzycki <dave@znu.io> wrote:

Hi Slava,

Interesting. Did I make a mistake in my test then? Both __shared @escaping and __shared @autoclosure are failing below.

Dave

On Dec 11, 2017, at 16:58, Slava Pestov via swift-dev <swift-dev@swift.org> wrote:

I think perhaps __shared @escaping and __shared @autoclosure should be OK. You’re just passing the context as a +0 value instead of +1. Also __shared varargs make sense for the same reason. But it’s not important to get that working right now.

The others look OK.

Slava

On Dec 11, 2017, at 1:15 PM, David Zarzycki via swift-dev <swift-dev@swift.org> wrote:

Hello! I’m trying to test which ParameterTypeFlags flag combinations are valid. I wrote the following test case. Are the results “as expected”, or are some of the failures incorrect?

// RUN: %target-typecheck-verify-swift

//
// isVariadic is NOT compatible with any flag combinations
//
// expected-error@+1 {{@autoclosure must not be used on variadic parameters}}
func v_and_autoclosure(arg : @autoclosure ()->()...) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func v_and_escaping(arg : @escaping ()->()...) {}
// expected-error@+1 {{'inout' must not be used on variadic parameters}}
func v_and_inout(arg : inout Int...) {}
// expected-error@+1 {{'__shared' must not be used on variadic parameters}}
func v_and_shared(arg : __shared Int...) {}

//
// 'inout' is NOT compatible with remaining parameter flag combinations
//
// expected-error@+1 {{parameter must not have multiple '__owned', 'inout', '__shared', 'var', or 'let' specifiers}}
func inout_and_shared(arg : inout __shared Int) {}
// expected-error@+1 {{'inout' may only be used on parameters}}
func inout_and_escaping(arg : @escaping inout ()->()) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func escaping_and_inout(arg : inout @escaping ()->()) {}
// expected-error@+1 {{@autoclosure may only be used on parameters}}
func inout_and_autoclosure(arg : inout @autoclosure ()->()) {}
// expected-error@+1 {{'inout' may only be used on parameters}}
func autoclosure_and_inout(arg : @autoclosure inout ()->()) {}

//
// '__shared' is NOT compatible with remaining parameter flag combinations
//
// expected-error@+1 {{'__shared' may only be used on parameters}}
func autoclosure_and_shared(arg : @autoclosure __shared ()->()) {}
// expected-error@+1 {{@autoclosure may only be used on parameters}}
func shared_and_autoclosure(arg : __shared @autoclosure ()->()) {}
// expected-error@+1 {{'__shared' may only be used on parameters}}
func escaping_and_shared(arg : @escaping __shared ()->()) {}
// expected-error@+1 {{@escaping attribute may only be used in function parameter position}}
func shared_and_escaping(arg : __shared @escaping ()->()) {}

//
// @autoclosure and @escaping are the only valid parameter flag combinations
//
func autoclosure_and_escaping(arg : @autoclosure @escaping ()->()) {}
func escaping_and_autoclosure(arg : @escaping @autoclosure ()->()) {}
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

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