| 1255 | } |
| 1256 | |
| 1257 | Expect<void> |
| 1258 | Validator::validateCanonLift(const AST::Component::Canonical &Canon) noexcept { |
| 1259 | const uint32_t CoreFuncIdx = Canon.getIndex(); |
| 1260 | const uint32_t CoreFuncSpaceSize = |
| 1261 | CompCtx.getCoreSortIndexSize(AST::Component::Sort::CoreSortType::Func); |
| 1262 | // 1. Core func index bounds. |
| 1263 | if (CoreFuncIdx >= CoreFuncSpaceSize) { |
| 1264 | spdlog::error(ErrCode::Value::InvalidIndex); |
| 1265 | spdlog::error( |
| 1266 | " canon lift: core func index {} exceeds core func index space size {}"sv, |
| 1267 | CoreFuncIdx, CoreFuncSpaceSize); |
| 1268 | spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical)); |
| 1269 | return Unexpect(ErrCode::Value::InvalidIndex); |
| 1270 | } |
| 1271 | const uint32_t TypeIdx = Canon.getTargetIndex(); |
| 1272 | const uint32_t TypeSpaceSize = |
| 1273 | CompCtx.getSortIndexSize(AST::Component::Sort::SortType::Type); |
| 1274 | // 2. Target type index bounds. |
| 1275 | if (TypeIdx >= TypeSpaceSize) { |
| 1276 | spdlog::error(ErrCode::Value::InvalidIndex); |
| 1277 | spdlog::error( |
| 1278 | " canon lift: type index {} exceeds type index space size {}"sv, |
| 1279 | TypeIdx, TypeSpaceSize); |
| 1280 | spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical)); |
| 1281 | return Unexpect(ErrCode::Value::InvalidIndex); |
| 1282 | } |
| 1283 | // 3. Target type must be a component FuncType. |
| 1284 | const auto *DT = CompCtx.getDefType(TypeIdx); |
| 1285 | if (DT == nullptr) { |
| 1286 | // Unresolved slot: the index was registered by an import or outer alias |
| 1287 | // but the concrete definition has not been filled in yet. |
| 1288 | spdlog::error(ErrCode::Value::InvalidTypeReference); |
| 1289 | spdlog::error( |
| 1290 | " canon lift: target type index {} is an unresolved type slot"sv, |
| 1291 | TypeIdx); |
| 1292 | spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical)); |
| 1293 | return Unexpect(ErrCode::Value::InvalidTypeReference); |
| 1294 | } |
| 1295 | if (!DT->isFuncType()) { |
| 1296 | spdlog::error(ErrCode::Value::InvalidTypeReference); |
| 1297 | spdlog::error( |
| 1298 | " canon lift: target type index {} does not reference a component func type"sv, |
| 1299 | TypeIdx); |
| 1300 | spdlog::error(ErrInfo::InfoAST(ASTNodeAttr::Comp_Canonical)); |
| 1301 | return Unexpect(ErrCode::Value::InvalidTypeReference); |
| 1302 | } |
| 1303 | // 4. Validate canonical options (Lift site allows all). |
| 1304 | EXPECTED_TRY(validateCanonOptions(Canon.getOpCode(), Canon.getOptions())); |
| 1305 | // 5. Allocate component func, binding the resolved FuncType. Full ABI |
| 1306 | // signature match (flat_lifted) deferred as GAP-C-1b. |
| 1307 | CompCtx.addFunc(&DT->getFuncType()); |
| 1308 | return {}; |
| 1309 | } |
| 1310 | |
| 1311 | Expect<void> |
| 1312 | Validator::validateCanonLower(const AST::Component::Canonical &Canon) noexcept { |
nothing calls this directly
no test coverage detected