Goose  Diff

Differences From Artifact [ef1f5063f2]:

  • File bs/builtins/types/template/tc-tdecl.cpp — part of check-in [64224a915f] at 2022-07-04 17:45:47 on branch trunk — Refactored some template rules and type checking rules to avoid calling BuildTemplateSignature from inside type checking rules (user: zlodo size: 7091)

To Artifact [e4e80c1046]:

  • File bs/builtins/types/template/tc-tdecl.cpp — part of check-in [9fd8a2a87e] at 2022-07-04 21:20:30 on branch trunk — typechecking: refactor type checking context to be able to hold more sub-context information than hole namespace indices (user: zlodo size: 6977)

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
                auto tdeclHole = HOLE( name );

                auto pat = ValueToEIR( Value( move( typeSig ), HOLE( "_"_sid ) ) );
                for( auto&& [s,tcc] : TypeCheck( pat, rhs, tcc ) )
                {
                    // We need to typecheck 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.
                    auto savedRHSNamespaceIndex = tcc.RHSNamespaceIndex();
                    tcc.setRHSNamespaceIndex( tcc.LHSNamespaceIndex() );

                    for( auto&& [s,tcc] : TypeCheck( s, tdeclHole, tcc ) )
                    {
                        tcc.setRHSNamespaceIndex( savedRHSNamespaceIndex );
                        co_yield { s, tcc };
                    }
                }
            } );

        e.typeCheckingRuleSet()->addUnificationRule( TCRINFOS, tDeclPat, ANYTERM( _ ),
            []( const Term& lhs, const Term& rhs, TypeCheckingContext tcc ) -> TCGen
            {
                auto [name,typeSig] = DecomposeTDSig( lhs );
                auto tdeclHole = HOLE( name );

                auto pat = ValueToEIR( Value( move( typeSig ), HOLE( "_"_sid ) ) );
                for( auto&& [s,tcc] : Unify( pat, rhs, tcc ) )
                {
                    // 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.
                    auto savedRHSNamespaceIndex = tcc.RHSNamespaceIndex();
                    tcc.setRHSNamespaceIndex( tcc.LHSNamespaceIndex() );

                    for( auto&& [s,tcc] : Unify( s, tdeclHole, tcc ) )
                    {
                        tcc.setRHSNamespaceIndex( savedRHSNamespaceIndex );
                        co_yield { s, tcc };
                    }
                }
            } );

        // tfunc tdecl param / tfunc arg
        auto tDeclTFuncPat = TDeclSigPattern( ANYTERM( _ ), TFuncTypeSigPattern( ANYTERM( _ ), ANYTERM( _ ) ) );







|
|



|
















|
|



|







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
                auto tdeclHole = HOLE( name );

                auto pat = ValueToEIR( Value( move( typeSig ), HOLE( "_"_sid ) ) );
                for( auto&& [s,tcc] : TypeCheck( pat, rhs, tcc ) )
                {
                    // We need to typecheck 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.
                    auto savedRHSSubContext = tcc.RHSSubContext();
                    tcc.RHSSubContext() = tcc.LHSSubContext();

                    for( auto&& [s,tcc] : TypeCheck( s, tdeclHole, tcc ) )
                    {
                        tcc.RHSSubContext() = savedRHSSubContext;
                        co_yield { s, tcc };
                    }
                }
            } );

        e.typeCheckingRuleSet()->addUnificationRule( TCRINFOS, tDeclPat, ANYTERM( _ ),
            []( const Term& lhs, const Term& rhs, TypeCheckingContext tcc ) -> TCGen
            {
                auto [name,typeSig] = DecomposeTDSig( lhs );
                auto tdeclHole = HOLE( name );

                auto pat = ValueToEIR( Value( move( typeSig ), HOLE( "_"_sid ) ) );
                for( auto&& [s,tcc] : Unify( pat, rhs, tcc ) )
                {
                    // 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.
                    auto savedRHSSubContext = tcc.RHSSubContext();
                    tcc.RHSSubContext() = tcc.LHSSubContext();

                    for( auto&& [s,tcc] : Unify( s, tdeclHole, tcc ) )
                    {
                        tcc.RHSSubContext() = savedRHSSubContext;
                        co_yield { s, tcc };
                    }
                }
            } );

        // tfunc tdecl param / tfunc arg
        auto tDeclTFuncPat = TDeclSigPattern( ANYTERM( _ ), TFuncTypeSigPattern( ANYTERM( _ ), ANYTERM( _ ) ) );
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
            auto rhsVal = *EIRToValue( rhs );

            ConstrainedFunc cfunc( tfSig, GetTFuncInvocationRule(), rhsVal );
            auto cFuncTerm = ValueToEIR( ToValue( move( cfunc ) ) );

            // Create a new named hole namespace to isolate holes from the passed function from those in
            // the called function.
            auto savedRHSNamespaceIndex = tcc.RHSNamespaceIndex();
            tcc.setRHSNamespaceIndex( tcc.newNamespaceIndex() );

            auto oldValueRequired = tcc.isValueResolutionRequired();
            tcc.setValueResolutionRequired( false );

            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.
                tcc.setRHSNamespaceIndex( tcc.LHSNamespaceIndex() );

                for( auto&& [s,tcc] : Unify( cFuncTerm, tdeclHole, tcc ) )
                {
                    tcc.setRHSNamespaceIndex( savedRHSNamespaceIndex );
                    co_yield { s, tcc };
                }
            }
        } );

        // tfunc tdecl param / overloadset arg
        e.typeCheckingRuleSet()->addTypeCheckingRule( TCRINFOS,







|
|







|




|



|







85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
            auto rhsVal = *EIRToValue( rhs );

            ConstrainedFunc cfunc( tfSig, GetTFuncInvocationRule(), rhsVal );
            auto cFuncTerm = ValueToEIR( ToValue( move( cfunc ) ) );

            // Create a new named hole namespace to isolate holes from the passed function from those in
            // the called function.
            auto savedRHSSubContext = tcc.RHSSubContext();
            tcc.RHSSubContext().namespaceIndex = tcc.newNamespaceIndex();

            auto oldValueRequired = tcc.isValueResolutionRequired();
            tcc.setValueResolutionRequired( false );

            for( auto&& [s, tcc] : TypeCheck( callPat, rhs, tcc ) )
            {
                // Restore the namespace
                tcc.RHSSubContext() = savedRHSSubContext;
                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.
                tcc.RHSSubContext() = tcc.LHSSubContext();

                for( auto&& [s,tcc] : Unify( cFuncTerm, tdeclHole, tcc ) )
                {
                    tcc.RHSSubContext() = savedRHSSubContext;
                    co_yield { s, tcc };
                }
            }
        } );

        // tfunc tdecl param / overloadset arg
        e.typeCheckingRuleSet()->addTypeCheckingRule( TCRINFOS,
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
            auto rhsVal = *EIRToValue( rhs );

            ConstrainedFunc cfunc( tfSig, GetOverloadSetInvocationRule(), rhsVal );
            auto cFuncTerm = ValueToEIR( ToValue( move( cfunc ) ) );

            // Create a new named hole namespace to isolate holes from the passed function from those in
            // the called function.
            auto savedRHSNamespaceIndex = tcc.RHSNamespaceIndex();
            tcc.setRHSNamespaceIndex( tcc.newNamespaceIndex() );

            auto oldValueRequired = tcc.isValueResolutionRequired();
            tcc.setValueResolutionRequired( false );

            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.
                tcc.setRHSNamespaceIndex( tcc.LHSNamespaceIndex() );

                for( auto&& [s,tcc] : Unify( cFuncTerm, tdeclHole, tcc ) )
                {
                    tcc.setRHSNamespaceIndex( savedRHSNamespaceIndex );
                    co_yield { s, tcc };
                }
            }
        } );
    }
}







|
|







|




|



|






134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
            auto rhsVal = *EIRToValue( rhs );

            ConstrainedFunc cfunc( tfSig, GetOverloadSetInvocationRule(), rhsVal );
            auto cFuncTerm = ValueToEIR( ToValue( move( cfunc ) ) );

            // Create a new named hole namespace to isolate holes from the passed function from those in
            // the called function.
            auto savedRHSSubContext = tcc.RHSSubContext();
            tcc.RHSSubContext().namespaceIndex = tcc.newNamespaceIndex();

            auto oldValueRequired = tcc.isValueResolutionRequired();
            tcc.setValueResolutionRequired( false );

            for( auto&& [s, tcc] : TypeCheck( callPat, rhs, tcc ) )
            {
                // Restore the namespace
                tcc.RHSSubContext() = savedRHSSubContext;
                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.
                tcc.RHSSubContext() = tcc.LHSSubContext();

                for( auto&& [s,tcc] : Unify( cFuncTerm, tdeclHole, tcc ) )
                {
                    tcc.RHSSubContext() = savedRHSSubContext;
                    co_yield { s, tcc };
                }
            }
        } );
    }
}