Skip to content

Commit

Permalink
Merge branch 'master' of github.com:JuliaLang/julia
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeXing committed Jul 2, 2011
2 parents 4bb72de + c163411 commit d2b66aa
Show file tree
Hide file tree
Showing 37 changed files with 349 additions and 295 deletions.
2 changes: 1 addition & 1 deletion doc/todo
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ issues 1/24/11
- some kind of no-specialize hint for slots like x in
assign(A::Array{Any}, x, i::Index) = arrayset(A,i,x)
where we know the function is identical for all types of x
- maybe make x::Any different from no type decl
* add x::ANY
- reuse specialized methods for multiple types in an Any slot
- implement SubArray
- isassigned predicates
Expand Down
2 changes: 1 addition & 1 deletion j/array.j
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ref{T}(a::Array{T,2}, i::Index, j::Index) = arrayref(a, (j-1)*arraysize(a,1)+i)
## Indexing: assign ##

assign(A::Array{Any}, x::Tensor, i::Index) = arrayset(A,i,x)
assign(A::Array{Any}, x, i::Index) = arrayset(A,i,x)
assign(A::Array{Any}, x::ANY, i::Index) = arrayset(A,i,x)
assign{T}(A::Array{T}, x::Tensor, i::Index) = arrayset(A,i,convert(T, x))
assign{T}(A::Array{T}, x, i::Index) = arrayset(A,i,convert(T, x))

Expand Down
2 changes: 1 addition & 1 deletion j/bool.j
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sizeof(::Type{Bool}) = 1
## boolean operations ##

!(x::Bool) = eq_int(unbox8(x),trunc8(unbox32(0)))
==(x::Bool, y::Bool) = eq_int(unbox8(x),unbox8(y))
isequal(x::Bool, y::Bool) = eq_int(unbox8(x),unbox8(y))

(~)(x::Bool) = !x
(&)(x::Bool, y::Bool) = (x&&y)
Expand Down
4 changes: 2 additions & 2 deletions j/cell.j
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function append(a1::Array{Any,1}, as::Array{Any,1}...)
a
end

function cell_1d(xs...)
function cell_1d(xs::ANY...)
n = length(xs)
a = Array(Any,n)
for i=1:n
Expand All @@ -27,7 +27,7 @@ function cell_1d(xs...)
a
end

function cell_2d(nr, nc, xs...)
function cell_2d(nr, nc, xs::ANY...)
a = Array(Any,nr,nc)
for i=1:(nr*nc)
arrayset(a,i,xs[i])
Expand Down
7 changes: 7 additions & 0 deletions j/complex.j
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ pi{T}(::Type{Complex{T}}) = pi(T)
## functions of complex numbers ##

==(z::ComplexNum, w::ComplexNum) = (real(z) == real(w) && imag(z) == imag(w))
==(z::ComplexNum, x::Real) = (real(z)==x && imag(z)==0)
==(x::Real, z::ComplexNum) = (real(z)==x && imag(z)==0)

isequal(z::ComplexNum, w::ComplexNum) =
isequal(real(z),real(w)) && isequal(imag(z),imag(w))

hash(z::ComplexNum) = bitmix(hash(real(z)),hash(imag(z)))

conj(z::ComplexNum) = complex(real(z),-imag(z))
norm(z::ComplexNum) = square(real(z)) + square(imag(z))
Expand Down
4 changes: 1 addition & 3 deletions j/expr.j
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ symbol(a::Array{Uint8,1}) =

gensym() = ccall(:jl_gensym, Any, ())::Symbol

(==)(x::Symbol, y::Symbol) = is(x, y)

## expressions ##

expr(hd::Symbol, args...) = Expr(hd, {args...}, Any)
expr(hd::Symbol, args::ANY...) = Expr(hd, {args...}, Any)
expr(hd::Symbol, args::Array{Any,1}) = Expr(hd, args, Any)
copy(e::Expr) = Expr(e.head, copy(e.args), e.type)

