Drasil icon indicating copy to clipboard operation
Drasil copied to clipboard

WIP: `declareHasChunkRefs`: Generate instances of `HasChunkRefs` where possible

Open balacij opened this issue 1 month ago • 3 comments

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

  1. Convert all -- FIXME: chunkRefs should actually collect the referenced chunks to declareHasChunkRefs ''Ty splices.
  2. Instantiate HasChunkRefs for all chunk atoms.
  3. Write more code comments!
  4. Test!
  5. I suppose this PR could also automate generating instances of HasChunkRefs for all of our chunk atoms as well... test?

balacij avatar Nov 20 '25 21:11 balacij

Pausing work on this until #4489 has resolved.

balacij avatar Nov 27 '25 21:11 balacij

Latest force-push is for rebasing atop main.

balacij avatar Dec 02 '25 22:12 balacij

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.

balacij avatar Dec 06 '25 04:12 balacij

#4489 is now merged, so I guess work on this can re-start?

JacquesCarette avatar Dec 10 '25 17:12 JacquesCarette

Since @Xinlu-Y has based 2 PRs on top of this one (indirectly), it becomes important that this gets resolved sooner rather than later.

JacquesCarette avatar Dec 10 '25 17:12 JacquesCarette