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
[...]
end
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.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> module Foo
struct Int end
end
Foo
julia> parentmodule(Int)
Core
julia> parentmodule(Foo.Int)
Foo
[...]
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?
Ah, I see 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.