As swift 6.x starts to use different swiftmodule for TypeSystemSwiftTypeRefForExpression when constructing swift ast context, we are required to provide all our swiftmodules to linker with -add-ast-path . with --serialize-debugging-options on.
In this case, the product swiftmodule file will have many local absolute paths in the option_blocks & input_blocks
Currently we are using bazel as our build system, which means we cannot cache these swiftmodule.
I found there is already one swift-frontend command line option -prefix-serialized-debugging-options handling this case.
I think with this option we can map all frontend parameters related to bazel root andbox. We can recover them if needed from lldb side.
Unfortunately, it only handles SDK_NAME, XCC, SEARCH_PATH. The PLUGIN_SEARCH_OPTION related ones are untouched, which makes it not possible to make the swiftmodule cacheable.
And I just checked lldb source code, lldb only use the information in swiftmodule for ClangImporter, these PLUGIN_SEARCH_OPTIONs will not even be used.
Can we make the PLUGIN_SEARCH_OPTION also be mapped using the same way?
Thanks for bringing up the concern for swift binary module's cacheability. I think it makes sense to provide an option to prefix mapped the plugin search that goes into binary swift module, and extending -prefix-serialized-debugging-options to handle that seems reasonable.
On the other hand, LLDB does read the plugin search options from the swift binary module to set up its ASTContext so the expression evaluator can handle swift macros. We do need to teach LLDB to map the path back in order for debugging to work. There are various layers of path remapping in LLDB (e.g. target.source-map), and we need to teach LLDB to remap plugin search options when it creates swift ASTContext.
After all the changes, user can use the swift-frontend flag together with lldb options to achieve cacheable swift module and also not sacrificing debugging capability. Can you file an issue to keep track of the problem?
I saw you have been already working on it here. https://github.com/swiftlang/swift/pull/80474
Is it all the changes from module generating side? Just wondering why we only do the extra mapping for only PluginSearchOption::Kind::ResolvedPluginConfig but not for other PluginSearchOption enum.
Also I checked the lldb code when reconstructing swift ast context:
For ResolvedPluginConfig,LoadPluginExecutable and the 2nd part of ExternalPluginPath (an absolute path to a swift-plugin-server inside xcode set as xcode default), the paths are read directly while other option kinds ( LoadPluginLibrary/PluginPath) are mapped with swift-plugin-server-for-path lldb setting option.
Will it work as expected after making plugin paths in swiftmodule relative from compiler change you made?
I am not sure if I missed something, do you know if any following changes in lldb should be made ?
If I were you, I will not rely on my PR to handle Bazel. My patch is about the CAS based swift caching using explicit module build, and it cannot be used in Bazel without someone who can do a proper integration. Bazel, as it is right now, needs a different path remapping option in compiler.
However, I think both can utilize the same path remapping function in LLDB. I think you found the correct place for reading the option from module and there is a remap function in that scope and we can just use that to achieve what we need. @Adrian_Prantl is the expert here.