Skip to content

Commit

Permalink
WIP Types
Browse files Browse the repository at this point in the history
  • Loading branch information
decioferreira committed Dec 19, 2024
1 parent 14021a7 commit 617f843
Show file tree
Hide file tree
Showing 58 changed files with 4,821 additions and 4,725 deletions.
388 changes: 182 additions & 206 deletions src/Builder/Build.elm

Large diffs are not rendered by default.

53 changes: 26 additions & 27 deletions src/Builder/Deps/Diff.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Builder.Http as Http
import Builder.Reporting.Exit as Exit exposing (DocsProblem(..))
import Builder.Stuff as Stuff
import Compiler.Data.Name as Name
import Compiler.Elm.Compiler.Type as Type
import Compiler.Elm.Docs as Docs
import Compiler.Elm.Magnitude as M
import Compiler.Elm.Version as V exposing (Version)
Expand All @@ -33,7 +32,7 @@ type PackageChanges


type ModuleChanges
= ModuleChanges (Changes String T.CDN_Name Docs.CED_Union) (Changes String T.CDN_Name Docs.CED_Alias) (Changes String T.CDN_Name Docs.CED_Value) (Changes String T.CDN_Name Docs.CED_Binop)
= ModuleChanges (Changes String T.CDN_Name T.CED_Union) (Changes String T.CDN_Name T.CED_Alias) (Changes String T.CDN_Name T.CED_Value) (Changes String T.CDN_Name T.CED_Binop)


type Changes c k v
Expand Down Expand Up @@ -77,8 +76,8 @@ diff oldDocs newDocs =
(Dict.keys compare removed)


diffModule : ( Docs.CED_Module, Docs.CED_Module ) -> ModuleChanges
diffModule ( Docs.CED_Module _ _ u1 a1 v1 b1, Docs.CED_Module _ _ u2 a2 v2 b2 ) =
diffModule : ( T.CED_Module, T.CED_Module ) -> ModuleChanges
diffModule ( T.CED_Module _ _ u1 a1 v1 b1, T.CED_Module _ _ u2 a2 v2 b2 ) =
ModuleChanges
(getChanges identity compare isEquivalentUnion u1 u2)
(getChanges identity compare isEquivalentAlias a1 a2)
Expand All @@ -90,18 +89,18 @@ diffModule ( Docs.CED_Module _ _ u1 a1 v1 b1, Docs.CED_Module _ _ u2 a2 v2 b2 )
-- EQUIVALENCE


isEquivalentUnion : Docs.CED_Union -> Docs.CED_Union -> Bool
isEquivalentUnion (Docs.CED_Union oldComment oldVars oldCtors) (Docs.CED_Union newComment newVars newCtors) =
isEquivalentUnion : T.CED_Union -> T.CED_Union -> Bool
isEquivalentUnion (T.CED_Union oldComment oldVars oldCtors) (T.CED_Union newComment newVars newCtors) =
let
equiv : List Type.CECT_Type -> List Type.CECT_Type -> Bool
equiv : List T.CECT_Type -> List T.CECT_Type -> Bool
equiv oldTypes newTypes =
let
allEquivalent : List Bool
allEquivalent =
List.map2
isEquivalentAlias
(List.map (Docs.CED_Alias oldComment oldVars) oldTypes)
(List.map (Docs.CED_Alias newComment newVars) newTypes)
(List.map (T.CED_Alias oldComment oldVars) oldTypes)
(List.map (T.CED_Alias newComment newVars) newTypes)
in
(List.length oldTypes == List.length newTypes)
&& List.all identity allEquivalent
Expand All @@ -111,8 +110,8 @@ isEquivalentUnion (Docs.CED_Union oldComment oldVars oldCtors) (Docs.CED_Union n
&& List.all identity (Dict.values compare (Utils.mapIntersectionWith identity compare equiv (Dict.fromList identity oldCtors) (Dict.fromList identity newCtors)))


isEquivalentAlias : Docs.CED_Alias -> Docs.CED_Alias -> Bool
isEquivalentAlias (Docs.CED_Alias _ oldVars oldType) (Docs.CED_Alias _ newVars newType) =
isEquivalentAlias : T.CED_Alias -> T.CED_Alias -> Bool
isEquivalentAlias (T.CED_Alias _ oldVars oldType) (T.CED_Alias _ newVars newType) =
case diffType oldType newType of
Nothing ->
False
Expand All @@ -122,14 +121,14 @@ isEquivalentAlias (Docs.CED_Alias _ oldVars oldType) (Docs.CED_Alias _ newVars n
&& isEquivalentRenaming (List.map2 Tuple.pair oldVars newVars ++ renamings)


isEquivalentValue : Docs.CED_Value -> Docs.CED_Value -> Bool
isEquivalentValue (Docs.CED_Value c1 t1) (Docs.CED_Value c2 t2) =
isEquivalentAlias (Docs.CED_Alias c1 [] t1) (Docs.CED_Alias c2 [] t2)
isEquivalentValue : T.CED_Value -> T.CED_Value -> Bool
isEquivalentValue (T.CED_Value c1 t1) (T.CED_Value c2 t2) =
isEquivalentAlias (T.CED_Alias c1 [] t1) (T.CED_Alias c2 [] t2)


isEquivalentBinop : Docs.CED_Binop -> Docs.CED_Binop -> Bool
isEquivalentBinop (Docs.CED_Binop c1 t1 a1 p1) (Docs.CED_Binop c2 t2 a2 p2) =
isEquivalentAlias (Docs.CED_Alias c1 [] t1) (Docs.CED_Alias c2 [] t2)
isEquivalentBinop : T.CED_Binop -> T.CED_Binop -> Bool
isEquivalentBinop (T.CED_Binop c1 t1 a1 p1) (T.CED_Binop c2 t2 a2 p2) =
isEquivalentAlias (T.CED_Alias c1 [] t1) (T.CED_Alias c2 [] t2)
&& (a1 == a2)
&& (p1 == p2)

Expand All @@ -138,23 +137,23 @@ isEquivalentBinop (Docs.CED_Binop c1 t1 a1 p1) (Docs.CED_Binop c2 t2 a2 p2) =
-- DIFF TYPES


diffType : Type.CECT_Type -> Type.CECT_Type -> Maybe (List ( T.CDN_Name, T.CDN_Name ))
diffType : T.CECT_Type -> T.CECT_Type -> Maybe (List ( T.CDN_Name, T.CDN_Name ))
diffType oldType newType =
case ( oldType, newType ) of
( Type.CECT_Var oldName, Type.CECT_Var newName ) ->
( T.CECT_Var oldName, T.CECT_Var newName ) ->
Just [ ( oldName, newName ) ]

( Type.CECT_Lambda a b, Type.CECT_Lambda a_ b_ ) ->
( T.CECT_Lambda a b, T.CECT_Lambda a_ b_ ) ->
Maybe.map2 (++) (diffType a a_) (diffType b b_)

( Type.CECT_Type oldName oldArgs, Type.CECT_Type newName newArgs ) ->
( T.CECT_Type oldName oldArgs, T.CECT_Type newName newArgs ) ->
if not (isSameName oldName newName) || List.length oldArgs /= List.length newArgs then
Nothing

else
Maybe.map List.concat (Utils.zipWithM diffType oldArgs newArgs)

( Type.CECT_Record fields maybeExt, Type.CECT_Record fields_ maybeExt_ ) ->
( T.CECT_Record fields maybeExt, T.CECT_Record fields_ maybeExt_ ) ->
case ( maybeExt, maybeExt_ ) of
( Nothing, Just _ ) ->
Nothing
Expand All @@ -168,10 +167,10 @@ diffType oldType newType =
( Just oldExt, Just newExt ) ->
Maybe.map ((::) ( oldExt, newExt )) (diffFields fields fields_)

( Type.CECT_Unit, Type.CECT_Unit ) ->
( T.CECT_Unit, T.CECT_Unit ) ->
Just []

( Type.CECT_Tuple a b cs, Type.CECT_Tuple x y zs ) ->
( T.CECT_Tuple a b cs, T.CECT_Tuple x y zs ) ->
if List.length cs /= List.length zs then
Nothing

Expand Down Expand Up @@ -207,7 +206,7 @@ isSameName oldFullName newFullName =
oldFullName == newFullName


diffFields : List ( T.CDN_Name, Type.CECT_Type ) -> List ( T.CDN_Name, Type.CECT_Type ) -> Maybe (List ( T.CDN_Name, T.CDN_Name ))
diffFields : List ( T.CDN_Name, T.CECT_Type ) -> List ( T.CDN_Name, T.CECT_Type ) -> Maybe (List ( T.CDN_Name, T.CDN_Name ))
diffFields oldRawFields newRawFields =
if List.length oldRawFields /= List.length newRawFields then
Nothing
Expand All @@ -218,11 +217,11 @@ diffFields oldRawFields newRawFields =
sort fields =
List.sortBy Tuple.first fields

oldFields : List ( T.CDN_Name, Type.CECT_Type )
oldFields : List ( T.CDN_Name, T.CECT_Type )
oldFields =
sort oldRawFields

newFields : List ( T.CDN_Name, Type.CECT_Type )
newFields : List ( T.CDN_Name, T.CECT_Type )
newFields =
sort newRawFields
in
Expand Down
54 changes: 14 additions & 40 deletions src/Builder/Elm/Details.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module Builder.Elm.Details exposing
( BED_BuildID
, BED_Local(..)
, Details(..)
( Details(..)
, Extras
, Foreign(..)
, Interfaces
Expand Down Expand Up @@ -58,38 +56,14 @@ import Utils.Main as Utils


type Details
= Details File.BF_Time ValidOutline BED_BuildID (Dict String T.CEMN_Raw BED_Local) (Dict String T.CEMN_Raw Foreign) Extras


type alias BED_BuildID =
Int
= Details T.BF_Time ValidOutline T.BED_BuildID (Dict String T.CEMN_Raw T.BED_Local) (Dict String T.CEMN_Raw Foreign) Extras


type ValidOutline
= ValidApp (NE.Nonempty Outline.SrcDir)
| ValidPkg T.CEP_Name (List T.CEMN_Raw) (Dict ( String, String ) T.CEP_Name V.Version {- for docs in reactor -})



-- NOTE: we need two ways to detect if a file must be recompiled:
--
-- (1) _time is the modification time from the last time we compiled the file.
-- By checking EQUALITY with the current modification time, we can detect file
-- saves and `git checkout` of previous versions. Both need a recompile.
--
-- (2) _lastChange is the BuildID from the last time a new interface file was
-- generated, and _lastCompile is the BuildID from the last time the file was
-- compiled. These may be different if a file is recompiled but the interface
-- stayed the same. When the _lastCompile is LESS THAN the _lastChange of any
-- imports, we need to recompile. This can happen when a project has multiple
-- entrypoints and some modules are compiled less often than their imports.
--


type BED_Local
= BED_Local T.FilePath File.BF_Time (List T.CEMN_Raw) Bool BED_BuildID BED_BuildID


type Foreign
= Foreign T.CEP_Name (List T.CEP_Name)

Expand Down Expand Up @@ -184,7 +158,7 @@ load style scope root =
-- GENERATE


generate : Reporting.Style -> BW.Scope -> T.FilePath -> File.BF_Time -> IO (Result Exit.Details Details)
generate : Reporting.Style -> BW.Scope -> T.FilePath -> T.BF_Time -> IO (Result Exit.Details Details)
generate style scope root time =
Reporting.trackDetails style
(\key ->
Expand Down Expand Up @@ -249,7 +223,7 @@ type alias Task a =
Task.Task Exit.Details a


verifyPkg : Env -> File.BF_Time -> Outline.PkgOutline -> Task Details
verifyPkg : Env -> T.BF_Time -> Outline.PkgOutline -> Task Details
verifyPkg env time (Outline.PkgOutline pkg _ _ _ exposed direct testDirect elm) =
if Con.goodElm elm then
union identity Pkg.compareName noDups direct testDirect
Expand All @@ -274,7 +248,7 @@ verifyPkg env time (Outline.PkgOutline pkg _ _ _ exposed direct testDirect elm)
Task.throw (Exit.DetailsBadElmInPkg elm)


verifyApp : Env -> File.BF_Time -> Outline.AppOutline -> Task Details
verifyApp : Env -> T.BF_Time -> Outline.AppOutline -> Task Details
verifyApp env time ((Outline.AppOutline elmVersion srcDirs direct _ _ _) as outline) =
if elmVersion == V.compiler then
checkAppDeps outline
Expand Down Expand Up @@ -399,7 +373,7 @@ fork_Maybe_CASTO_GlobalGraph work =
-- VERIFY DEPENDENCIES


verifyDependencies : Env -> File.BF_Time -> ValidOutline -> Dict ( String, String ) T.CEP_Name Solver.Details -> Dict ( String, String ) T.CEP_Name a -> Task Details
verifyDependencies : Env -> T.BF_Time -> ValidOutline -> Dict ( String, String ) T.CEP_Name Solver.Details -> Dict ( String, String ) T.CEP_Name a -> Task Details
verifyDependencies ((Env key scope root cache _ _ _) as env) time outline solution directDeps =
Task.eio identity
(Reporting.report key (Reporting.DStart (Dict.size solution))
Expand Down Expand Up @@ -915,7 +889,7 @@ getDepHome fi =


type DResult
= RLocal T.CEI_Interface T.CASTO_LocalGraph (Maybe Docs.CED_Module)
= RLocal T.CEI_Interface T.CASTO_LocalGraph (Maybe T.CED_Module)
| RForeign T.CEI_Interface
| RKernelLocal (List T.CEK_Chunk)
| RKernelForeign
Expand Down Expand Up @@ -946,7 +920,7 @@ compile pkg mvar status =
ifaces =
I.fromModule pkg canonical annotations

docs : Maybe Docs.CED_Module
docs : Maybe T.CED_Module
docs =
makeDocs docsStatus canonical
in
Expand Down Expand Up @@ -1001,7 +975,7 @@ getDocsStatus cache pkg vsn =
)


makeDocs : T.BED_DocsStatus -> Can.Module -> Maybe Docs.CED_Module
makeDocs : T.BED_DocsStatus -> Can.Module -> Maybe T.CED_Module
makeDocs status modul =
case status of
T.BED_DocsNeeded ->
Expand All @@ -1027,7 +1001,7 @@ writeDocs cache pkg vsn status results =
IO.pure ()


toDocs : DResult -> Maybe Docs.CED_Module
toDocs : DResult -> Maybe T.CED_Module
toDocs result =
case result of
RLocal _ _ docs ->
Expand Down Expand Up @@ -1262,8 +1236,8 @@ statusDictDecoder =
D.assocListDict identity ModuleName.rawDecoder Utils.mVarDecoder


localEncoder : BED_Local -> Encode.Value
localEncoder (BED_Local path time deps hasMain lastChange lastCompile) =
localEncoder : T.BED_Local -> Encode.Value
localEncoder (T.BED_Local path time deps hasMain lastChange lastCompile) =
Encode.object
[ ( "type", Encode.string "Local" )
, ( "path", Encode.string path )
Expand All @@ -1275,9 +1249,9 @@ localEncoder (BED_Local path time deps hasMain lastChange lastCompile) =
]


localDecoder : Decode.Decoder BED_Local
localDecoder : Decode.Decoder T.BED_Local
localDecoder =
Decode.map6 BED_Local
Decode.map6 T.BED_Local
(Decode.field "path" Decode.string)
(Decode.field "time" File.timeDecoder)
(Decode.field "deps" (Decode.list ModuleName.rawDecoder))
Expand Down
23 changes: 9 additions & 14 deletions src/Builder/File.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Builder.File exposing
( BF_Time(..)
, exists
( exists
, getTime
, readBinary
, readUtf8
Expand All @@ -27,18 +26,14 @@ import Utils.Main as Utils
-- TIME


type BF_Time
= BF_Time Time.Posix


getTime : T.FilePath -> IO BF_Time
getTime : T.FilePath -> IO T.BF_Time
getTime path =
IO.fmap BF_Time (Utils.dirGetModificationTime path)
IO.fmap T.BF_Time (Utils.dirGetModificationTime path)


zeroTime : BF_Time
zeroTime : T.BF_Time
zeroTime =
BF_Time (Time.millisToPosix 0)
T.BF_Time (Time.millisToPosix 0)



Expand Down Expand Up @@ -189,11 +184,11 @@ remove path =
-- ENCODERS and DECODERS


timeEncoder : BF_Time -> Encode.Value
timeEncoder (BF_Time posix) =
timeEncoder : T.BF_Time -> Encode.Value
timeEncoder (T.BF_Time posix) =
Encode.int (Time.posixToMillis posix)


timeDecoder : Decode.Decoder BF_Time
timeDecoder : Decode.Decoder T.BF_Time
timeDecoder =
Decode.map (BF_Time << Time.millisToPosix) Decode.int
Decode.map (T.BF_Time << Time.millisToPosix) Decode.int
6 changes: 3 additions & 3 deletions src/Builder/Generate.elm
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ loadTypesHelp root modul =
|> IO.bind
(\cachedInterface ->
case cachedInterface of
Build.BB_Unneeded ->
T.BB_Unneeded ->
Utils.newEmptyMVar
|> IO.bind
(\mvar ->
Expand All @@ -294,9 +294,9 @@ loadTypesHelp root modul =
|> IO.fmap (\_ -> mvar)
)

Build.BB_Loaded iface ->
T.BB_Loaded iface ->
Utils.newMVar (Utils.maybeEncoder Extract.typesEncoder) (Just (Extract.fromInterface name iface))

Build.BB_Corrupted ->
T.BB_Corrupted ->
Utils.newMVar (Utils.maybeEncoder Extract.typesEncoder) Nothing
)
Loading

0 comments on commit 617f843

Please sign in to comment.