| 1408 | } |
| 1409 | |
| 1410 | core::TypedExprPtr ExpressionFuzzer::ExprBank::getRandomExpression( |
| 1411 | const bytedance::bolt::TypePtr& returnType, |
| 1412 | int uptoLevelOfNesting) { |
| 1413 | BOLT_CHECK_LE(uptoLevelOfNesting, maxLevelOfNesting_); |
| 1414 | auto typeString = returnType->toString(); |
| 1415 | if (typeToExprsByLevel_.find(typeString) == typeToExprsByLevel_.end()) { |
| 1416 | return nullptr; |
| 1417 | } |
| 1418 | auto& expressionsByLevel = typeToExprsByLevel_[typeString]; |
| 1419 | int totalToConsider = 0; |
| 1420 | for (int i = 0; i <= uptoLevelOfNesting; i++) { |
| 1421 | totalToConsider += expressionsByLevel[i].size(); |
| 1422 | } |
| 1423 | if (totalToConsider > 0) { |
| 1424 | int choice = boost::random::uniform_int_distribution<uint32_t>( |
| 1425 | 0, totalToConsider - 1)(rng_); |
| 1426 | for (int i = 0; i <= uptoLevelOfNesting; i++) { |
| 1427 | if (choice >= expressionsByLevel[i].size()) { |
| 1428 | choice -= expressionsByLevel[i].size(); |
| 1429 | continue; |
| 1430 | } |
| 1431 | return expressionsByLevel[i][choice]; |
| 1432 | } |
| 1433 | BOLT_CHECK(false, "Should have found an expression."); |
| 1434 | } |
| 1435 | return nullptr; |
| 1436 | } |
| 1437 | |
| 1438 | TypePtr ExpressionFuzzer::fuzzReturnType() { |
| 1439 | auto chooseFromConcreteSignatures = rand32(0, 1); |