Repository navigation
$IterationLimit: count the current chain of rewrites, not every lookup - #2000
Open
tombouctou wants to merge 2 commits into
Open
tombouctou wants to merge 2 commits into
tombouctou wants to merge 2 commits into
Conversation
Symbol.evaluate incremented evaluation.iteration_count on each ownvalue
rewrite and never decremented it, so the count was a total over the
whole evaluation. Any long computation that merely looked up symbols
with values 4096 times failed:
x = {a}; Do[x, {5000}]; x (* $IterationLimit::itlim *)
Give the step back once the lookup is done, so that the count is the
length of the current chain x -> y -> ..., which is what
$IterationLimit bounds. Endless chains such as yin := yang;
yang := yin are still stopped.
Fixes Mathics3#1993.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
LGTM |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1993.
Since #1477,
Symbol.evaluateadds 1 toevaluation.iteration_counteach time it rewrites a symbol by an ownvalue. It never subtracts it again, and the count is only reset at the start of a top-level evaluation. So the count is the total number of symbol lookups in the whole evaluation, not the length of one chain of rewrites. Any long computation that just looks up a variable 4096 times is aborted:WMA returns
{a}here. Its$IterationLimitreference page describes the limit as "the maximum length of evaluation chain used in trying to evaluate any expression". In practice, loading a package of a few thousand definitions withGetfails partway through.This PR gives the step back when the lookup finishes, using
try/finally. The count is then the depth of the current chainx -> y -> ..., which is what$IterationLimitshould bound. Endless chains are still stopped. The doctestBlock[{$IterationLimit = 20}, yin := yang; yang := yin; yin]and the tests added in #1477 pass unchanged.New tests in
test/builtin/test_evaluation.py:$IterationLimit = 20give the value. This test fails on master.pytest and the doctests give the same results as on master (the only failures are environmental ones, XML/ZIP/JPEG
FileFormatand the CLI tests).🤖 Generated with Claude Code