Printing declaration bodies via `swiftc -print-ast`?

Is there a way to invoke swiftc -print-ast in a way that prints function bodies? If not, how's the idea of adding a flag to enable that?

Motivation: I’d like to see what synthesized code (e.g. function builder code) looks like in printed form, not in the less readable swiftc -dump-ast s-expr form.

I believe PrintOptions in the compiler has all kinds of knobs for toggling printing behavior, including "print declaration bodies". Exposing these knobs as additional flags to swiftc -print-ast may take some design.

I don't know the answer to your first question but for the second question:

If not, how's the idea of adding a flag to enable that?

Yes, I think this would be useful if it's not already possible.

Small nitpick though: This should be a frontend flag (not a driver flag) because this is primarily for internal development.

1 Like

Cool! I may look into adding a "print declaration bodies" frontend flag sometime, after priorities. I'll update here.

AFAIK, we don't have Expr printer so far. Although .swiftinterface printer prints @inlinable function bodies, it just copies text from the source code.

Aha, thanks @rintaro. Expr printer seems like a requirement for the use cases I'm interested in (printing compiler-synthesized code).

I guess I can continue to use swiftc dump-ast.