Skip to content

CS: Handle unbound references to @objc optional methods #41849

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 11 commits into from
Mar 31, 2022

Conversation

AnthonyLatsis
Copy link
Collaborator

@AnthonyLatsis AnthonyLatsis commented Mar 17, 2022

Mostly a cleanup and refactoring so that the target change fits nicely. The dynamic lookup case needs more work.

Resolves rdar://69761566

@objc protocol P {
  @objc optional func f()
}

let x: (P) -> (() -> Void)? = P.f

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test macOS

@slavapestov
Copy link
Contributor

CC @beccadax

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test macOS

@hborla
Copy link
Member

hborla commented Mar 17, 2022

Awesome, I've been wanting to get rid of buildPropertyWrapperFnThunk by generalizing the thunk-building code in CSApply for a long time! I'll try to take a look tomorrow 🙂

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test macOS

@AnthonyLatsis AnthonyLatsis force-pushed the dyn_unbound_ref branch 3 times, most recently from a19f4dd to f2d84c2 Compare March 18, 2022 17:35
@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test macOS

Copy link
Member

@hborla hborla left a comment

Choose a reason for hiding this comment

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

The property wrapper changes look great, thank you!


newCalleeParams.push_back(calleeParam.withType(paramRef->getType()));

// FIXME: inout/vararg?
Copy link
Member

Choose a reason for hiding this comment

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

inout wrapped parameters were intentionally left out of SE-0293: https://github.com/apple/swift-evolution/blob/main/proposals/0293-extend-property-wrappers-to-function-and-closure-parameters.md#support-inout-in-wrapped-function-parameters

Good point about variadics, presumably this should work and it doesn't today

@propertyWrapper struct Wrapper {
  var wrappedValue: [Int]
}

func test(@Wrapper value: Int...) {
  print(value)
}

let f = test(value:)
f(1, 2, 3) // error: extra arguments in call

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see, will mark inout as a TODO: then! Was it supposed to be an error to have an inout wrapped parameter?

Good point about variadics, presumably this should work and it doesn't today

Interesting, I was expecting @Wrapper value: Int... to mean [Wrapper<Int>] rather than Wrapper<[Int]>.

Copy link
Member

Choose a reason for hiding this comment

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

I think a variadic wrapped parameter would have to mean the wrapped value is an array type because of the restriction that the parameter to init(wrappedValue:) must either exactly match the wrappedValue type or be an autoclosure returning the wrappedValue type.

Was it supposed to be an error to have an inout wrapped parameter?

Oops, yeah I think that should be an error at the declaration. Hopefully no code is actually using an inout wrapped parameter, because the synthesized accessors inside the body don't actually let you mutate the parameter anyway. I also suspect the compiler will crash in the case where the wrapper has init(projectedValue:)

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I misread your comment about variadics as Wrapper<Int>, I understand what you're saying now. Interesting! My brain definitely interpreted @Wrapper value: Int... as a single wrapper.

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@AnthonyLatsis AnthonyLatsis requested a review from xedin March 26, 2022 15:39
@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please test source compatibility

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

Is it worth adding an executable test as well, since there are so many moving parts here?

@AnthonyLatsis
Copy link
Collaborator Author

AnthonyLatsis commented Mar 30, 2022

Is it worth adding an executable test as well, since there are so many moving parts here?

Just for optional methods, or function references in general?

UPD: Added some executable tests for optional methods.

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please test source compatibility

@AnthonyLatsis
Copy link
Collaborator Author

@slavapestov Must've been tiring to even skim through all of this, thank you!

@AnthonyLatsis AnthonyLatsis merged commit 4c2e88b into swiftlang:main Mar 31, 2022
@AnthonyLatsis AnthonyLatsis deleted the dyn_unbound_ref branch March 31, 2022 01:01
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this pull request Apr 21, 2022
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this pull request Apr 21, 2022
swift-ci added a commit that referenced this pull request Apr 22, 2022
AnthonyLatsis added a commit that referenced this pull request Apr 25, 2022
…okup-unbound-ref

🍒 [5.7] Add CHANGELOG entry for #41849 and #42332
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.

3 participants