Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    r7ff3e522 r07de76b  
    2525#include <vector>
    2626
    27 #include "AST/Copy.hpp"
    2827#include "AST/Decl.hpp"
    2928#include "AST/Node.hpp"
    3029#include "AST/Pass.hpp"
    31 #include "AST/Print.hpp"
    3230#include "AST/Type.hpp"
    3331#include "AST/TypeEnvironment.hpp"
     
    137135                findOpenVars( newSecond, open, closed, need, have, FirstOpen );
    138136
    139                 return unifyExact(newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab );
     137                return unifyExact(
     138                        newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab );
    140139        }
    141140
     
    149148                newFirst->get_qualifiers() = Type::Qualifiers();
    150149                newSecond->get_qualifiers() = Type::Qualifiers();
    151 
     150///   std::cerr << "first is ";
     151///   first->print( std::cerr );
     152///   std::cerr << std::endl << "second is ";
     153///   second->print( std::cerr );
     154///   std::cerr << std::endl << "newFirst is ";
     155///   newFirst->print( std::cerr );
     156///   std::cerr << std::endl << "newSecond is ";
     157///   newSecond->print( std::cerr );
     158///   std::cerr << std::endl;
    152159                bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    153160                delete newFirst;
     
    163170                ast::AssertionSet need, have;
    164171
    165                 ast::Type * newFirst  = shallowCopy( first  );
    166                 ast::Type * newSecond = shallowCopy( second );
    167                 newFirst ->qualifiers = {};
    168                 newSecond->qualifiers = {};
    169                 ast::ptr< ast::Type > t1_(newFirst );
    170                 ast::ptr< ast::Type > t2_(newSecond);
    171 
    172                 ast::ptr< ast::Type > subFirst = env.apply(newFirst).node;
    173                 ast::ptr< ast::Type > subSecond = env.apply(newSecond).node;
     172                ast::ptr<ast::Type> newFirst{ first }, newSecond{ second };
     173                env.apply( newFirst );
     174                env.apply( newSecond );
     175                reset_qualifiers( newFirst );
     176                reset_qualifiers( newSecond );
    174177
    175178                return unifyExact(
    176                         subFirst,
    177                         subSecond,
    178                         newEnv, need, have, open, noWiden(), symtab );
     179                        newFirst, newSecond, newEnv, need, have, open, noWiden(), symtab );
    179180        }
    180181
     
    325326
    326327        void markAssertionSet( AssertionSet &assertions, DeclarationWithType *assert ) {
     328///   std::cerr << "assertion set is" << std::endl;
     329///   printAssertionSet( assertions, std::cerr, 8 );
     330///   std::cerr << "looking for ";
     331///   assert->print( std::cerr );
     332///   std::cerr << std::endl;
    327333                AssertionSet::iterator i = assertions.find( assert );
    328334                if ( i != assertions.end() ) {
     335///     std::cerr << "found it!" << std::endl;
    329336                        i->second.isUsed = true;
    330337                } // if
     
    702709                const ast::SymbolTable & symtab;
    703710        public:
    704                 static size_t traceId;
    705711                bool result;
    706712
     
    937943
    938944        private:
    939                 // Returns: other, cast as XInstType
    940                 // Assigns this->result: whether types are compatible (up to generic parameters)
    941                 template< typename XInstType >
    942                 const XInstType * handleRefType( const XInstType * inst, const ast::Type * other ) {
     945                template< typename RefType >
     946                const RefType * handleRefType( const RefType * inst, const ast::Type * other ) {
    943947                        // check that the other type is compatible and named the same
    944                         auto otherInst = dynamic_cast< const XInstType * >( other );
    945                         this->result = otherInst && inst->name == otherInst->name;
     948                        auto otherInst = dynamic_cast< const RefType * >( other );
     949                        result = otherInst && inst->name == otherInst->name;
    946950                        return otherInst;
    947951                }
     
    964968                }
    965969
    966                 template< typename XInstType >
    967                 void handleGenericRefType( const XInstType * inst, const ast::Type * other ) {
     970                template< typename RefType >
     971                void handleGenericRefType( const RefType * inst, const ast::Type * other ) {
    968972                        // check that other type is compatible and named the same
    969                         const XInstType * otherInst = handleRefType( inst, other );
    970                         if ( ! this->result ) return;
     973                        const RefType * inst2 = handleRefType( inst, other );
     974                        if ( ! inst2 ) return;
    971975
    972976                        // check that parameters of types unify, if any
    973977                        const std::vector< ast::ptr< ast::Expr > > & params = inst->params;
    974                         const std::vector< ast::ptr< ast::Expr > > & params2 = otherInst->params;
     978                        const std::vector< ast::ptr< ast::Expr > > & params2 = inst2->params;
    975979
    976980                        auto it = params.begin();
     
    11361140        };
    11371141
    1138         // size_t Unify_new::traceId = Stats::Heap::new_stacktrace_id("Unify_new");
    11391142        bool unify(
    11401143                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
     
    11851188                        ast::Pass<Unify_new> comparator{ type2, env, need, have, open, widen, symtab };
    11861189                        type1->accept( comparator );
    1187                         return comparator.core.result;
     1190                        return comparator.pass.result;
    11881191                }
    11891192        }
     
    11991202                // force t1 and t2 to be cloned if their qualifiers must be stripped, so that type1 and
    12001203                // type2 are left unchanged; calling convention forces type{1,2}->strong_ref >= 1
    1201                 ast::Type * t1 = shallowCopy(type1.get());
    1202                 ast::Type * t2 = shallowCopy(type2.get());
    1203                 t1->qualifiers = {};
    1204                 t2->qualifiers = {};
    1205                 ast::ptr< ast::Type > t1_(t1);
    1206                 ast::ptr< ast::Type > t2_(t2);
     1204                ast::ptr<ast::Type> t1{ type1 }, t2{ type2 };
     1205                reset_qualifiers( t1 );
     1206                reset_qualifiers( t2 );
    12071207
    12081208                if ( unifyExact( t1, t2, env, need, have, open, widen, symtab ) ) {
     1209                        t1 = nullptr; t2 = nullptr; // release t1, t2 to avoid spurious clones
     1210
    12091211                        // if exact unification on unqualified types, try to merge qualifiers
    12101212                        if ( q1 == q2 || ( ( q1 > q2 || widen.first ) && ( q2 > q1 || widen.second ) ) ) {
    1211                                 t1->qualifiers = q1 | q2;
    1212                                 common = t1;
     1213                                common = type1;
     1214                                reset_qualifiers( common, q1 | q2 );
    12131215                                return true;
    12141216                        } else {
     
    12171219
    12181220                } else if (( common = commonType( t1, t2, widen, symtab, env, open ) )) {
     1221                        t1 = nullptr; t2 = nullptr; // release t1, t2 to avoid spurious clones
     1222
    12191223                        // no exact unification, but common type
    1220                         auto c = shallowCopy(common.get());
    1221                         c->qualifiers = q1 | q2;
    1222                         common = c;
     1224                        reset_qualifiers( common, q1 | q2 );
    12231225                        return true;
    12241226                } else {
Note: See TracChangeset for help on using the changeset viewer.