Skip to content
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

Fix arg=str() default argument #6193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

da-woods
Copy link
Contributor

Fixes #6192.

The basic issue is that the argument is deduced to be dynamic default argument, and then at a late stage is optimized into an empty string literal.

This means that correct handling code for the literal is skipped because is has "is_dynamic" set, and the correct assignment code into the dynamic struct is skipped because it's a literal.

I think the solution is to make the code that writes into the dynamic struct more tolerant of literals.

Fixes cython#6192.

The basic issue is that the argument is deduced to be dynamic
default argument, and then at a late stage is optimized into
an empty string literal.

This means that correct handling code for the literal is skipped
because is has "is_dynamic" set, and the correct assignment code
into the dynamic struct is skipped because it's a literal.

I think the solution is to make the code that writes into the
dynamic struct more tolerant of literals.
Copy link
Contributor

@matusvalo matusvalo left a comment

Choose a reason for hiding this comment

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

LGTM

@scoder
Copy link
Contributor

scoder commented May 12, 2024

and then at a late stage is optimized into an empty string literal.

Isn't rather this the problem? Can we do this earlier somehow?

It seems strange to do "oops, we're doing the wrong thing here so let's do something else" kind of operations at code generation time.

@da-woods
Copy link
Contributor Author

and then at a late stage is optimized into an empty string literal.

Isn't rather this the problem? Can we do this earlier somehow?

It seems strange to do "oops, we're doing the wrong thing here so let's do something else" kind of operations at code generation time.

That implies that either no optimisations should be made after the AnalyseExpressions stage. Or that annotations should be decided on much later (which may be true... Annotations are a mess and probably do need a clean-up).

I don't think this PR is the most messy fix though. All it really does is just is_dynamic as the only decider about whether something should go into a struct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Possible regression in handling of default function arguments
3 participants