Skip to content

Commit

Permalink
Rename Oden.Core to Oden.Core.Typed
Browse files Browse the repository at this point in the history
  • Loading branch information
owickstrom committed Apr 30, 2016
1 parent 3b425da commit 8e21f91
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 59 deletions.
2 changes: 1 addition & 1 deletion cli/Oden/CLI/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import Oden.Compiler
import Oden.Compiler.Validation
import Oden.Compiler.Resolution

import Oden.Core as Core
import Oden.Core.Monomorphed (MonomorphedPackage(..))
import Oden.Core.Resolved
import Oden.Core.Typed

import Oden.Explode
import qualified Oden.Go.Importer as Go
Expand Down
2 changes: 1 addition & 1 deletion cli/Oden/CLI/PrintPackage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import Oden.Scanner
import Oden.CLI
import Oden.CLI.Build

import Oden.Core
import Oden.Core.Definition
import Oden.Core.Package
import Oden.Core.Typed

import Control.Monad.Reader

Expand Down
2 changes: 1 addition & 1 deletion oden.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library
Oden.Compiler.TypeEncoder,
Oden.Compiler.Validation,
Oden.Compiler.LiteralEval,
Oden.Core,
Oden.Core.Typed,
Oden.Core.Definition,
Oden.Core.Expr,
Oden.Core.Operator,
Expand Down
8 changes: 4 additions & 4 deletions src/Oden/Compiler/Resolution.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
-- implementations available for now.
module Oden.Compiler.Resolution where

