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

[red-knot] Refactor KnownFunction::takes_expression_arguments() #15406

Merged
merged 2 commits into from
Jan 10, 2025

Conversation

AlexWaygood
Copy link
Member

Summary

Refactors the KnownFunction::takes_expression_arguments(). By introducing a custom type rather than passing around a u32 everywhere, we improve readability, the documentation of the code, and type safety, without introducing any allocation.

Test Plan

cargo test -p red_knot_python_semantic

@AlexWaygood AlexWaygood added the red-knot Multi-file analysis & type inference label Jan 10, 2025
Copy link
Contributor

github-actions bot commented Jan 10, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Nice. Using bitset! over a hand written bitset would probably have been an alternative solution.

/// Whether a specific parameter in the function expects a type expression can be queried
/// using [`ParameterExpectations::expectation_at_index`].
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
enum ParameterExpectations {
Copy link
Member

Choose a reason for hiding this comment

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

I don't really have a better suggestion but the name is somewhat vague. ParameterKindness? ParameterValueKind?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree it's not a great name but I can't think of anything better, and I'm not sure I love either of these 😆

@AlexWaygood
Copy link
Member Author

Nice. Using bitset! over a hand written bitset would probably have been an alternative solution.

Yeah -- I considered it, but ultimately concluded it wouldn't buy us much here, since there's only a limited number of special-cased functions anyway

@carljm
Copy link
Contributor

carljm commented Jan 10, 2025

Pretty sure this will use more memory than a bitset (I don't think Rust will pack a slice of one-bit enums into a bitset automatically?) but yeah, it shouldn't matter.

@MichaReiser
Copy link
Member

MichaReiser commented Jan 10, 2025

Pretty sure this will use more memory than a bitset (I don't think Rust will pack a slice of one-bit enums into a bitset automatically?) but yeah, it shouldn't matter.

Yeah, it should be 2 words but we never store the data structure anywhere so...

@AlexWaygood
Copy link
Member Author

AlexWaygood commented Jan 10, 2025

Pretty sure this will use more memory than a bitset (I don't think Rust will pack a slice of one-bit enums into a bitset automatically?) but yeah, it shouldn't matter.

I also agree that I don't think it matters, but if it makes you happier I've switched to a representation where it's now smaller than on main (1 byte instead of 4 :-)

@AlexWaygood AlexWaygood force-pushed the alex/takes-expr-arguments branch 2 times, most recently from 8dae19f to 860c523 Compare January 10, 2025 19:02
@AlexWaygood AlexWaygood force-pushed the alex/takes-expr-arguments branch from 860c523 to 656ef0c Compare January 10, 2025 19:04
@AlexWaygood AlexWaygood enabled auto-merge (squash) January 10, 2025 19:05
@AlexWaygood AlexWaygood merged commit c82932e into main Jan 10, 2025
20 checks passed
@AlexWaygood AlexWaygood deleted the alex/takes-expr-arguments branch January 10, 2025 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants