KEMBAR78
[mypyc] Allow specifying primitives as pure by JukkaL · Pull Request #17263 · python/mypy · GitHub
Skip to content

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented May 18, 2024

Pure primitives have no side effects, take only immutable arguments,
and never fail. These properties will enable additional
optimizations. For example, it doesn't matter in which order
these primitives are evaluated, and we can perform common
subexpression elimination on them.

Only mark a few primitives as pure for now, but we can generalize
this later.

JukkaL added 2 commits May 18, 2024 10:49
Pure primitives have no side effects, take only immutable arguments,
and never fail. These properties will enable additional
optimizations. For example, it doesn't matter in which order
these primitives are evaluated, and we can perform common
subexpression elimination on them.

Only mark a few primitivies as pure for now, but we can generalize
this later.
@JukkaL JukkaL merged commit ac8a5a7 into master May 19, 2024
@JukkaL JukkaL deleted the mypyc-pure-prim branch May 19, 2024 08:58
@dmadisetti
Copy link

Is there a timeline / roadmap for pure function detection? Or is this more exploratory?

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jun 4, 2024

This is specific to primitives, i.e. it isn't used for user-defined functions. Since there is a closed set of primitives, it wouldn't be hard to manually annotate all of them that are pure. There are no plans currently to automatically detect if user-defined functions are pure, if that's what you are interested in.

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.

3 participants