Goose  Diff

Differences From Artifact [41ede5e823]:

  • File bs/builtins/types/localvar/localvar.cpp — part of check-in [10df99e08a] at 2020-05-04 18:43:39 on branch trunk — Refactored the Initialize() extension point to take a mutable reference instead of directly taking a locvar. (user: achavasse size: 9403)

To Artifact [0463157510]:

  • File bs/builtins/types/localvar/localvar.cpp — part of check-in [ebdba2e941] at 2020-05-13 18:15:01 on branch trunk — References:
    • When doing variable declaration local type inference, look for an initialization function that takes a mutable reference on the lhs, instead of a local variable.
    • As a result of the above, got rid of Initialize() overloads for local variables.
    • The assignment operator now takes a mutable reference on the lhs, instead of directly working on a local variable.
    (user: achavasse size: 9438)

80
81
82
83
84
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

        auto bb = cfg->currentBB();
        if( !bb )
            return PoisonValue();

        // To infer the type and obtain a suitable initialization function,
        // we want the declaration to behave as if it were the following function call:
        // Params: ( $T,  _ ( LocalVar[$T], initValType ) initFunc )
        // Args:   ( pat, Initialize                               )
        //
        // Where pat is the TNamedDecl's type pattern and initValType is the initialization
        // expression's type.

        // We construct the above expressions and unify them. The best solution (if any)
        // will give us the wanted type and the function to invoke to initialize it.

        // Create the _ texpr.
        static auto anyTVar = ValueToIRExpr( ToValue( TVar( "_"_sid ) ) );

        // The $T texpr.
        static auto TTVar = ValueToIRExpr( ToValue( TVar( "T"_sid ) ) );

        // Create the LocalVar[$T] param.
        auto locVarPatParam = ValueToIRExpr( ToValue( TNamedDecl( GetValueType< LocalVar >( TTVar ), "lv"_sid ) ) );

        auto initValPattern = ValueToIRExpr( ValuePattern( TSID( constant ), initVal.type(), MkHole( "_"_sid ) ) );

        // Create the _ ( LocalVar[pat], initType ) initFunc param.
        auto initFuncTFTParam = ValueToIRExpr( ToValue(
            TNamedDecl( ValueToIRExpr( ToValue( TFuncType( DomainAny(), anyTVar, VEC( move( locVarPatParam ), move( initValPattern ) ),
            make_shared< vector< TermLoc > >(), make_shared< vector< TermLoc > >() ) ) ), "initFunc"_sid ) ) );

        // Create our parameter list pattern.
        auto paramPat = VEC(
            *BuildTemplateSignature( c, TTVar ),
            *BuildTemplateSignature( c, initFuncTFTParam )
        );







|
|













|
|



|

|







80
81
82
83
84
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

        auto bb = cfg->currentBB();
        if( !bb )
            return PoisonValue();

        // To infer the type and obtain a suitable initialization function,
        // we want the declaration to behave as if it were the following function call:
        // Params: ( $T,  _ ( MutRef[$T], initValType ) initFunc )
        // Args:   ( pat, Initialize                             )
        //
        // Where pat is the TNamedDecl's type pattern and initValType is the initialization
        // expression's type.

        // We construct the above expressions and unify them. The best solution (if any)
        // will give us the wanted type and the function to invoke to initialize it.

        // Create the _ texpr.
        static auto anyTVar = ValueToIRExpr( ToValue( TVar( "_"_sid ) ) );

        // The $T texpr.
        static auto TTVar = ValueToIRExpr( ToValue( TVar( "T"_sid ) ) );

        // Create the MutRef[$T] param.
        auto mutRefParamPattern = ValueToIRExpr( ToValue( TNamedDecl( GetValueType< Reference >( TTVar, ReferenceType::Behavior::Mutable ), "lv"_sid ) ) );

        auto initValPattern = ValueToIRExpr( ValuePattern( TSID( constant ), initVal.type(), MkHole( "_"_sid ) ) );

        // Create the _ ( MutRef[pat], initType ) initFunc param.
        auto initFuncTFTParam = ValueToIRExpr( ToValue(
            TNamedDecl( ValueToIRExpr( ToValue( TFuncType( DomainAny(), anyTVar, VEC( move( mutRefParamPattern ), move( initValPattern ) ),
            make_shared< vector< TermLoc > >(), make_shared< vector< TermLoc > >() ) ) ), "initFunc"_sid ) ) );

        // Create our parameter list pattern.
        auto paramPat = VEC(
            *BuildTemplateSignature( c, TTVar ),
            *BuildTemplateSignature( c, initFuncTFTParam )
        );