On Mon, Aug 8, 2016 at 7:14 AM, Andrei Zh <[email protected]> wrote:
> Then maybe the whole approach is incorrect, so let me describe what I try > to achieve. > > The general idea is to extract AST of a function and do some > Without knowing more higher level information, if this is what you want to do then > transformations on it. To do so, I use `Base.uncompressed_ast` (borrowed > from ReverseDiffSource.jl > <https://github.com/JuliaDiff/ReverseDiffSource.jl/blob/master/src/frdiff.jl#L48>), > iterate over it and > ^^ this is the right way to do it. > sometimes create new expressions using either `Expr(head, args...)` or > plain :(expr) notation. Somewhere in this chain I get both - > `GlobalRef(Module, func)` and `:(Module.func)`. > > 1. Should I use `Base.uncompressed_ast` for this task at all? > 2. What is a set of nodes that I should work with? E.g. should I try to > avoid `GlobalRef`? > It strongly depend on what you want to do and whether you care about what they represent. > > I know that AST is (somewhat intentionally) poorly documented, but some > guidelines would be very helpful. > The devdoc should have fairly complete description of what these nodes are. Note that the internal AST is currently, well, internal and might change very often. (we try to keep the surface AST relatively stable). > > > > On Monday, August 8, 2016 at 1:55:51 AM UTC+3, Yichao Yu wrote: >> >> >> >> On Mon, Aug 8, 2016 at 3:57 AM, Andrei Zh <[email protected]> wrote: >> >>> While parsing Julia expressions, I noticed that sometimes calls to >>> >> >> This shouldn't happen. >> >> >>> global functions resolve to `GloablRef` and sometimes to >>> >> >> and GlobalRef should only happen during lowering. >> >> >>> getfield(Module, func). Could somebody please clarify: >>> >>> 1. Why do we need both? >>> >> >> GlobalRef is essentially an optimization. It's more restricted and easier >> to interpret/codegen and is emitted by lowering/type inference when it is >> legal to do so. >> >> >>> 2. Is it safe to replace one by the other (assuming only modules and >>> functions are involved)? >>> >> >> Not always. There are certainly cases where a GlobalRef currently can't >> be used (method definition for example) I'm not sure if there's cases the >> other way around. >> >>
