Changeset 0c840fc


Ignore:
Timestamp:
May 2, 2023, 3:45:08 AM (12 months ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ast-experimental, master
Children:
34b4268
Parents:
46da46b
Message:

WIP some bugs show up resolving array tuple indexing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/SatisfyAssertions.cpp

    r46da46b r0c840fc  
    143143        };
    144144
    145 
     145        enum AssertionResult {Fail, Skip, Success} ;
    146146
    147147        /// Binds a single assertion, updating satisfaction state
     
    164164
    165165        /// Satisfy a single assertion
    166         bool satisfyAssertion( ast::AssertionList::value_type & assn, SatState & sat, bool skipUnbound = false) {
     166        AssertionResult satisfyAssertion( ast::AssertionList::value_type & assn, SatState & sat, bool skipUnbound = false) {
    167167                // skip unused assertions
    168168                static unsigned int cnt = 0;
    169                 if ( ! assn.second.isUsed ) return true;
     169                if ( ! assn.second.isUsed ) return AssertionResult::Success;
    170170
    171171                if (assn.first->var->name[1] == '|') std::cerr << ++cnt << std::endl;
     
    186186                        if (thisArgType.as<ast::PointerType>()) otypeKey = Mangle::Encoding::pointer;
    187187                        else if (!isUnboundType(thisArgType)) otypeKey = Mangle::mangle(thisArgType, Mangle::Type | Mangle::NoGenericParams);
    188                         else if (skipUnbound) return false;
     188                        else if (skipUnbound) return AssertionResult::Skip;
    189189
    190190                        candidates = sat.symtab.specialLookupId(kind, otypeKey);
     
    251251                // break if no satisfying match
    252252                if ( matches.empty() ) matches = std::move(inexactMatches);
    253                 if ( matches.empty() ) return false;
     253                if ( matches.empty() ) return AssertionResult::Fail;
    254254
    255255                // defer if too many satisfying matches
    256256                if ( matches.size() > 1 ) {
    257257                        sat.deferred.emplace_back( assn.first, assn.second, std::move( matches ) );
    258                         return true;
     258                        return AssertionResult::Success;
    259259                }
    260260
     
    267267
    268268                bindAssertion( assn.first, assn.second, sat.cand, match, sat.inferred );
    269                 return true;
     269                return AssertionResult::Success;
    270270        }
    271271
     
    456456                                for ( auto & assn : sat.need ) {
    457457                                        // fail early if any assertion is not satisfiable
    458                                         if ( ! satisfyAssertion( assn, sat, !next.empty() ) ) {
    459                                                 next.emplace_back(assn);
    460                                                 // goto nextSat;
    461                                         }
    462                                 }
    463                                 // success
    464                                 if (next.empty()) break;
    465                                 // fail if nothing resolves
    466                                 else if (next.size() == sat.need.size()) {
    467                                         // if (allowConversion) {
     458                                        auto result = satisfyAssertion( assn, sat, !next.empty() );
     459                                        if ( result == AssertionResult::Fail ) {
    468460                                                Indenter tabs{ 3 };
    469461                                                std::ostringstream ss;
     
    471463                                                print( ss, *sat.cand, ++tabs );
    472464                                                ss << (tabs-1) << "Could not satisfy assertion:\n";
    473                                                 ast::print( ss, next[0].first, tabs );
     465                                                ast::print( ss, assn.first, tabs );
    474466
    475467                                                errors.emplace_back( ss.str() );
    476468                                                goto nextSat;
    477                                         // }
    478 
    479                                         // else {
    480                                         //      allowConversion = true;
    481                                         //      continue;
    482                                         // }
    483                                 }
     469                                        }
     470                                        else if ( result == AssertionResult::Skip ) {
     471                                                next.emplace_back(assn);
     472                                                // goto nextSat;
     473                                        }
     474                                }
     475                                // success
     476                                if (next.empty()) break;
     477
    484478                                sat.need = std::move(next);
    485479                        }
Note: See TracChangeset for help on using the changeset viewer.