-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wip #13
base: main
Are you sure you want to change the base?
wip #13
Conversation
@joshday, what else do you want to get in here before merging? This eval isn't going to cause world age issues, right? My heuristic for that is "is this eval going to be in a loop any time soon?" |
Well I haven't actually run the tests yet to see if I broke anything... |
No world age issues with eval. You will be missing a necessary method for |
I tested this and found a bug where the constructor doesn't drop the I did this: for T in concrete_subtypes(AbstractTerm)
@eval function $(parentmodule(T)).$(T.name.name)(x::NamedTuple)
fields = filter(x -> x != :_type, fieldnames($T))
args = collect(x[fields])
@show args
$(parentmodule(T)).$(T.name.name)(args...)
end
end But the @show call isn't producing output and the constructor is still getting a It looks like JSON3 is invoking Stacktrace:
[1] construct(T::Type, args::NamedTuple{(:_type, :name, :schema, :description, :schema_name, :model_version), Tuple{Symbol, Vararg{String, 5}}}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ StructTypes ~/.julia/packages/StructTypes/AK4aM/src/StructTypes.jl:327
[2] construct(T::Type, args::NamedTuple{(:_type, :name, :schema, :description, :schema_name, :model_version), Tuple{Symbol, Vararg{String, 5}}})
@ StructTypes ~/.julia/packages/StructTypes/AK4aM/src/StructTypes.jl:327
[3] #read#44
@ ~/.julia/packages/JSON3/L8Yfy/src/structs.jl:435 [inlined]
[4] read(::StructTypes.CustomStruct, buf::Base.CodeUnits{UInt8, String}, pos::Int64, len::Int64, b::UInt8, ::Type{Header})
@ JSON3 ~/.julia/packages/JSON3/L8Yfy/src/structs.jl:432
[5] (::JSON3.StructClosure{Base.CodeUnits{UInt8, String}, NamedTuple{(), Tuple{}}})(i::Int64, nm::Symbol, TT::Type; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ JSON3 ~/.julia/packages/JSON3/L8Yfy/src/structs.jl:557 I also deleted a call to |
Got the example at https://algebraicjulia.github.io/SyntacticModels.jl/dev/generated/uwd_examples/ working
The cool thing is that the code I've added (Moved to SyntacticModels.jl from SyntacticModelsBase.jl) should make every struct created via MLStyle work out of the box. You don't need to add StructTypes boilerplate anymore.
The bummer is that I had to use
@eval
to do it. It's possible to do all the StructTypes stuff without using eval except for MLStyle-generated structs that only have one field.My editor deleted whitespace at the end of lines...making the diff artificially bigger.