Skip to content

Swift: Control-flow for key paths #9373

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 2 commits into from
Jun 2, 2022
Merged

Conversation

MathiasVP
Copy link
Contributor

@MathiasVP MathiasVP commented May 30, 2022

In Swift one can define a kind of "first-class getter" called a key path expression. For example:

struct B {
  var x : Int
}

struct A {
  var bs : [B]
}

func giveMeTheFirstInt(a : A) -> Int {
  return a[keyPath: \A.bs[0].x]
}

As I understand it, the semantics of a[keyPath: \A.bs[0].x] is roughly the same as (fun arg:A -> arg.bs[0].x)(a), and that's also how I think we'll end up modeling this in dataflow: Each key path expression generates a callable whose body generates a bunch of read steps.

This PR makes each key path expression a new Scope in the CFG (and a Callable in dataflow). As can be seen in the tests we're still missing CFG for the body of the key path expressions: Most of the enter #keyPath(...) CFG nodes flows directly to a TBD (UnresolvedDotExpr).

@MathiasVP MathiasVP requested a review from a team as a code owner May 30, 2022 16:18
@github-actions github-actions bot added the Swift label May 30, 2022
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Swift
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants