Skip to content

Commit

Permalink
constant-fold construction of tuple types
Browse files Browse the repository at this point in the history
a small improvement to effect_free, which helps inlining

definitions used by ccall need to be available earlier
  • Loading branch information
JeffBezanson committed Nov 19, 2013
1 parent 505ceb0 commit c53772d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
12 changes: 12 additions & 0 deletions base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ typealias Callable Union(Function,DataType)
convert(T, x) = convert_default(T, x, convert)
convert(T::Tuple, x::Tuple) = convert_tuple(T, x, convert)

ptr_arg_convert{T}(::Type{Ptr{T}}, x) = convert(T, x)
ptr_arg_convert(::Type{Ptr{Void}}, x) = x

# conversion used by ccall
cconvert(T, x) = convert(T, x)
# use the code in ccall.cpp to safely allocate temporary pointer arrays
cconvert{T}(::Type{Ptr{Ptr{T}}}, a::Array) = a
# TODO: for some reason this causes a strange type inference problem
#cconvert(::Type{Ptr{Uint8}}, s::String) = bytestring(s)

abstract IO

type ErrorException <: Exception
Expand Down Expand Up @@ -129,6 +139,8 @@ function precompile(f, args::Tuple)
end
end

esc(e::ANY) = Expr(:escape, e)

macro boundscheck(yesno,blk)
quote
$(Expr(:boundscheck,yesno))
Expand Down
10 changes: 0 additions & 10 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@

import Core.Intrinsics.cglobal

ptr_arg_convert{T}(::Type{Ptr{T}}, x) = convert(T, x)
ptr_arg_convert(::Type{Ptr{Void}}, x) = x

# conversion used by ccall
cconvert(T, x) = convert(T, x)
# use the code in ccall.cpp to safely allocate temporary pointer arrays
cconvert{T}(::Type{Ptr{Ptr{T}}}, a::Array) = a
# TODO: for some reason this causes a strange type inference problem
#cconvert(::Type{Ptr{Uint8}}, s::String) = bytestring(s)

# constants to match JL_RTLD_* in src/julia.h
const RTLD_LOCAL = 0x00000000
const RTLD_GLOBAL = 0x00000001
Expand Down
2 changes: 0 additions & 2 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ macro gensym(names...)
return blk
end

esc(e::ANY) = Expr(:escape, e)

## expressions ##

splicedexpr(hd::Symbol, args::Array{Any,1}) = (e=Expr(hd); e.args=args; e)
Expand Down
7 changes: 5 additions & 2 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1682,12 +1682,12 @@ function without_linenums(a::Array{Any,1})
l
end

_pure_builtins = {getfield, tuple, tupleref, tuplelen, fieldtype}
_pure_builtins = {getfield, tuple, tupleref, tuplelen, fieldtype, apply_type}

# detect some important side-effect-free calls
function effect_free(e::ANY, sv)
if isa(e,Symbol) || isa(e,SymbolNode) || isa(e,Number) || isa(e,String) ||
isa(e,TopNode) || isa(e,QuoteNode)
isa(e,TopNode) || isa(e,QuoteNode) || isa(e,Type)
return true
end
if isa(e,Expr)
Expand Down Expand Up @@ -1763,6 +1763,9 @@ function inlineable(f, e::Expr, sv, enclosing_ast)
end
end
end
if is(f,tuple) && isa(e.typ,Tuple) && all(isType,e.typ) && isleaftype(e.typ) && effect_free(e,sv)
return (map(t->t.parameters[1], e.typ), ())
end
if isa(f,IntrinsicFunction)
return NF
end
Expand Down

0 comments on commit c53772d

Please sign in to comment.