ExplicitImports.jl icon indicating copy to clipboard operation
ExplicitImports.jl copied to clipboard

WIP: track where explicit imports come from

Open ericphanson opened this issue 4 months ago • 1 comments

currently, we only track the names being explicitly imported. That is generally sufficient, since within a module a global name only resolves to one thing, and we can figure out what that is via which.

However, not having this info available from parsing makes things like stale_explicit_exports somewhat non-specific, since we only know the name that is stale, not the import statement that is stale, and resolving the name via which isn't perfect since it will tell us the "source" module, not the specific module we are importing it from (that may re-export it).

Additionally, for the purposes of https://github.com/ericphanson/ExplicitImports.jl/issues/6 it helps to have which specific modules each name is being explicitly imported from, so that we can check whether or not the name is public in that module specifically. E.g. this can distinguish between "this name is public in it's source module, and is present in the namespace of the module you are explicitly importing it from, but it is not public in that module" vs "it is public from the module you are importing it from". (Basically the same non-specificity problem as in the previous paragraph).

TODO-

  • [ ] track the module path of where names are coming from
  • [ ] reconcile that against the module path of where in the code we are, to get a module path relative to the caller
  • [ ] resolve that path into an actual module object (via recursive getglobal)
  • [ ] call Base.ispublic on that on v1.11+ to figure out the name
  • [ ] warn on explicit imports of non-public names on v1.11+, thereby closing half of #6
  • [ ] decide if stale_explicit_exports should get some form of this information as well, or if show_location is sufficient.

some of this might make more sense in followup PRs.

ericphanson avatar Mar 09 '24 13:03 ericphanson