Skip to content

Commit 7b22a97

Browse files
committed
Revert "feat: add functional version of nif for easier @generated"
This reverts commit e745e3f.
1 parent e745e3f commit 7b22a97

File tree

3 files changed

+0
-101
lines changed

3 files changed

+0
-101
lines changed

src/Utils.jl

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -153,55 +153,4 @@ struct ResultOk2{A<:AbstractArray,B<:AbstractArray}
153153
ok::Bool
154154
end
155155

156-
#! format: on
157-
"""
158-
nif(condition, expression, [else_expression,] ::Val{N}) where {N}
159-
160-
Generate a sequence of `if ... elseif ... else ... end` statements.
161-
This is copied from https://github.com/JuliaLang/julia/pull/55093.
162-
163-
# Arguments
164-
- `condition`: A function that takes an integer between `1` and `N-1` and
165-
returns a boolean condition.
166-
- `expression`: A function that takes an integer between `1` and `N` (or,
167-
only up to `N-1`, if `else_expression` is provided) and is called if
168-
the condition is true.
169-
- `else_expression`: (optional) A function that takes `N` as input
170-
returns an expression to be evaluated if all conditions are false.
171-
- `N`: The number of conditions to check, passed as a `Val{N}` instance.
172-
This function is similar to the `@nif` macro but can be used in cases
173-
where `N` is not known at parse time.
174-
# Examples
175-
For example, here we find the first index of a positive element in a
176-
fixed-size tuple using `nif`:
177-
```jldoctest
178-
julia> x = (0, -1, 1, 0)
179-
(0, -1, 1, 0)
180-
julia> Base.Cartesian.nif(d -> x[d] > 0, d -> d, Val(4))
181-
3
182-
```
183-
"""
184-
@inline function nif(condition::F, expression::G, ::Val{N}) where {F,G,N}
185-
return nif(condition, expression, expression, Val(N))
186-
end
187-
@inline function nif(
188-
condition::F, expression::G, else_expression::H, ::Val{N}
189-
) where {F,G,H,N}
190-
n = N::Int # Can improve inference; see #54544
191-
(n >= 0) || throw(ArgumentError("if statement length should be ≥ 0, got $n"))
192-
if @generated
193-
:(Base.Cartesian.@nif $N d -> condition(d) d -> expression(d) d ->
194-
else_expression(d))
195-
else
196-
for d in 1:(n - 1)
197-
if condition(d)
198-
return expression(d)
199-
end
200-
end
201-
return else_expression(n)
202-
end
203-
end
204-
typeof(function nif end).name.max_methods = UInt8(2)
205-
#! format: off
206-
207156
end

test/test_nif.jl

Lines changed: 0 additions & 49 deletions
This file was deleted.

test/unittest.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,3 @@ include("test_operator_construction_edgecases.jl")
129129
include("test_node_interface.jl")
130130
include("test_expression_math.jl")
131131
include("test_structured_expression.jl")
132-
include("test_nif.jl")

0 commit comments

Comments
 (0)