-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ModuleTrace] Emit import graph to ease debugging import issues. #33980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[ModuleTrace] Emit import graph to ease debugging import issues. #33980
Conversation
It used to be a method because it used a cache in ABIDependencyEvaluator; however that cache has been removed.
When looking at a module being shadowed by a separate (cross-import) overlay: before: filter (potentially) = {ShadowedBySeparateOverlay} requiredFilter = {Private, ShadowedBySeparateOverlay} filter.contains(requiredFilter) = false // incorrect after: filter (potentially) = {ShadowedBySeparateOverlay} requiredFilter = {ShadowedBySeparateOverlay} filter.contains(requiredFilter) = true
This should make it easier to spot cycles in import graphs, as well as funky behavior involving both default/private imports + SPI imports.
@swift-ci please test |
Build failed |
Build failed |
else if (!separatelyImportedOverlays.lookup(desc.module.importedModule).empty()) | ||
requiredFilter |= ModuleDecl::ImportFilterKind::ShadowedBySeparateOverlay; | ||
else | ||
requiredFilter |= ModuleDecl::ImportFilterKind::Private; | ||
|
||
if (!separatelyImportedOverlays.lookup(desc.module.importedModule).empty()) | ||
requiredFilter |= ModuleDecl::ImportFilterKind::ShadowedBySeparateOverlay; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This "fix" is incorrect. The ShadowedBySeparateOverlay
filter is essentially a different axis altogether.
| @_exported | private | @_implementationOnly | @_spi
-------------+------------+---------+----------------------+------
Not shadowed | EN | PN | IN | SN
Shadowed | ES | PS | IS | SS
Ideally, we'd be passing in two OptionSet
s, not one IMO. If you pass in newFilter = {{@_exported}, {not shadowed}}
, you get EN. If you pass in newFilter = {{@_exported | private}, {shadowed}}
, you'd get ES and PS.
Today, if you pass in filter = {@_exported}
, you get EN whereas if you pass in filter = {shadowed}
, you get nothing. That's unnecessarily confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, @_spi
is a different axis, so the table in ^ is wrong.
Adds functionality to see an import graph describing the imports of different modules.
Here is an example for a module only importing
Combine
, which has a small dependency footprint.In practice, you'll likely have a much larger dependency footprint. For example, here's what you're dragging in if you import
MapKit
andSwiftUI
.There are still some non-determinism issues in the graphviz output, need to look at the printing code again more carefully.
Marking as a draft because there are some unresolved questions:
jq
but for GraphViz graphs), but unfortunately I don't think such a tool exists. It seems like it would be easy functionality to add though, maybe even within the scope of aStarterBug
.Current TODOs:
Answering potential questions:
Q: Why have redundancy in the colors and the "(S)"/"(C)"?
A: The colors make it easier to spot things for people who can distinguish orange/grey. If you cannot visually distinguish the colors, the additional "(S)" and "(C)" are helpful.
Q: Can you change the edges labels to use a different scheme/convention instead?
A: Yes, I'm happy to change those, so long as the new scheme shows both default + SPI when both imports are used along the same edge (leading to a compiler warning). Simply showing the attribute (@_exported/@_implementationOnly/@_spi), and hence not showing "Def" at all, doesn't have that property.