Skip to content

Conversation

gnumonik
Copy link
Collaborator

We need these to write the code generator, unfortunately.

This is a bit of a mess (partly due to me needing to get this done ASAP today) in that we have

module Covenant.Internal.Term
  ( Id (Id, UnId, UnsafeId),
    Arg (Arg, UnArg, UnsafeArg),
   ...
  )

We could remove the non-pattern constructor exports from there... but it'd require a decent amount of fix-up that I do not have the time to do right now. If you suggest it I will be happy to do that later/tomorrow.

@gnumonik gnumonik requested a review from kozross October 21, 2025 02:18
Copy link
Member

@kozross kozross left a comment

Choose a reason for hiding this comment

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

I think this warrants a minor version bump. Add @sinces to the pattern synonyms and (new) constructor names to go along with the Haddocks, and update the changelog.

Comment on lines +317 to +330
-- | This is the *safe* read-only pattern
pattern UnId :: Word64 -> Id
pattern UnId w <- Id w

-- | This is the *unsafe* pattern.
-- This should ONLY ever be used for tests and you should
-- NEVER use this to construct Ids manually.
pattern UnsafeId :: Word64 -> Id
pattern UnsafeId w = Id w

{-# COMPLETE UnId #-}

{-# COMPLETE UnsafeId #-}

Copy link
Member

Choose a reason for hiding this comment

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

You can do it like this. In Covenant.Internal.Term, define

newtype Id = UnsafeId Word64
...

Export Id(..). Then, in Covenant.ASG, import Id (UnsafeId), then define

pattern UnId :: Word64 -> Id
pattern UnId w64 <- UnsafeId w64

{-# COMPLETE UnId #-}

Then export Id (UnId) from Covenant.ASG.

Comment on lines +356 to +370
-- | This is the 'safe' pattern which can be used anywhere to
-- deconstruct an arg
pattern UnArg :: DeBruijn -> Index "arg" -> Arg
pattern UnArg db i <- Arg db i _

-- | This is the *unsafe* pattern, which should NEVER
-- be used to manually construct 'Arg's in an AST, and should
-- ONLY ever be used for tests.
pattern UnsafeArg :: DeBruijn -> Index "arg" -> ValT AbstractTy -> Arg
pattern UnsafeArg db i t = Arg db i t

{-# COMPLETE UnArg #-}

{-# COMPLETE UnsafeArg #-}

Copy link
Member

Choose a reason for hiding this comment

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

Same story.

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.

2 participants