From e8c931188a4110e1fa4a5adf54a407b138fe9e96 Mon Sep 17 00:00:00 2001 From: Dennis Yatunin Date: Wed, 18 Sep 2024 12:09:11 -0700 Subject: [PATCH] Remove all recursion limits and make some lazy maps eager --- .github/workflows/invalidations.yml | 2 +- src/UnrolledUtilities.jl | 14 ++++++-- src/recursion_limits.jl | 56 ----------------------------- 3 files changed, 12 insertions(+), 60 deletions(-) delete mode 100644 src/recursion_limits.jl diff --git a/.github/workflows/invalidations.yml b/.github/workflows/invalidations.yml index 881ebec..7439f9f 100644 --- a/.github/workflows/invalidations.yml +++ b/.github/workflows/invalidations.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: julia-actions/setup-julia@v1 with: - version: '1' + version: '1.10' # JET and SnoopCompile do not yet support Julia 1.11 - uses: actions/checkout@v4 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-invalidations@v1 diff --git a/src/UnrolledUtilities.jl b/src/UnrolledUtilities.jl index 56ba671..8377705 100644 --- a/src/UnrolledUtilities.jl +++ b/src/UnrolledUtilities.jl @@ -72,7 +72,7 @@ include("generatively_unrolled_functions.jl") val_unrolled_reduce(op, val_N, init) @inline unrolled_mapreduce(f, op, itrs...; init = NoInit()) = - unrolled_reduce(op, Iterators.map(f, itrs...), init) + unrolled_reduce(op, unrolled_map(f, itrs...), init) @inline unrolled_accumulate_into_tuple(op, itr, init, transform) = (rec_unroll(itr) ? rec_unrolled_accumulate : gen_unrolled_accumulate)( @@ -148,7 +148,7 @@ include("generatively_unrolled_functions.jl") unrolled_reduce(unrolled_append, itr; init = promoted_empty(itr)) @inline unrolled_flatmap(f, itrs...) = - unrolled_flatten(Iterators.map(f, itrs...)) + unrolled_flatten(unrolled_map(f, itrs...)) @inline unrolled_product(itrs...) = unrolled_reduce(itrs; init = (promoted_empty(itrs),)) do product_itr, itr @@ -172,6 +172,14 @@ abstract type StaticSequence{N} end include("StaticOneTo.jl") include("StaticBitVector.jl") -include("recursion_limits.jl") # This must be included at the end of the module. +# Remove the default recursion limit from every function defined in this module. +@static if hasfield(Method, :recursion_relation) + module_names = names(@__MODULE__; all = true) + module_values = map(Base.Fix1(getproperty, @__MODULE__), module_names) + module_functions = filter(Base.Fix2(isa, Function), module_values) + for f in module_functions, method in methods(f) + method.recursion_relation = Returns(true) + end +end end diff --git a/src/recursion_limits.jl b/src/recursion_limits.jl deleted file mode 100644 index 9f9c279..0000000 --- a/src/recursion_limits.jl +++ /dev/null @@ -1,56 +0,0 @@ -# Remove recursion limits from functions that call themselves, and also from all -# functions whose arguments can be arbitrary functions (including themselves). -@static if hasfield(Method, :recursion_relation) - for func in ( - generic_getindex, - output_type_for_promotion, - _rec_unrolled_any, - _rec_unrolled_all, - _rec_unrolled_foreach, - _rec_unrolled_map, - _rec_unrolled_applyat, - _rec_unrolled_reduce, - _rec_unrolled_accumulate, - rec_unrolled_any, - rec_unrolled_all, - rec_unrolled_foreach, - rec_unrolled_map, - rec_unrolled_applyat, - rec_unrolled_reduce, - rec_unrolled_accumulate, - _gen_unrolled_any, - _gen_unrolled_all, - _gen_unrolled_foreach, - _gen_unrolled_map, - _gen_unrolled_applyat, - _gen_unrolled_reduce, - _gen_unrolled_accumulate, - gen_unrolled_any, - gen_unrolled_all, - gen_unrolled_foreach, - gen_unrolled_map, - gen_unrolled_applyat, - gen_unrolled_reduce, - gen_unrolled_accumulate, - val_unrolled_reduce, - unrolled_any, - unrolled_all, - unrolled_foreach, - unrolled_map_into_tuple, - unrolled_map_into, - unrolled_map, - unrolled_applyat, - unrolled_reduce, - unrolled_mapreduce, - unrolled_accumulate_into_tuple, - unrolled_accumulate_into, - unrolled_accumulate, - unrolled_filter, - unrolled_split, - unrolled_flatmap, - ) - for method in methods(func) - method.recursion_relation = Returns(true) - end - end -end