Expand Down
16 changes: 10 additions & 6 deletions j/inference.j
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function (T, dims...)
Array{et,nd}
end)

function static_convert(to, from)
function static_convert(to::ANY, from::ANY)
if !isa(to,Tuple) || !isa(from,Tuple)
return (subtype(from, to) ? from : to)
end
Expand Down Expand Up @@ -575,14 +575,18 @@ function abstract_eval_expr(e, vtypes, sv::StaticVarInfo)
t = abstract_eval(e.args[1], vtypes, sv)
# intersect with Any to remove Undef
t = tintersect(t, Any)
return Type{t}
if isleaftype(t) || isa(t,TypeVar)
return Type{t}
else
return Type{typevar(:T,t)}
end
end
Any
end

ast_rettype(ast) = ast.args[3].type

function abstract_eval_constant(x)
function abstract_eval_constant(x::ANY)
if isa(x,TagKind) || isa(x,BitsKind) || isa(x,StructKind) ||
isa(x,FuncKind) || isa(x,UnionKind)
return Type{x}
Expand Down Expand Up @@ -670,7 +674,7 @@ function interpret(e::Expr, vtypes, sv::StaticVarInfo)
return vtypes
end

tchanged(n, o) = is(o,NF) || (!is(n,NF) && !subtype(n,o))
tchanged(n::ANY, o::ANY) = is(o,NF) || (!is(n,NF) && !subtype(n,o))

function stchanged(new::Union(StateUpdate,VarTable), old, vars)
if is(old,())
Expand All @@ -687,7 +691,7 @@ end

badunion(t) = ccall(:jl_union_too_complex, Int32, (Any,), t) != 0

function tmerge(typea, typeb)
function tmerge(typea::ANY, typeb::ANY)
if is(typea,NF)
return typeb
end
Expand Down Expand Up @@ -1066,7 +1070,7 @@ function contains_is(arr, item)
return false
end
function exprtype(x)
function exprtype(x::ANY)
if isa(x,Expr)
return x.type
elseif isa(x,Symbol)
Expand Down
88 changes: 55 additions & 33 deletions j/multi.j
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,6 @@ type RemoteRef
r
end

global WeakRemoteRef
function WeakRemoteRef(w, wh, id)
return new(w, wh, id)
end

REQ_ID::Int32 = 0
function RemoteRef(pid::Int)
rr = RemoteRef(pid, myid(), REQ_ID)
Expand All @@ -221,36 +216,51 @@ type RemoteRef
RemoteRef(w::LocalProcess) = RemoteRef(myid())
RemoteRef(w::Worker) = RemoteRef(w.id)
RemoteRef() = RemoteRef(myid())

global WeakRemoteRef
function WeakRemoteRef(w, wh, id)
return new(w, wh, id)
end

function WeakRemoteRef(pid::Int)
rr = WeakRemoteRef(pid, myid(), REQ_ID)
REQ_ID += 1
rr
end

WeakRemoteRef(w::LocalProcess) = WeakRemoteRef(myid())
WeakRemoteRef(w::Worker) = WeakRemoteRef(w.id)
WeakRemoteRef() = WeakRemoteRef(myid())
end

hash(r::RemoteRef) = hash(r.whence)+3*hash(r.id)
isequal(r::RemoteRef, s::RemoteRef) = (r.whence==s.whence && r.id==s.id)

rr2id(r::RemoteRef) = (r.whence, r.id)

let bottom_func() = assert(false)
global lookup_ref
function lookup_ref(id)
global PGRP
wi = get((PGRP::ProcessGroup).refs, id, ())
if is(wi, ())
# first we've heard of this ref
wi = WorkItem(bottom_func)
# this WorkItem is just for storing the result value
PGRP.refs[id] = wi
add(wi.clientset, id[1])
end
wi
end
# is a ref uninitialized? (for locally-owned refs only)
function ref_uninitialized(id)
wi = lookup_ref(id)
!wi.done && is(wi.thunk,bottom_func)
bottom_func() = assert(false)

function lookup_ref(id)
global PGRP
wi = get((PGRP::ProcessGroup).refs, id, ())
if is(wi, ())
# first we've heard of this ref
wi = WorkItem(bottom_func)
# this WorkItem is just for storing the result value
PGRP.refs[id] = wi
add(wi.clientset, id[1])
end
ref_uninitialized(r::RemoteRef) = (assert(r.where==myid());
ref_uninitialized(rr2id(r)))
wi
end

# is a ref uninitialized? (for locally-owned refs only)
function ref_uninitialized(id)
wi = lookup_ref(id)
!wi.done && is(wi.thunk,bottom_func)
end
ref_uninitialized(r::RemoteRef) = (assert(r.where==myid());
ref_uninitialized(rr2id(r)))

function isready(rr::RemoteRef)
rid = rr2id(rr)
if rr.where == myid()
Expand Down Expand Up @@ -283,7 +293,7 @@ function send_del_client(rr::RemoteRef)
else
W = worker_from_id(rr.where)
push(W.del_msgs, (rr2id(rr), myid()))
if length(W.del_msgs) >= 16
if length(W.del_msgs) >= 10
#print("sending delete of $(W.del_msgs)\n")
remote_do(rr.where, del_clients, W.del_msgs...)
del_all(W.del_msgs)
Expand Down Expand Up @@ -377,10 +387,12 @@ remote_call(id::Int, f, args...) = remote_call(worker_from_id(id), f, args...)
remote_call_fetch(w::LocalProcess, f, args...) = f(args...)

function remote_call_fetch(w::Worker, f, args...)
rr = RemoteRef(w)
# can be weak, because the program will have no way to refer to the Ref
# itself, it only gets the result.
rr = WeakRemoteRef(w)
oid = rr2id(rr)
send_msg(w, :call_fetch, oid, f, args)
force(yieldto(Scheduler, WaitFor(:fetch, oid)))
force(yieldto(Scheduler, WaitFor(:call_fetch, oid)))
end

remote_call_fetch(id::Int, f, args...) =
Expand Down Expand Up @@ -420,7 +432,11 @@ function sync_msg(verb::Symbol, r::RemoteRef)
if r.where==myid() || isa(pg.workers[r.where], LocalProcess)
wi = lookup_ref(oid)
if wi.done
return is(verb,:fetch) ? work_result(wi) : r
if is(verb,:fetch)
return work_result(wi)
else
return r
end
else
# add to WorkItem's notify list
wi.notify = ((), verb, oid, wi.notify)
Expand Down Expand Up @@ -561,6 +577,7 @@ function perform_work(job::WorkItem)
job.task = ()
# do notifications
notify_done(job)
job.thunk = bottom_func # avoid reference retention
else
# job interrupted
if is(job.task,runner)
Expand All @@ -581,7 +598,7 @@ end

function deliver_result(sock::IOStream, msg, oid, value)
#print("$(myid()) sending result\n")
if is(msg,:fetch)
if is(msg,:fetch) || is(msg,:call_fetch)
val = value
else
@assert is(msg, :wait)
Expand Down Expand Up @@ -629,6 +646,11 @@ function notify_done(job::WorkItem)
else
deliver_result(sock, msg, oid, wr)
end
if is(msg,:call_fetch)
# can delete the ref right away since we know it is
# unreferenced by the client
del(PGRP.refs, oid)
end
end
end
end
Expand Down Expand Up @@ -681,7 +703,7 @@ function message_handler(fd, sockets)
#print("$(myid()) got call\n")
wi = schedule_call(id, f, args)
if is(msg, :call_fetch)
wi.notify = (sock, :fetch, id, wi.notify)
wi.notify = (sock, :call_fetch, id, wi.notify)
elseif is(msg, :call_wait)
wi.notify = (sock, :wait, id, wi.notify)
end
Expand Down Expand Up @@ -1117,9 +1139,9 @@ function at_each(grp::ProcessGroup, f, args...)
end
end

