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

Replace UnstableIO with IOContext{IO} #3735

Merged
merged 7 commits into from
Apr 23, 2024

Conversation

mkitti
Copy link
Contributor

@mkitti mkitti commented Dec 17, 2023

While trying to send UnstableIO into Julia base, two suggestions arose:

  1. Use Base.inferencebarrier to prevent specialization:
    Fix Pkg.BinaryPlatforms invalidations by moving module to Base julia#52249 (comment)
  2. Use IOContext{IO} rather than introducing a new type:
    Fix Pkg.BinaryPlatforms invalidations by moving module to Base julia#52249 (comment)

Fix #3722 (IOContext has closewrite)
Addresses part of #3702 by removing UnstableIO and its associated invalidations.

_io = Base.inferencebarrier(io)
IOContext{IO}(
_io,
get(_io,:color,false) ? Base.ImmutableDict{Symbol,Any}(:color, true) : Base.ImmutableDict{Symbol,Any}()
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have another suggestion as how one might construct a IOContext{IO}?

julia> IOContext{IO}(stdout)
ERROR: MethodError: no method matching IOContext{IO}(::Base.TTY)

Closest candidates are:
  IOContext{IO_t}(::IO_t, ::Base.ImmutableDict{Symbol, Any}) where IO_t<:IO
   @ Base show.jl:291

Copy link
Member

Choose a reason for hiding this comment

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

Okay, I understand. You need to call the inner constructor and the default for the dict is what is given here:

https://github.com/JuliaLang/julia/blob/b57f8d168dc88be8570e1c9ff7cd352fc5e11c98/base/show.jl#L303

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An alternative is that I use Base.unwrapcontext instead of copying the code. I'm not sure if that complicates the inference barrier or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does cause compilation of get for the IO though.

src/Pkg.jl Outdated
struct UnstableIO <: IO
io::IO
# See discussion in https://github.com/JuliaLang/julia/pull/52249
const UnstableIO = IOContext{IO}
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed I think? Or is it used somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a few other references to UnstableIO in Pkg.jl. I could get rid of the alias as its uses. Is that what you mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed references to UnstableIO in 9d57162

@KristofferC
Copy link
Member

Looks like this has to be rebased to update for another use of UnstableIO (looking at the CI):

┌ Pkg
│  WARNING: could not import Pkg.UnstableIO into Operations
└  
     Testing Running tests...
ERROR: LoadError: UndefVarError: `UnstableIO` not defined in `Pkg.Operations`
Stacktrace:
  [1] subprocess_handler(cmd::Cmd, io::IOContext{IO}, error_msg::String)
    @ Pkg.Operations ~/work/Pkg.jl/Pkg.jl/src/Operations.jl:2223
  [2] (::Pkg.Operations.var"#138#143"{Pkg.Types.Context})()
    @ Pkg.Operations ~/work/Pkg.jl/Pkg.jl/src/Operations.jl:2129

@mkitti
Copy link
Contributor Author

mkitti commented Apr 15, 2024

I will take a look, thanks.

@mkitti
Copy link
Contributor Author

mkitti commented Apr 17, 2024

@KristofferC CI is now passing here.

@KristofferC KristofferC merged commit 195e17e into JuliaLang:master Apr 23, 2024
7 checks passed
@KristofferC
Copy link
Member

👍

KristofferC pushed a commit that referenced this pull request Apr 25, 2024
KristofferC pushed a commit that referenced this pull request May 9, 2024
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.

missing API method closewrite for Pkg.UnstableIO
2 participants