- File:
-
- 1 edited
-
src/ResolvExpr/CandidateFinder.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r2f31773 r06ecda9 1241 1241 Cost minCastCost = Cost::infinity; 1242 1242 for ( CandidateRef & cand : finder.candidates ) { 1243 ast::ptr< ast::Type > fromType = cand->expr->result;1244 assert( fromType );1245 fromType = resolveTypeof( fromType, context );1246 fromType = adjustExprType( fromType, tenv, symtab );1247 1248 1243 ast::AssertionSet need( cand->need.begin(), cand->need.end() ), have; 1249 1244 ast::OpenVarSet open( cand->open ); … … 1255 1250 // subexpression results that are cast directly. The candidate is invalid if it 1256 1251 // has fewer results than there are types to cast to. 1257 int discardedValues = fromType->size() - toType->size();1252 int discardedValues = cand->expr->result->size() - toType->size(); 1258 1253 if ( discardedValues < 0 ) continue; 1259 1254 1260 1255 // unification run for side-effects 1261 unify( toType, fromType, cand->env, need, have, open );1256 unify( toType, cand->expr->result, cand->env, need, have, open ); 1262 1257 Cost thisCost = 1263 1258 (castExpr->isGenerated == ast::GeneratedFlag::GeneratedCast) 1264 ? conversionCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env )1265 : castCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env );1259 ? conversionCost( cand->expr->result, toType, cand->expr->get_lvalue(), symtab, cand->env ) 1260 : castCost( cand->expr->result, toType, cand->expr->get_lvalue(), symtab, cand->env ); 1266 1261 1267 1262 // Redefine enum cast 1268 auto argAsEnum = fromType.as<ast::EnumInstType>();1263 auto argAsEnum = cand->expr->result.as<ast::EnumInstType>(); 1269 1264 auto toAsEnum = toType.as<ast::EnumInstType>(); 1270 1265 if ( argAsEnum && toAsEnum && argAsEnum->name != toAsEnum->name ) { … … 1277 1272 PRINT( 1278 1273 std::cerr << "working on cast with result: " << toType << std::endl; 1279 std::cerr << "and expr type: " << fromType<< std::endl;1274 std::cerr << "and expr type: " << cand->expr->result << std::endl; 1280 1275 std::cerr << "env: " << cand->env << std::endl; 1281 1276 ) … … 1286 1281 // count one safe conversion for each value that is thrown away 1287 1282 thisCost.incSafe( discardedValues ); 1288 1289 // See Aaron Moss, page 47; this reasoning does not hold since implicit conversions1290 // can create the same resolution issue. The C intrinsic interpretations are pruned1291 // immediately for the lowest cost option regardless of result type. Related code in1292 // postvisit (UntypedExpr).1293 // Cast expression costs are updated now to use the general rules.1294 /*1295 1283 // select first on argument cost, then conversion cost 1296 1284 if ( cand->cost < minExprCost || ( cand->cost == minExprCost && thisCost < minCastCost ) ) { … … 1301 1289 // ambigious case, still output candidates to print in error message 1302 1290 if ( cand->cost == minExprCost && thisCost == minCastCost ) { 1303 */1304 cand->cost += thisCost;1305 if (cand->cost < minExprCost) {1306 minExprCost = cand->cost;1307 matches.clear();1308 }1309 if (cand->cost == minExprCost) {1310 1291 CandidateRef newCand = std::make_shared<Candidate>( 1311 1292 restructureCast( cand->expr, toType, castExpr->isGenerated ), 1312 copy( cand->env ), std::move( open ), std::move( need ), cand->cost );1293 copy( cand->env ), std::move( open ), std::move( need ), cand->cost + thisCost); 1313 1294 // currently assertions are always resolved immediately so this should have no effect. 1314 1295 // if this somehow changes in the future (e.g. delayed by indeterminate return type)
Note:
See TracChangeset
for help on using the changeset viewer.