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

[BinaryPlatforms] Change "shortest match" algorithm to "best match" #49502

Merged
merged 1 commit into from
Apr 25, 2023

Conversation

staticfloat
Copy link
Member

My assertion in the previous attempt to fix this issue was incorrect:

We define a simpler match as one that has fewer tags overall.
As these candidate matches have already been filtered to match the
given platform, the only other tags that exist are ones that are in
addition to the tags declared by the platform. Hence, selecting the
minimum in number of tags is equivalent to selecting the closest match.

This is demonstrably false, by my own test case:

platforms = Dict(
    Platform("x86_64", "linux") => "bad",
    Platform("x86_64", "linux"; sanitize="memory") => "good",
)
select_platform(platforms, Platform("x86_64", "linux"; sanitize="memory")) == "good"

In this case, because there exists a candidate that is more general than the provided platform type, the shortest match is no longer the best match.

This PR performs a more rigorous matching that works more reliably in all cases.

My assertion in the previous attempt to fix this issue was incorrect:

> We define a simpler match as one that has fewer tags overall.
> As these candidate matches have already been filtered to match the
> given platform, the only other tags that exist are ones that are in
> addition to the tags declared by the platform.  Hence, selecting the
> minimum in number of tags is equivalent to selecting the closest match.

This is demonstrably false, by my own test case:

```
platforms = Dict(
    Platform("x86_64", "linux") => "bad",
    Platform("x86_64", "linux"; sanitize="memory") => "good",
)
select_platform(platforms, Platform("x86_64", "linux"; sanitize="memory")) == "good"
```

In this case, because there exists a candidate that is _more general_
than the provided platform type, the shortest match is no longer the
best match.

This PR performs a more rigorous matching that works more reliably in
all cases.
@staticfloat staticfloat added the backport 1.9 Change should be backported to release-1.9 label Apr 25, 2023
@staticfloat
Copy link
Member Author

This fixes #49491

@staticfloat
Copy link
Member Author

@StefanKarpinski I'm totally open to the idea of using natural sort here; but such a sort function needs to be available pretty early on in the bootstrap process; do we have one?

@@ -330,8 +330,7 @@ end
# Ambiguity test
@test select_platform(platforms, P("aarch64", "linux")) == "linux3"
@test select_platform(platforms, P("aarch64", "linux"; libgfortran_version=v"3")) == "linux3"
# This one may be surprising, but we still match `linux3`, and since linux3 is shorter, we choose it.
@test select_platform(platforms, P("aarch64", "linux"; libgfortran_version=v"3", libstdcxx_version=v"3.4.18")) === "linux3"
@test select_platform(platforms, P("aarch64", "linux"; libgfortran_version=v"3", libstdcxx_version=v"3.4.18")) === "linux5"
Copy link
Member Author

Choose a reason for hiding this comment

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

As an aside, this "surprise" should have been my hint that my previous implementation was incorrect.

@staticfloat staticfloat mentioned this pull request Apr 25, 2023
1 task
@giordano giordano linked an issue Apr 25, 2023 that may be closed by this pull request
@giordano
Copy link
Contributor

I think this looks better now, thanks!

@staticfloat staticfloat merged commit 7fc3e35 into master Apr 25, 2023
@staticfloat staticfloat deleted the sf/fix_artifacts branch April 25, 2023 22:20
@KristofferC KristofferC mentioned this pull request May 8, 2023
51 tasks
@KristofferC KristofferC removed the backport 1.9 Change should be backported to release-1.9 label May 8, 2023
@KristofferC
Copy link
Member

Removing backport since original PR causing this was reverted on 1.9.

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.

Base.BinaryPlatforms.select_platform broken on master and 1.9
3 participants