There is not currently a way to see Swift source code for the result builder transform. I believe the closest output you can get today is the type-checked AST, but unfortunately mapping the AST back to source code isn't fully implemented in the compiler. Also note that the result builder transform can express some things that manually-written Swift code today cannot (control flow statements in result builders are effectively if/switch expressions whose results get assigned to synthesized local variables).
I think your best bet for now is the documentation in the SE-0298 proposal.
I figured this transform was don’t on the AST and doesn’t literally rewrite the source text, but I’m surprised the AST can’t be serialized back out as source, why is that? Is generating the AST a lossy process that can’t be fully reversed?
That’s a pretty good reference, thanks!
You can approximate this using an immediate evaluated closure, like:
let x: Int = {
if predicate {
return 123
else {
return 456
}
}()
The type-checked AST definitely has more information than source, but the compiler should be able to translate a type-checked AST back to source that type checks in the same way. I believe the main reason why the compiler only supports printing declarations today is because expression printing hasn't been fully implemented yet in the ASTPrinter. The only place where the compiler needs to print expressions today is in inlinable code in Swift interfaces, and it's simply printed as written in source.
Please excuse the maybe-dumb question, but what more information could the AST possibly have than the source—is "the source" not the sole input to the compiler for producing the AST?
I think she meant that the AST contains more explicitly stated information than the source, which is readily available for querying.
Not to get too epistemological, but the compiler can only do deductive reasoning: drawing conclusions from premises (your source, and the definition of the language that's encoded into its implementation). No "net new" information is obtained in that process, it's merely surfacing things that were true all along.