Skip to content

[AST/Sema] Associate @autoclosure flag with parameter declaration #20152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Nov 10, 2018

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Oct 30, 2018

These changes aim to:

  • Move @autoclosure flag from function type to parameter declaration
    • Serialize @autoclosure as part of the parameter declaration
    • Convert it from being a type attribute to be declaration attribute
    • Remove it from AnyFunctionType::ExtInfo
  • Cleanup logic in constraint solver associated with @autoclosure handling
    and clarify overloading behavior
  • Add more tests

Resolves: rdar://problem/30906031

@xedin xedin requested a review from DougGregor October 30, 2018 07:12
@xedin xedin force-pushed the add-autoclosure-flag-to-param-decl branch 3 times, most recently from 6034e41 to 642caa5 Compare November 1, 2018 23:43
@xedin xedin changed the title [WIP][AST/Sema] Associate @autoclosure flag with parameter declaration [AST/Sema] Associate @autoclosure flag with parameter declaration Nov 2, 2018
@xedin
Copy link
Contributor Author

xedin commented Nov 2, 2018

The way I wanted to change parser didn't work out so I think this is really for review, because I can add some more tests to test/Compatibility separately too

@xedin
Copy link
Contributor Author

xedin commented Nov 2, 2018

@swift-ci please clean test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@xedin
Copy link
Contributor Author

xedin commented Nov 2, 2018

@swift-ci please test source compatibility

@xedin xedin force-pushed the add-autoclosure-flag-to-param-decl branch from b2c2666 to d6fc3cf Compare November 5, 2018 06:28
@xedin
Copy link
Contributor Author

xedin commented Nov 5, 2018

@swift-ci please test

@swiftlang swiftlang deleted a comment from swift-ci Nov 5, 2018
@swiftlang swiftlang deleted a comment from swift-ci Nov 5, 2018
@xedin
Copy link
Contributor Author

xedin commented Nov 5, 2018

@swift-ci please test Linux platform

@xedin
Copy link
Contributor Author

xedin commented Nov 5, 2018

@swift-ci please test macOS platform

@xedin xedin requested a review from rudkx November 5, 2018 18:20
Copy link
Contributor

@rudkx rudkx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! It's a pretty big change and could probably use another pair of eyes, though!

@xedin xedin force-pushed the add-autoclosure-flag-to-param-decl branch from e4c2288 to fa306b1 Compare November 5, 2018 23:07
@xedin
Copy link
Contributor Author

xedin commented Nov 5, 2018

@swift-ci please test

@swiftlang swiftlang deleted a comment from swift-ci Nov 6, 2018
@swiftlang swiftlang deleted a comment from swift-ci Nov 6, 2018
@xedin
Copy link
Contributor Author

xedin commented Nov 6, 2018

@swift-ci please test

@swiftlang swiftlang deleted a comment from swift-ci Nov 6, 2018
@swift-ci
Copy link
Contributor

swift-ci commented Nov 6, 2018

Build failed
Swift Test Linux Platform
Git Sha - fa306b1c16f0c5d077c13b494e10f444c7bee94d

@xedin xedin force-pushed the add-autoclosure-flag-to-param-decl branch from a31137d to 9a4b6ba Compare November 7, 2018 02:52
@xedin
Copy link
Contributor Author

xedin commented Nov 7, 2018

If there are no other problems, I'll soon make changes to XCTest calls which pass @autoclosure functions types from one call to another, and that would be the end of this PR :)

@xedin
Copy link
Contributor Author

xedin commented Nov 7, 2018

/cc @moiseev XCTest overlay was doing a lot of @autoclosure <-> @autoclosure conversions which I fixed by calling expression* and message explicitly. Could you please take a look?

@jrose-apple
Copy link
Contributor

cc @stmontgomery too (about XCTest)

@@ -146,17 +146,17 @@ public func XCTAssertNil(_ expression: @autoclosure () throws -> Any?, _ message
if !passed {
// TODO: @auto_string expression

_XCTRegisterFailure(true, _XCTFailureDescription(assertionType, 0, expressionValueStr as NSString), message, file, line)
_XCTRegisterFailure(true, _XCTFailureDescription(assertionType, 0, expressionValueStr as NSString), message(), file, line)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to remove @autoclosure from the message: parameter of the _XCTRegisterFailure helper function, now? Are there any remaining use cases for that to be @autoclosure?

/cc @briancroom

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that _XCTRegisterFailure unconditionally evaluates the message parameter, I doubt there's any need for it to actually be an autoclosure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you guys want me to make that change or would you handle it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW: XCTest as well as the majority of other overlays is built in Swift 4 mode, and so this change is not strictly required. Thanks @xedin for fixing it anyways. LGTM, removing an autoclosure completely also works, and can probably be done separately.

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 4c8ca4913e7978091239d0790ebc6d22e7f22043

xedin added 17 commits November 10, 2018 11:58
It should become a declaration attribute instead,
but it can't be done at the moment because `@autoclosure`
is a type attribute.
`typeCheckParameterDefault` is used to type-check default value
expression associated with a given parameter. It makes it possible
to look-through `@autoclosure` function to use its result as
contextual type, and later build implicit autoclosure expression
if needed.
Make sure that presence of `@autoclosure` attribute handled
in one place - `matchCallArguments`, which makes it possible
to remove the rest of (now redundant) autoclosure related
logic scattered throughout solver.
There is one place which handles `@autoclosure` attribute
associated with parameters - `matchCallArguments`.
…arameter flags

There is only one place where we need to do that - `typeCheckArgumentChildIndependently`
Mangled implicit closures shouldn't have `@autoclosure` flag
associated with them, because their type is just a regular
function type.
…ity mode

Swift versions < 5 allowed argument passed to @autoclosure parameter
to be @autoclosure function type, we need to make sure that such
behavior is preserved.
… < 5

Since it was allowed to pass function types to @autoclosure
parameters in Swift versions < 5, it has to be handled as
a regular function coversion by `coerceToType`.
@xedin xedin force-pushed the add-autoclosure-flag-to-param-decl branch from c106e54 to 7bd2688 Compare November 10, 2018 20:00
@xedin
Copy link
Contributor Author

xedin commented Nov 10, 2018

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Nov 10, 2018

@swift-ci please test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - c106e54a464289920fac761af0885b1d357a5cac

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - c106e54a464289920fac761af0885b1d357a5cac

@xedin
Copy link
Contributor Author

xedin commented Nov 10, 2018

Source compat failure with Tagged is unrelated, merging.

@xedin xedin merged commit 2ad754d into swiftlang:master Nov 10, 2018
@xedin
Copy link
Contributor Author

xedin commented Nov 11, 2018

Looks like with all these rebases I've lost commit with added tests Slava requested me to add, going to add them in follow-up commit...

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.

9 participants