swiftlang / swift-syntax

A set of Swift libraries for parsing, inspecting, generating, and transforming Swift source code.
Apache License 2.0
3.13k stars 393 forks source link

Add dependsOn(immortal) #2674

Closed meg-gupta closed 1 month ago

meg-gupta commented 1 month ago

Used in cases where a nonescapable value must be constructed without any owner that can stand in as the source of a dependence. See https://gist.github.com/atrick/9ed708431e9a18059c22d37d18759c6d for details

Fixes rdar://129183196

meg-gupta commented 1 month ago

Please test with following pull request: https://github.com/apple/swift/pull/74195 @swift-ci test

meg-gupta commented 1 month ago

@ahoppen We represent self separately from identifier as well - https://github.com/apple/swift-syntax/blob/1f220251532b12bdff8e574c012a9aea5b85b38d/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift#L520 I thought we want to represent nodes in the swift-syntax AST separately when possible so that this information can be reconstructed if needed later.

ahoppen commented 1 month ago

We only needed to represent self specifically because it’s an unconditional keyword. But immortal isn’t a special keyword, so that’s fine.

I do have a question on the language design though. If I have

func foo(immortal: Int) -> dependsOn(immortal) X

Does this mean that the result depend on the parameter named immortal or is it this custom syntax? If it is your new syntax, how can I make the result depend on the immortal parameter?

atrick commented 1 month ago

Does this mean that the result depend on the parameter named immortal or is it this custom syntax? If it is your new syntax, how can I make the result depend on the immortal parameter?

That needs to be a syntax error: conflict between the parameter name and keyword. We should point that out in the proposal.

meg-gupta commented 1 month ago

@ahoppen I'll close this PR and raise error for the scenario you brought up in Sema.