-
Notifications
You must be signed in to change notification settings - Fork 364
[swiftsrc2cpg] Proper closure call handling #5685
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
base: master
Are you sure you want to change the base?
Conversation
| |import Foundation | ||
| | | ||
| |func main() { | ||
| | // closure call is allways "function_ref": "single_apply" | ||
| | | ||
| | let compare = { (s1: String, s2: String) -> Bool in | ||
| | return s1 > s2 | ||
| | } | ||
| | let compareResult = compare("1", "2") | ||
| | | ||
| | var customersInLine = ["Chris", "Alex", "Ewa", "Barry", "Daniella"] | ||
| | // auto-closure example 1: | ||
| | let customerProvider = { customersInLine.remove(at: 0) } | ||
| | let customerProviderResult = customerProvider() | ||
| | | ||
| | // auto-closure example 2: | ||
| | let greet = { | ||
| | print("Hello, World!") | ||
| | } | ||
| | greet() | ||
| | | ||
| | let greetUser = { (name: String) in | ||
| | print("Hey there, \(name).") | ||
| | } | ||
| | greetUser("Alex") | ||
| | | ||
| | let findSquare = { (num: Int) -> (Int) in | ||
| | let square = num * num | ||
| | return square | ||
| | } | ||
| | let findSquareResult = findSquare(5) | ||
| |}""".stripMargin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split up the different examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not do that on purpose because every Swift compilation for such a snippet (+ its boilerplate project code) takes ~30 seconds on my Windows system. We test 5 closures here so that means 5 times 30 seconds which does not help when running the tests. On Mac and Linux it is no issue at all (~5 seconds).
|
|
||
| // compare ((Swift.String,Swift.String)->Swift.Bool) | ||
| val List(compareLocal) = cpg.local.nameExact("compare").l | ||
| compareLocal.typeFullName shouldBe "Swift.Function" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot just use a generic Swift.Function as type as this would conflate more functions into a single hierarchy then necessary, resulting in higher computational effort during e.g. call resolution. So we should use separate types for all the different function signatures. Same goes for all other places where Swift.Function is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did the same thing as javasrc2cpg did where everything is java.util.function.Function.
Should I change it to incorparate the signature for differentations, e.g., here in this example Swift.Function:(Swift.String,Swift.String)->Swift.Bool?
No description provided.