From 2ae7a62d6e4300a2ae3c017111ac18a53a376fe9 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 23 Oct 2024 16:14:34 +0200 Subject: [PATCH 1/2] Enable idiomatic record.pt syntax --- src/all_implementations.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/all_implementations.jl b/src/all_implementations.jl index 6c159e1..e3a6a5a 100644 --- a/src/all_implementations.jl +++ b/src/all_implementations.jl @@ -2093,11 +2093,16 @@ slot( layout::Record{FIELDS,CONTENTS}, f::Symbol, ) where {FIELDS,CONTENTS<:Base.Tuple{Vararg{Content}}} + + Base.getindex( + layout::AwkwardArray.Record, + f::Symbol, + ) = getfield(layout, :array).contents[f][getfield(layout, :at)] """ Base.getindex( - layout::Record{FIELDS,CONTENTS}, - f::Symbol, -) where {FIELDS,CONTENTS<:Base.Tuple{Vararg{Content}}} = layout.array.contents[f][layout.at] + layout::AwkwardArray.Record, + f::Symbol, + ) = getfield(layout, :array).contents[f][getfield(layout, :at)] """ Base.:(==)( From b5ec98571b6f5e5b71873d87532daeb4ece93f56 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Wed, 23 Oct 2024 17:06:12 +0200 Subject: [PATCH 2/2] more getfield(layout, :array) --- src/all_implementations.jl | 58 ++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/src/all_implementations.jl b/src/all_implementations.jl index e3a6a5a..177ee4b 100644 --- a/src/all_implementations.jl +++ b/src/all_implementations.jl @@ -2089,21 +2089,18 @@ slot( ) where {FIELDS,CONTENTS<:Base.Tuple{Vararg{Content}},BEHAVIOR} = layout[f] """ - Base.getindex( - layout::Record{FIELDS,CONTENTS}, - f::Symbol, - ) where {FIELDS,CONTENTS<:Base.Tuple{Vararg{Content}}} - Base.getindex( layout::AwkwardArray.Record, f::Symbol, - ) = getfield(layout, :array).contents[f][getfield(layout, :at)] + ) """ Base.getindex( layout::AwkwardArray.Record, f::Symbol, ) = getfield(layout, :array).contents[f][getfield(layout, :at)] +Base.getproperty(layout::Record, f::Symbol) = layout[f] + """ Base.:(==)( layout1::RecordArray{FIELDS,CONTENTS1}, @@ -2393,15 +2390,16 @@ end """ Base.getindex( - layout::SlotRecord{CONTENTS}, + layout::SlotRecord, f::Int64, - ) where {CONTENTS<:Base.Tuple{Vararg{Content}}} + ) """ Base.getindex( - layout::SlotRecord{CONTENTS}, + layout::SlotRecord, f::Int64, -) where {CONTENTS<:Base.Tuple{Vararg{Content}}} = - layout.array.contents[f][layout.at] +) = getfield(layout, :array).contents[f][getfield(layout, :at)] + +Base.getproperty(layout::SlotRecord, f::Symbol) = layout[f] """ Base.:(==)( @@ -2450,7 +2448,7 @@ function Base.:(==)( CONTENTS1<:Base.Tuple{Vararg{Content,N}}, CONTENTS2<:Base.Tuple{Vararg{Content,N}}, } - for i in eachindex(layout1.array.contents) # same number of indexes by type constraint + for i in eachindex(getfield(layout1, :array).contents) # same number of indexes by type constraint if layout1[i] != layout2[i] # compare tuple items return false end @@ -4007,8 +4005,8 @@ Base.getindex(layout::UnionArray, f::Symbol) = function Base.push!(special::Specialization, input) tmp = length(special.tagged) push!(special.tagged, input) - push!(special.array.tags, special.tag - firstindex(special.array.contents)) - push!(special.array.index, tmp) + push!(getfield(special, :array).tags, special.tag - firstindex(getfield(special, :array).contents)) + push!(getfield(special, :array).index, tmp) special end @@ -4028,8 +4026,8 @@ end function end_list!(special::Specialization) tmp = length(special.tagged) end_list!(special.tagged) - push!(special.array.tags, special.tag - firstindex(special.array.contents)) - push!(special.array.index, tmp) + push!(getfield(special, :array).tags, special.tag - firstindex(getfield(special, :array).contents)) + push!(getfield(special, :array).index, tmp) special end @@ -4039,8 +4037,8 @@ end function end_record!(special::Specialization) tmp = length(special.tagged) end_record!(special.tagged) - push!(special.array.tags, special.tag - firstindex(special.array.contents)) - push!(special.array.index, tmp) + push!(getfield(special, :array).tags, special.tag - firstindex(getfield(special, :array).contents)) + push!(getfield(special, :array).index, tmp) special end @@ -4050,8 +4048,8 @@ end function end_tuple!(special::Specialization) tmp = length(special.tagged) end_tuple!(special.tagged) - push!(special.array.tags, special.tag - firstindex(special.array.contents)) - push!(special.array.index, tmp) + push!(getfield(special, :array).tags, special.tag - firstindex(getfield(special, :array).contents)) + push!(getfield(special, :array).index, tmp) special end @@ -4065,8 +4063,8 @@ function push_null!( ) where {ARRAY<:UnionArray,TAGGED<:OptionType} tmp = length(special.tagged) push_null!(special.tagged) - push!(special.array.tags, special.tag - firstindex(special.array.contents)) - push!(special.array.index, tmp) + push!(getfield(special, :array).tags, special.tag - firstindex(getfield(special, :array).contents)) + push!(getfield(special, :array).index, tmp) special end @@ -4076,8 +4074,8 @@ end function push_dummy!(special::Specialization) tmp = length(special.tagged) push_dummy!(special.tagged) - push!(special.array.tags, special.tag - firstindex(special.array.contents)) - push!(special.array.index, tmp) + push!(getfield(special, :array).tags, special.tag - firstindex(getfield(special, :array).contents)) + push!(getfield(special, :array).index, tmp) special end @@ -4241,7 +4239,7 @@ to_vector( view::Bool = false, na::Union{Missing,Nothing} = missing, ) where {FIELDS,CONTENTS<:Base.Tuple{Vararg{Content}}} = NamedTuple{FIELDS}( - to_vector_or_scalar(record.array.contents[f][record.at], view = view, na = na) for + to_vector_or_scalar(getfield(record, :array).contents[f][record.at], view = view, na = na) for f in FIELDS ) @@ -4258,7 +4256,7 @@ to_vector( na::Union{Missing,Nothing} = missing, ) where {CONTENTS<:Base.Tuple{Vararg{Content}}} = Base.Tuple( to_vector_or_scalar(content[record.at], view = view, na = na) for - content in tuple.array.contents + content in getfield(tuple, :array).contents ) """ @@ -4736,7 +4734,7 @@ function _horizontal(data::Any, limit_cols::Int) limit_cols -= 5 # anticipate the ", ..." which = 0 - fields = keys(data.array.contents) + fields = keys(getfield(data, :array).contents) for field in fields key = Base.string(field) @@ -4803,7 +4801,7 @@ function _horizontal(data::Any, limit_cols::Int) limit_cols -= 5 # anticipate the ", ..." which = 0 - fields = eachindex(data.array.contents) + fields = eachindex(getfield(data, :array).contents) for field in fields if which == 0 for_comma = 0 @@ -4921,7 +4919,7 @@ function _vertical(data::Union{Content,Record,Tuple}, limit_rows::Int, limit_col front = Vector{String}([]) # 1-indexed which = 0 - fields = keys(data.array.contents) + fields = keys(getfield(data, :array).contents) for field in fields key = Base.string(field) if occursin(r"^[A-Za-z_][A-Za-z_0-9]*$", key) @@ -4962,7 +4960,7 @@ function _vertical(data::Union{Content,Record,Tuple}, limit_rows::Int, limit_col front = Vector{String}([]) # 1-indexed which = 0 - fields = eachindex(data.array.contents) + fields = eachindex(getfield(data, :array).contents) for field in fields (_, strs) = _horizontal(data[field], limit_cols - 2) push!(front, join(strs, ""))