Skip to content

Commit ae487d3

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Add agent guidance on handling JIT errors
Summary: Agents are still very eager to use `JIT_CHECK` and `JIT_ABORT`. I'd like to start pushing them towards raising C++ exceptions instead, which we can recover from. Reviewed By: yoney Differential Revision: D117412143 fbshipit-source-id: 368e4f730009668ecc2ba7e3245b8c2336c254fb
1 parent 3b07910 commit ae487d3

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

cinderx/AGENTS.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,27 @@ If the instruction needs to call a custom runtime helper function:
110110
- Declare it in **Jit/jit_rt.h**
111111
- Implement it in **Jit/jit_rt.cpp**
112112

113+
## Handling JIT compile-time errors
114+
115+
If an error is hit when JIT-compiling a Python function, the preference is to
116+
raise a C++ exception. This will unwind the stack and silently fail the compile,
117+
causing the Python function to return back to the interpreter as usual.
118+
119+
The `JIT_THROW` and `JIT_THROW_IF` macros make it easy to raise an exception
120+
that is tagged with the offending file and line number, to make debugging
121+
easier. These are the preferred tool for handling irrecoverable JIT-compilation
122+
errors.
123+
124+
The `JIT_ABORT` and `JIT_CHECK` macros are similar but will crash the entire
125+
process, which is usually undesirable. They should be used sparingly, and in
126+
very restricted scenarios where throwing a C++ exception does not make sense.
127+
128+
The `JIT_DCHECK` macro is intended for invariants that we'd like to enforce, but
129+
cannot do so in production builds because they lie in performance-sensitive code
130+
paths (e.g. the function vectorcall entry point that we install).
131+
113132
## Investigating JIT failures
133+
114134
If you're investigating a JIT issue you may want to isolate the issue to a
115135
single function. You can use `cinderx.jit.force_compile` to compile an
116136
individual function if you suspect that a specific function is problematic.

0 commit comments

Comments
 (0)