Skip to content

Conversation

@havogt
Copy link
Contributor

@havogt havogt commented Feb 6, 2026

Sort closure variables for deterministic results. The effect was FunctionDefinitions were in non-deterministic order in itir.Program.

This problem only surfaced on beverin.

Sort closure variables for deterministic results.

Problem only surfaced on beverin.
@havogt havogt requested a review from tehrengruber February 6, 2026 13:45
Copy link
Contributor

@tehrengruber tehrengruber left a comment

Choose a reason for hiding this comment

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

Good to go if you agree with my suggestion.

return {**builtins, **globals, **nonlocals} # nonlocals override globals

# nonlocals override globals, sorted for deterministic results
return dict(sorted({**builtins, **globals, **nonlocals}.items()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return dict(sorted({**builtins, **globals, **nonlocals}.items()))
return dict(sorted({**builtins, **globals, **nonlocals}.items(), key=lambda v: v[0]))

Otherwise it's also doing __lte__ on the values right? I'm surprised this works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it doesn't compare the second element of the tuple (values) unless the first (keys) are equal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So not sure if my version is considered canonical @egparedes

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah and since they are unique it only considers the first one. I'd still use the key for clarity, but both fine with me.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think @havogt is the standard one, since we are sure that all keys are different.

@havogt havogt merged commit bf0d467 into main Feb 6, 2026
23 checks passed
@havogt havogt deleted the fix_indeterministic_get_closure_vars branch February 6, 2026 14:50
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