Goose  Artifact [999bd78afd]

Artifact 999bd78afd19b8fe6925a4716fcfdeac01be4c75005058559ed4fb6d660b5f0f:

  • File bs/sema/overloadset.cpp — part of check-in [0b47976c86] at 2021-09-23 21:32:13 on branch failed-ovl-resolution-optim-attempt — An attempt at optimizing overload resolution which works but provides no gain, archived in case some of the code might end up being useful some day (user: achavasse size: 1309)

#include "builtins/builtins.h"

using namespace goose::sema;

bool OverloadSet::add( const Env& e, const Value& callee )
{
    auto pInvRule = GetInvocationRule( e, callee );
    assert( pInvRule );
    return add( e, callee, pInvRule );
}

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

    auto sigDecomp = Decompose( *signature,
        Val< pvec >()
    );

    assert( sigDecomp );

    auto pOverload = make_shared< Overload >( Overload{ pInvRule, callee } );

    bool success = false;
    m_trie = m_trie->merge( *sigDecomp->get(), [&]( auto&& previous ) -> ptr< Overload >
    {
        if( previous )
            return move( previous );

        success = true;
        return pOverload;
    } );

    return success;
}

OverloadSet::TCGen OverloadSet::typeCheck( const Term& callPat, const TypeCheckingContext& tcc ) const
{
    auto callDecomp = Decompose( callPat,
        Val< pvec >()
    );

    if( !callDecomp )
        co_return;

    for( auto&& [callVec,uniCallVec,ovl,tcc] : m_trie->typeCheck( *callDecomp->get(), tcc ) )
    {
        auto uniCall = TERM( make_shared< Vector >( uniCallVec ) );
        co_yield { move( uniCall ), ovl, tcc };
    }
}