macro bcast(thk)
macro bcast(ex)
quote
at_each(()->eval($expr(:quote,thk)))
at_each(()->eval($expr(:quote,ex)))
end
end

Expand Down
13 changes: 8 additions & 5 deletions j/operators.j
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@

## comparison ##

==(x, y) = false
isequal(x, y) = is(x, y)

==(x, y) = isequal(x, y)
!=(x, y) = !(x == y)
==(x::Number, y::Number) = (==)(promote(x,y)...)

# this definition allows Number types to implement == instead of isequal,
# which is more idiomatic.
isequal{T<:Number}(x::T, y::T) = (x == y)

< (x::Real, y::Real) = (<)(promote(x,y)...)
> (x::Real, y::Real) = (y < x)
<=(x::Real, y::Real) = (x < y) || (x == y)
>=(x::Real, y::Real) = (x > y) || (x == y)

isequal{T}(x::T, y::T) = (x==y)
isequal(x, y) = isequal(promote(x,y)...)

## definitions providing basic traits of arithmetic operators ##

+() = 0
Expand Down Expand Up @@ -151,5 +154,5 @@ ${T<:Int}(x::T, y::T) = no_op_err("\$", T)
## miscellaneous ##
copy(x::Any) = x
copy(x::ANY) = x
foreach(f::Function, itr) = for x = itr; f(x); end
2 changes: 1 addition & 1 deletion j/pointer.j
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ulong(x) = convert(Ulong, x)

## limited pointer arithmetic & comparison ##

==(x::Ptr, y::Ptr) = uint(x) == uint(y)
isequal(x::Ptr, y::Ptr) = uint(x) == uint(y)
-(x::Ptr, y::Ptr) = uint(x) - uint(y)

+{T}(x::Ptr{T}, y::Int) = pointer(T, uint(x) + uint(y))
Expand Down
12 changes: 5 additions & 7 deletions j/process.j
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ global STDIN = FileDes(ccall(:jl_stdin, Int32, ()))
global STDOUT = FileDes(ccall(:jl_stdout, Int32, ()))
global STDERR = FileDes(ccall(:jl_stderr, Int32, ()))

==(fd1::FileDes, fd2::FileDes) = (fd1.fd == fd2.fd)
isequal(fd1::FileDes, fd2::FileDes) = (fd1.fd == fd2.fd)

hash(fd::FileDes) = hash(fd.fd)

Expand All @@ -55,15 +55,15 @@ type Pipe
end
end

==(p1::Pipe, p2::Pipe) = (p1.in == p2.in && p1.out == p2.out)
isequal(p1::Pipe, p2::Pipe) = (p1.in == p2.in && p1.out == p2.out)

abstract PipeEnd
type PipeIn <: PipeEnd; pipe::Pipe; end
type PipeOut <: PipeEnd; pipe::Pipe; end

==(p1::PipeEnd, p2::PipeEnd) = false
==(p1::PipeIn , p2::PipeIn ) = (p1.pipe == p2.pipe)
==(p1::PipeOut, p2::PipeOut) = (p1.pipe == p2.pipe)
isequal(p1::PipeEnd, p2::PipeEnd) = false
isequal(p1::PipeIn , p2::PipeIn ) = (p1.pipe == p2.pipe)
isequal(p1::PipeOut, p2::PipeOut) = (p1.pipe == p2.pipe)

in (p::Pipe) = PipeIn(p)
out(p::Pipe) = PipeOut(p)
Expand Down Expand Up @@ -170,8 +170,6 @@ end

exec(cmd::Cmd) = exec(cmd.exec)

==(c1::Cmd, c2::Cmd) = is(c1,c2)

## Port: a file descriptor on a particular command ##

type Port
Expand Down
Loading

0 comments on commit d2b66aa

Please sign in to comment.