Emit SIL per module into build products?

Hi, I would like to dump all the symbols and methods type-resolved with source module. SIL looks promising.

However the -emit-sil -o File option can only specify one output file, as the error below

error: cannot specify -o when generating multiple output files

and I would like to dump the SIL into build products per module. How can I do that?

If you're just interested in the symbols that make up the module's API, have you looked at -emit-api-descriptor? That might be more easily consumable than SIL.

The 6.1 compiler will also have a -dump-ast-format json feature that would provide this information (and much more) by dumping the entire AST in a parsable format.

Thank you very much for your pointers.
Unfortunately neither fulfills my need - I want to see for a source file, all the symbols it references (including types and functions) and which module they come from, not only its public-facing apis. In fact, I can get to know the public api by -emit-swift-interface as well.

-dump-ast-format does not resolve the type. If module Foo and Bar both have a doSomething() method, I couldn't possibly know which module's method this AST references.

Maybe -index-store-path could be the solution. Combined with index store parsers like below, I may be able to query all the symbol references and where they come from.

The JSON format does resolve the type for references like this. The type will be represented as a USR, which is just the mangling of the type which includes the fully qualified name (among other information).

Until that lands in a production compiler, indexstore might also be a viable approach, though not as complete as the full AST.

1 Like

Possibly silly question: how do I dump ast for a whole target/project?

swift build -Xswiftc -dump-ast

produces

<unknown>:0: error: this mode does not support emitting dependency files