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

SameQ[] and Expression module tweaks #1079

Merged
merged 5 commits into from
Aug 31, 2024
Merged

SameQ[] and Expression module tweaks #1079

merged 5 commits into from
Aug 31, 2024

Conversation

rocky
Copy link
Member

@rocky rocky commented Aug 31, 2024

@mmatera looked the code over and do not find anything wrong with it.

I made some small changes to the docstring comment and addressed some of the lint errors my editor is telling me about.

We can't use generators here since there we access and then "rewind" sometimes. And this is essentially a version without the tail recursions. So I've removed the comments concerning doubt.

If you have the example that caused the failure on 3.12 without this change, it would be interesting to benchmark just this test inside a Mathics3 session to see if there's any difference in execution time.

Other comments I'll put in the specific code changes in this PR.

rocky added 3 commits August 31, 2024 08:52
Docstring comment tweak on expression_sameQ, and uncertainty comments of implementation.

Some linting was done on expression module.

Mathics -> Mathics3 more places.
"""
# TODO: Consider a faster implementation.
Copy link
Member Author

Choose a reason for hiding this comment

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

It is not clear to me this is not fast enough. What is done here is equivalent to tail recursion elimination.

Actually, on my home machine I've never ran into the recursion limit problem. I guess I have more memory. The reason Python 3.12 put compiler/OS limitation to recursion was no doubt some sort of security thing. People aren't going to know (or care about) what is being referred to with "the issue".

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, comparing the time the tests takes in GithubActions, it seems that this is faster than the recursive implementation.

# causes Boxing to mess up. Untangle this mess.
if expr._cache is None:
return None

Copy link
Member Author

Choose a reason for hiding this comment

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

My linter is telling me correctly that expr can be uninitialized, and indeed it is the loop iterator variable in the preceding "for" loop. Testing that after the loop ends is weird. Removing this doesn't cause any test failure.

@rocky rocky requested a review from mmatera August 31, 2024 14:15
@rocky rocky changed the title Sameq tweaks SameQ[] tweaks Aug 31, 2024
@rocky rocky changed the title SameQ[] tweaks SameQ[] and Expression module tweaks Aug 31, 2024
Copy link
Contributor

@mmatera mmatera left a comment

Choose a reason for hiding this comment

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

LGTM

@rocky rocky merged commit 48ff686 into sameQ_nonrecursive Aug 31, 2024
8 checks passed
@rocky rocky deleted the sameq-tweaks branch August 31, 2024 17:17
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