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

Improve inference broadly throughout REPL #37081

Merged
merged 6 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ function pipe_reader end
function pipe_writer end

write(io::AbstractPipe, byte::UInt8) = write(pipe_writer(io)::IO, byte)
unsafe_write(io::AbstractPipe, p::Ptr{UInt8}, nb::UInt) = unsafe_write(pipe_writer(io)::IO, p, nb)
unsafe_write(io::AbstractPipe, p::Ptr{UInt8}, nb::UInt) = unsafe_write(pipe_writer(io)::IO, p, nb)::Union{Int,UInt}
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Methods for Union{Core.CoreSTDERR,Core.CoreSTDOUT} and Base.FileSystem.File return UInt, the rest (I think) return Int. Should we make them all one or the other?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Not to derail the main point too much, but for overall context:

julia> for (m, rt) in zip(methods(write, (IO, Any)), Base.return_types(write, (IO, Any)))
           println(m => rt)
       end
write(io::Union{Core.CoreSTDERR, Core.CoreSTDOUT}, x::UInt8) in Base at coreio.jl:26 => Int64
write(s::IO, x::Union{Float16, Float32, Float64, Int128, Int16, Int32, Int64, UInt128, UInt16, UInt32, UInt64}) in Base at io.jl:649 => Any
write(io::IO, s::Union{SubString{String}, String}) in Base at strings/io.jl:185 => Int64
write(io::IO, s::Base.CodeUnits) in Base at strings/basic.jl:744 => Int64
write(to::IO, p::Ptr) in Base at io.jl:654 => Any
write(io::IO, x::Enum{T}) where T<:Integer in Base.Enums at Enums.jl:21 => Any
write(s::IO, a::SubArray{T,N,var"#s68",I,L} where L where I where var"#s68"<:Array) where {T, N} in Base at io.jl:675 => Any
write(s::IO, z::Rational) in Base at rational.jl:94 => Int64
write(io::IO, s::AbstractString) in Base at strings/io.jl:181 => Int64
write(s::IO, a::Array) in Base at io.jl:667 => Any
write(s::IO, x::Ref{T}) where T in Base at io.jl:647 => Any
write(s::IO, z::Complex) in Base at complex.jl:220 => Int64
write(s::IO, B::BitArray) in Base at bitarray.jl:1823 => Any
write(s::IO, A::AbstractArray) in Base at io.jl:656 => Any
write(s::IO, x::Bool) in Base at io.jl:653 => Any
write(io::IO, s::Symbol) in Base at io.jl:708 => Any
write(io::IO, c::Char) in Base at io.jl:696 => Int64
write(io::IO, cred::LibGit2.GitCredential) in LibGit2 at /home/tim/src/julia-master/usr/share/julia/stdlib/v1.6/LibGit2/src/gitcredential.jl:94 => Nothing
write(io::IO, s::Base.SecretBuffer) in Base at secretbuffer.jl:126 => Any
write(s::IO, x::Int8) in Base at io.jl:648 => Any
write(io::Base.AbstractPipe, byte::UInt8) in Base at io.jl:360 => Any
write(to::Base.GenericIOBuffer, from::Base.GenericIOBuffer) in Base at iobuffer.jl:408 => Int64
write(to::IO, from::IO) in Base at io.jl:713 => Any
write(to::Base.GenericIOBuffer, a::UInt8) in Base at iobuffer.jl:445 => Int64
write(pipe::Base64.Base64EncodePipe, x::UInt8) in Base64 at /home/tim/src/julia-master/usr/share/julia/stdlib/v1.6/Base64/src/encode.jl:98 => Int64
write(io::Base.SecretBuffer, b::UInt8) in Base at secretbuffer.jl:112 => Int64
write(s::Base.BufferStream, b::UInt8) in Base at stream.jl:1351 => Int64
write(s::Base.LibuvStream, b::UInt8) in Base at stream.jl:1091 => Int64
write(f::Base.Filesystem.File, c::UInt8) in Base.Filesystem at filesystem.jl:136 => UInt64
write(::Base.DevNull, ::UInt8) in Base at coreio.jl:16 => Int64
write(s::IOStream, b::UInt8) in Base at iostream.jl:366 => Int64
write(s::IO, x::UInt8) in Base at io.jl:224 => Union{}
write(io::IO, x) in Base at io.jl:635 => Union{}

buffer_writes(io::AbstractPipe, args...) = buffer_writes(pipe_writer(io)::IO, args...)
flush(io::AbstractPipe) = flush(pipe_writer(io)::IO)

Expand Down
2 changes: 1 addition & 1 deletion base/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ end
function unsafe_write(to::GenericIOBuffer, p::Ptr{UInt8}, nb::UInt)
ensureroom(to, nb)
ptr = (to.append ? to.size+1 : to.ptr)
written = Int(min(nb, length(to.data) - ptr + 1))
written = Int(min(nb, Int(length(to.data))::Int - ptr + 1))
towrite = written
d = to.data
while towrite > 0
Expand Down
4 changes: 2 additions & 2 deletions base/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ string(a::Symbol) = String(a)
# note: print uses an encoding determined by `io` (defaults to UTF-8), whereas
# write uses an encoding determined by `s` (UTF-8 for `String`)
print(io::IO, s::AbstractString) = for c in s; print(io, c); end
write(io::IO, s::AbstractString) = (len = 0; for c in s; len += write(io, c); end; len)
write(io::IO, s::AbstractString) = (len = 0; for c in s; len += Int(write(io, c))::Int; end; len)
show(io::IO, s::AbstractString) = print_quoted(io, s)

# optimized methods to avoid iterating over chars
write(io::IO, s::Union{String,SubString{String}}) =
GC.@preserve s unsafe_write(io, pointer(s), reinterpret(UInt, sizeof(s)))
GC.@preserve s Int(unsafe_write(io, pointer(s), reinterpret(UInt, sizeof(s))))::Int
print(io::IO, s::Union{String,SubString{String}}) = (write(io, s); nothing)

## printing literal quoted string data ##
Expand Down