@@ -5,6 +5,8 @@ eltypes(::Type{T}) where {T<:Tuple} =
5
5
tuple_type_cons (eltype (tuple_type_head (T)), eltypes (tuple_type_tail (T)))
6
6
eltypes (:: Type{NamedTuple{K, V}} ) where {K, V} = eltypes (V)
7
7
8
+ Base. @pure SkipConstructor (:: Type ) = false
9
+
8
10
@generated function get_ith (s:: StructArray{T} , I... ) where {T}
9
11
args = []
10
12
for key in fields (T)
31
33
end
32
34
end
33
35
34
- createinstance (:: Type{T} , args... ) where {T} = T (args... )
36
+ function createinstance (:: Type{T} , args... ) where {T}
37
+ SkipConstructor (T) ? unsafe_createinstance (T, args... ) : T (args... )
38
+ end
39
+
35
40
createinstance (:: Type{T} , args... ) where {T<: Union{Tuple, NamedTuple} } = T (args)
36
41
42
+ @generated function unsafe_createinstance (:: Type{T} , args... ) where {T}
43
+ v = fieldnames (T)
44
+ new_tup = Expr (:(= ), Expr (:tuple , v... ), :args )
45
+ construct = Expr (:new , :T , (:(convert (fieldtype (T, $ (Expr (:quote , sym))), $ sym)) for sym in v). .. )
46
+ Expr (:block , new_tup, construct)
47
+ end
48
+
37
49
createtype (:: Type{T} , :: Type{C} ) where {T<: NamedTuple{N} , C} where {N} = NamedTuple{N, C}
38
50
createtype (:: Type{T} , :: Type{C} ) where {T, C} = T
0 commit comments