import Oden.Core as Core
import Oden.Core.Typed as Typed
import Oden.Core.Definition
import Oden.Core.ProtocolImplementation
import Oden.Core.Resolved as Resolved
import Oden.Core.Resolved as Resolved
import Oden.Core.Traversal
import Oden.Metadata
import Oden.Predefined
Expand Down Expand Up @@ -87,9 +87,9 @@ resolveInExpr' = traverseExpr traversal
implementationMethod <- lookupMethodImplementation (unwrap si) protocol method
return (si, ResolvedMethodReference protocol method implementationMethod, type')
onMemberAccess' = \case
Core.RecordFieldAccess expr identifier ->
Typed.RecordFieldAccess expr identifier ->
Resolved.RecordFieldAccess <$> resolveInExpr' expr <*> return identifier
Core.PackageMemberAccess pkg member ->
Typed.PackageMemberAccess pkg member ->
return (Resolved.PackageMemberAccess pkg member)

resolveInDefinition' :: TypedDefinition -> Resolve ResolvedDefinition
Expand Down
2 changes: 1 addition & 1 deletion src/Oden/Compiler/Validation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# LANGUAGE FlexibleContexts #-}
module Oden.Compiler.Validation where

import Oden.Core as Core
import Oden.Core.Typed
import Oden.Core.Definition
import Oden.Core.Expr
import Oden.Core.Operator
Expand Down
2 changes: 1 addition & 1 deletion src/Oden/Core.hs → src/Oden/Core/Typed.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-# LANGUAGE TypeSynonymInstances #-}
module Oden.Core where
module Oden.Core.Typed where

import Oden.Core.Definition
import Oden.Core.Expr
Expand Down
24 changes: 12 additions & 12 deletions src/Oden/Infer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Data.Foldable
import qualified Data.Map as Map
import qualified Data.Set as Set

import Oden.Core as Core
import Oden.Core.Typed as Typed
import Oden.Core.Definition
import Oden.Core.Expr
import Oden.Core.Operator
Expand Down Expand Up @@ -87,7 +87,7 @@ data TypeError
| PackageNotInScope SourceInfo Identifier
| NotInScope SourceInfo Identifier
| MemberNotInPackage SourceInfo Identifier Identifier
| ArgumentCountMismatch Core.TypedExpr [Type] [Type]
| ArgumentCountMismatch Typed.TypedExpr [Type] [Type]
| TypeSignatureSubsumptionError Identifier SubsumptionError
| InvalidPackageReference SourceInfo Identifier
| ValueUsedAsType SourceInfo Identifier
Expand All @@ -106,7 +106,7 @@ runInfer env m = runExcept $ evalRWST m env initInfer
-- environment.
inferExpr :: TypingEnvironment
-> UntypedExpr
-> Either TypeError Core.CanonicalExpr
-> Either TypeError Typed.CanonicalExpr
inferExpr env ex = do
(te, cs) <- runInfer env (infer ex)
subst <- left UnificationError $ runSolve cs
Expand All @@ -116,15 +116,15 @@ inferExpr env ex = do
-- expression.
constraintsExpr :: TypingEnvironment
-> UntypedExpr
-> Either TypeError ([UnifyConstraint], Subst, Core.TypedExpr, Scheme)
-> Either TypeError ([UnifyConstraint], Subst, Typed.TypedExpr, Scheme)
constraintsExpr env ex = do
(te, cs) <- runInfer env (infer ex)
subst <- left UnificationError $ runSolve cs
let (sc, te') = closeOver $ apply subst te
return (cs, subst, te', sc)

-- | Canonicalize and return the polymorphic top-level type.
closeOver :: Core.TypedExpr -> Core.CanonicalExpr
closeOver :: Typed.TypedExpr -> Typed.CanonicalExpr
closeOver = normalize . generalize empty

-- | Unify two types.
Expand Down Expand Up @@ -215,7 +215,7 @@ instantiate (Forall _ qs cs t) = do
-- | Given a typed expression, return a canonical expression with the free
-- type variables (not present in the environment) declared as type quantifiers
-- for the expression.
generalize :: TypingEnvironment -> Core.TypedExpr -> Core.CanonicalExpr
generalize :: TypingEnvironment -> Typed.TypedExpr -> Typed.CanonicalExpr
generalize env expr = (scheme, expr')
where quantifiers = map (TVarBinding $ Metadata Missing) (Set.toList $ ftv expr `Set.difference` ftv env)
(expr', constraints) = collectConstraints expr
Expand All @@ -233,7 +233,7 @@ instantiateMethod protocol@(Protocol _ _ param _) (ProtocolMethod _ _ scheme) =
universeType :: Metadata SourceInfo -> String -> Type
universeType si n = TCon si (nameInUniverse n)

wrapForeign :: Metadata SourceInfo -> Core.TypedExpr -> Type -> Infer Core.TypedExpr
wrapForeign :: Metadata SourceInfo -> Typed.TypedExpr -> Type -> Infer Typed.TypedExpr
wrapForeign si expr t =
case t of
TForeignFn _ _ [] returnTypes -> do
Expand All @@ -259,7 +259,7 @@ wrapForeign si expr t =
-- inferred typed expression. Constraints are collected in the 'Infer' monad
-- and substitutions are made before the inference is complete, so the
-- expressions returned from 'infer' are not the final results.
infer :: UntypedExpr -> Infer Core.TypedExpr
infer :: UntypedExpr -> Infer Typed.TypedExpr
infer = \case
Literal si Unit Untyped ->
return (Literal si Unit (TCon si (nameInUniverse "unit")))
Expand Down Expand Up @@ -419,7 +419,7 @@ infer = \case
protocolType <- lookupProtocol si protocol
method' <- findMethod (unwrap si) protocolType method
methodType <- instantiateMethod protocolType method'
let ref = Core.UnresolvedMethodReference protocolType method'
let ref = Typed.UnresolvedMethodReference protocolType method'
return (MethodReference si ref methodType)

ForeignFnApplication (Metadata si) _ _ _ ->
Expand Down Expand Up @@ -482,7 +482,7 @@ type ShouldCloseOver = Bool

-- | Infer the untyped definition in the Infer monad, returning a typed
-- version. Resolves type signatures of optionally type-annotated definitions.
inferDef :: Untyped.Definition -> Infer (Core.TypedDefinition, ShouldCloseOver)
inferDef :: Untyped.Definition -> Infer (Typed.TypedDefinition, ShouldCloseOver)
inferDef (Untyped.Definition si name signature expr) = do
env <- ask
case signature of
Expand Down Expand Up @@ -517,7 +517,7 @@ inferDef (Untyped.ProtocolDefinition si name (SignatureVarBinding vsi var) metho

-- | Infer a top-level definitition, returning a typed version and the typing
-- environment extended with the definitions name and type.
inferDefinition :: TypingEnvironment -> Untyped.Definition -> Either TypeError (TypingEnvironment, Core.TypedDefinition)
inferDefinition :: TypingEnvironment -> Untyped.Definition -> Either TypeError (TypingEnvironment, Typed.TypedDefinition)
inferDefinition env def = do
-- Infer the definition.
((def', shouldCloseOver), cs) <- runInfer env (inferDef def)
Expand Down Expand Up @@ -558,7 +558,7 @@ inferPackage (UntypedPackage (PackageDeclaration psi name) imports defs) = do

-- | Swaps all type variables names for generated ones based on 'letters' to
-- get a nice sequence.
normalize :: (Scheme, Core.TypedExpr) -> (Scheme, Core.TypedExpr)
normalize :: (Scheme, Typed.TypedExpr) -> (Scheme, Typed.TypedExpr)
normalize (Forall si _ constraints exprType, te) =
(Forall si newBindings (apply subst constraints) (apply subst exprType), apply subst te)
where
Expand Down
2 changes: 1 addition & 1 deletion src/Oden/Infer/ConstraintCollection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Oden.Infer.ConstraintCollection (collectConstraints) where

import Control.Monad.Writer

import Oden.Core
import Oden.Core.Typed
import Oden.Core.Traversal
import Oden.Type.Polymorphic
import Oden.Type.Traversal
Expand Down
2 changes: 1 addition & 1 deletion src/Oden/Infer/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module Oden.Infer.Environment (
fromPackages
) where

import Oden.Core
import Oden.Core.Definition
import Oden.Core.Expr
import Oden.Core.Package
import Oden.Core.Resolved

import Oden.Environment hiding (map)
import Oden.Identifier
import Oden.Metadata
Expand Down
2 changes: 1 addition & 1 deletion src/Oden/Infer/Substitution.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{-# LANGUAGE LambdaCase #-}
module Oden.Infer.Substitution where

import Oden.Core as Core
import Oden.Core.Typed
import Oden.Core.Expr
import Oden.Type.Polymorphic as Poly

Expand Down
4 changes: 2 additions & 2 deletions src/Oden/Infer/Subsumption.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Oden.Infer.Subsumption (
collectSubstitutions
) where

import Oden.Core as Core
import Oden.Core.Typed as Typed
import Oden.Core.Expr (typeOf)
import Oden.Infer.Substitution
import Oden.Metadata
Expand Down Expand Up @@ -63,7 +63,7 @@ collectSubstitutions t1 t2 = throwError (SubsumptionError (getSourceInfo t2) t1
-- | Test if a type scheme is subsumed by an expression with a more general
-- type. If so, return the expression specialized to the less general type (all
-- subexpression types being substituted as well).
subsumedBy :: Scheme -> Core.TypedExpr -> Either SubsumptionError Core.CanonicalExpr
subsumedBy :: Scheme -> Typed.TypedExpr -> Either SubsumptionError Typed.CanonicalExpr
subsumedBy s@(Forall _ _ _ st) expr = do
subst <- snd <$> runExcept (runStateT (collectSubstitutions st (typeOf expr)) Map.empty)
return (s, apply (Subst subst) expr)
10 changes: 5 additions & 5 deletions src/Oden/Pretty.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, LambdaCase #-}
module Oden.Pretty where

import Oden.Core as Core
import Oden.Core.Typed as Typed
import Oden.Core.Definition
import Oden.Core.Expr
import qualified Oden.Core.Untyped as Untyped
Expand Down Expand Up @@ -156,8 +156,8 @@ instance Pretty (ImportedPackage ResolvedPackage) where
pretty (ImportedPackage _ _ (ResolvedPackage (PackageDeclaration _ pkgName) _ _)) =
text "import" <+> pretty pkgName

instance Pretty Core.TypedPackage where
pretty (Core.TypedPackage decl imports defs) =
instance Pretty Typed.TypedPackage where
pretty (Typed.TypedPackage decl imports defs) =
vcat (punctuate line (pretty decl : map pretty imports ++ map pretty defs))

instance Pretty Poly.TVar where
Expand Down Expand Up @@ -278,9 +278,9 @@ instance Pretty (TypeSignature a) where
text "forall" <+> hsep (map pretty vars) <> text "." <+> pretty expr

instance Pretty TypedMemberAccess where
pretty (Core.RecordFieldAccess expr name) =
pretty (Typed.RecordFieldAccess expr name) =
pretty expr <> text "." <> pretty name
pretty (Core.PackageMemberAccess expr name) =
pretty (Typed.PackageMemberAccess expr name) =
pretty expr <> text "." <> pretty name

instance Pretty MonoTypedMemberAccess where
Expand Down
2 changes: 1 addition & 1 deletion test/Oden/Compiler/LiteralEvalSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Oden.Compiler.LiteralEvalSpec where
import Test.Hspec

import Oden.Compiler.LiteralEval
import Oden.Core
import Oden.Core.Typed
import Oden.Core.Expr
import Oden.Core.Operator
import Oden.Identifier
Expand Down
38 changes: 19 additions & 19 deletions test/Oden/Compiler/ResolutionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module Oden.Compiler.ResolutionSpec where

import Oden.Compiler.Resolution

import Oden.Core
import Oden.Core.Expr
import Oden.Core.ProtocolImplementation
import Oden.Core.Resolved
import Oden.Core.Typed

import Oden.Environment
import Oden.Identifier
Expand Down Expand Up @@ -36,11 +36,11 @@ aToBool = TFn predefined tvarA typeBool

one = Literal missing (Int 1) typeInt

unresolved protocol method type' =
MethodReference missing (UnresolvedMethodReference protocol method) type'
unresolved protocol method =
MethodReference missing (UnresolvedMethodReference protocol method)

resolved protocol method implMethod type' =
MethodReference missing (ResolvedMethodReference protocol method implMethod) type'
resolved protocol method implMethod =
MethodReference missing (ResolvedMethodReference protocol method implMethod)

testableProtocolMethod =
ProtocolMethod
Expand Down Expand Up @@ -84,11 +84,11 @@ spec =
testableProtocolMethod
aToBool)
`shouldSucceedWith`
(resolved
testableProtocol
testableProtocolMethod
(boolTestableMethod "myImpl")
aToBool)
resolved
testableProtocol
testableProtocolMethod
(boolTestableMethod "myImpl")
aToBool

it "resolves a single matching implementation for a less general type" $
resolveInExpr
Expand All @@ -102,15 +102,15 @@ spec =
one
typeBool)
`shouldSucceedWith`
(Application
missing
(resolved
testableProtocol
testableProtocolMethod
(boolTestableMethod "myImpl")
boolToBool)
one
typeBool)
Application
missing
(resolved
testableProtocol
testableProtocolMethod
(boolTestableMethod "myImpl")
boolToBool)
one
typeBool

it "throws error if there's multiple matching implementations" $
resolveInExpr
Expand Down
4 changes: 2 additions & 2 deletions test/Oden/Compiler/ValidationSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Test.Hspec

import Oden.Compiler.Validation

import Oden.Core as Core
import Oden.Core.Typed as Typed
import Oden.Core.Definition
import Oden.Core.Expr
import Oden.Core.Operator
Expand Down Expand Up @@ -225,7 +225,7 @@ spec = do
(canonical
(MemberAccess
missing
(Core.PackageMemberAccess (Identifier "other") (Identifier "s"))
(Typed.PackageMemberAccess (Identifier "other") (Identifier "s"))
typeInt))
])
`shouldSucceedWith`
Expand Down
6 changes: 3 additions & 3 deletions test/Oden/Infer/Fixtures.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Oden.Infer.Fixtures where

import Oden.Core as Core
import Oden.Core.Typed as Typed
import Oden.Core.Definition
import Oden.Core.Expr
import Oden.Core.Operator
Expand Down Expand Up @@ -170,7 +170,7 @@ intToInt = typeFn typeInt typeInt
intToIntToInt :: Type
intToIntToInt = typeFn typeInt (typeFn typeInt typeInt)

countToZeroTyped :: Core.TypedDefinition
countToZeroTyped :: Typed.TypedDefinition
countToZeroTyped =
tDefinition
(Identifier "f")
Expand Down Expand Up @@ -211,7 +211,7 @@ twiceUntyped =
Untyped)
Untyped

twiceTyped :: Core.TypedDefinition
twiceTyped :: Typed.TypedDefinition
twiceTyped =
tDefinition (Identifier "twice") (scheme (typeFn (typeFn tvarA tvarA) (typeFn tvarA tvarA)),
tFn
Expand Down
Loading

0 comments on commit 8e21f91

Please sign in to comment.