Goose  Diff

Differences From Artifact [ebe39847e3]:

  • File bs/builtins/types/template/tc-tdecl.cpp — part of check-in [3bf30e74ac] at 2021-01-13 11:46:18 on branch trunk — Sema: simplification: the "half-unification" rules don't need to be generators, they can only output one result. (user: achavasse size: 7734)

To Artifact [b0d4d12599]:

  • File bs/builtins/types/template/tc-tdecl.cpp — part of check-in [7b9f645074] at 2021-01-21 21:05:48 on branch trunk — Removed the vector "typechecking rule", whose existence made no sense. Typechecking rules should operate only on values and pattern of values. Typechecking multiple values against multiple params is now done through a specific function instead. (user: achavasse size: 7756)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "builtins/builtins.h"

namespace goose::builtins
{
    Term BuildArgPatternFromTDecl( const TDecl& td )
    {
        return ValueToEIR( ValuePattern( HOLE( "_"_sid ), td.type(), HOLE( "_"_sid ) ) );
    }

    TCGen UnifyTDecl( const Term& lhs, const Term& rhs, TypeCheckingContext tcc )
    {
        auto tdecl = FromValue< TDecl >( *ValueFromEIR( lhs ) );
        assert( tdecl );

        auto tdeclHole = HOLE( tdecl->name() );

        auto pat = ValueToEIR( Value( tdecl->type(), HOLE( "_"_sid ) ) );

        // We are replacing lhs with a different terms and re-unifying,
        // so update the complexity accordingly. The structure of the tdecl
        // shouldn't count, only its pattern.
        tcc.subComplexity( GetComplexity( lhs ) );
        tcc.addComplexity( GetComplexity( pat ) );

        for( auto&& [s,tcc] : Unify( pat, rhs, tcc ) )
        {









|








|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "builtins/builtins.h"

namespace goose::builtins
{
    Term BuildArgPatternFromTDecl( const TDecl& td )
    {
        return ValueToEIR( ValuePattern( HOLE( "_"_sid ), td.type(), HOLE( "_"_sid ) ) );
    }

    TCGen TypeCheckTDecl( const Term& lhs, const Term& rhs, TypeCheckingContext tcc )
    {
        auto tdecl = FromValue< TDecl >( *ValueFromEIR( lhs ) );
        assert( tdecl );

        auto tdeclHole = HOLE( tdecl->name() );

        auto pat = ValueToEIR( Value( tdecl->type(), HOLE( "_"_sid ) ) );

        // We are replacing lhs with a different terms and typechecking again,
        // so update the complexity accordingly. The structure of the tdecl
        // shouldn't count, only its pattern.
        tcc.subComplexity( GetComplexity( lhs ) );
        tcc.addComplexity( GetComplexity( pat ) );

        for( auto&& [s,tcc] : Unify( pat, rhs, tcc ) )
        {
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
            []( const Term& lhs, TypeCheckingContext& c )
            {
                auto tdecl = FromValue< TDecl >( *ValueFromEIR( lhs ) );
                assert( tdecl );
                return HalfUnify( tdecl->type(), c );
            } );

        e.typeCheckingRuleSet()->addTypeCheckingRule( TCRINFOS, tDeclPat, ANYTERM( _ ), UnifyTDecl );
        e.typeCheckingRuleSet()->addTypeCheckingRule( TCRINFOS, tDeclPat, tDeclPat, UnifyTDecl );

        // tfunc tdecl param / tfunc arg
        auto tFuncTypePat = ValueToEIR( Value( TypeType(), VEC( TSID( texpr ), TSID( tfunc ),
            ANYTERM( _ ), ANYTERM( _ ), ANYTERM( _ ), ANYTERM( _ ) ) ) );

        auto tDeclTFuncPat = ParamPat( GetValueType< TDecl >(), VEC( tFuncTypePat, ANYTERM( _ ) ) );








|
|







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
            []( const Term& lhs, TypeCheckingContext& c )
            {
                auto tdecl = FromValue< TDecl >( *ValueFromEIR( lhs ) );
                assert( tdecl );
                return HalfUnify( tdecl->type(), c );
            } );

        e.typeCheckingRuleSet()->addTypeCheckingRule( TCRINFOS, tDeclPat, ANYTERM( _ ), TypeCheckTDecl );
        e.typeCheckingRuleSet()->addTypeCheckingRule( TCRINFOS, tDeclPat, tDeclPat, TypeCheckTDecl );

        // tfunc tdecl param / tfunc arg
        auto tFuncTypePat = ValueToEIR( Value( TypeType(), VEC( TSID( texpr ), TSID( tfunc ),
            ANYTERM( _ ), ANYTERM( _ ), ANYTERM( _ ), ANYTERM( _ ) ) ) );

        auto tDeclTFuncPat = ParamPat( GetValueType< TDecl >(), VEC( tFuncTypePat, ANYTERM( _ ) ) );

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

            // We are replacing lhs with a different terms and re-unifying,
            // so update the complexity accordingly. The structure of the tdecl
            // shouldn't count, only its pattern.
            tcc.subComplexity( GetComplexity( lhs ) );
            tcc.addComplexity( GetComplexity( callPat ) );

            for( auto&& [s, tcc] : TypeCheck( callPat, rhs, tcc ) )
            {
                // Restore the namespace
                tcc.setRHSNamespaceIndex( savedRHSNamespaceIndex );
                tcc.setValueResolutionRequired( oldValueRequired );

                // We need to unify the result with a hole named after the decl. However, since both sides of
                // this unification orignally appeared on the LHS, we need to setup RHS to alias the LHS namespace for this.







|







99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

            // We are replacing lhs with a different terms and re-unifying,
            // so update the complexity accordingly. The structure of the tdecl
            // shouldn't count, only its pattern.
            tcc.subComplexity( GetComplexity( lhs ) );
            tcc.addComplexity( GetComplexity( callPat ) );

            for( auto&& [s, tcc] : TypeCheckVec( callPat, rhs, tcc ) )
            {
                // Restore the namespace
                tcc.setRHSNamespaceIndex( savedRHSNamespaceIndex );
                tcc.setValueResolutionRequired( oldValueRequired );

                // We need to unify the result with a hole named after the decl. However, since both sides of
                // this unification orignally appeared on the LHS, we need to setup RHS to alias the LHS namespace for this.