Skip to content
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

[SR-9420] Swift 5 produces error on passing closure generated by @autoclosure parameter to @autoclosure parameter #51884

Open
norio-nomura opened this issue Dec 6, 2018 · 9 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@norio-nomura
Copy link
Contributor

Previous ID SR-9420
Radar None
Original Reporter @norio-nomura
Type Bug
Environment

swift-5.0-DEVELOPMENT-SNAPSHOT-2018-12-04-a

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 0afa0fd517eaeea80cddf5bef958186a

Issue Description:

$ docker run --privileged -it --rm norionomura/swift:5020181204a swift
Welcome to Swift version 5.0-dev (LLVM 9a8bf9ce12, Clang eba26b8d1c, Swift b74d54a27c).
Type :help for assistance.
  1> func takeAutoclosure(_ closure: @autoclosure () -> String) { 
  2.     takeAutoclosure(closure) 
  3. }
error: repl.swift:2:21: error: function produces expected type 'String'; did you mean to call it with '()'?
    takeAutoclosure(closure)
                    ^~~~~~~
                           ()

Is this the intended behavior?

@norio-nomura
Copy link
Contributor Author

@rintaro taught me that it was the behavior that was intentionally introduced in #20152.

@rintaro
Copy link
Mannequin

rintaro mannequin commented Dec 6, 2018

#20693 improves the diagnostics.

@belkadan
Copy link
Contributor

belkadan commented Dec 6, 2018

Yes, this is correct behavior. The syntax with parentheses will work on previous versions of Swift as well.

@eeckstein, @xedin, do we already have a bug making sure the performance is the same?

@xedin
Copy link
Member

xedin commented Dec 6, 2018

@belkadan I'm not sure, but at least I didn't add any myself, will look into that.

@xedin
Copy link
Member

xedin commented Dec 6, 2018

@eeckstein Looked a the benchmarks some and I'm not really sure how to make it so performance of two different calls is compared. What do you think the best approach here would be?

@eeckstein
Copy link
Member

Do we even expect a change in the generated code? This sound to me like a lit test would be better than a benchmark

@xedin
Copy link
Member

xedin commented Dec 6, 2018

I have checked-in multiple test-cases already including some into test/Compatibility, the difference I think is that call is going to be wrapped into an implicit closure where before it would just be a function conversion on SIL level. John and Slava agree that such forwarding isn't something which is supposed to be correct.

@eeckstein
Copy link
Member

Actually, what I meant with lit test is a test which compiles with -O (and maybe also -Osize) and checks if the generated SIL (or llvm IR) code is what we expect.
For small, isolated code patterns, where we expect the optimizer to remove almost everything, this is a better approach than a benchmark.
For example: https://github.com/apple/swift/blob/master/test/SILOptimizer/character_literals.swift or https://github.com/apple/swift/blob/master/test/SILOptimizer/unused_containers.swift

@xedin
Copy link
Member

xedin commented Dec 6, 2018

Ah interesting, I'll take a look, thank you Erik!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

4 participants