Skip to content

Commit

Permalink
better codegen for getfield on type objects (#3938)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Aug 7, 2013
1 parent 9bd1b56 commit ac226f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,11 @@ function inlineable(f, e::Expr, sv, enclosing_ast)
# remove redundant unbox
return (e.args[3],())
end
if isdefined(Main.Base,:isbits) && is(f,Main.Base.isbits) &&
length(atypes)==1 && isType(atypes[1]) && effect_free(argexprs[1]) &&
isleaftype(atypes[1].parameters[1])
return (isbits(atypes[1].parameters[1]),())
end
# special-case inliners for known pure functions that compute types
if isType(e.typ)
if (is(f,apply_type) || is(f,fieldtype) ||
Expand All @@ -1679,10 +1684,6 @@ function inlineable(f, e::Expr, sv, enclosing_ast)
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)
Expand Down
2 changes: 2 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,8 @@ static Value *emit_getfield(jl_value_t *expr, jl_sym_t *name, jl_codectx_t *ctx)
}

jl_datatype_t *sty = (jl_datatype_t*)expr_type(expr, ctx);
if (jl_is_type_type((jl_value_t*)sty) && jl_is_leaf_type(jl_tparam0(sty)))
sty = (jl_datatype_t*)jl_typeof(jl_tparam0(sty));
JL_GC_PUSH1(&sty);
if (jl_is_structtype(sty) && sty != jl_module_type && sty->uid != 0) {
unsigned idx = jl_field_index(sty, name, 0);
Expand Down

0 comments on commit ac226f8

Please sign in to comment.