Skip to content

Replace HasUID with IsChunk in drasil-lang type constraints#4718

Closed
Copilot wants to merge 4 commits intomainfrom
copilot/switch-hasuid-to-ischunk
Closed

Replace HasUID with IsChunk in drasil-lang type constraints#4718
Copilot wants to merge 4 commits intomainfrom
copilot/switch-hasuid-to-ischunk

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

Migrates all HasUID constraints in drasil-lang to IsChunk, strengthening the type system to require proper chunk dependency tracking via HasChunkRefs.

Background

IsChunk is a constraint alias combining three requirements:

type IsChunk a = (HasUID a, HasChunkRefs a, Typeable a)

Previously, many type signatures only required HasUID, allowing chunks without dependency tracking.

Changes

Added Missing HasChunkRefs Instances (9 types)

Types with HasUID but missing HasChunkRefs:

  • Code generation: CodeChunk, CodeVarChunk, CodeFuncChunk
  • Document structure: Section, DecRef
  • Chunk types: RelationConcept, UnitalChunk, CI, ConstrConcept, UncertQ, QDefinition

All instances use stub implementation per instructions:

instance HasChunkRefs X where
  chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.

Replaced Constraints in Type Signatures

Class constraints:

  • NamedIdea: class HasUID c => NamedIdea cclass IsChunk c => NamedIdea c
  • Referable: class (HasUID s, ...) => Referable sclass (IsChunk s, ...) => Referable s

Function constraints (24 functions across 7 modules):

-- Before
apply :: (HasUID f, HasSymbol f) => f -> [r] -> r
sy :: (HasUID c, HasSymbol c) => c -> r

-- After  
apply :: (IsChunk f, HasSymbol f) => f -> [r] -> r
sy :: (IsChunk c, HasSymbol c) => c -> r

Affected modules:

  • Drasil.Code.CodeExpr.Class (6 functions)
  • Language.Drasil.Expr.Class (5 functions)
  • Language.Drasil.Reference (5 functions)
  • Language.Drasil.ModelExpr.Class (2 functions)
  • Language.Drasil.DecoratedReference (2 functions)
  • Language.Drasil.Chunk.Eq (3 functions)
  • Language.Drasil.Sentence (1 function)

Impact

16 files modified. All changes are backwards compatible at the call site level—existing code satisfying HasUID constraints will continue to work if types also implement HasChunkRefs (which they now do).

Original prompt

This section details on the original issue you should resolve

<issue_title>Switch all HasUID usage in drasil-lang to IsChunk.</issue_title>
<issue_description>We should switch all HasUID usage in drasil-lang to IsChunk.

Originally posted by @balacij in #4716 (comment)
</issue_description>

<agent_instructions>All HasUID usage in drasil-lang and related packages really should be IsChunk. Go through all of them and replace them with IsChunk.

For any type (X) that does not satisfy IsChunk's HasChunkRefs constraint, you should instantiate it using the following TEMPLATE code underneath the definition of said type:

instance HasChunkRefs X where
  chunkRefs = const mempty -- FIXME: `chunkRefs` should actually collect the referenced chunks.

Do not try to fill in chunkRefs properly. Restrict yourself to only replacing X from the template, adding it in places as necessary.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 30, 2026 18:37
Co-authored-by: balacij <1627302+balacij@users.noreply.github.com>
Co-authored-by: balacij <1627302+balacij@users.noreply.github.com>
Copilot AI changed the title [WIP] Switch all HasUID usage in drasil-lang to IsChunk Replace HasUID with IsChunk in drasil-lang type constraints Jan 30, 2026
Copilot AI requested a review from balacij January 30, 2026 19:24
@balacij
Copy link
Collaborator

balacij commented Jan 31, 2026

Closing this in favour of restarting on my own using: #4723 and #4724 as a base.

@balacij balacij closed this Jan 31, 2026
@balacij balacij deleted the copilot/switch-hasuid-to-ischunk branch January 31, 2026 20:00
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.

Switch all HasUID usage in drasil-lang to IsChunk.

2 participants