Compilation Options
Curry code runs the way Python code does: import it and it runs. Nothing on this page needs to be configured for that. The page is for the reader who wants to know what happens behind the import, how to choose between the interpreter, the just-in-time compiler and compilation ahead of time, what each platform supports and how to watch the choice at work.
Three ways to run a function
Every Curry function reaches the runtime as ICurry, the intermediate language of the compiler (The Curry Compilation Pipeline). The C++ runtime can run it in three ways, with the same scheduler, the same rewrite steps and the same answers:
- Interpreted
The runtime interprets a bytecode made from the ICurry when the module loads. Nothing is compiled and no compiler is needed. This is how a freshly written module starts.
- Compiled just in time
A tier of the runtime compiles interpreted functions to machine code while the program runs and swaps the compiled code in at a safepoint of the scheduler. Two backends do this: LLVM, through the Python package
llvmlite, compiles single functions in the process; the C++ backend writes the generated C++ of a module and compiles it with the C++ compiler (g++, clang++ or clang-cl on Windows) in a child process, then adopts the object. The C++ backend compiles the modules of the program; the modules of the Curry library run from the objects of the installation. A compile still running when the program ends is canceled, so a short program never waits for a compiler and leaves no object behind;sprite-make --sowrites one.LLVM keeps one native object per function in
M.jitbeside the module image. On the next import, only the index is read. Cached code links as its functions run, under bothinterpret:newandinterpret:all;jit:eagerresolves all cached functions at load. A miss follows the selected eager or hot tier.jit:offreads no JIT cache. A read-only product directory usesSPRITE_JIT_CACHEwhen set to a writable directory; otherwise compilation stays in memory.make stagefills the library cache when llvmlite is available;SPRITE_STAGE_JIT_CACHE=0skips that fill. Wheels exclude these machine-specific objects; a hot run fills the cache with the functions that become hot, while an eager run fills the whole module.- Compiled ahead of time
sprite-make --so M.currycompiles a module to a shared object beside its source andmake stagecompiles the Curry library into the installation. A current object loads underinterpret:newandinterpret:off, whatever the JIT settings say.curry.savewrites such an object, or a program around it, for use elsewhere (Using the API).
The default combines them: current objects load, everything else starts interpreted and the functions that run often are compiled behind the scenes. The front end runs once per change of a module and not at all when its products are current.
The flags
Three interpreter flags select the behavior. Set them for a process in
SPRITE_INTERPRETER_FLAGS or for a session with curry.reset
(Interpreter flags):
SPRITE_INTERPRETER_FLAGS=jit:off python -m curry Peano.curry
For a Python session:
>>> import curry
>>> curry.reset(jit='eager', jit_backend='llvm')
Flag |
Values |
Meaning |
|---|---|---|
|
|
|
|
|
|
|
|
|
With no backend available and jit_backend:auto, the process runs the
interpreter alone and says so once in its log, at INFO. The program still
runs; only its speed changes.
What is installed decides
The backends are optional. What you install selects them:
pip install --pre "curry[jit]"addsllvmliteand with it the LLVM backend, on every platform that has a wheel for it.A C++ compiler on the machine (g++, clang++ from Xcode or clang-cl of Visual Studio on Windows) adds the C++ compiler backend and compilation ahead of time. A source build records its compiler at
tools/cxx; a wheel usesCXXwhen set; otherwiseg++from PATH, or on Windows the clang-cl of Visual Studio, then a clang-cl on PATH.Neither is needed to run Curry code: Installing and Running Without a C++ Compiler describes an installation with the interpreter alone.
Platform |
Interpreter |
JIT: LLVM |
JIT: C++ |
Ahead of time |
|---|---|---|---|---|
Linux x86-64 |
yes |
yes |
yes |
yes |
Linux aarch64 |
yes |
yes |
yes |
yes |
macOS arm64 |
yes |
yes |
yes |
yes |
macOS x86-64 |
yes |
conda [1] |
yes |
yes |
Windows x64 |
yes |
yes |
yes [2] |
yes [2] |
Watching the choice
Two environment variables turn on the log of the package
(Environment Variables). At INFO the
package says what it decided for each module and for the process:
SPRITE_LOG_LEVEL=INFO python -m curry Peano.curry
The lines name the backend chosen and why: jit: backend llvm ... or
jit: no backend, interpreter only .... Each module reports how it loads:
module Peano: compiled object loaded ... or module Peano: interpreted
... with the reason. Hot compiles report their functions and time:
jit hot: compiled ... or cxx hot: module ... compiled ... swapped.
The log also records product-cache hits, misses and runs of the front end.
LLVM reports jit cache: module M, miss, stored N functions and
indexed N functions at the attach, and resolved M.f, T ms at the
first call of a cached function; resolved functions contribute to
swapped in --stats, the index alone contributes none. A failed
resolution logs once per function and restores its interpreter step.
SPRITE_LOG_FILE sends the records to a file instead; child processes
write to the same file with their process id.
Other variables serve the JIT itself: SPRITE_JIT_THRESHOLD sets the
number of calls that makes a function hot and SPRITE_JIT_DUMP names a
directory into which the LLVM backend writes the optimized IR and the
assembly of each batch.
From Python, curry.flags shows the interpreter flags of the session.