Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions clash-protocols/src/Data/Constraint/Nat/Extra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ leModulusDivisor :: forall a b. (1 <= b) => Dict (Mod a b + 1 <= b)
leModulusDivisor = unsafeCoerce (Dict :: Dict (0 <= 0))

-- | if (1 <= a) and (1 <= b) then (1 <= DivRU a b)
strictlyPositiveDivRu :: forall a b. (1 <= a, 1 <= b) => Dict (1 <= DivRU a b)
strictlyPositiveDivRu = unsafeCoerce (Dict :: Dict (0 <= 0))
strictlyPositiveDivRu ::
forall a b.
(1 <= a, 1 <= b) =>
-- | XXX: The 'Constraint' equality is there to work around
-- issue github.com/clash-lang/ghc-typelits-extra/issues/68.
Dict ((1 <= DivRU a b) ~ (() :: Constraint))
strictlyPositiveDivRu = unsafeCoerce (Dict :: Dict (() ~ ()))

-- | if (1 <= a) then (b <= ceil(b/a) * a)
leTimesDivRu :: forall a b. (1 <= a) => Dict (b <= a * DivRU b a)
Expand Down
4 changes: 3 additions & 1 deletion clash-protocols/src/Protocols/PacketStream/Packetizers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ packetizeFromDfT ::
(KnownNat headerBytes) =>
(KnownNat dataWidth) =>
(1 <= dataWidth) =>
(1 <= headerBytes `DivRU` dataWidth) =>
-- \| XXX: The 'Constraint' equality is there to work around
Copy link
Member

@rowanG077 rowanG077 Jan 7, 2026

Choose a reason for hiding this comment

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

I think this will force users to have both ((1 <= headerBytes DivRU dataWidth) ~ (() :: Constraint)) which is confusing. I think it's probably better to have a constraintImpliesUnitConstraint :: forall a. a => Dict (a ~ (() :: Constraint)) and apply that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, makes sense to me

Copy link
Member Author

Choose a reason for hiding this comment

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

I talked to Christiaan in the office btw, hence skipping the review. Glad you caught it though.

-- issue github.com/clash-lang/ghc-typelits-extra/issues/68.
((1 <= headerBytes `DivRU` dataWidth) ~ (() :: Constraint)) =>
((dataWidth + 1) <= headerBytes) =>
-- | Mapping from `Df` input to output `_meta`
(a -> metaOut) ->
Expand Down
Loading