Stabel

Check-in [ecc08d85a0]
Login
Overview
Comment:Store in metadata whether a function is exposed or not.
Timelines: family | ancestors | descendants | both | module-definition
Files: files | file ages | folders
SHA3-256: ecc08d85a0e8a3d6889656043607ece238e033e19f365156b4b1fa958c58a91c
User & Date: robin.hansen on 2021-05-07 08:41:02
Other Links: branch diff | manifest | tags
Context
2021-05-07
09:07
Qualifier now throws an error if trying to call an unexposed function in a different module. check-in: fa15a3e3bd user: robin.hansen tags: module-definition
08:41
Store in metadata whether a function is exposed or not. check-in: ecc08d85a0 user: robin.hansen tags: module-definition
08:07
Refactored ModuleDefinition to be a custom type of either Defined or Undefined. check-in: 83e76bc143 user: robin.hansen tags: module-definition
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Data/Metadata.elm from [3efee805a7] to [3dff0edb1c].

9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
..
61
62
63
64
65
66
67





type alias Metadata =
    { isEntryPoint : Bool
    , type_ : TypeSignature
    , isQuoted : Bool
    , sourceLocationRange : Maybe SourceLocationRange
    , aliases : Dict String String
    , imports : Dict String (List String)

    }


default : Metadata
default =
    { isEntryPoint = False
    , type_ = NotProvided
    , isQuoted = False
    , sourceLocationRange = Nothing
    , aliases = Dict.empty
    , imports = Dict.empty

    }


asEntryPoint : Metadata -> Metadata
asEntryPoint meta =
    { meta | isEntryPoint = True }

................................................................................
withAlias ali val meta =
    { meta | aliases = Dict.insert ali val meta.aliases }


withImport : String -> List String -> Metadata -> Metadata
withImport ns vals meta =
    { meta | imports = Dict.insert ns vals meta.imports }












>











>







 







>
>
>
>
>
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
..
63
64
65
66
67
68
69
70
71
72
73
74
type alias Metadata =
    { isEntryPoint : Bool
    , type_ : TypeSignature
    , isQuoted : Bool
    , sourceLocationRange : Maybe SourceLocationRange
    , aliases : Dict String String
    , imports : Dict String (List String)
    , isExposed : Bool
    }


default : Metadata
default =
    { isEntryPoint = False
    , type_ = NotProvided
    , isQuoted = False
    , sourceLocationRange = Nothing
    , aliases = Dict.empty
    , imports = Dict.empty
    , isExposed = True
    }


asEntryPoint : Metadata -> Metadata
asEntryPoint meta =
    { meta | isEntryPoint = True }

................................................................................
withAlias ali val meta =
    { meta | aliases = Dict.insert ali val meta.aliases }


withImport : String -> List String -> Metadata -> Metadata
withImport ns vals meta =
    { meta | imports = Dict.insert ns vals meta.imports }


isExposed : Bool -> Metadata -> Metadata
isExposed val meta =
    { meta | isExposed = val }

Modified src/Play/Qualifier.elm from [02ca7b631a] to [c9b8e2da71].

273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
...
310
311
312
313
314
315
316


317



318
319
320
321
322
323
324
325
...
336
337
338
339
340
341
342







343
344
345
346
347
348
349
                |> List.foldr (qualifyWhen config qualifiedTypes unqualifiedWord.name moduleReferences) ( acc, [] )
                |> Tuple.mapSecond Result.combine

        ( newWordsAfterImpl, qualifiedImplementationResult ) =
            initQualifyNode config unqualifiedWord.name moduleReferences newWordsAfterWhens impl

        qualifiedMetadataResult =
            qualifyMetadata config qualifiedTypes unqualifiedWord.metadata

        qualifiedName =
            qualifyName config unqualifiedWord.name
    in
    case ( qualifiedWhensResult, qualifiedImplementationResult, qualifiedMetadataResult ) of
        ( Ok qualifiedWhens, Ok qualifiedImplementation, Ok qualifiedMetadata ) ->
            ( errors
................................................................................

        ( _, _, Err metaError ) ->
            ( metaError :: errors
            , newWordsAfterImpl
            )




qualifyMetadata : RunConfig -> Dict String TypeDefinition -> Metadata -> Result Problem Metadata



qualifyMetadata config qualifiedTypes meta =
    let
        wordRange =
            Maybe.withDefault SourceLocation.emptyRange meta.sourceLocationRange
    in
    TypeSignature.toMaybe meta.type_
        |> Maybe.map (\ts -> ts.input ++ ts.output)
        |> Maybe.withDefault []
................................................................................
                                }
                            )
                            meta.type_
                in
                { meta
                    | type_ =
                        TypeSignature.map (resolveUnions qualifiedTypes) ts







                }
            )


