Skip to content
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

improved IR #15609

Merged
merged 6 commits into from
Mar 29, 2016
Merged
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
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ Compiler/Runtime improvements
Breaking changes
----------------

* Local variables and arguments are represented in lowered code as numbered `Slot`
objects instead of as symbols ([#15609]).

* The information that used to be in the `ast` field of the `LambdaStaticData` type
is now divided among the fields `code`, `slotnames`, `slottypes`, `slotflags`,
`gensymtypes`, `rettype`, `nargs`, and `isva` in the `LambdaInfo` type ([#15609]).

Library improvements
--------------------

Expand Down Expand Up @@ -173,3 +180,4 @@ Deprecated or removed
[#15242]: https://github.com/JuliaLang/julia/issues/15242
[#15258]: https://github.com/JuliaLang/julia/issues/15258
[#15550]: https://github.com/JuliaLang/julia/issues/15550
[#15609]: https://github.com/JuliaLang/julia/issues/15609
14 changes: 5 additions & 9 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ export
InterruptException, OutOfMemoryError, ReadOnlyMemoryError, OverflowError,
StackOverflowError, SegmentationFault, UndefRefError, UndefVarError, TypeError,
# AST representation
Expr, GotoNode, LabelNode, LineNumberNode, QuoteNode, SymbolNode, TopNode,
GlobalRef, NewvarNode, GenSym,
Expr, GotoNode, LabelNode, LineNumberNode, QuoteNode, TopNode,
GlobalRef, NewvarNode, GenSym, Slot,
# object model functions
fieldtype, getfield, setfield!, nfields, throw, tuple, is, ===, isdefined, eval,
# sizeof # not exported, to avoid conflicting with Base.sizeof
Expand Down Expand Up @@ -217,12 +217,6 @@ type TypeError <: Exception
got
end

type SymbolNode
name::Symbol
typ
SymbolNode(name::Symbol, t::ANY) = new(name, t)
end

abstract DirectIndexString <: AbstractString

immutable ASCIIString <: DirectIndexString
Expand Down Expand Up @@ -283,11 +277,13 @@ _new(typ::Symbol, argty::Symbol) = eval(:((::Type{$typ})(n::$argty) = $(Expr(:ne
_new(:LabelNode, :Int)
_new(:GotoNode, :Int)
_new(:TopNode, :Symbol)
_new(:NewvarNode, :Symbol)
_new(:NewvarNode, :Slot)
_new(:QuoteNode, :ANY)
_new(:GenSym, :Int)
eval(:((::Type{LineNumberNode})(f::Symbol, l::Int) = $(Expr(:new, :LineNumberNode, :f, :l))))
eval(:((::Type{GlobalRef})(m::Module, s::Symbol) = $(Expr(:new, :GlobalRef, :m, :s))))
eval(:((::Type{Slot})(n::Int) = $(Expr(:new, :Slot, :n, Any))))
eval(:((::Type{Slot})(n::Int, t::ANY) = $(Expr(:new, :Slot, :n, :t))))

Module(name::Symbol=:anonymous, std_imports::Bool=true) = ccall(:jl_f_new_module, Any, (Any, Bool), name, std_imports)::Module

Expand Down
4 changes: 4 additions & 0 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ function precompile(f::ANY, args::Tuple)
ccall(:jl_compile_hint, Void, (Any,), Tuple{Core.Typeof(f), args...})
end

function precompile(argt::Type)
ccall(:jl_compile_hint, Void, (Any,), argt)
end

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

macro boundscheck(blk)
Expand Down
22 changes: 14 additions & 8 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ 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(s::Slot) = Slot(s.id, s.typ)

# copy parts of an AST that the compiler mutates
astcopy(x::Union{SymbolNode,Expr}) = copy(x)
astcopy(x::Union{Slot,Expr}) = copy(x)
astcopy(x::Array{Any,1}) = Any[astcopy(a) for a in x]
astcopy(x) = x

==(x::Expr, y::Expr) = x.head === y.head && x.args == y.args
==(x::QuoteNode, y::QuoteNode) = x.value == y.value
==(x::SymbolNode, y::SymbolNode) = x.name === y.name && x.typ === y.typ
==(x::Slot, y::Slot) = x.id === y.id && x.typ === y.typ

expand(x) = ccall(:jl_expand, Any, (Any,), x)
macroexpand(x) = ccall(:jl_macroexpand, Any, (Any,), x)
Expand Down Expand Up @@ -133,7 +133,7 @@ end

function popmeta!(body::Expr, sym::Symbol)
body.head == :block || return false, []
found, metaex = findmeta_block(body)
found, metaex = findmeta_block(body.args)
if !found
return false, []
end
Expand All @@ -151,23 +151,29 @@ function popmeta!(body::Expr, sym::Symbol)
false, []
end
popmeta!(arg, sym) = (false, [])
function popmeta!(body::Array{Any,1}, sym::Symbol)
ex = Expr(:block); ex.args = body
popmeta!(ex, sym)
end

function findmeta(ex::Expr)
if ex.head == :function || (ex.head == :(=) && typeof(ex.args[1]) == Expr && ex.args[1].head == :call)
body::Expr = ex.args[2]
body.head == :block || error(body, " is not a block expression")
return findmeta_block(ex)
return findmeta_block(ex.args)
end
error(ex, " is not a function expression")
end

function findmeta_block(ex::Expr)
for a in ex.args
findmeta(ex::Array{Any,1}) = findmeta_block(ex)

function findmeta_block(exargs)
for a in exargs
if isa(a, Expr)
if (a::Expr).head == :meta
return true, a::Expr
elseif (a::Expr).head == :block
found, exb = findmeta_block(a)
found, exb = findmeta_block(a.args)
if found
return found, exb
end
Expand Down
2 changes: 1 addition & 1 deletion base/hashing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ else
end

hash(x::QuoteNode, h::UInt) = hash(x.value, hash(QuoteNode, h))
hash(x::SymbolNode, h::UInt) = hash(x.name, hash(x.typ, hash(SymbolNode, h)))
hash(x::Slot, h::UInt) = hash(x.id, hash(x.typ, hash(Slot, h)))

# hashing ranges by component at worst leads to collisions for very similar ranges
const hashr_seed = UInt === UInt64 ? 0x80707b6821b70087 : 0x21b70087
Expand Down
Loading