I’m interested in understanding how Julia determines the scope of each symbol during compilation. I’d like to get detailed information about the scope of every symbol instance in the code, ideally as output from the compilation process itself.
- Is there a built-in way in Julia to get information about symbol scoping during compilation?
- Are there any flags or compiler options that can be used to generate this information as output?
- If not, are there any recommended approaches or tools for analyzing symbol scope within the Julia compiler pipeline?
- Any insights or references on how the Julia compiler handles symbol resolution and scope determination would be greatly appreciated!
Here’s what I’ve tried:
- I searched the Julia documentation and online resources, but I couldn’t find any built-in features to achieve this.
1 Like
@caleb-allen asked a very similar question on Slack the other day. To surmise:
Scoping rules are defined here Scope of Variables · The Julia Language
Roughly the pipeline looks like:
- Parsing, implemented in JuliaSyntax.jl and
src/julia-parser.scm
- Lowering, currently implemented in
src/julia-syntax.scm
- Type inference
- Optimizations
So take a look at src/jlfrontend.scm
and in particular resolve-scoped
in src/julia-syntax.scm
I don’t think there are currently any tools to give you symbol scope information. The current infrastructure is based on transforming the AST to implement the scope rules.
3 Likes
I’m trying to test the Julia parser using the flisp
frontend in the Julia project. I followed the documentation and ran the following commands:
cd src
flisp/flisp
(load “jlfrontend.scm”)
(jl-parse-file “filename”)
;;Example: (jl-parse-file “test.jl”)
However, the last command returns #f
instead of parsing the file. The file <filename>
exists in the current directory (src) where jlfrontend.scm
is also present. I’m not sure why jl-parse-file
is failing.
@Akhil_Akkapelli have you considered using the JuliaSyntax.jl frontend to test the parser? It is now the default frontend and is simple to use.
I’m still exploring Julia’s scoping, but as @vchuravy mentioned, the scoping happens at lowering time (rather than parse time). I’d be very interested in any insights you gain, if you’re willing to share!
1 Like