From a0ab4e723e4bf4a9d3033d743a9f1ae15eadd239 Mon Sep 17 00:00:00 2001 From: OlivierHnt <38465572+OlivierHnt@users.noreply.github.com> Date: Tue, 27 Apr 2021 12:52:37 -0400 Subject: [PATCH 1/4] Update tuple.jl --- base/tuple.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/base/tuple.jl b/base/tuple.jl index ad08bf42f5e1a..07480652a8fc6 100644 --- a/base/tuple.jl +++ b/base/tuple.jl @@ -52,11 +52,10 @@ function setindex(x::Tuple, v, i::Integer) _setindex(v, i, x...) end -function _setindex(v, i::Integer, first, tail...) +function _setindex(v, i::Integer, args...) @_inline_meta - return (ifelse(i == 1, v, first), _setindex(v, i - 1, tail...)...) + return ntuple(j -> ifelse(j == i, v, args[j]), length(args)) end -_setindex(v, i::Integer) = () ## iterating ## From eb5b4638bc8e9a026f23d5d9509bf03a25abcabc Mon Sep 17 00:00:00 2001 From: OlivierHnt <38465572+OlivierHnt@users.noreply.github.com> Date: Thu, 29 Apr 2021 14:33:33 -0400 Subject: [PATCH 2/4] Add inference tests for `_setindex` --- test/tuple.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/tuple.jl b/test/tuple.jl index 7c274851ea555..f57d33e1d93b2 100644 --- a/test/tuple.jl +++ b/test/tuple.jl @@ -522,6 +522,9 @@ end @test Base.setindex((1, 2, 4), 4, true) === (4, 2, 4) @test_throws BoundsError Base.setindex((1, 2), 2, false) + + f() = Base._setindex(9, 1, (1:1, 2:2, 3:3)...) + @test @inferred(f()) == (9, 2:2, 3:3) end @testset "inferrable range indexing with constant values" begin From 5c174cfcbc8dc53631e0411341dd52ff21c21581 Mon Sep 17 00:00:00 2001 From: OlivierHnt <38465572+OlivierHnt@users.noreply.github.com> Date: Thu, 29 Apr 2021 14:44:53 -0400 Subject: [PATCH 3/4] Fix trailing white space issue --- test/tuple.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tuple.jl b/test/tuple.jl index f57d33e1d93b2..0d43756566756 100644 --- a/test/tuple.jl +++ b/test/tuple.jl @@ -522,7 +522,7 @@ end @test Base.setindex((1, 2, 4), 4, true) === (4, 2, 4) @test_throws BoundsError Base.setindex((1, 2), 2, false) - + f() = Base._setindex(9, 1, (1:1, 2:2, 3:3)...) @test @inferred(f()) == (9, 2:2, 3:3) end From 9a03ed2a7787f0f2e960b9bd3963ba75d52d210f Mon Sep 17 00:00:00 2001 From: OlivierHnt <38465572+OlivierHnt@users.noreply.github.com> Date: Tue, 29 Jun 2021 18:07:59 -0400 Subject: [PATCH 4/4] Call `setindex`method --- test/tuple.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tuple.jl b/test/tuple.jl index 6ccff5963572d..9b44e421184d3 100644 --- a/test/tuple.jl +++ b/test/tuple.jl @@ -534,7 +534,7 @@ end @test Base.setindex((1, 2, 4), 4, true) === (4, 2, 4) @test_throws BoundsError Base.setindex((1, 2), 2, false) - f() = Base._setindex(9, 1, (1:1, 2:2, 3:3)...) + f() = Base.setindex((1:1, 2:2, 3:3), 9, 1) @test @inferred(f()) == (9, 2:2, 3:3) end