Skip to content

_loader: Use the sort algorithm from Python 3.12 for dependencies#1993

Merged
juergbi merged 3 commits intomasterfrom
juerg/sort
Feb 17, 2025
Merged

_loader: Use the sort algorithm from Python 3.12 for dependencies#1993
juergbi merged 3 commits intomasterfrom
juerg/sort

Conversation

@juergbi
Copy link
Contributor

@juergbi juergbi commented Feb 14, 2025

The comparison function used to sort dependencies does not impose a total ordering. This means that the order of the sorted list depends on the order of inputs and implementation details of the sort algorithm.

Python 3.13 changes the sort algorithm in a way that may affect the sorting of dependencies. This in turn affects the staging order and cache keys of elements.

This commit embeds the list sort algorithm from Python 3.12.9 in BuildStream and uses that to sort dependencies. This restores cache key compatibility across Python versions despite the flaw of the comparison function.

The comparison function is not modified at this point to prevent changes in staging order and cache keys on Python <= 3.12.

Fixes #1988.

@juergbi juergbi self-assigned this Feb 14, 2025
The comparison function used to sort dependencies does not impose a
total ordering. This means that the order of the sorted list depends on
the order of inputs and implementation details of the sort algorithm.

Python 3.13 changes the sort algorithm in a way that may affect the
sorting of dependencies. This in turn affects the staging order and
cache keys of elements.

This commit embeds the list sort algorithm from Python 3.12.9 in
BuildStream and uses that to sort dependencies. This restores cache key
compatibility across Python versions despite the flaw of the comparison
function.

The comparison function is not modified at this point to prevent changes
in staging order and cache keys on Python <= 3.12.

Fixes #1988.
@juergbi juergbi force-pushed the juerg/sort branch 2 times, most recently from b332c68 to efe4e9b Compare February 14, 2025 14:53
Add test elements that would result in a cache key difference between
Python 3.12 and Python 3.13 without the embedded sort algorithm.
Copy link
Contributor

@gtristan gtristan left a comment

Choose a reason for hiding this comment

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

Looks good to me !

@gtristan
Copy link
Contributor

Asides from landing this, we should keep an additional issue open about dependency ordering in bst files incorrectly affecting staging order and cache keys.

@juergbi
Copy link
Contributor Author

juergbi commented Feb 17, 2025

Asides from landing this, we should keep an additional issue open about dependency ordering in bst files incorrectly affecting staging order and cache keys.

I've opened #1995 to keep track of this.

@juergbi juergbi merged commit ba70052 into master Feb 17, 2025
17 checks passed
@juergbi juergbi deleted the juerg/sort branch February 17, 2025 11: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.

Cache key of element changes between Python 3.12 and 3.13

2 participants