validateTypeReferences : RunConfig -> Dict String TypeDefinition -> SourceLocationRange -> Type -> Result Problem Type
validateTypeReferences config typeDefs wordRange type_ =
    case type_ of







|







 







>
>
|
>
>
>
|







 







>
>
>
>
>
>
>







273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
...
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
...
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
                |> List.foldr (qualifyWhen config qualifiedTypes unqualifiedWord.name moduleReferences) ( acc, [] )
                |> Tuple.mapSecond Result.combine

        ( newWordsAfterImpl, qualifiedImplementationResult ) =
            initQualifyNode config unqualifiedWord.name moduleReferences newWordsAfterWhens impl

        qualifiedMetadataResult =
            qualifyMetadata config qualifiedTypes unqualifiedWord.name unqualifiedWord.metadata

        qualifiedName =
            qualifyName config unqualifiedWord.name
    in
    case ( qualifiedWhensResult, qualifiedImplementationResult, qualifiedMetadataResult ) of
        ( Ok qualifiedWhens, Ok qualifiedImplementation, Ok qualifiedMetadata ) ->
            ( errors
................................................................................

        ( _, _, Err metaError ) ->
            ( metaError :: errors
            , newWordsAfterImpl
            )


qualifyMetadata :
    RunConfig
    -> Dict String TypeDefinition
    -> String
    -> Metadata
    -> Result Problem Metadata
qualifyMetadata config qualifiedTypes fnName meta =
    let
        wordRange =
            Maybe.withDefault SourceLocation.emptyRange meta.sourceLocationRange
    in
    TypeSignature.toMaybe meta.type_
        |> Maybe.map (\ts -> ts.input ++ ts.output)
        |> Maybe.withDefault []
................................................................................
                                }
                            )
                            meta.type_
                in
                { meta
                    | type_ =
                        TypeSignature.map (resolveUnions qualifiedTypes) ts
                    , isExposed =
                        case config.ast.moduleDefinition of
                            Parser.Undefined ->
                                True

                            Parser.Defined def ->
                                Set.member fnName def.exposes
                }
            )


validateTypeReferences : RunConfig -> Dict String TypeDefinition -> SourceLocationRange -> Type -> Result Problem Type
validateTypeReferences config typeDefs wordRange type_ =
    case type_ of

Modified tests/Test/Qualifier.elm from [386043c227] to [74c8820178].

1347
1348
1349
1350
1351
1352
1353

1354

1355
1356
1357
1358
1359
1360
1361
....
1407
1408
1409
1410
1411
1412
1413

1414
1415
1416
1417
1418
1419
1420
....
1465
1466
1467
1468
1469
1470
1471

1472

1473
1474
1475
1476
1477
1478
1479
....
1527
1528
1529
1530
1531
1532
1533

1534
1535
1536
1537
1538
1539
1540
....
1550
1551
1552
1553
1554
1555
1556















1557








1558






























































































                            }

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"

                                      , metadata = Metadata.default

                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Word emptyRange "internal/mod/value"
                                                , Word emptyRange "/external/package/mod/add"
                                                ]
                                      }
................................................................................
                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default

                                                |> Metadata.withAlias "internal" "internal/mod"
                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Word emptyRange "internal/mod/value"
                                                , Word emptyRange "/external/package/mod/add"
                                                ]
