Skip to content

Implement the simplified pattern selection algorithm in the spec (#898) #1080

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

catamorphism
Copy link
Collaborator

Implement Mark Davis's suggested pattern selection algorithm in the spec. Update the "resolved values" example to use the match() and compare() methods instead of selectKeys().
Rewrite the numeric and :string selector specs accordingly.

@catamorphism catamorphism force-pushed the alternative-selection branch 6 times, most recently from 64da247 to a166fef Compare June 10, 2025 22:39
…code-org#898)

Implement Mark Davis's suggested pattern selection algorithm in the spec.
Update the "resolved values" example to use the `match()` and
`compare()` methods instead of `selectKeys()`.
Rewrite the numeric and `:string` selector specs accordingly.
@catamorphism catamorphism force-pushed the alternative-selection branch from a166fef to eff3bac Compare June 10, 2025 22:42
@catamorphism catamorphism marked this pull request as ready for review June 10, 2025 22:45
@catamorphism catamorphism requested review from aphillips, eemeli, macchiati and mihnita and removed request for aphillips June 10, 2025 22:45
Copy link
Member

@macchiati macchiati left a comment

Choose a reason for hiding this comment

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

I gave this preliminary review, and it's looking good.

Comment on lines +587 to +588
The selection method is defined in terms of two auxiliary operations,
`selectorsMatch` and `selectorsCompare`. These operations in turn assume
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's not change multiple things at the same time, so please keep abstract method references in the same style as MatchSelectorKeys previously, and follow semantic line breaks.

and `rv.compare(k1, k2)` returns (for any keys `k1` and `k2`)
a value from the set `{WORSE, SAME, BETTER}`.

Other than the `match()` and `compare()` operations on resolved values,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are rv.match(k) and match() referring to the same thing, or to different things? I presume they're meant to be the same, and if so, the name should not vary.

Comment on lines +609 to +610
1. Let `nomatch` be a _resolved value_ for which `match(k)` is false
for any key `k`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the third time the match method is referenced in the text, and it's the third different way of referring to it.

in their first element have the same relative order in `sorted`).
Next, using `res`:

1. Set `bestVariant` to `UNSET`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is bestVariant? Please include a "Let" statement when first introducing a variable.

1. Set `bestVariant` to `var`.
1. Else:
1. Let `bestVariantKeys` be the keys of `bestVariant`.
1. If `selectorsCompare(res, keys, bestVariantKeys)` is `BETTER`
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we only care whether the result of this comparison is BETTER or not, why do we differentiate SAME and WORSE?

I previously asked about this in #898 (comment).

1. Else:
1. Return `result`.

The result of `selectorsCompare(selectors, keys1, keys2)` is `result`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not true, given the early returns around catch-all keys.

1. Else:
1. Return `result`.

The result of `selectorsCompare(selectors, keys1, keys2)` is `result`.

#### Pattern Selection Examples
Copy link
Collaborator

Choose a reason for hiding this comment

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

These non-normative examples are getting verbose enough that we ought to move them to an annex rather than having them interrupt the prose here.

Comment on lines +693 to +694
1. ASSERT: `resolvedSelector.match(key1)`.
1. ASSERT: `resolvedSelector.match(key2)`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
1. ASSERT: `resolvedSelector.match(key1)`.
1. ASSERT: `resolvedSelector.match(key2)`.
1. Assert that `resolvedSelector.match(key1)` is true.
1. Assert that `resolvedSelector.match(key2)` is true.

Comment on lines +671 to +672
1. Let `k1` be the _resolved value_ of `key1` in Unicode Normalization Form C [\[UAX#15\]](https://www.unicode.org/reports/tr15).
1. Let `k2` be the _resolved value_ of `key2` in Unicode Normalization Form C [\[UAX#15\]](https://www.unicode.org/reports/tr15).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Defining these as resolved values does not match how they're presumed to be strings later on.

Comment on lines +63 to +64
1. ASSERT: `resolvedSelector.match(key1)`.
1. ASSERT: `resolvedSelector.match(key2)`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the role of these assertions when key1 and key2 are unused later on?

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