Skip to content

Commit

Permalink
add NFData instance for Core.Module
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira authored and paulcadman committed Nov 8, 2024
1 parent ca56b6b commit 62927b2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Juvix/Compiler/Core/Data/Module.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ data Module = Module
-- B will be in the imports table of M nonetheless.
_moduleImportsTable :: InfoTable
}
deriving stock (Generic)

instance NFData Module

makeLenses ''Module

Expand Down
6 changes: 6 additions & 0 deletions src/Juvix/Compiler/Core/Info.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ newtype Info = Info
}
deriving newtype (Semigroup, Monoid)

-- | NOTE the NFData instance for Info is a noop. I don't think it's possible to
-- provide an NFData instance for it because a Dynamic can't have an instance.
-- Still, having this instance is useful so we can derive NFData for Node.
instance NFData Info where
rnf _info = ()

type Key = Proxy

makeLenses ''Info
Expand Down
4 changes: 3 additions & 1 deletion src/Juvix/Compiler/Core/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ data Node
{ _closureEnv :: !Env,
_closureNode :: !Node
}
deriving stock (Eq)
deriving stock (Eq, Generic)

instance NFData Node

-- Other things we might need in the future:
-- - laziness annotations (converting these to closure/thunk creation should be
Expand Down
22 changes: 22 additions & 0 deletions src/Juvix/Compiler/Core/Language/Nodes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ data Match' i a = Match
_matchValues :: !(NonEmpty a),
_matchBranches :: ![MatchBranch' i a]
}
deriving stock (Generic)

-- | The patterns introduce binders from left to right, with the binder for a
-- constructor before the binders for the subpatterns, e.g., matching on the
Expand All @@ -185,15 +186,18 @@ data MatchBranch' i a = MatchBranch
_matchBranchPatterns :: !(NonEmpty (Pattern' i a)),
_matchBranchRhs :: !(MatchBranchRhs' i a)
}
deriving stock (Generic)

data Pattern' i a
= PatWildcard (PatternWildcard' i a)
| PatConstr (PatternConstr' i a)
deriving stock (Generic)

data PatternWildcard' i a = PatternWildcard
{ _patternWildcardInfo :: i,
_patternWildcardBinder :: Binder' a
}
deriving stock (Generic)

data PatternConstr' i a = PatternConstr
{ _patternConstrInfo :: i,
Expand All @@ -202,22 +206,26 @@ data PatternConstr' i a = PatternConstr
_patternConstrTag :: !Tag,
_patternConstrArgs :: ![Pattern' i a]
}
deriving stock (Generic)

data MatchBranchRhs' i a
= MatchBranchRhsExpression !a
| MatchBranchRhsIfs !(NonEmpty (SideIfBranch' i a))
deriving stock (Generic)

data SideIfBranch' i a = SideIfBranch
{ _sideIfBranchInfo :: i,
_sideIfBranchCondition :: !a,
_sideIfBranchBody :: !a
}
deriving stock (Generic)

-- | Useful for unfolding Pi
data PiLhs' i a = PiLhs
{ _piLhsInfo :: i,
_piLhsBinder :: Binder' a
}
deriving stock (Generic)

-- | Dependent Pi-type. Compilation-time only. Pi implicitly introduces a binder
-- in the body, exactly like Lambda. So `Pi info ty body` is `Pi x : ty .
Expand Down Expand Up @@ -335,6 +343,20 @@ instance (Serialize i) => Serialize (Univ' i)

instance (NFData i) => NFData (Univ' i)

instance (NFData i, NFData a) => NFData (PatternWildcard' i a)

instance (NFData i, NFData a) => NFData (PatternConstr' i a)

instance (NFData i, NFData a) => NFData (Pattern' i a)

instance (NFData i, NFData a) => NFData (MatchBranchRhs' i a)

instance (NFData i, NFData a) => NFData (SideIfBranch' i a)

instance (NFData i, NFData a) => NFData (MatchBranch' i a)

instance (NFData i, NFData a) => NFData (Match' i a)

instance (Serialize i) => Serialize (TypePrim' i)

instance (NFData i) => NFData (TypePrim' i)
Expand Down

0 comments on commit 62927b2

Please sign in to comment.