Stabel

Check-in [c1e42b8f60]
Login
Overview
Comment:Fixed known bugs in PackageLoader.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c1e42b8f6018477229e02d8d2c1c1f67530ab180fe84b23ef08498f39bdf2e9e
User & Date: robin.hansen on 2021-08-06 09:39:32
Other Links: manifest | tags
Context
2021-08-06
15:17
Add source refs to parser problems. check-in: c7f7dbae5f user: robin.hansen tags: trunk
09:39
Fixed known bugs in PackageLoader. check-in: c1e42b8f60 user: robin.hansen tags: trunk
2021-08-05
18:02
Remove dead function in Data/SourceLocation. Use explicit exports in Parser/SourceLocation. check-in: d64aee902c user: robin.hansen tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Stabel/PackageLoader.elm from [a599786d84] to [be88572e7f].

103
104
105
106
107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
...
258
259
260
261
262
263
264
265
266




267
268
269
270
271
272
273
274
...
485
486
487
488
489
490
491





492
493
494
495
496
497
498
499
500
501
502
503
504
505

506
507
508
509
510
511
512
...
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
...
595
596
597
598
599
600
601




























602
603
604
605
606
607
608
...
618
619
620
621
622
623
624
625
626
    }


type alias ParsedModuleInfo =
    { packageName : PackageName
    , modulePath : ModuleName
    , ast : Parser.AST

    , requiredModules : Set String
    , source : String
    }


emptyState : InitOptions -> PackageInfo -> State
emptyState initOptions rootPackage =
    { rootPackage = rootPackage
    , dependencies = rootPackage.metadata.dependencies
    , dependentPackages = Dict.empty
    , filePathToModule = Dict.empty
    , moduleNameToPackageName = Dict.empty
    , absoluteModuleNameToDetails = Dict.empty
    , parsedModuleNames = Set.empty
................................................................................
                                metadataWithStdLib =
                                    { metadata
                                        | packagePaths =
                                            metadata.packagePaths ++ [ PackagePath.fromString initOpts.stdLibPath ]
                                    }

                                state =
                                    emptyState initOpts
                                        { path = path
                                        , metadata = metadataWithStdLib
                                        , modules = []
                                        }

                                pathsToLoad =
                                    List.map (PackagePath.prefix path) metadataWithStdLib.packagePaths
................................................................................
                                    List.remove (PackagePath.Directory path) remainingPaths
                            in
                            nextStep pathsToLoad state ""

                        Just _ ->
                            let
                                updatedState =
                                    -- TODO: Register dependencies of sub-packages
                                    { state




                                        | dependentPackages =
                                            Dict.update
                                                (PackageName.toString metadata.name)
                                                (insertHighestPackage
                                                    { path = path
                                                    , metadata = metadata
                                                    , modules = []
                                                    }
................................................................................
                    let
                        fullModuleName =
                            absoluteModuleName packageName moduleName

                        updatedParsedModules =
                            Set.insert fullModuleName state.parsedModuleNames






                        requiredModules =
                            Qualifier.requiredModules
                                { packageName = PackageName.toString packageName
                                , ast = parserAst
                                , externalModules = state.moduleNameToPackageName
                                }

                        updatedState =
                            { state
                                | parsedModuleNames = updatedParsedModules
                                , parsedModules =
                                    { packageName = packageName
                                    , modulePath = moduleName
                                    , ast = parserAst

                                    , requiredModules = requiredModules
                                    , source = content
                                    }
                                        :: state.parsedModules
                            }

                        modulesQueuedForOrAlreadyParsed =
................................................................................
                qualifyAst parsedModInfo ( qast, es ) =
                    let
                        qualifierResult =
                            Qualifier.run
                                { packageName = PackageName.toString parsedModInfo.packageName
                                , modulePath = ModuleName.toString parsedModInfo.modulePath
                                , ast = parsedModInfo.ast
                                , externalModules = state.moduleNameToPackageName
                                , inProgressAST = qast
                                }
                    in
                    case qualifierResult of
                        Err qualifierError ->
                            ( qast
                            , QualifierError parsedModInfo.source qualifierError :: es
................................................................................
        ( packageInfo, moduleName ) :: otherModules ->
            let
                ( path, fileName ) =
                    readModuleFromDisk packageInfo.path moduleName
            in
            Parsing state otherModules (ReadFile path fileName)






























sortByRequiredModules : ParsedModuleInfo -> ParsedModuleInfo -> Order
sortByRequiredModules a b =
    let
        aQualifiedName =
            absoluteModuleName a.packageName a.modulePath

................................................................................
    case ( aRequiredByB, bRequiredByA ) of
        ( True, False ) ->
            LT

        ( False, True ) ->
            GT

        otherwise ->
            EQ







>





|
|







 







|







 







<

>
>
>
>
|







 







>
>
>
>
>




|









>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
...
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
...
259
260
261
262
263
264
265

266
267
268
269
270
271
272
273
274
275
276
277
278
...
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
...
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
...
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
...
656
657
658
659
660
661
662
663
664
    }


type alias ParsedModuleInfo =
    { packageName : PackageName
    , modulePath : ModuleName
    , ast : Parser.AST
    , externalModules : Dict String String
    , requiredModules : Set String
    , source : String
    }


emptyState : PackageInfo -> State
emptyState rootPackage =
    { rootPackage = rootPackage
    , dependencies = rootPackage.metadata.dependencies
    , dependentPackages = Dict.empty
    , filePathToModule = Dict.empty
    , moduleNameToPackageName = Dict.empty
    , absoluteModuleNameToDetails = Dict.empty
    , parsedModuleNames = Set.empty
................................................................................
                                metadataWithStdLib =
                                    { metadata
                                        | packagePaths =
                                            metadata.packagePaths ++ [ PackagePath.fromString initOpts.stdLibPath ]
                                    }

                                state =
                                    emptyState
                                        { path = path
                                        , metadata = metadataWithStdLib
                                        , modules = []
                                        }

                                pathsToLoad =
                                    List.map (PackagePath.prefix path) metadataWithStdLib.packagePaths
................................................................................
                                    List.remove (PackagePath.Directory path) remainingPaths
                            in
                            nextStep pathsToLoad state ""

                        Just _ ->
                            let
                                updatedState =

                                    { state
                                        | dependencies =
                                            Dict.union
                                                state.dependencies
                                                metadata.dependencies
                                        , dependentPackages =
                                            Dict.update
                                                (PackageName.toString metadata.name)
                                                (insertHighestPackage
                                                    { path = path
                                                    , metadata = metadata
                                                    , modules = []
                                                    }
................................................................................
                    let
                        fullModuleName =
                            absoluteModuleName packageName moduleName

                        updatedParsedModules =
                            Set.insert fullModuleName state.parsedModuleNames

                        externalModules =
                            packageInfoByName state packageName
                                |> Maybe.map (buildExternalModules state)
                                |> Maybe.withDefault Dict.empty

                        requiredModules =
                            Qualifier.requiredModules
                                { packageName = PackageName.toString packageName
                                , ast = parserAst
                                , externalModules = externalModules
                                }

                        updatedState =
                            { state
                                | parsedModuleNames = updatedParsedModules
                                , parsedModules =
                                    { packageName = packageName
                                    , modulePath = moduleName
                                    , ast = parserAst
                                    , externalModules = externalModules
                                    , requiredModules = requiredModules
                                    , source = content
                                    }
                                        :: state.parsedModules
                            }

                        modulesQueuedForOrAlreadyParsed =
................................................................................
                qualifyAst parsedModInfo ( qast, es ) =
                    let
                        qualifierResult =
                            Qualifier.run
                                { packageName = PackageName.toString parsedModInfo.packageName
                                , modulePath = ModuleName.toString parsedModInfo.modulePath
                                , ast = parsedModInfo.ast
                                , externalModules = parsedModInfo.externalModules
                                , inProgressAST = qast
                                }
                    in
                    case qualifierResult of
                        Err qualifierError ->
                            ( qast
                            , QualifierError parsedModInfo.source qualifierError :: es
................................................................................
        ( packageInfo, moduleName ) :: otherModules ->
            let
                ( path, fileName ) =
                    readModuleFromDisk packageInfo.path moduleName
            in
            Parsing state otherModules (ReadFile path fileName)


packageInfoByName : State -> PackageName -> Maybe PackageInfo
packageInfoByName state packageName =
    if state.rootPackage.metadata.name == packageName then
        Just state.rootPackage

    else
        Dict.get (PackageName.toString packageName) state.dependentPackages


buildExternalModules : State -> PackageInfo -> Dict String String
buildExternalModules state package =
    package.metadata.dependencies
        |> Dict.keys
        |> List.filterMap (\packageName -> Dict.get packageName state.dependentPackages)
        |> List.map .metadata
        |> List.concatMap
            (\packageMeta ->
                packageMeta.exposedModules
                    |> List.map
                        (\modName ->
                            ( "/" ++ ModuleName.toString modName
                            , PackageName.toString packageMeta.name
                            )
                        )
            )
        |> Dict.fromList


sortByRequiredModules : ParsedModuleInfo -> ParsedModuleInfo -> Order
sortByRequiredModules a b =
    let
        aQualifiedName =
            absoluteModuleName a.packageName a.modulePath

................................................................................
    case ( aRequiredByB, bRequiredByA ) of
        ( True, False ) ->
            LT

        ( False, True ) ->
            GT

        _ ->
            EQ

Modified tests/Test/PackageLoader.elm from [356f240719] to [0e4aad1e63].

174
175
176
177
178
179
180
181




182
183
184
185
186
187
188
                            Expect.fail "Did not expect qualification to fail"

                        Ok _ ->
                            Expect.pass
            , test "An external reference shouldn't match an internal module" <|
                \_ ->
                    case load testFilesExternalRef of
                        Err _ ->




                            Expect.fail "Did not expect failure"

                        Ok _ ->
                            Expect.pass
            ]
        ]








|
>
>
>
>







174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
                            Expect.fail "Did not expect qualification to fail"

                        Ok _ ->
                            Expect.pass
            , test "An external reference shouldn't match an internal module" <|
                \_ ->
                    case load testFilesExternalRef of
                        Err err ->
                            let
                                _ =
                                    Debug.log "err" err
                            in
                            Expect.fail "Did not expect failure"

                        Ok _ ->
                            Expect.pass
            ]
        ]