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

More consistent return value for annotations #53281

Merged

Conversation

tecosaur
Copy link
Contributor

This is a generally nice simplification, that tweaks the annotations API.

It also requires the adjustment in
JuliaLang/StyledStrings.jl#38 to be made, hence the
bump.

There are two different kinds of return value that annotations may
currently produce.
1. A vector of annotations (Pair{Symbol, Any})
2. A vector of region-annotation tuples (Tuple{UnitRange{Int},
   Pair{Symbol, Any}})

Currently, there is an excess of argument-return-type combinations:
1. (string) -> vector of region-annotation tuples
2. (substring, region) -> vector of annotation values
3. (string, region/index) -> vector of annotation values
4. (char) -> vector of annotation values

While wanting to get the annotations of a substring, it became apparent
that it behaved differently to fetching the annotations of an
AnnotatedString{String}. This is undesirable. Upon further reflection,
the diversity of return types when calling annotations on a string-like
form is excessive, and behaviours 1-3 can be merged into a single
behaviour, resulting in a simpler set of combinations:

1. (string-like, region/index?) -> vector of region-annotation tuples
2. (char) -> vector of annotation values

I consider this simplification highly desirable.

Since this changes the API, the usage in StyledStrings is also updated
to match, and we bump the version of StyledStrings to get the new
version compatible with this revised API.
@tecosaur tecosaur added the domain:strings "Strings!" label Feb 11, 2024
@tecosaur
Copy link
Contributor Author

Changes included in the StyledStrings bump:

e0ca0f8 * Adjust to changed annotations function return form
7ce4e69 * More consistent legacy color conversion
26b5d2f * Fix invalid non-empty state assumptions in macro
0625bce * More predictible parsing with escape_raw_string
57619c2 * New faces for stacktrace printing in Base
0af21d0 * printstyled specialisation for AnnotatedIOBuffer

@vtjnash vtjnash merged commit e1a76bb into JuliaLang:master Feb 12, 2024
6 of 8 checks passed
@vtjnash
Copy link
Sponsor Member

vtjnash commented Feb 12, 2024

Just FYI, I lost your good commit message here because github now automatically replaces them with the text in the PR title. If you want to ensure that content is preserved, I recommend including it in the Github PR text.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Feb 12, 2024

It looks like Example.jl is hitting an abort signal on all CI with this commit included. Is it possible you put @inbounds in places that should not have them?

@tecosaur
Copy link
Contributor Author

I don't think so, and it's hard for me to see how this commit would affect anything with @inbounds (since this changes the form of the list returned, not the length of it).

@tecosaur tecosaur deleted the more-consistent-annotated-return-forms branch February 12, 2024 05:12
vtjnash added a commit that referenced this pull request Feb 13, 2024
@tecosaur
Copy link
Contributor Author

I have just noticed that the implementation of annotations(s::SubString{<:AnnotatedString}) will return invalid ranges, not sure if that could have something to do with it.

vtjnash added a commit that referenced this pull request Feb 13, 2024
Reverts #53281 as it appears to have broken CI on all
subsequent commits:
#53281 (comment)

According to the CI logs, it is this test that aborts early on in the
rr-trace log:
```
Pkg.test(TEST_PKG.name; coverage = coverage_path)
```
@vtjnash
Copy link
Sponsor Member

vtjnash commented Feb 13, 2024

Are there any @inbounds statements that could be deleted? I see some here, and it makes me suspicious that they shouldn't be present in this code almost anywhere as it is not vectorizable code.

@tecosaur
Copy link
Contributor Author

tecosaur commented Feb 13, 2024

Aha! I think I might have found it, with the SubString returning invalid annotation ranges, I've since found some code that may assume that substring ranges are valid: https://github.com/JuliaLang/StyledStrings.jl/blob/e0ca0f85412ea5cafabfeaaec4d62ca26c3959d2/src/regioniterator.jl#L13

I'm not sure how to test this theory though...

@vtjnash
Copy link
Sponsor Member

vtjnash commented Feb 13, 2024

If you push a new PR, the net tests will pass/fail based on whether that fixes it. If necessarily, you might just delete the @inbounds there to see if it errors, if you aren't sure about the fix for it yet.

@tecosaur
Copy link
Contributor Author

#53333 now exists (hey, that's a surprisingly memorable PR number), which should let us confirm (or disprove) my suspicion 🤞

vtjnash pushed a commit that referenced this pull request Feb 20, 2024
Relands #53281 with some fixes noticed, though not the original causes
of the failure.
KristofferC pushed a commit that referenced this pull request Feb 26, 2024
Relands #53281 with some fixes noticed, though not the original causes
of the failure.

(cherry picked from commit fbc766a)
tecosaur added a commit to tecosaur/julia that referenced this pull request Mar 4, 2024
Relands JuliaLang#53281 with some fixes noticed, though not the original causes
of the failure.
mkitti pushed a commit to mkitti/julia that referenced this pull request Mar 7, 2024
Relands JuliaLang#53281 with some fixes noticed, though not the original causes
of the failure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants