Skip to content

Commit

Permalink
remove reduce.jl from compiler image
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jul 4, 2018
1 parent e9c78a7 commit 1e0ce67
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 131 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ COMPILER_SRCS := $(addprefix $(JULIAHOME)/, \
base/pointer.jl \
base/promotion.jl \
base/range.jl \
base/reduce.jl \
base/reflection.jl \
base/traits.jl \
base/refvalue.jl \
Expand Down
6 changes: 0 additions & 6 deletions base/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ include("indices.jl")
include("array.jl")
include("abstractarray.jl")

# map-reduce operators
macro simd(forloop)
esc(forloop)
end
include("reduce.jl")

# core structures
include("bitarray.jl")
include("bitset.jl")
Expand Down
8 changes: 6 additions & 2 deletions base/compiler/ssair/domtree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ function construct_domtree(cfg::CFG)
doms = collect(dominators[i])
for dom in doms
i == dom && continue
let i = i, dom = dom
any(p -> (p !== i && p !== dom && dom in dominators[p]), doms) && continue
hasany = false
for p in doms
if p !== i && p !== dom && dom in dominators[p]
hasany = true; break
end
end
hasany && continue
idoms[i] = dom
end
end
Expand Down
12 changes: 9 additions & 3 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,21 @@ function compute_value_for_use(ir::IRCode, domtree::DomTree, allblocks, du, phin
# Find the first dominating def
curblock = stmtblock = block_for_inst(ir.cfg, use_idx)
curblock = find_curblock(domtree, allblocks, curblock)
defblockdefs = [stmt for stmt in du.defs if block_for_inst(ir.cfg, stmt) == curblock]
defblockdefs = Int[stmt for stmt in du.defs if block_for_inst(ir.cfg, stmt) == curblock]
def = 0
if !isempty(defblockdefs)
if curblock != stmtblock
# Find the last def in this block
def = maximum(defblockdefs)
def = 0
for x in defblockdefs
def = max(def, x)
end
else
# Find the last def before our use
def = mapreduce(x->x >= use_idx ? 0 : x, max, defblockdefs)
def = 0
for x in defblockdefs
def = max(def, x >= use_idx ? 0 : x)
end
end
end
if def == 0
Expand Down
137 changes: 126 additions & 11 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,39 @@ julia> minmax('c','b')
"""
minmax(x,y) = isless(y, x) ? (y, x) : (x, y)

"""
extrema(itr) -> Tuple
Compute both the minimum and maximum element in a single pass, and return them as a 2-tuple.
# Examples
```jldoctest
julia> extrema(2:10)
(2, 10)
julia> extrema([9,pi,4.5])
(3.141592653589793, 9.0)
```
"""
extrema(itr) = _extrema_itr(itr)

function _extrema_itr(itr)
y = iterate(itr)
y === nothing && throw(ArgumentError("collection must be non-empty"))
(v, s) = y
vmin = vmax = v
while true
y = iterate(itr, s)
y === nothing && break
(x, s) = y
vmax = max(x, vmax)
vmin = min(x, vmin)
end
return (vmin, vmax)
end

extrema(x::Real) = (x, x)

## definitions providing basic traits of arithmetic operators ##

"""
Expand Down Expand Up @@ -872,17 +905,6 @@ used to implement specialized methods.
"""
==(x) = Fix2(==, x)

"""
in(x)
Create a function that checks whether its argument is [`in`](@ref) `x`, i.e.
a function equivalent to `y -> y in x`.
The returned function is of type `Base.Fix2{typeof(in)}`, which can be
used to implement specialized methods.
"""
in(x) = Fix2(in, x)

"""
splat(f)
Expand All @@ -905,3 +927,96 @@ julia> map(splat(+), zip(1:3,4:6))
```
"""
splat(f) = args->f(args...)

## in & contains

"""
in(x)
Create a function that checks whether its argument is [`in`](@ref) `x`, i.e.
a function equivalent to `y -> y in x`.
The returned function is of type `Base.Fix2{typeof(in)}`, which can be
used to implement specialized methods.
"""
in(x) = Fix2(in, x)

function in(x, itr)
anymissing = false
for y in itr
v = (y == x)
if v === missing
anymissing = true
elseif v
return true
end
end
return anymissing ? missing : false
end

const = in
(itr, x) = (x, itr)
(x, itr) = !(x, itr)
(itr, x) = !(itr, x)

"""
in(item, collection) -> Bool
∈(item, collection) -> Bool
∋(collection, item) -> Bool
Determine whether an item is in the given collection, in the sense that it is
[`==`](@ref) to one of the values generated by iterating over the collection.
Returns a `Bool` value, except if `item` is [`missing`](@ref) or `collection`
contains `missing` but not `item`, in which case `missing` is returned
([three-valued logic](https://en.wikipedia.org/wiki/Three-valued_logic),
matching the behavior of [`any`](@ref) and [`==`](@ref)).
Some collections follow a slightly different definition. For example,
[`Set`](@ref)s check whether the item [`isequal`](@ref) to one of the elements.
[`Dict`](@ref)s look for `key=>value` pairs, and the key is compared using
[`isequal`](@ref). To test for the presence of a key in a dictionary,
use [`haskey`](@ref) or `k in keys(dict)`. For these collections, the result
is always a `Bool` and never `missing`.
# Examples
```jldoctest
julia> a = 1:3:20
1:3:19
julia> 4 in a
true
julia> 5 in a
false
julia> missing in [1, 2]
missing
julia> 1 in [2, missing]
missing
julia> 1 in [1, missing]
true
julia> missing in Set([1, 2])
false
```
"""
in,

"""
∉(item, collection) -> Bool
∌(collection, item) -> Bool
Negation of `∈` and `∋`, i.e. checks that `item` is not in `collection`.
# Examples
```jldoctest
julia> 1 ∉ 2:4
true
julia> 1 ∉ 1:3
false
```
"""
,
2 changes: 2 additions & 0 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ maximum(r::AbstractUnitRange) = isempty(r) ? throw(ArgumentError("range must be
minimum(r::AbstractRange) = isempty(r) ? throw(ArgumentError("range must be non-empty")) : min(first(r), last(r))
maximum(r::AbstractRange) = isempty(r) ? throw(ArgumentError("range must be non-empty")) : max(first(r), last(r))

extrema(r::AbstractRange) = (minimum(r), maximum(r))

# Ranges are immutable
copy(r::AbstractRange) = r

Expand Down
107 changes: 1 addition & 106 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -500,42 +500,6 @@ julia> minimum([1,2,3])
"""
minimum(a) = mapreduce(identity, min, a)

## extrema

extrema(r::AbstractRange) = (minimum(r), maximum(r))
extrema(x::Real) = (x, x)

"""
extrema(itr) -> Tuple
Compute both the minimum and maximum element in a single pass, and return them as a 2-tuple.
# Examples
```jldoctest
julia> extrema(2:10)
(2, 10)
julia> extrema([9,pi,4.5])
(3.141592653589793, 9.0)
```
"""
extrema(itr) = _extrema_itr(itr)

function _extrema_itr(itr)
y = iterate(itr)
y === nothing && throw(ArgumentError("collection must be non-empty"))
(v, s) = y
vmin = vmax = v
while true
y = iterate(itr, s)
y === nothing && break
(x, s) = y
vmax = max(x, vmax)
vmin = min(x, vmin)
end
return (vmin, vmax)
end

## all & any

"""
Expand Down Expand Up @@ -707,77 +671,8 @@ function _all(f, itr, ::Colon)
return anymissing ? missing : true
end


## in & contains
in(x, itr) = any(y -> y == x, itr)
const = in
(itr, x) = (x, itr)
(x, itr) = !(x, itr)
(itr, x) = !(itr, x)

"""
in(item, collection) -> Bool
∈(item, collection) -> Bool
∋(collection, item) -> Bool
Determine whether an item is in the given collection, in the sense that it is
[`==`](@ref) to one of the values generated by iterating over the collection.
Returns a `Bool` value, except if `item` is [`missing`](@ref) or `collection`
contains `missing` but not `item`, in which case `missing` is returned
([three-valued logic](https://en.wikipedia.org/wiki/Three-valued_logic),
matching the behavior of [`any`](@ref) and [`==`](@ref)).
Some collections follow a slightly different definition. For example,
[`Set`](@ref)s check whether the item [`isequal`](@ref) to one of the elements.
[`Dict`](@ref)s look for `key=>value` pairs, and the key is compared using
[`isequal`](@ref). To test for the presence of a key in a dictionary,
use [`haskey`](@ref) or `k in keys(dict)`. For these collections, the result
is always a `Bool` and never `missing`.
# Examples
```jldoctest
julia> a = 1:3:20
1:3:19
julia> 4 in a
true
julia> 5 in a
false
julia> missing in [1, 2]
missing
julia> 1 in [2, missing]
missing
julia> 1 in [1, missing]
true
julia> missing in Set([1, 2])
false
```
"""
in,

"""
∉(item, collection) -> Bool
∌(collection, item) -> Bool
Negation of `∈` and `∋`, i.e. checks that `item` is not in `collection`.
# Examples
```jldoctest
julia> 1 ∉ 2:4
true
julia> 1 ∉ 1:3
false
```
"""
,

## count

"""
count(p, itr) -> Integer
count(itr) -> Integer
Expand Down
6 changes: 4 additions & 2 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,10 @@ function to_tuple_type(@nospecialize(t))
t = Tuple{t...}
end
if isa(t,Type) && t<:Tuple
if !all(p->(isa(p,Type)||isa(p,TypeVar)), t.parameters)
error("argument tuple type must contain only types")
for p in t.parameters
if !(isa(p,Type) || isa(p,TypeVar))
error("argument tuple type must contain only types")
end
end
else
error("expected tuple type")
Expand Down

0 comments on commit 1e0ce67

Please sign in to comment.