Skip to content

Compile code with debug symbols instead of interpreting it - #2174

Merged
slozier merged 1 commit into
IronLanguages:mainfrom
BCSharp:debug-compile
Nov 22, 2026
Merged

slozier merged 1 commit into
IronLanguages:mainfrom
BCSharp:debug-compile

Conversation

@BCSharp

@BCSharp BCSharp commented Nov 22, 2026

Copy link
Copy Markdown
Member

With -X Debug, module code, and the functions and classes compiled with it, ran in the System.Linq.Expressions interpreter instead of being compiled.

RuntimeScriptCode and PythonScriptCode call lambda.Compile(pc.EmitDebugSymbols(...)). The intended target is the DLR extension method CompilerHelpers.Compile<T>(this Expression<T>, bool emitDebugSymbols). On .NET and .NET Standard 2.0, however, Expression<T> has an instance method Compile(bool preferInterpretation), and C# picks it over the extension, so true meant "interpret". The three call sites now call CompilerHelpers.Compile as a static method. .NET Framework was not affected, because its Expression<T> has no Compile(bool). I guess this fell between the cracks when IronPython was ported to .NET Core. Not a big deal, since the whole -X Debug was meant primarily for Visual Studio (my guess), and now it is kind of defunct, but the code should still work here. Getting the whole -X Debug to work is another issue.

test_debug_compile.py checks that module code, a function and a class body have no interpreter frames on the .NET stack. There is one test per call site:

  • the main script with -X Debug (RuntimeScriptCode)
  • the main script with -X Debug -X Tracing (PythonScriptCode, tracing target)
  • a file run in a new scope of an engine in debug mode (PythonScriptCode)

@slozier slozier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Good catch, might be worth obsoleting our overload and adding one called CompileWithDebugSymbols (or something).

@slozier
slozier merged commit b2aade6 into IronLanguages:main Nov 22, 2026
39 of 41 checks passed
@BCSharp
BCSharp deleted the debug-compile branch November 22, 2026 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants