How to get information about symbol scoping in Julia while compilation?

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.

  1. Is there a built-in way in Julia to get information about symbol scoping during compilation?
  2. Are there any flags or compiler options that can be used to generate this information as output?
  3. If not, are there any recommended approaches or tools for analyzing symbol scope within the Julia compiler pipeline?
  4. 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:

  1. Parsing, implemented in JuliaSyntax.jl and src/julia-parser.scm
  2. Lowering, currently implemented in src/julia-syntax.scm
  3. Type inference
  4. 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.


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
(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