Skip to content

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Jul 1, 2020

Introduce an experimental attribute and command-line flag to replace
the "backward" matching algorithm for unlabeled trailing closure
arguments with a simpler "forward" algorithm. In this new algorithm,
unlabeled trailing closure arguments match the next parameter in the
parameter list that can accept an unlabeled trailing closure.

The "can accept an unlabeled trailing closure" criteria looks at the
parameter itself. The parameter accepts an unlabeled trailing closure
if all of the following are true:

  • The parameter is not variadic
  • The parameter is not inout
  • The adjusted type of the parameter (defined below) is a function type

The adjusted type of the parameter is the parameter's type as
declared, after performing two adjustments:

  • If the parameter is an @autoclosure, use the result type of the
    parameter's declared (function) type, before performing the second
    adjustment.
  • Remove all outer "optional" types.

For example, the following function illustrates both adjustments to
determine that the parameter "body" accepts an unlabeled trailing
closure:

func doSomething(body: @autoclosure () -> (((Int) -> String)?))

This source-breaking change is accessible in one of two ways. The new attribute

@_trailingClosureMatching(.forward)

can be applied to a function, initializer, or subscript to enable the
new forward matching algorithm for direct calls to that function. This
allows specific APIs to opt in to forward matching while leaving all
other calls unaffected.

The command-line parameter -enable-experimental-trailing-closure-matching
enables forward matching as the default algorithm. It is most useful
for experimenting with the source-compatibility effects of forward
matching.

Specific APIs can also explicitly request to use the current, backward
matching algorithm to maintain their existing behavior even under the
new command-line parameter, by using the other form of the new
trailing closure matching attribute:

@_trailingClosureMatching(.backward)

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

If we're matching the trailing closure at the end but haven't seen any
mismatches yet, consider the trailing closure to be a mismatch.
This function probably needs to be rewritten in terms of
matchCallArguments(), because it is performing an incorrect
approximation of label matching that doesn't work for multiple
trailing closures.
Introduce an experimental attribute and command-line flag to replace
the "backward" matching algorithm for unlabeled trailing closure
arguments with a simpler "forward" algorithm. In this new algorithm,
unlabeled trailing closure arguments match the next parameter in the
parameter list that can accept an unlabeled trailing closure.

The "can accept an unlabeled trailing closure" criteria looks at the
parameter itself. The parameter accepts an unlabeled trailing closure
if all of the following are true:

* The parameter is not variadic
* The parameter is not 'inout'
* The adjusted type of the parameter (defined below) is a function type

The adjusted type of the parameter is the parameter's type as
declared, after performing two adjustments:

* If the parameter is an @autoclosure, use the result type of the
parameter's declared (function) type, before performing the second
adjustment.
* Remove all outer "optional" types.

For example, the following function illustrates both adjustments to
determine that the parameter "body" accepts an unlabeled trailing
closure:

    func doSomething(body: @autoclosure () -> (((Int) -> String)?))

This source-breaking change is accessible in one of two ways. The new attribute

    @_trailingClosureMatching(.forward)

can be applied to a function, initializer, or subscript to enable the
new forward matching algorithm for direct calls to that function. This
allows specific APIs to opt in to forward matching while leaving all
other calls unaffected.

The command-line parameter `-enable-experimental-trailing-closure-matching`
enables forward matching as the default algorithm. It is most useful
for experimenting with the source-compatibility effects of forward
matching.

Specific APIs can also explicitly request to use the current, backward
matching algorithm to maintain their existing behavior even under the
new command-line parameter, by using the other form of the new
trailing closure matching attribute:

    @_trailingClosureMatching(.backward)
@DougGregor DougGregor force-pushed the forward-trailing-closure-matching branch from b689423 to 32ae69f Compare July 2, 2020 20:59
@DougGregor
Copy link
Member Author

@swift-ci test source compatibility

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci test source compatibility

@DougGregor
Copy link
Member Author

We're missing a lot of data here because of the current SwiftPM issue. However, there are only 3 failures that are clearly attributable to this new rule:

  • ACHNBrowserUI and MovieSwift fail because SwiftUI.View.sheet(isPresented:onDismiss:content:) only works properly with the backward rule.
  • ModelAssistant has its own API that only works properly with the backward rule.

@DougGregor
Copy link
Member Author

@swift-ci build toolchain

@DougGregor
Copy link
Member Author

@swift-ci please build toolchain

@DougGregor DougGregor force-pushed the forward-trailing-closure-matching branch from 32ae69f to f0b8eb1 Compare July 3, 2020 17:35
@DougGregor
Copy link
Member Author

@swift-ci please build toolchain

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@DougGregor
Copy link
Member Author

@swift-ci please build toolchain

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Jul 3, 2020

Build failed
Swift Test OS X Platform
Git Sha - f0b8eb1

@DougGregor
Copy link
Member Author

@swift-ci please test platform macOS

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please test platform macOS

@swift-ci
Copy link
Contributor

swift-ci commented Jul 3, 2020

Linux Toolchain (Ubuntu 16.04)
Download Toolchain
Git Sha - f0b8eb1

Install command
tar zxf swift-PR-32644-371-ubuntu16.04.tar.gz
More info

@swift-ci
Copy link
Contributor

swift-ci commented Jul 3, 2020

macOS Toolchain
Download Toolchain
Git Sha - f0b8eb1

Install command
tar -zxf swift-PR-32644-540-osx.tar.gz --directory ~/

@DougGregor
Copy link
Member Author

@swift-ci please smoke test platform macOS

@DougGregor
Copy link
Member Author

Closing out this dead-end approach. See #32891 for the proposed way forward

@DougGregor DougGregor closed this Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants