Goose  Diff

Differences From Artifact [7ede4c7a8e]:

  • File bs/sema/overloadset.cpp — part of check-in [c3f897359f] at 2020-06-20 14:32:02 on branch trunk —
    • Got rid of the gross system of performing unifications twice in all cases. It's only really needed when invoking template functions.
    • Since the above had the unexpected side effect of fixing the tuple Initialize() overloads not being called, fixed those (which were actually broken).
    (user: achavasse size: 2627)

To Artifact [9f06aaf715]:

  • File bs/sema/overloadset.cpp — part of check-in [568c366a36] at 2020-06-26 23:34:09 on branch trunk — Cleanup:
    • Removed the poorly thought out "domain" system that was intended to allow for different implementations of functions for runtime and for compilation time, which was adding an absurd amount of crap everywhere and should be unnecessary with the current planned approach for implementing data structures.
    • The using statement doesn't do lazy parsing anymore. Lazy parsing is better left to specific constructs that require them (such as function bodies and later on class/structs). This removes the only case of significant newline character in the language.
    (user: achavasse size: 1902)

12
13
14
15
16
17
18
19
20
21
22
23
24
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
67
68
69
70
71
72
73
74




75
76
77
78
79




80
81
82
83
84




85
86
87
88
89
90
12
13
14
15
16
17
18

19
20
21
22
23
24
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
67
68


69
70
71
72







-







-
+




-
-
-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
+
+
+
-
-
-
-
-
-





-
+








-
-
-
-
-
-
-
-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+
-
-




bool OverloadSet::add( const Env& e, const Value& callee, const ptr< InvocationRule >& pInvRule )
{
    auto signature = pInvRule->getSignature( callee );
    assert( signature );

    auto result = Decompose( *signature,
        Vec(
            SubTerm(),
            Val< pvec >(),
            SubTerm()
        )
    );

    assert( result );

    auto&& [domain, p, rt] = *result;
    auto&& [p, rt] = *result;
    const auto& rtype = rt;
    const auto& params = p;

    bool success = false;
    m_trie = Merge( m_trie, domain, [&]< class UT >( const ptr< UT >& paramUTrie )
    {
        auto uTrieMergeFunc = [&]( auto&& rtTrie )
        {
            return Merge( rtTrie, rtype, [&]( auto&& previous ) -> Overload
            {
                if( previous.callee )
                    return move( previous );
    m_trie = m_trie->merge( *params, [&]( auto&& rtTrie )
    {
        return Merge( rtTrie, rtype, [&]( auto&& previous ) -> Overload
        {
            if( previous.callee )
                return move( previous );

                success = true;
                return { pInvRule, callee };
            } );
            success = true;
            return { pInvRule, callee };
        } );
        };

        if( !paramUTrie )
            return UT().merge( *params, uTrieMergeFunc );

        return paramUTrie->merge( *params, uTrieMergeFunc );
    } );

    return success;
}

OverloadSet::UniGen OverloadSet::unify( const Term& domPat, const Term& argsPat, const Term& rtPat, const UnificationContext& uc ) const
OverloadSet::UniGen OverloadSet::unify( const Term& argsPat, const Term& rtPat, const UnificationContext& uc ) const
{
    auto argDecomp = Decompose( argsPat,
        Val< pvec >()
    );

    if( !argDecomp )
        co_return;

    for( auto&& [domain,paramUTrie] : Enumerate( m_trie ) )
    {
        auto localC = uc;
        localC.addComplexity( GetComplexity( domain ) + GetComplexity( domPat ) );

        for( auto&& [uniDom,uc] : Unify( domain, domPat, localC ) )
        {
            for( auto&& [paramsVec,uniParamsVec,rtTrie,uc] : paramUTrie->unify( *argDecomp->get(), uc ) )
            {
                auto params = TERM( make_shared< Vector >( paramsVec ) );
                auto uniParams = TERM( make_shared< Vector >( uniParamsVec ) );
    for( auto&& [paramsVec,uniParamsVec,rtTrie,uc] : m_trie->unify( *argDecomp->get(), uc ) )
    {
        auto params = TERM( make_shared< Vector >( paramsVec ) );
        auto uniParams = TERM( make_shared< Vector >( uniParamsVec ) );

                for( auto&& [rt,ovl] : Enumerate( rtTrie ) )
                {
                    auto localC = uc;
                    localC.addComplexity( GetComplexity( rt ) + GetComplexity( rtPat ) );
        for( auto&& [rt,ovl] : Enumerate( rtTrie ) )
        {
            auto localC = uc;
            localC.addComplexity( GetComplexity( rt ) + GetComplexity( rtPat ) );

                    for( auto&& [uniRt,uc] : Unify( rt, rtPat, localC ) )
                    {
                        auto uniCall = TERM( Vector::Make( uniDom, uniParams, uniRt ) );
                        co_yield { move( uniCall ), ovl, uc };
            for( auto&& [uniRt,uc] : Unify( rt, rtPat, localC ) )
            {
                auto uniCall = TERM( Vector::Make( uniParams, uniRt ) );
                co_yield { move( uniCall ), ovl, uc };
                    }
                }
            }
        }
    }
}