Skip to content

Improvements to static-show #239

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

Draft
wants to merge 3 commits into
base: v1.10.2+RAI
Choose a base branch
from
Draft

Conversation

kpamnany
Copy link
Collaborator

@kpamnany kpamnany commented May 23, 2025

PR Description

The first commit backports JuliaLang#52799.

  • Show strings with escaping, rather than trying to output the text unmodified.
  • Show symbols with the same formatting as Strings
  • Avoid accidentally defining a broken Core.show method for NamedTuple

The next four commits backport JuliaLang#58512.

Makes more types survive jl_static_show:

Symbols
    Symbols printed in the :var"foo" form use raw string escaping, fixing :var"a\b", :var"a\\", :var"$a", etc.
    Symbols that require parens use parens (:(=), ...)
Signed integers: Except for Int, signed integers print like Int8(1).
Floats: floats are printed in a naive but reversible (TODO: double check) way. Inf(16|32|) and NaN(16|32|) are printed, and Float16/Float32 print the type (Float32(1.5)). Float64s are printed with a trailing .0 if it is necessary to disambiguate from Int.

Checklist

Requirements for merging:

- Show strings with escaping, rather than trying to output the text
unmodified.
- Show symbols with the same formatting as Strings
- Avoid accidentally defining a broken Core.show method for NamedTuple
xal-0 and others added 2 commits May 29, 2025 17:33
Makes more types survive `jl_static_show` unambiguously:
- Symbols
- Symbols printed in the `:var"foo"` form use raw string escaping,
fixing `:var"a\b"`, `:var"a\\"`, `:var"$a"`, etc.
  - Symbols that require parens use parens (`:(=)`, ...)
- Signed integers: Except for `Int`, signed integers print like
`Int8(1)`.
- Floats: floats are printed in a naive but reversible (TODO: double
check) way. `Inf(16|32|)` and `NaN(16|32|)` are printed, and
`Float16`/`Float32` print the type (`Float32(1.5)`). `Float64`s are
printed with a trailing `.0` if it is necessary to disambiguate from
`Int`.

Fixes JuliaLang#52677,
JuliaLang#58484 (comment),
JuliaLang#58484 (comment),
and the specific case mentioned in JuliaLang#58484. Improves the situation for
round-trip (inexhaustive list):
- Non-canonical NaNs
- BFloat16
- User-defined primitive types. This one is tricky, because they can
have a size different from any type we have literals for.
`julia_half_to_float` came in with an LLVM version upgrade after
v1.10.
@kpamnany kpamnany force-pushed the kp-backport-58512 branch from 43fcdd9 to 3caf825 Compare May 29, 2025 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants