Stabel

Check-in [38b29fb9b2]
Login
Overview
Comment:Remove fields from qualifier ast required by previous way of discovering dependencies. Next step is to get qualifier to fail when it comes across a type or word not already qualified.
Timelines: family | ancestors | descendants | both | module-definition
Files: files | file ages | folders
SHA3-256: 38b29fb9b23b1b37d1b9fa922a24ac1b0757417d71015dfe4eaa5b3b00ac3add
User & Date: robin.hansen on 2021-05-05 08:26:06
Other Links: branch diff | manifest | tags
Context
2021-05-05
12:38
Qualifier now requires the full qualified AST as it looks right now, so that if the qualifier comes ... check-in: 73a6ca37a7 user: robin.hansen tags: module-definition
08:26
Remove fields from qualifier ast required by previous way of discovering dependencies. Next step is ... check-in: 38b29fb9b2 user: robin.hansen tags: module-definition
08:18
PackageLoader now parses each module first, then uses new dependency information for finding new mod... check-in: 73872525cb user: robin.hansen tags: module-definition
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/PackageLoader.elm from [cd381958d8] to [067186eac4].

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53


type Model
    = Initializing InitOptions SideEffect
    | LoadingMetadata State (List PackagePath) SideEffect
    | ResolvingModulePaths State (List PackageInfo) SideEffect
    | Parsing State (List ( PackageInfo, ModuleName )) SideEffect
    | Done Qualifier.ExposedAST
    | Failed Problem


type alias State =
    { possibleEntryPoint : Maybe String
    , rootPackage : PackageInfo
    , dependencies : Dict String SemanticVersion







|







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53


type Model
    = Initializing InitOptions SideEffect
    | LoadingMetadata State (List PackagePath) SideEffect
    | ResolvingModulePaths State (List PackageInfo) SideEffect
    | Parsing State (List ( PackageInfo, ModuleName )) SideEffect
    | Done Qualifier.AST
    | Failed Problem


type alias State =
    { possibleEntryPoint : Maybe String
    , rootPackage : PackageInfo
    , dependencies : Dict String SemanticVersion

Modified src/Play/Qualifier.elm from [ba63605abc] to [b995e072fc].

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
..
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import Play.Parser as Parser
import Play.Qualifier.Problem exposing (Problem(..))
import Result.Extra as Result
import Set exposing (Set)


type alias AST =
    { types : Dict String TypeDefinition
    , words : Dict String WordDefinition
    , additionalModulesRequired : Set String
    , checkForExistingTypes : Set String
    , checkForExistingWords : Set String
    }


type alias ExposedAST =
    { types : Dict String TypeDefinition
    , words : Dict String WordDefinition
    }


type TypeDefinition
    = CustomTypeDef String SourceLocationRange (List String) (List ( String, Type ))
................................................................................
    let
        ( typeErrors, qualifiedTypes ) =
            Dict.foldl (\_ val acc -> qualifyType config val acc) ( [], Dict.empty ) config.ast.types
                |> Tuple.mapSecond (\qt -> Dict.map (\_ v -> resolveUnionInTypeDefs qt v) qt)

        ( wordErrors, externalWords, qualifiedWords ) =
            Dict.foldl (\_ val acc -> qualifyDefinition config qualifiedTypes val acc) ( [], Set.empty, Dict.empty ) config.ast.words

        additionalRequiredModules =
            Set.toList externalWords
                |> List.map Tuple.first
                |> Set.fromList

        wordsToCheck =
            Set.toList externalWords
                |> List.map (\( path, name ) -> path ++ "/" ++ name)
                |> Set.fromList
    in
    case ( typeErrors, wordErrors ) of
        ( [], [] ) ->
            Ok
                { types = qualifiedTypes
                , words = qualifiedWords
                , additionalModulesRequired = additionalRequiredModules
                , checkForExistingTypes = Set.empty
                , checkForExistingWords = wordsToCheck
                }

        _ ->
            Err <| typeErrors ++ wordErrors


resolveUnionInTypeDefs : Dict String TypeDefinition -> TypeDefinition -> TypeDefinition







<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<






<
<
<







9
10
11
12
13
14
15









16
17
18
19
20
21
22
..
85
86
87
88
89
90
91










92
93
94
95
96
97



98
99
100
101
102
103
104
import Play.Parser as Parser
import Play.Qualifier.Problem exposing (Problem(..))
import Result.Extra as Result
import Set exposing (Set)


type alias AST =









    { types : Dict String TypeDefinition
    , words : Dict String WordDefinition
    }


type TypeDefinition
    = CustomTypeDef String SourceLocationRange (List String) (List ( String, Type ))
................................................................................
    let
        ( typeErrors, qualifiedTypes ) =
            Dict.foldl (\_ val acc -> qualifyType config val acc) ( [], Dict.empty ) config.ast.types
                |> Tuple.mapSecond (\qt -> Dict.map (\_ v -> resolveUnionInTypeDefs qt v) qt)

        ( wordErrors, externalWords, qualifiedWords ) =
            Dict.foldl (\_ val acc -> qualifyDefinition config qualifiedTypes val acc) ( [], Set.empty, Dict.empty ) config.ast.words










    in
    case ( typeErrors, wordErrors ) of
        ( [], [] ) ->
            Ok
                { types = qualifiedTypes
                , words = qualifiedWords



                }

        _ ->
            Err <| typeErrors ++ wordErrors


resolveUnionInTypeDefs : Dict String TypeDefinition -> TypeDefinition -> TypeDefinition

Modified tests/Test/PackageLoader.elm from [da9199a4ec] to [6a7e40be54].

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
            Expect.equalLists [] (sfDiff ++ sfDiffRev)


resolveSideEffects :
    Dict String String
    -> List PackageLoader.SideEffect
    -> PackageLoader.Model
    -> Result String ( List PackageLoader.SideEffect, Qualifier.ExposedAST )
resolveSideEffects fileSystem seenSfs model =
    case PackageLoader.getSideEffect model of
        Nothing ->
            case model of
                PackageLoader.Done ast ->
                    Ok ( seenSfs, ast )








|







144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
            Expect.equalLists [] (sfDiff ++ sfDiffRev)


resolveSideEffects :
    Dict String String
    -> List PackageLoader.SideEffect
    -> PackageLoader.Model
    -> Result String ( List PackageLoader.SideEffect, Qualifier.AST )
resolveSideEffects fileSystem seenSfs model =
    case PackageLoader.getSideEffect model of
        Nothing ->
            case model of
                PackageLoader.Done ast ->
                    Ok ( seenSfs, ast )

Modified tests/Test/Qualifier.elm from [4bae61eb94] to [103000ab89].

1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
                                        SoloImpl
                                            [ GetMember "/play/test/some/module/Wallet" "value" ]
                                  }
                                ]
                        }
                in
                QualifierUtil.expectModuleOutput unqualifiedAst expectedAst
        , describe "Module loading"
            [ test "Detects package reference in simple word" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Integer emptyRange 1
                                                , AST.PackageWord emptyRange [ "package", "module" ] "sample"
                                                ]
                                      }
                                    ]
                            }

                        expectedAst =
                            { additionalModulesRequired =
                                Set.fromList
                                    [ "/play/test/package/module" ]
                            , checkForExistingTypes = Set.empty
                            , checkForExistingWords =
                                Set.fromList
                                    [ "/play/test/package/module/sample" ]
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "/play/test/package/tests/call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Word emptyRange "/play/test/package/module/sample"
                                                ]
                                      }
                                    ]
                            }

                        result =
                            run
                                { packageName = "play/test"
                                , modulePath = "package/tests"
                                , ast = unqualifiedAst
                                , externalModules = Dict.empty
                                }
                    in
                    case result of
                        Err err ->
                            Expect.fail <| "Did not expect qualification to fail with error: " ++ Debug.toString err

                        Ok actualAst ->
                            Expect.equal expectedAst actualAst
            , test "Detects external reference in simple word" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.ExternalWord emptyRange [ "package", "module" ] "sample" ]
                                      }
                                    ]
                            }

                        expectedAst =
                            { additionalModulesRequired =
                                Set.fromList
                                    [ "/external/test/package/module" ]
                            , checkForExistingTypes = Set.empty
                            , checkForExistingWords =
                                Set.fromList
                                    [ "/external/test/package/module/sample"
                                    ]
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "/play/test/package/tests/call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            SoloImpl
                                                [ Word emptyRange "/external/test/package/module/sample" ]
                                      }
                                    ]
                            }

                        result =
                            run
                                { packageName = "play/test"
                                , modulePath = "package/tests"
                                , ast = unqualifiedAst
                                , externalModules =
                                    Dict.fromList
                                        [ ( "/package/module", "external/test" )
                                        ]
                                }
                    in
                    case result of
                        Err err ->
                            Expect.fail <| "Did not expect qualification to fail with error: " ++ Debug.toString err

                        Ok actualAst ->
                            Expect.equal expectedAst actualAst
            , test "Detects package reference in multiword" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange Type.Int [ ( "value", AST.LiteralInt 1 ) ]
                                                  , [ AST.PackageWord emptyRange [ "package", "module" ] "when-one"
                                                    ]
                                                  )
                                                ]
                                                [ AST.PackageWord emptyRange [ "package", "module" ] "when-other-one" ]
                                      }
                                    ]
                            }

                        expectedAst =
                            { additionalModulesRequired =
                                Set.fromList
                                    [ "/play/test/package/module" ]
                            , checkForExistingTypes = Set.empty
                            , checkForExistingWords =
                                Set.fromList
                                    [ "/play/test/package/module/when-one"
                                    , "/play/test/package/module/when-other-one"
                                    ]
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "/play/test/package/tests/call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange Type.Int [ ( "value", LiteralInt 1 ) ]
                                                  , [ Word emptyRange "/play/test/package/module/when-one"
                                                    ]
                                                  )
                                                ]
                                                [ Word emptyRange "/play/test/package/module/when-other-one" ]
                                      }
                                    ]
                            }

                        result =
                            run
                                { packageName = "play/test"
                                , modulePath = "package/tests"
                                , ast = unqualifiedAst
                                , externalModules = Dict.empty
                                }
                    in
                    case result of
                        Err err ->
                            Expect.fail <| "Did not expect qualification to fail with error: " ++ Debug.toString err

                        Ok actualAst ->
                            Expect.equal expectedAst actualAst
            , test "Detects external reference in multiword" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.emptyModuleDefinition
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange Type.Int [ ( "value", AST.LiteralInt 1 ) ]
                                                  , [ AST.ExternalWord emptyRange [ "package", "module" ] "when-one"
                                                    ]
                                                  )
                                                ]
                                                [ AST.ExternalWord emptyRange [ "package", "module" ] "when-other-one" ]
                                      }
                                    ]
                            }

                        expectedAst =
                            { additionalModulesRequired =
                                Set.fromList
                                    [ "/external/test/package/module" ]
                            , checkForExistingTypes = Set.empty
                            , checkForExistingWords =
                                Set.fromList
                                    [ "/external/test/package/module/when-one"
                                    , "/external/test/package/module/when-other-one"
                                    ]
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "/play/test/package/tests/call-external"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange Type.Int [ ( "value", LiteralInt 1 ) ]
                                                  , [ Word emptyRange "/external/test/package/module/when-one"
                                                    ]
                                                  )
                                                ]
                                                [ Word emptyRange "/external/test/package/module/when-other-one" ]
                                      }
                                    ]
                            }

                        result =
                            run
                                { packageName = "play/test"
                                , modulePath = "package/tests"
                                , ast = unqualifiedAst
                                , externalModules =
                                    Dict.fromList
                                        [ ( "/package/module", "external/test" )
                                        ]
                                }
                    in
                    case result of
                        Err err ->
                            Expect.fail <| "Did not expect qualification to fail with error: " ++ Debug.toString err

                        Ok actualAst ->
                            Expect.equal expectedAst actualAst
            ]
        , test "Retrieve dependant modules" <|
            \_ ->
                let
                    unqualifiedAst =
                        { moduleDefinition =
                            { aliases =
                                Dict.fromList







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1030
1031
1032
1033
1034
1035
1036

















































































































































































































































1037
1038
1039
1040
1041
1042
1043
                                        SoloImpl
                                            [ GetMember "/play/test/some/module/Wallet" "value" ]
                                  }
                                ]
                        }
                in
                QualifierUtil.expectModuleOutput unqualifiedAst expectedAst

















































































































































































































































        , test "Retrieve dependant modules" <|
            \_ ->
                let
                    unqualifiedAst =
                        { moduleDefinition =
                            { aliases =
                                Dict.fromList

Modified tests/Test/Qualifier/Util.elm from [f85a91ec9e] to [345820cd2a].

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import Expect exposing (Expectation)
import Play.Data.Metadata as Metadata
import Play.Data.SourceLocation exposing (emptyRange)
import Play.Data.Type as Type exposing (Type)
import Play.Parser as Parser
import Play.Qualifier as AST
    exposing
        ( ExposedAST
        , Node(..)
        , TypeDefinition
        , TypeMatch(..)
        , TypeMatchValue(..)
        , WordDefinition
        , WordImplementation(..)
        )
................................................................................
            (ctor :: setters)
                ++ getters
                |> Dict.fromListBy .name
    in
    { ast | words = Dict.union ast.words allFuncs }


stripLocations : ExposedAST -> ExposedAST
stripLocations ast =
    { types = Dict.map (\_ t -> stripTypeLocation t) ast.types
    , words = Dict.map (\_ d -> stripWordLocation d) ast.words
    }


stripTypeLocation : TypeDefinition -> TypeDefinition







|







 







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import Expect exposing (Expectation)
import Play.Data.Metadata as Metadata
import Play.Data.SourceLocation exposing (emptyRange)
import Play.Data.Type as Type exposing (Type)
import Play.Parser as Parser
import Play.Qualifier as AST
    exposing
        ( AST
        , Node(..)
        , TypeDefinition
        , TypeMatch(..)
        , TypeMatchValue(..)
        , WordDefinition
        , WordImplementation(..)
        )
................................................................................
            (ctor :: setters)
                ++ getters
                |> Dict.fromListBy .name
    in
    { ast | words = Dict.union ast.words allFuncs }


stripLocations : AST -> AST
stripLocations ast =
    { types = Dict.map (\_ t -> stripTypeLocation t) ast.types
    , words = Dict.map (\_ d -> stripWordLocation d) ast.words
    }


stripTypeLocation : TypeDefinition -> TypeDefinition