WIP: `declareHasChunkRefs`: Generate instances of `HasChunkRefs` where possible
Contributes to #4434 and #4349
WIP DESCRIPTION:
A Chunk (in the code) is defined by the following constraint:
-- | Constraint for anything that may be considered a valid chunk type.
type IsChunk a = (HasUID a, HasChunkRefs a, Typeable a)
Currently, none of our HasChunkRefs instances are meaningfully filled in (#4349). The goal of #4434 is to fill them in. The goal of this PR is to assist with #4434 by "automating the boring stuff." #4434 commonly contains code of the following form:
let ideaRefs = chunkRefs (c ^. idea)
defnRefs = collectSentenceRefs (c ^. defn')
domainRefs = S.fromList (cdom' c)
... = ...
in ideaRefs `S.union` defnRefs `S.union` domainRefs `S.union` ...
This PR introduces a bit of Generics- and TH-based automation to derive these 'boring' instances, for example those that merely take the union of the various atoms within a chunk.
TODOs
- Convert all
-- FIXME: chunkRefs should actually collect the referenced chunkstodeclareHasChunkRefs ''Tysplices. - Instantiate
HasChunkRefsfor all chunk atoms. - Write more code comments!
- Test!
- I suppose this PR could also automate generating instances of
HasChunkRefsfor all of our chunk atoms as well... test?
Pausing work on this until #4489 has resolved.
Latest force-push is for rebasing atop main.
We should be able to remove https://github.com/JacquesCarette/Drasil/blob/main/code/drasil-printers/lib/Language/Drasil/Debug/Print.hs in favour of a more generic approach similar to the one we take in this PR.
#4489 is now merged, so I guess work on this can re-start?
Since @Xinlu-Y has based 2 PRs on top of this one (indirectly), it becomes important that this gets resolved sooner rather than later.