Skip to content

Commit

Permalink
Use expression equivalence instead of Haskell equality
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Feb 3, 2025
1 parent ec0003c commit 5eaafc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Juvix/Compiler/Builtins/Anoma.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ checkAnomaByteArrayToAnomaContents f = do
byteArray <- getBuiltinNameScoper l BuiltinByteArray
nat_ <- getBuiltinNameScoper l BuiltinNat
unless
(ftype == (byteArray --> nat_))
(ftype === (byteArray --> nat_))
$ builtinsErrorText l "toAnomaContents must be of type ByteArray -> Nat"

checkAnomaByteArrayFromAnomaContents :: (Members '[Reader BuiltinsTable, Error ScoperError, NameIdGen] r) => AxiomDef -> Sem r ()
Expand All @@ -105,7 +105,7 @@ checkAnomaByteArrayFromAnomaContents f = do
byteArray <- getBuiltinNameScoper l BuiltinByteArray
nat_ <- getBuiltinNameScoper l BuiltinNat
unless
(ftype == (nat_ --> nat_ --> byteArray))
(ftype === (nat_ --> nat_ --> byteArray))
$ builtinsErrorText l "fromAnomaContents must be of type Nat -> Nat -> ByteArray"

checkAnomaSha256 :: (Members '[Reader BuiltinsTable, Error ScoperError, NameIdGen] r) => AxiomDef -> Sem r ()
Expand All @@ -115,7 +115,7 @@ checkAnomaSha256 f = do
byteArray <- getBuiltinNameScoper l BuiltinByteArray
nat_ <- getBuiltinNameScoper l BuiltinNat
unless
(ftype == (nat_ --> byteArray))
(ftype === (nat_ --> byteArray))
$ builtinsErrorText l "anomaSha256 must be of type Nat -> ByteArray"

checkResource :: (Members '[Reader BuiltinsTable, Error ScoperError] r) => InductiveDef -> Sem r ()
Expand Down Expand Up @@ -257,23 +257,23 @@ checkAnomaIsCommitment f = do
let l = getLoc f
nat_ <- getBuiltinNameScoper l BuiltinNat
bool_ <- getBuiltinNameScoper l BuiltinBool
unless (f ^. axiomType == (nat_ --> bool_)) $
unless (f ^. axiomType === (nat_ --> bool_)) $
builtinsErrorText l "isCommitment must be of type Nat -> Bool"

checkAnomaIsNullifier :: (Members '[Reader BuiltinsTable, Error ScoperError] r) => AxiomDef -> Sem r ()
checkAnomaIsNullifier f = do
let l = getLoc f
nat_ <- getBuiltinNameScoper l BuiltinNat
bool_ <- getBuiltinNameScoper l BuiltinBool
unless (f ^. axiomType == (nat_ --> bool_)) $
unless (f ^. axiomType === (nat_ --> bool_)) $
builtinsErrorText l "isNullifier must be of type Nat -> Bool"

checkAnomaSet :: (Members '[Error ScoperError] r) => AxiomDef -> Sem r ()
checkAnomaSet t = do
let ty = t ^. axiomType
l = getLoc t
u = ExpressionUniverse smallUniverseNoLoc
unless (ty == (u --> u)) $
unless (ty === (u --> u)) $
builtinsErrorText l "AnomaSet should have type: Type -> Type"

checkAnomaSetToList :: (Members '[Reader BuiltinsTable, Error ScoperError, NameIdGen] r) => AxiomDef -> Sem r ()
Expand Down
3 changes: 3 additions & 0 deletions src/Juvix/Compiler/Internal/Extra/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ matchExpressions = go
-- Soft free vars are allowed to be matched
isSoftFreeVar :: VarName -> Sem r Bool
isSoftFreeVar = asks . HashSet.member

go :: Expression -> Expression -> Sem r ()
go a b = case (a, b) of
(ExpressionIden ia, ExpressionIden ib) -> case (ia, ib) of
Expand Down Expand Up @@ -805,8 +806,10 @@ matchFunctionParameter pa pb = do
where
goParamType :: Expression -> Expression -> Sem r ()
goParamType ua ub = matchExpressions ua ub

goParamImplicit :: IsImplicit -> IsImplicit -> Sem r ()
goParamImplicit ua ub = unless (ua == ub) (throw @Text "implicit mismatch")

goParamName :: Maybe VarName -> Maybe VarName -> Sem r ()
goParamName (Just va) (Just vb) = addName va vb
goParamName _ _ = return ()
Expand Down

0 comments on commit 5eaafc8

Please sign in to comment.