Skip to content

Conversation

max-leuthaeuser
Copy link
Contributor

No description provided.

@ml86 ml86 self-requested a review October 23, 2025 09:13
Comment on lines +15 to +46
|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
Copy link
Contributor

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.

Copy link
Contributor Author

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"
Copy link
Contributor

@ml86 ml86 Oct 23, 2025

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.

Copy link
Contributor Author

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?

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