Skip to content

Commit

Permalink
add custom inliner for isbits(). fixes #3938
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Aug 7, 2013
1 parent 0cc4b8f commit dd82ffe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
29 changes: 18 additions & 11 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1667,20 +1667,27 @@ function inlineable(f, e::Expr, sv, enclosing_ast)
return (e.args[3],())
end
end
# special-case inliners for known pure functions that compute types
if (is(f,apply_type) || is(f,fieldtype) ||
(isdefined(Main.Base,:typejoin) && is(f,Main.Base.typejoin)) ||
(isdefined(Main.Base,:promote_type) && is(f,Main.Base.promote_type))) &&
isType(e.typ) && isleaftype(e.typ.parameters[1])
return (e.typ.parameters[1],())
end
if length(atypes)==2 && is(f,unbox) && isa(atypes[2],DataType)
# remove redundant unbox
return (e.args[3],())
end
if is(f,Union) && isType(e.typ)
union = e.typ.parameters[1]
if isa(union,UnionType) && all(isleaftype, (union::UnionType).types)
return (union,())
# special-case inliners for known pure functions that compute types
if isType(e.typ)
if (is(f,apply_type) || is(f,fieldtype) ||
(isdefined(Main.Base,:typejoin) && is(f,Main.Base.typejoin)) ||
(isdefined(Main.Base,:promote_type) && is(f,Main.Base.promote_type))) &&
isleaftype(e.typ.parameters[1])
return (e.typ.parameters[1],())
end
if isdefined(Main.Base,:isbits) && is(f,Main.Base.isbits) &&
isleaftype(e.typ.parameters[1])
return (isbits(e.typ.parameters[1]),())
end
if is(f,Union)
union = e.typ.parameters[1]
if isa(union,UnionType) && all(isleaftype, (union::UnionType).types)
return (union,())
end
end
end
if isa(f,IntrinsicFunction)
Expand Down
2 changes: 1 addition & 1 deletion base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object_id(x::ANY) = ccall(:jl_object_id, Uint, (Any,), x)
const isimmutable = x->(isa(x,Tuple) || !typeof(x).mutable)
isstructtype(t::DataType) = t.names!=() || (t.size==0 && !t.abstract)
isstructtype(x) = false
isbits(t::DataType) = !t.mutable && t.pointerfree
isbits(t::DataType) = !t.mutable & t.pointerfree
isbits(t::Type) = false
isbits(x) = isbits(typeof(x))
isleaftype(t::ANY) = ccall(:jl_is_leaf_type, Int32, (Any,), t) != 0
Expand Down

0 comments on commit dd82ffe

Please sign in to comment.