AI Game Status Update – Removing Dynamic Dispatch from GBNF Limits
Published: 2024-03-26T19:08:31+01:00
This is a copy of a journal entry from the AI game page.
The AI game can now limit output using the gbnf_limit feature, but it requires dynamic trait objects for this. Rather than generating a so-called “limit struct” with proper concrete types, the code relies on using dynamic typing of anything that can produce a GbnfLimit. This makes the code easier to understand, but creating limit structs does is not ergonomic:
- Lots of Box::new.
- Performance implications of dynamic dispatch.
I am trying to fix this on a separate branch that is not yet uploaded to the Git repository, because it's a giant mess. I have made some progress, but I'm running into the limitations of Rust's (very powerful) generics system. Namely, blanket traits are not so specific: an impl for Option also counts as an impl for Option>. This can be solved by something called “trait specialization,” but that's an unstable nightly-only feature and has its own set of issues.
I have almost worked out a way to make the concrete types work. But much like the initial implementation of the GBNF grammar generator, I've sort of hit a roadblock due to trying to remove dynamic dispatch.
I've been spending my time creating gemfreely instead.
I hope to return to the AI game soon and get the dynamic dispatch fully removed from GBNF Limit code, so development on at least one interactive command can resume!
License: CC-BY-SA-4.0.
Written by: @[email protected]