................................................................................
                            }

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"

                                      , metadata = Metadata.default

                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Word emptyRange "internal/mod/value"
                                                , Word emptyRange "/external/package/mod/add"
                                                ]
                                      }
................................................................................
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withImport "/mod" [ "add" ]

                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Word emptyRange "internal/mod/value"
                                                , Word emptyRange "/external/package/mod/add"
                                                ]
                                      }
................................................................................
                                    ]
                            }
                    in
                    QualifierUtil.expectExternalOutput
                        inProgressAst
                        unqualifiedAst
                        expectedAst















            ]








        ]





































































































>
|
>







 







>







 







>
|
>







 







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
....
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
....
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
....
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
....
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
                            }

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.isExposed False
                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Word emptyRange "internal/mod/value"
                                                , Word emptyRange "/external/package/mod/add"
                                                ]
                                      }
................................................................................
                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.isExposed False
                                                |> Metadata.withAlias "internal" "internal/mod"
                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Word emptyRange "internal/mod/value"
                                                , Word emptyRange "/external/package/mod/add"
                                                ]
................................................................................
                            }

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.isExposed False
                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Word emptyRange "internal/mod/value"
                                                , Word emptyRange "/external/package/mod/add"
                                                ]
                                      }
................................................................................
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "external-call"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withImport "/mod" [ "add" ]
                                                |> Metadata.isExposed False
                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Word emptyRange "internal/mod/value"
                                                , Word emptyRange "/external/package/mod/add"
                                                ]
                                      }
................................................................................
                                    ]
                            }
                    in
                    QualifierUtil.expectExternalOutput
                        inProgressAst
                        unqualifiedAst
                        expectedAst
            , test "When module doesn't have a definition, all functions are exposed" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition = AST.Undefined
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "fn1"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Integer emptyRange 1
                                                , AST.Integer emptyRange 2
                                                , AST.Word emptyRange "+"
                                                ]
                                      }
                                    , { name = "fn2"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Integer emptyRange 2
                                                , AST.Integer emptyRange 3
                                                , AST.Word emptyRange "+"
                                                ]
                                      }
                                    ]
                            }

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "fn1"
                                      , metadata = Metadata.default
                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Integer emptyRange 2
                                                , Builtin emptyRange Builtin.Plus
                                                ]
                                      }
                                    , { name = "fn2"
                                      , metadata = Metadata.default
                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 2
                                                , Integer emptyRange 3
                                                , Builtin emptyRange Builtin.Plus
                                                ]
                                      }
                                    ]
                            }
                    in
                    QualifierUtil.expectOutput unqualifiedAst expectedAst
            , test "When module does have a definition, only functions defined to be exposed are" <|
                \_ ->
                    let
                        unqualifiedAst =
                            { moduleDefinition =
                                AST.Defined
                                    { aliases = Dict.empty
                                    , imports = Dict.empty
                                    , exposes = Set.fromList [ "fn2" ]
                                    }
                            , types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "fn1"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Integer emptyRange 1
                                                , AST.Integer emptyRange 2
                                                , AST.Word emptyRange "+"
                                                ]
                                      }
                                    , { name = "fn2"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.SoloImpl
                                                [ AST.Integer emptyRange 2
                                                , AST.Integer emptyRange 3
                                                , AST.Word emptyRange "+"
                                                ]
                                      }
                                    ]
                            }

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "fn1"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.isExposed False
                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 1
                                                , Integer emptyRange 2
                                                , Builtin emptyRange Builtin.Plus
                                                ]
                                      }
                                    , { name = "fn2"
                                      , metadata = Metadata.default
                                      , implementation =
                                            SoloImpl
                                                [ Integer emptyRange 2
                                                , Integer emptyRange 3
                                                , Builtin emptyRange Builtin.Plus
                                                ]
                                      }
                                    ]
                            }
                    in
                    QualifierUtil.expectOutput unqualifiedAst expectedAst
            ]
        ]