Play

Check-in [a64dc94e65]
Login
Overview
Comment:Fix bug where generic arguments in quotations didn't renamed properly in the type checking phase, causing bugs due to arguments not being unique and colliding with other generic arguments. Std library now compiles and runs successfully.
Timelines: family | ancestors | descendants | both | stdlib
Files: files | file ages | folders
SHA3-256: a64dc94e6514dba2804a709242762d4fd47419c59f38c7a392d14bd2416c8c02
User & Date: robin.hansen on 2021-04-16 14:56:21
Other Links: branch diff | manifest | tags
Context
2021-04-17
11:04
Add a couple of more functions to list module. Closed-Leaf check-in: 442b0f85ca user: robin.hansen tags: stdlib
2021-04-16
14:56
Fix bug where generic arguments in quotations didn't renamed properly in the type checking phase, ca... check-in: a64dc94e65 user: robin.hansen tags: stdlib
09:00
Undo bad commit. check-in: 8dbdb99d0a user: robin.hansen tags: stdlib
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/TypeChecker.elm from [b8dcd8121c] to [03b15c559b].

1054
1055
1056
1057
1058
1059
1060






1061
1062
1063
1064
1065
1066
1067
            Type.Generic (genName ++ String.fromInt idx)

        Type.CustomGeneric name generics ->
            Type.CustomGeneric name (List.map (tagGeneric idx) generics)

        Type.Union members ->
            Type.Union (List.map (tagGeneric idx) members)







        _ ->
            type_


wordTypeToStackEffects : WordType -> List StackEffect
wordTypeToStackEffects wordType =







>
>
>
>
>
>







1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
            Type.Generic (genName ++ String.fromInt idx)

        Type.CustomGeneric name generics ->
            Type.CustomGeneric name (List.map (tagGeneric idx) generics)

        Type.Union members ->
            Type.Union (List.map (tagGeneric idx) members)

        Type.Quotation wt ->
            Type.Quotation
                { input = List.map (tagGeneric idx) wt.input
                , output = List.map (tagGeneric idx) wt.output
                }

        _ ->
            type_


wordTypeToStackEffects : WordType -> List StackEffect
wordTypeToStackEffects wordType =

Modified src/Play/TypeChecker/Problem.elm from [4e260c0773] to [63d1018a02].

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
        TypeError range name actual expected ->
            SourceLocation.extractFromString source range
                ++ "\n\n"
                ++ "The type of '"
                ++ name
                ++ "' is specified to be:\n\n"
                ++ Type.wordTypeToString actual
                ++ "\n\nHowever, it seems that the actual type is: "
                ++ Type.wordTypeToString expected

        UnexpectedType range name actual expected ->
            SourceLocation.extractFromString source range
                ++ "\n\n"
                ++ "Found a problem in the implementation of '"
                ++ name







|







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
        TypeError range name actual expected ->
            SourceLocation.extractFromString source range
                ++ "\n\n"
                ++ "The type of '"
                ++ name
                ++ "' is specified to be:\n\n"
                ++ Type.wordTypeToString actual
                ++ "\n\nHowever, it seems that the actual type is:\n\n"
                ++ Type.wordTypeToString expected

        UnexpectedType range name actual expected ->
            SourceLocation.extractFromString source range
                ++ "\n\n"
                ++ "Found a problem in the implementation of '"
                ++ name

Modified tests/Test/TypeChecker.elm from [b208d7f987] to [51729be1c5].

392
393
394
395
396
397
398




































































































































































































399
400
401
402
403
404
405
                                ]
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
                case run input of
                    Err err ->
                        err




































































































































































































                            |> List.map (Problem.toString "")
                            |> String.join "\n"
                            |> (++) "Did not expect type check to fail.\n"
                            |> Expect.fail

                    Ok _ ->
                        Expect.pass







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







