How to find an indirect dependency inside a module?

Say that I have a package Foo with direct and indirect dependencies A <- B <- C (i.e., A loads B and B loads C) and my package looks like

module Foo

using A



also say that I’m given a type T in C printed as C.T as a String.

What is now the easiest way to find C? Because if I do @show C, then I get a “C undefined” error. I can do @show A.B.C, but then I first need to find it

The reason that I ask this is because I’m experimenting a bit with the --trace-compile flag.

help> parentmodule

  parentmodule(t::DataType) -> Module

  Determine the module containing the definition of a (potentially
  UnionAll-wrapped) DataType.


  julia> module Foo
             struct Int end
  julia> parentmodule(Int)
  julia> parentmodule(Foo.Int)

1 Like

Close, but what if I have a String object and not a DataType?

Ah. Think that I got it via Base.loaded_modules

I’d first question why you only have that as a string and see if you can get the type directly instead, but otherwise parentmodule(eval(Meta.parse(...)))?

Getting a proper type object first is of course preferrable - though your example with @show C implies that you want to already have some kind of reference to a type in the first place, right?

1 Like

That looks like an internal variable to me - I’d look through the Pkg API for querying what dependencies the current active project has instead.

1 Like

Yeah true. My example wasn’t the clearest. I didn’t have a ref yet.

Because that is the output of julia --trace-compile=traces.jl [...].

Check. I’ll try that

Ah, I see :thinking: Sadly, that part lives in C (check src/gf.c:2013, the function is called record_precompile_statement and it’s called during compilation), so getting a type out there is difficult… Then I don’t think there’s a way around eval(Meta.parse(...)).

I do wish the compiler would expose some sort of diagnostics interface, for interacting with these sorts of things programmatically. Other kinds of diagnostics I’d be interested in would be getting a log of inlining/vectorization/etc. decisions and the reasoning why something was (not) done, without having to reparse emitted LLVM IR.

1 Like