Skip to content

RFC: Add generic copy stagedfunction for all types #9270

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ copy(e::Expr) = (n = Expr(e.head);
n.args = astcopy(e.args);
n.typ = e.typ;
n)
copy(s::SymbolNode) = SymbolNode(s.name, s.typ)
copy(n::GetfieldNode) = GetfieldNode(n.value, n.name, n.typ)

# copy parts of an AST that the compiler mutates
astcopy(x::Union(SymbolNode,GetfieldNode,Expr)) = copy(x)
Expand Down
1 change: 0 additions & 1 deletion base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ndims(J::UniformScaling) = 2
getindex(J::UniformScaling, i::Integer,j::Integer) = ifelse(i==j,J.λ,zero(J.λ))

show(io::IO, J::UniformScaling) = print(io, "$(typeof(J))\n$(J.λ)*I")
copy(J::UniformScaling) = UniformScaling(J.λ)

transpose(J::UniformScaling) = J
ctranspose(J::UniformScaling) = UniformScaling(conj(J.λ))
Expand Down
19 changes: 18 additions & 1 deletion base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,27 @@ widen{T<:Number}(x::T) = convert(widen(T), x)

sizeof(x) = Core.sizeof(x)

# copying immutable things
# copying immutables is a no-op; mutables create a new object with the same contents
stagedfunction Base.copy(x)
if !x.mutable
:x
else
quote
y = ccall(:jl_new_struct_uninit, Any, (Any,), $x)
for i in 1:length($(x.names))
!isdefined(x, i) && continue
fld = getfield(x, i)
setfield!(y, i, ifelse(x === fld, y, fld))
end
y
end
end
end
# Avoid staging for common immutable types
copy(x::Union(Symbol,Number,AbstractString,Function,Tuple,LambdaStaticData,
TopNode,QuoteNode,DataType,UnionType)) = x


# function pipelining
|>(x, f::Callable) = f(x)

Expand Down
1 change: 0 additions & 1 deletion base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ end

immutable DevNullStream <: AsyncStream end
const DevNull = DevNullStream()
copy(::DevNullStream) = DevNull
uvhandle(::DevNullStream) = C_NULL
uvhandle(x::Ptr) = x
uvtype(::Ptr) = UV_STREAM
Expand Down
2 changes: 1 addition & 1 deletion base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ maximum(r::Range) = isempty(r) ? error("range must be non-empty") : max(first(r
ctranspose(r::Range) = [x for _=1, x=r]
transpose(r::Range) = r'

# Ranges are immutable
# Ranges are immutable, but the AbstractArray copy method doesn't know that
copy(r::Range) = r


Expand Down