Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement positivity checker #3057

Merged
merged 27 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
4 changes: 4 additions & 0 deletions src/Juvix/Compiler/Internal/Data/Name.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ type ConstrName = Name

type InductiveName = Name

type InductiveId = NameId

type InductiveParam = Name

fromConcreteSymbol :: Interval -> S.Symbol -> Name
fromConcreteSymbol loc s = fromConcreteSymbolPretty loc (S.symbolText s) s

Expand Down
2 changes: 2 additions & 0 deletions src/Juvix/Compiler/Internal/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ data NormalizedExpression = NormalizedExpression
}

makePrisms ''Expression
makePrisms ''MutualStatement

makeLenses ''SideIfBranch
makeLenses ''SideIfs
makeLenses ''CaseBranchRhs
Expand Down
40 changes: 40 additions & 0 deletions src/Juvix/Compiler/Internal/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import Juvix.Compiler.Internal.Data.NameDependencyInfo
import Juvix.Compiler.Internal.Data.TypedHole
import Juvix.Compiler.Internal.Language
import Juvix.Compiler.Internal.Pretty.Options
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.Positivity.Occurrences
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.CheckerNew.Arity qualified as New
import Juvix.Compiler.Store.Internal.Data.InfoTable
import Juvix.Data.CodeAnn
import Juvix.Data.Keyword.All qualified as Kw
import Juvix.Prelude
import Prettyprinter qualified as PP

doc :: (PrettyCode c) => Options -> c -> Doc Ann
doc opts =
Expand Down Expand Up @@ -407,6 +409,35 @@ instance PrettyCode TypedHole where
vars <- ppCode _typedHoleLocalVars
return (h <+> kwColon <+> ty <> kwAt <> vars)

instance PrettyCode Polarity where
ppCode = return . annotate AnnKeyword . pretty

instance (PrettyCode k, PrettyCode v) => PrettyCode (HashMap k v) where
ppCode m = do
res <- forM (HashMap.toList m) $ \(k, v) -> do
k' <- ppCode k
v' <- ppCode v
return (k' <+> "↦" <+> v')
return (bracesEncloseIndent res)

instance PrettyCode AppLhs where
ppCode = \case
AppVar v -> ppCode v
AppAxiom v -> ppCode v
AppInductive v -> ppCode v

instance PrettyCode FunctionSide where
ppCode = return . annotate AnnKeyword . pretty

instance PrettyCode Occurrences where
ppCode Occurrences {..} = do
ps <- ppCode _occurrences
return
( bracesEncloseIndent
[ header "occurrences" <+> kwAssign <+> ps
]
)

instance PrettyCode InfoTable where
ppCode tbl = do
inds <- ppCode (HashMap.keys (tbl ^. infoInductives))
Expand Down Expand Up @@ -463,6 +494,15 @@ instance (PrettyCode a) => PrettyCode (Maybe a) where
Nothing -> return "Nothing"
Just p -> ("Just" <+>) <$> ppCode p

bracesEncloseIndent :: forall l ann. (Foldable l) => l (Doc ann) -> Doc ann
bracesEncloseIndent ls =
PP.group $
"{"
<> line'
<> indent' (concatWith (\x y -> x <> ";" <> line <> y) ls)
<> line'
<> "}"

tuple :: [Doc ann] -> Doc ann
tuple = encloseSep "(" ")" ", "

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Juvix.Compiler.Internal.Translation.FromInternal.Analysis.Positivity
( module Juvix.Compiler.Internal.Translation.FromInternal.Analysis.Positivity.Checker,
module Juvix.Compiler.Internal.Translation.FromInternal.Analysis.Positivity.Error,
)
where

import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.Positivity.Checker
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.Positivity.Error
Loading
Loading