Skip to content

Conversation

@tomasr8
Copy link
Member

@tomasr8tomasr8 commented Apr 23, 2025

CALL_STR_1 is equivalent to str(...).

Very similar to previous work on splitting up CALL_TYPE_1: #132419
This splits the instruction into a smaller instruction + 2 guards which can be optimized away. This also sets the return type to str.

Comment on lines 859 to 863
if (sym_matches_type(arg, &PyUnicode_Type)){
// e.g. str('foo') or str(foo) where foo is known to be a string
PyObject*value=sym_get_const(ctx, arg);
res=sym_new_const(ctx, value);
}
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This is an optimization that Brandt suggested. When in str(foo), foo is known to be a string, we can propagate it to the output. I also added a test for this case.

Copy link
Member

@brandtbucherbrandtbucher left a comment

Choose a reason for hiding this comment

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

Looks great! Just two suggestions:

@brandtbucherbrandtbucher merged commit 0a387b3 into python:mainApr 24, 2025
64 checks passed
@tomasr8tomasr8 deleted the jit-call-str-1 branch April 24, 2025 19:58
@tomasr8
Copy link
MemberAuthor

Thanks for the review!

Sign up for freeto 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

@tomasr8@brandtbucher