Skip to content

declareHasChunkRefs: Generate instances of HasChunkRefs where possible#4476

Merged
JacquesCarette merged 10 commits intomainfrom
derivingHasChunkRefs
Dec 11, 2025
Merged

declareHasChunkRefs: Generate instances of HasChunkRefs where possible#4476
JacquesCarette merged 10 commits intomainfrom
derivingHasChunkRefs

Conversation

@balacij
Copy link
Collaborator

@balacij balacij commented Nov 20, 2025

Contributes to #4434 and #4349

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.

@balacij balacij requested a review from Xinlu-Y November 20, 2025 21:29
@balacij balacij changed the title WIP: Automate generating HasChunkRefs; declareChunkType WIP: Automate generating boring HasChunkRefs; declareHasChunkRefs Nov 20, 2025
@balacij balacij changed the title WIP: Automate generating boring HasChunkRefs; declareHasChunkRefs WIP: declareHasChunkRefs: Generate instances of HasChunkRefs where possible Nov 20, 2025
@balacij
Copy link
Collaborator Author

balacij commented Nov 27, 2025

Pausing work on this until #4489 has resolved.

balacij and others added 3 commits December 2, 2025 17:36
Reed suggested (and assisted in implementing) using 'deriving-via' rather than
'deriving-anyclass' as the strategy for sharing the default
implementation of `HasChunkRefs`.

Co-Authored-By: Reed Mullanix <reedmullanix@gmail.com>
@balacij balacij force-pushed the derivingHasChunkRefs branch from 388c0a3 to 07f54c9 Compare December 2, 2025 22:38
@balacij
Copy link
Collaborator Author

balacij commented Dec 2, 2025

Latest force-push is for rebasing atop main.

@balacij
Copy link
Collaborator Author

balacij commented Dec 6, 2025

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.

@Xinlu-Y Xinlu-Y mentioned this pull request Dec 9, 2025
@Xinlu-Y Xinlu-Y mentioned this pull request Dec 9, 2025
@JacquesCarette
Copy link
Owner

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

@JacquesCarette
Copy link
Owner

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

@balacij balacij changed the title WIP: declareHasChunkRefs: Generate instances of HasChunkRefs where possible declareHasChunkRefs: Generate instances of HasChunkRefs where possible Dec 11, 2025
Copy link
Collaborator Author

@balacij balacij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Once we convert external usage of UID to TypedUIDRef (excluding the times where a UID should actually indicate the UID of a chunk carrying said UID), we can also use deriveHasChunkRefs on our 'chunk atoms.' Furthermore, when this is done, we can also generate HasUID. Future work!
  2. After this PR, we can slowly convert the instance hasChunkRefs we currently have on our chunk types to declareHasChunkRefs (which I believe @Xinlu-Y wants to work on?).

For now, I'm content with this PR's scope.

Ready for review @JacquesCarette @Xinlu-Y ! Thank you!

@balacij balacij marked this pull request as ready for review December 11, 2025 19:35
@JacquesCarette JacquesCarette merged commit 774de56 into main Dec 11, 2025
5 checks passed
@JacquesCarette JacquesCarette deleted the derivingHasChunkRefs branch December 11, 2025 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants