Skip to content

Commit

Permalink
Merge pull request #15609 from JuliaLang/jb/linear3
Browse files Browse the repository at this point in the history
improved IR
  • Loading branch information
JeffBezanson committed Mar 29, 2016
2 parents 48a8493 + 1ee954a commit 96fb049
Show file tree
Hide file tree
Showing 34 changed files with 1,271 additions and 1,460 deletions.
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 @@ -128,6 +128,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

0 comments on commit 96fb049

Please sign in to comment.