|
414 | 414 |
|
415 | 415 | subsumes_index(i::Colon, ::Colon) = error("Colons cannot be subsumed")
|
416 | 416 | subsumes_index(i, ::Colon) = error("Colons cannot be subsumed")
|
| 417 | +# Necessary to avoid ambiguity errors. |
| 418 | +subsumes_index(::AbstractVector, ::Colon) = error("Colons cannot be subsumed") |
417 | 419 | subsumes_index(i::Colon, j) = true
|
418 | 420 | subsumes_index(i::AbstractVector, j) = issubset(j, i)
|
419 | 421 | subsumes_index(i, j) = i == j
|
@@ -520,11 +522,11 @@ julia> x = (a = [1.0 2.0; 3.0 4.0; 5.0 6.0], );
|
520 | 522 | julia> @varname(x.a[1:end, end][:], true)
|
521 | 523 | x.a[1:3,2][:]
|
522 | 524 |
|
523 |
| -julia> @varname(x.a[end]) |
| 525 | +julia> @varname(x.a[end], false) # disable concretization |
524 | 526 | ERROR: LoadError: Variable name `x.a[end]` is dynamic and requires concretization!
|
525 | 527 | [...]
|
526 | 528 |
|
527 |
| -julia> @varname(x.a[end], true) |
| 529 | +julia> @varname(x.a[end]) # concretization occurs by default if deemed necessary |
528 | 530 | x.a[6]
|
529 | 531 |
|
530 | 532 | julia> # Note that "dynamic" here refers to usage of `begin` and/or `end`,
|
@@ -575,12 +577,13 @@ julia> x = (a = [(b = rand(2), )], ); getlens(@varname(x.a[1].b[end], true))
|
575 | 577 | Using `begin` in an indexing expression to refer to the first index requires at least
|
576 | 578 | Julia 1.5.
|
577 | 579 | """
|
578 |
| -macro varname(expr::Union{Expr,Symbol}, concretize::Bool=false) |
| 580 | +macro varname(expr::Union{Expr,Symbol}, concretize::Bool=Setfield.need_dynamic_lens(expr)) |
579 | 581 | return varname(expr, concretize)
|
580 | 582 | end
|
581 | 583 |
|
582 |
| -varname(sym::Symbol, concretize=false) = :($(AbstractPPL.VarName){$(QuoteNode(sym))}()) |
583 |
| -function varname(expr::Expr, concretize=false) |
| 584 | +varname(sym::Symbol) = :($(AbstractPPL.VarName){$(QuoteNode(sym))}()) |
| 585 | +varname(sym::Symbol, _) = varname(sym) |
| 586 | +function varname(expr::Expr, concretize=Setfield.need_dynamic_lens(expr)) |
584 | 587 | if Meta.isexpr(expr, :ref) || Meta.isexpr(expr, :.)
|
585 | 588 | # Split into object/base symbol and lens.
|
586 | 589 | sym_escaped, lens = Setfield.parse_obj_lens(expr)
|
|
0 commit comments