392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
                                ]
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
                case run input of
                    Err err ->
                        err
                            |> List.map (Problem.toString "")
                            |> String.join "\n"
                            |> (++) "Did not expect type check to fail.\n"
                            |> Expect.fail

                    Ok _ ->
                        Expect.pass
        , test "Generic types with generic quotations" <|
            \_ ->
                let
                    listUnion =
                        [ Type.Custom "Empty"
                        , Type.CustomGeneric "NonEmpty" [ Type.Generic "a" ]
                        ]

                    input =
                        { types =
                            Dict.fromListBy QAST.typeDefinitionName
                                [ QAST.CustomTypeDef "Pair"
                                    emptyRange
                                    [ "a", "b" ]
                                    [ ( "first", Type.Generic "a" )
                                    , ( "second", Type.Generic "b" )
                                    ]
                                , QAST.UnionTypeDef "List"
                                    emptyRange
                                    [ "a" ]
                                    listUnion
                                , QAST.CustomTypeDef "NonEmpty"
                                    emptyRange
                                    [ "a" ]
                                    [ ( "head", Type.Generic "a" )
                                    , ( "rest", Type.Union listUnion )
                                    ]
                                , QAST.CustomTypeDef "Empty" emptyRange [] []
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = "main"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [] [ Type.Int ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.Integer emptyRange 1
                                            , QAST.Integer emptyRange 2
                                            , QAST.Integer emptyRange 3
                                            , QAST.Word emptyRange "Empty"
                                            , QAST.Word emptyRange ">NonEmpty"
                                            , QAST.Word emptyRange ">NonEmpty"
                                            , QAST.Word emptyRange ">NonEmpty"
                                            , QAST.Integer emptyRange 0
                                            , QAST.WordRef emptyRange "main__quot1"
                                            , QAST.Word emptyRange "fold"
                                            ]
                                  }
                                , { name = "main__quot1"
                                  , metadata = Metadata.default
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.Builtin emptyRange Builtin.Plus
                                            ]
                                  }
                                , { name = "fold"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.Union listUnion
                                                , Type.Generic "b"
                                                , Type.Quotation
                                                    { input =
                                                        [ Type.Generic "a"
                                                        , Type.Generic "b"
                                                        ]
                                                    , output =
                                                        [ Type.Generic "b"
                                                        ]
                                                    }
                                                ]
                                                [ Type.Generic "b" ]
                                  , implementation =
                                        QAST.MultiImpl
                                            [ ( QAST.TypeMatch emptyRange (Type.Custom "Empty") []
                                              , [ QAST.Builtin emptyRange Builtin.StackDrop
                                                , QAST.Builtin emptyRange Builtin.StackSwap
                                                , QAST.Builtin emptyRange Builtin.StackDrop
                                                ]
                                              )
                                            , ( QAST.TypeMatch emptyRange (Type.CustomGeneric "NonEmpty" [ Type.Generic "a" ]) []
                                              , [ QAST.Word emptyRange ">Pair"
                                                , QAST.Builtin emptyRange Builtin.StackSwap
                                                , QAST.WordRef emptyRange "fold_quot1"
                                                , QAST.WordRef emptyRange "fold_quot2"
                                                , QAST.Word emptyRange "split"
                                                , QAST.Builtin emptyRange Builtin.StackRightRotate
                                                , QAST.Builtin emptyRange Builtin.StackSwap
                                                , QAST.Builtin emptyRange Builtin.StackDuplicate
                                                , QAST.Builtin emptyRange Builtin.StackRightRotate
                                                , QAST.Word emptyRange "spill"
                                                , QAST.Builtin emptyRange Builtin.Apply
                                                , QAST.Builtin emptyRange Builtin.StackSwap
                                                , QAST.Word emptyRange "second>"
                                                , QAST.Word emptyRange "fold"
                                                ]
                                              )
                                            ]
                                            []
                                  }
                                , { name = "fold_quot1"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.isQuoted
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.Word emptyRange "head>" ]
                                  }
                                , { name = "fold_quot2"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.isQuoted
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.Word emptyRange "rest>" ]
                                  }
                                , { name = "split"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.Generic "a"
                                                , Type.Quotation
                                                    { input = [ Type.Generic "a" ]
                                                    , output = [ Type.Generic "b" ]
                                                    }
                                                , Type.Quotation
                                                    { input = [ Type.Generic "a" ]
                                                    , output = [ Type.Generic "c" ]
                                                    }
                                                ]
                                                [ Type.Generic "b"
                                                , Type.Generic "c"
                                                ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.Builtin emptyRange Builtin.StackLeftRotate
                                            , QAST.Builtin emptyRange Builtin.StackDuplicate
                                            , QAST.Builtin emptyRange Builtin.StackLeftRotate
                                            , QAST.Builtin emptyRange Builtin.Apply
                                            , QAST.Builtin emptyRange Builtin.StackSwap
                                            , QAST.Builtin emptyRange Builtin.StackLeftRotate
                                            , QAST.Builtin emptyRange Builtin.Apply
                                            , QAST.Builtin emptyRange Builtin.StackSwap
                                            ]
                                  }
                                , { name = "spill"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType
                                                [ Type.CustomGeneric "Pair"
                                                    [ Type.Generic "a"
                                                    , Type.Generic "b"
                                                    ]
                                                ]
                                                [ Type.Generic "a"
                                                , Type.Generic "b"
                                                ]
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.WordRef emptyRange "spill_quot1"
                                            , QAST.WordRef emptyRange "spill_quot2"
                                            , QAST.Word emptyRange "split"
                                            ]
                                  }
                                , { name = "spill_quot1"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.isQuoted
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.Word emptyRange "first>" ]
                                  }
                                , { name = "spill_quot2"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.isQuoted
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.Word emptyRange "second>" ]
                                  }
                                ]
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
                case run input of
                    Err err ->
                        err
                            |> Debug.log "err"
                            |> List.map (Problem.toString "")
                            |> String.join "\n"
                            |> (++) "Did not expect type check to fail.\n"
                            |> Expect.fail

                    Ok _ ->
                        Expect.pass