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 
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 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`? 

I know that AST is (somewhat intentionally) poorly documented, but some 
guidelines would be very helpful. 



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] 
> <javascript:>> 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.
>
>

Reply via email to