Goose  Diff

Differences From Artifact [4e8c5b5e0d]:

  • File bs/builtins/types/localvar/localvar.cpp — part of check-in [3cf6ab5249] at 2021-03-04 21:47:51 on branch trunk —
    • Refactored and simplified the way integer and string constants are handled: we no longer try to resolve them during typechecking, this breaks when parametric types are involved and also it makes no sense, typechecking is about types, not values
    • Fixed multiple places where locationIds weren't propagated
    • Verifier: variable assignments now verify the destination variable type's refinement conditions
    • Fixed a test where the above change detected a bug, kept the bugged version as a new verification failure test
    (user: achavasse size: 9559)

To Artifact [920f615b51]:

  • File bs/builtins/types/localvar/localvar.cpp — part of check-in [b2945b5bb1] at 2021-03-05 17:56:37 on branch trunk — Implemented refinement type predicate unification. Predicate violations by variable initialization are now properly detected. (user: achavasse size: 9660)

15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29







-
+








    const Term& LocalVar::PatternAnyOfTypeT::GetPattern()
    {
        static auto pattern = GetValueType< LocalVar >( HOLE( "T"_sid ) );
        return pattern;
    }

    Value DeclareLocalVar( const Context& c, const Term& type, StringId name, const optional< Value >& initializer )
    Value DeclareLocalVar( const Context& c, const Term& type, StringId name, const optional< Value >& initializer, uint32_t locId )
    {
        const auto& cb = c.codeBuilder();
        assert( cb );
        const auto& cfg = cb->cfg();

        auto index = cfg->getNewTemporaryIndex();

46
47
48
49
50
51
52
53

54
55
56
57
58
59

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
46
47
48
49
50
51
52

53
54
55
56
57
58

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87







-
+





-
+




















-
+







        {
            DiagnosticsContext dc( 0, "When invoking Initialize." );

            if( initializer )
            {
                initResult = InvokeOverloadSet( c,
                    c.env()->extInitialize(),
                    MakeTuple( ToValue( lv ), *initializer ) );
                    MakeTuple( ToValue( lv ).setLocationId( locId ), *initializer ) );
            }
            else
            {
                initResult = InvokeOverloadSet( c,
                    c.env()->extInitialize(),
                    MakeTuple( ToValue( lv ) ) );
                    MakeTuple( ToValue( lv ).setLocationId( locId ) ) );
            }
        }

        if( !initResult.isPoison() )
        {
            DiagnosticsContext dc2( initResult.locationId(), "When invoking DropValue." );
            InvokeOverloadSet( c, c.env()->extDropValue(),
                MakeTuple( move( initResult ) ) );
        }

        auto locVar = ToValue( lv );
        auto identity = AppendToVectorTerm( c.identity(), name );

        c.env()->storeValue( identity, ANYTERM( _ ),
            ValueToEIR( locVar ) );

        cb->pushLiveValue( locVar, lv.index() );
        return locVar;
    }

    Value DeclareLocalVarWithTypeInference( Context& c, const Term& typeTExpr, StringId name, const Value& initVal )
    Value DeclareLocalVarWithTypeInference( Context& c, const Term& typeTExpr, StringId name, const Value& initVal, uint32_t locId )
    {
        const auto& cb = c.codeBuilder();
        assert( cb );
        const auto& cfg = cb->cfg();

        auto bb = cfg->currentBB();
        if( !bb )
186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200







-
+








        bb->emplace_back( AllocVar( ValueFromEIR( lv.type() )->setLocationId( typeLoc ), index ) );

        DiagnosticsContext dc( 0, "When invoking Initialize." );

        auto initResult = InvokeOverloadSet( c,
            c.env()->extInitialize(),
            MakeTuple( ToValue( lv ), initVal ) );
            MakeTuple( ToValue( lv ).setLocationId( locId ), initVal ) );

        if( !initResult.isPoison() )
        {
            DiagnosticsContext dc2( initResult.locationId(), "When invoking DropValue." );
            InvokeOverloadSet( c, c.env()->extDropValue(),
                MakeTuple( move( initResult ) ) );
        }