Skip to content

Demo: Switch Sentence's SyCh constructor from UID to UIDRefs.#4716

Draft
balacij wants to merge 1 commit intomainfrom
syChUIDRef
Draft

Demo: Switch Sentence's SyCh constructor from UID to UIDRefs.#4716
balacij wants to merge 1 commit intomainfrom
syChUIDRef

Conversation

@balacij
Copy link
Collaborator

@balacij balacij commented Jan 30, 2026

Contributes to #4541.

This PR already needs to be broken up, but it's helpful to have it live as a PR that I can potentially re-purpose.

Comment on lines 33 to +39
-- | Find a chunk by a 'UIDRef', erroring if not found.
unhideOrErr :: IsChunk t => UIDRef t -> ChunkDB -> t
unhideOrErr tu cdb = fromMaybe (error "Typed UID dereference failed.") (unhide tu cdb)
unhideOrErr tu cdb = fromMaybe (error $ "Typed UID dereference failed for UID: " ++ show (raw tu)) (unhide tu cdb)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These messages just need to be upgraded a bit.

Comment on lines +33 to +35
-- | Get the raw 'UID' from a 'UIDRef'.
raw :: UIDRef t -> UID
raw (UIDRef u) = u
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Being able to dump the UID from a UIDRef is helpful, in particular in the case of quantities in Drasil because: (a) we have many 'quantity' types, but (b) only insert a single variant of them (DefinedQuantityDicts) in the ChunkDB, so (c) de-referencing will always expect to look up a D-Q-D-. But I think we should be able to avoid exposing raw.

IMs :: [Sentence] -> Fields -> [InstanceModel] -> DerivationDisplay -> SCSSub
-- | Constraints.
Constraints :: (HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => Sentence -> [c] -> SCSSub
Constraints :: (IsChunk c, HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => Sentence -> [c] -> SCSSub
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We should switch all HasUID usage in drasil-lang to IsChunk.

getUIDs (Ch TermStyle _ _) = []
getUIDs (Ch PluralTerm _ _) = []
getUIDs (SyCh a) = [a]
getUIDs (SyCh a) = [raw a]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This function now becomes tricky. What should the output type be? Previously: getUIDs :: Sentence -> [UID].

It is used as part of chunkRefs. Does this mean we need to re-design chunkRefs a bit? Should HasChunkRefs give us UnitypedUIDRefs instead of raw UIDs?

Comment on lines +65 to +71
-- | Look up a symbol given a chunk database and a 'UID' associated with the
-- symbol. Hack: Always uses 'DefinedQuantityDict' as the chunk type to look up,
-- despite that not being the _actual type_ of the chunk being looked up.
lookupSymb :: (IsChunk t, HasSymbol t) => PrintingInformation -> UIDRef t -> Symbol
lookupSymb pinfo u = sytyF (pinfo ^. stg) (findOrErr (raw u) (pinfo ^. sysdb) :: DefinedQuantityDict)
where sytyF Equational = eqSymb
sytyF Implementation = codeSymb
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

findOrErr (raw u) (pinfo ^. sysdb) :: DefinedQuantityDict here ignores the t type parameter! It could be looking up anything but we need to always resolve it to a DefinedQuantityDict here because: we only insert DefinedQuantityDicts (extract from other 'quantity'-like types) in the ChunkDB.

balacij added a commit that referenced this pull request Jan 31, 2026
This will simplify work necessary for re-writing #4716.

As a result of this, it was sensible to also replace `HasUID` usage in
`NamedIdea` to `IsChunk` as well (this results in a smaller diff, and is
sensible; `UID`s should be best kept as 'secret' as possible, even
though this doesn't really do that).
balacij added a commit that referenced this pull request Feb 1, 2026
This will simplify work necessary for re-writing #4716.

As a result of this, it was sensible to also replace `HasUID` usage in
`NamedIdea` to `IsChunk` as well (this results in a smaller diff, and is
sensible; `UID`s should be best kept as 'secret' as possible, even
though this doesn't really do that).
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.

1 participant