Skip to content

Commit 6546c49

Browse files
committed
Merge branch 'master' into tor/use-gensym-in-setmacro
2 parents cb1d984 + 2d3c9f7 commit 6546c49

File tree

6 files changed

+101
-37
lines changed

6 files changed

+101
-37
lines changed

.github/workflows/CI.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: CI
2+
on:
3+
- push
4+
- pull_request
5+
jobs:
6+
test:
7+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
version:
13+
- 1.0
14+
- 1
15+
- 'nightly'
16+
os:
17+
- ubuntu-latest
18+
# - macOS-latest
19+
- windows-latest
20+
arch:
21+
- x64
22+
steps:
23+
- uses: actions/checkout@v2
24+
- uses: julia-actions/setup-julia@v1
25+
with:
26+
version: ${{ matrix.version }}
27+
arch: ${{ matrix.arch }}
28+
- uses: actions/cache@v1
29+
env:
30+
cache-name: cache-artifacts
31+
with:
32+
path: ~/.julia/artifacts
33+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
34+
restore-keys: |
35+
${{ runner.os }}-test-${{ env.cache-name }}-
36+
${{ runner.os }}-test-
37+
${{ runner.os }}-
38+
- uses: julia-actions/julia-buildpkg@latest
39+
- uses: julia-actions/julia-runtest@latest
40+
docs:
41+
name: Documentation
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v2
45+
- uses: julia-actions/setup-julia@v1
46+
with:
47+
version: 1
48+
- run: |
49+
julia --project=docs -e '
50+
using Pkg
51+
Pkg.develop(PackageSpec(path=pwd()))
52+
Pkg.instantiate()'
53+
- run: |
54+
julia --project=docs -e '
55+
using Documenter: doctest
56+
using Setfield
57+
doctest(Setfield)'
58+
- run: julia --project=docs docs/make.jl
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

.travis.yml

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

Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Setfield"
22
uuid = "efcf1570-3423-57d1-acb7-fd33fddbac46"
3-
version = "0.7.0"
3+
version = "0.7.1"
44

55
[deps]
66
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
@@ -26,4 +26,3 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2626

2727
[targets]
2828
test = ["Test", "Documenter", "PerformanceTestTools", "QuickTypes", "StaticArrays", "BenchmarkTools", "InteractiveUtils", "StaticNumbers"]
29-

src/sugar.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,35 @@ foldtree(op, init, x) = op(init, x)
6161
foldtree(op, init, ex::Expr) =
6262
op(foldl((acc, x) -> foldtree(op, acc, x), ex.args; init=init), ex)
6363

64-
need_dynamic_lens(ex) =
65-
foldtree(false, ex) do yes, x
66-
yes || x === :end || x === :_
67-
end
64+
const HAS_BEGIN_INDEXING = VERSION v"1.5.0-DEV.666"
6865

69-
replace_underscore(ex, to) = postwalk(x -> x === :_ ? to : x, ex)
66+
function need_dynamic_lens(ex)
67+
return foldtree(false, ex) do yes, x
68+
(yes || x === :end || (HAS_BEGIN_INDEXING && x === :begin) || x === :_)
69+
end
70+
end
7071

7172
function lower_index(collection::Symbol, index, dim)
7273
if isexpr(index, :call)
7374
return Expr(:call, lower_index.(collection, index.args, dim)...)
74-
elseif index === :end
75+
elseif (index === :end)
7576
if dim === nothing
7677
return :($(Base.lastindex)($collection))
7778
else
7879
return :($(Base.lastindex)($collection, $dim))
7980
end
81+
elseif HAS_BEGIN_INDEXING && (index === :begin)
82+
if dim === nothing
83+
return :($(Base.firstindex)($collection))
84+
else
85+
return :($(Base.firstindex)($collection, $dim))
86+
end
8087
end
8188
return index
8289
end
8390

91+
replace_underscore(ex, to) = postwalk(x -> x === :_ ? to : x, ex)
92+
8493
function parse_obj_lenses_composite(lensexprs::Vector)
8594
if isempty(lensexprs)
8695
return esc(:_), ()

test/dynamiclens_begin.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
l = @lens _[begin]
2+
@test l isa Setfield.DynamicIndexLens
3+
obj = (1,2,3)
4+
@test get(obj, l) == 1
5+
@test set(obj, l, true) == (true,2,3)
6+
7+
l = @lens _[2*begin]
8+
@test l isa Setfield.DynamicIndexLens
9+
obj = (1,2,3)
10+
@test get(obj, l) == 2
11+
@test set(obj, l, true) == (1,true,3)
12+
13+
one = 1
14+
plustwo(x) = x + 2
15+
l = @lens _.a[plustwo(begin) - one].b
16+
obj = (a=(1, (a=10, b=20), 3), b=4)
17+
@test get(obj, l) == 20
18+
@test set(obj, l, true) == (a=(1, (a=10, b=true), 3), b=4)

test/test_core.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ end
281281
obj = (a=(1, (a=10, b=20), 3), b=4)
282282
@test get(obj, l) == 20
283283
@test set(obj, l, true) == (a=(1, (a=10, b=true), 3), b=4)
284+
285+
if Setfield.HAS_BEGIN_INDEXING
286+
# Need to keep this in a separate file since `begin` won't parse
287+
# on older Julia versions.
288+
include("dynamiclens_begin.jl")
289+
end
284290
end
285291

286292
@testset "StaticNumbers" begin

0 commit comments

Comments
 (0)