diff --git a/parser-typechecker/src/Unison/Codecs.hs b/parser-typechecker/src/Unison/Codecs.hs index 4546482c6..6fa9315b9 100644 --- a/parser-typechecker/src/Unison/Codecs.hs +++ b/parser-typechecker/src/Unison/Codecs.hs @@ -21,7 +21,7 @@ import qualified Unison.ABT as ABT import qualified Unison.Blank as Blank import qualified Unison.DataDeclaration as DD import qualified Unison.Hash as Hash -import Unison.Reference +import Unison.Reference (Reference(..)) import Unison.Term import qualified Unison.Typechecker.Components as Components import Unison.UnisonFile (UnisonFile(..)) diff --git a/parser-typechecker/src/Unison/DataDeclaration.hs b/parser-typechecker/src/Unison/DataDeclaration.hs index 5e44f6c79..33f7f6487 100644 --- a/parser-typechecker/src/Unison/DataDeclaration.hs +++ b/parser-typechecker/src/Unison/DataDeclaration.hs @@ -20,6 +20,7 @@ import qualified Unison.Reference as Reference import Unison.Type (AnnotatedType) import qualified Unison.Type as Type import Unison.Var (Var) +import Unison.Hash (Hash) type DataDeclaration v = DataDeclaration' v () @@ -132,6 +133,15 @@ fromABT (ABT.AbsN' bound ( [((), v, unsafeUnwrapType t) | (v, t) <- names `zip` stuff] fromABT a = error $ "ABT not of correct form to convert to DataDeclaration: " ++ show a +hashDecls2 + :: (Eq v, Var v) + => Map v (DataDeclaration' v a) + -> [(Hash, [v])] +hashDecls2 decls = fixup <$> ABT.hashComponents mkRef (toABT . void <$> decls) + where mkRef h i = ABT.tm (Type (Type.Ref (Reference.Derived h))) + fixup (h, scc) = (h, fst <$> scc) +-- use this to impl hashDecls + -- Implementation detail of `hashDecls`, works with unannotated data decls hashDecls0 :: (Eq v, Var v) diff --git a/parser-typechecker/src/Unison/Reference.hs b/parser-typechecker/src/Unison/Reference.hs index 9f70156b9..40efedd50 100644 --- a/parser-typechecker/src/Unison/Reference.hs +++ b/parser-typechecker/src/Unison/Reference.hs @@ -6,11 +6,26 @@ import GHC.Generics import Unison.Hashable as Hashable import qualified Data.Text as Text import qualified Unison.Hash as H +import Data.Word (Word64) -- could add a `Word` parameter to `Derived` -- associated with each hash would actually be a list of terms / type decls data Reference = Builtin Text.Text | Derived H.Hash deriving (Eq,Ord,Generic) +type Pos = Word64 +type Size = Word64 + +derived :: H.Hash -> Pos -> Size -> Reference +derived _h _pos _size = error "todo" + +component :: H.Hash -> [k] -> [(k, Reference)] +component h ks = let + size = fromIntegral (length ks) + in [ (k, derived h i size) | (k, i) <- ks `zip` [0..]] + +components :: [(H.Hash, [k])] -> [[(k, Reference)]] +components sccs = uncurry component <$> sccs + instance Show Reference where show (Builtin t) = Text.unpack t show (Derived h) = "#" <> show h