Skip to content

[mypyc] Add debug op (and builder helper) for printing str or Value #18552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 28, 2025

Conversation

svalentin
Copy link
Collaborator

It generates C code to print to stdout, but tries to preserve the error state and not affect the code it's added to.

Added test for it, but also tested this by adding
builder.debug_print(typ) in add_non_ext_class_attr_ann and it prints the class name.
It's also useful to use it like builder.debug_print("MARKER") and then to search in the generated C code for MARKER. For more complex debugging tasks, this is useful in finding your way around the generated C code and quickly looking at the interesting part.

I saw that there's already a misc op CPyDebug_Print. I haven't seen it used though. I think we can remove that one if this is proving useful.

It generates C code to print to stdout, but tries to preserve the error
state and not affect the code it's added to.

Added test for it, but also tested this by adding
`builder.debug_print(typ)` in `add_non_ext_class_attr_ann` and it prints
the class name.
It's also useful to use it like `builder.debug_print("MARKER")` and then
to search in the generated C code for MARKER. For more complex debugging
tasks, this is useful in finding your way around the generated C code
and quickly looking at the interesting part.

I saw that there's already a misc op `CPyDebug_Print`. I haven't seen it
used though. I think we can remove that one if this is proving useful.
@svalentin svalentin requested a review from JukkaL January 27, 2025 23:04
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks, looks good!

@JukkaL JukkaL merged commit c08719d into python:master Jan 28, 2025
12 checks passed
@svalentin svalentin deleted the debug-primitive branch January 28, 2025 13:31
x612skm pushed a commit to x612skm/mypy-dev that referenced this pull request Feb 24, 2025
…ython#18552)

It generates C code to print to stdout, but tries to preserve the error
state and not affect the code it's added to.

Added test for it, but also tested this by adding
`builder.debug_print(typ)` in `add_non_ext_class_attr_ann` and it prints
the class name.
It's also useful to use it like `builder.debug_print("MARKER")` and then
to search in the generated C code for MARKER. For more complex debugging
tasks, this is useful in finding your way around the generated C code
and quickly looking at the interesting part.

I saw that there's already a misc op `CPyDebug_Print`. I haven't seen it
used though. I think we can remove that one if this is proving useful.
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