Commit 5120740
authored
Clarify and test gradual function application (#15173)
* Implement gradual function domains and tighten function application
Add fun_domain/1 to compute function domains for static, dynamic, and mixed function types, including explicit :badfun and {:badarity, ...} outcomes when domain extraction is not well-defined.
Refine gradual function application internals by separating static and dynamic normalization paths, documenting behavior for purely dynamic and mixed cases, and clarifying domain/compatibility handling.
Expand descr tests with gradual-application edge cases and a dedicated fun_domain test suite covering static, dynamic, mixed, and arity-error scenarios.
* Refactor function application and domain handling
* Remove fun_domain, recover coverage via fun_apply tests
fun_domain was only used in tests; its behavior is fully observable
through fun_apply (wrong-domain arg → :badarg, right-domain → :ok).
Removed it and converted the domain tests to fun_apply assertions,
adding a few previously uncovered cases along the way: pure non-fun
badfun, union-arg-type enforcement, 2-arity, mixed-arity badarity
for both static and dynamic unions, and the mixed static+dynamic
gradual domain case.
* Remove dead helpers introduced alongside fun_domain
fun_single_arity, fun_single_arity_pair, fun_non_empty_arities_of,
and fun_non_empty_arities are now unreachable. Also revert
dynamic_fun_top? to the simpler map == %{} check — the semantic
emptiness scan added in the refactor was only needed to handle
the same edge cases fun_domain was handling.
* Move mixed-arity badarity check to static side of fun_normalize_both
fun_normalize itself stays simple (no arity cross-check). The check
for other non-empty arities now lives in fun_normalize_both via
fun_other_non_empty_arities/2, and only fires for the static
component. This means:
- union(fun/1, fun/2) applied with 1 arg → {:badarity, [1, 2]}
(static: we know one branch will always fail at runtime)
- union(dynamic_fun/1, dynamic_fun/2) applied with 1 arg →
{:ok, dynamic(integer())} (dynamic: picks matching-arity arrows,
wraps in dynamic() to reflect that the other branch may fail)
* Add tests for mixed-arity union behavior
Static union: badarity regardless of which arity is called with,
with the called arity listed first followed by the others.
Dynamic union: picks the matching-arity arrows and wraps in dynamic(),
gives badarity only when no arity matches at all, and falls back to
dynamic() when the arg is outside the domain but dynamically compatible.1 parent 78a5151 commit 5120740
2 files changed
Lines changed: 197 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1360 | 1360 | | |
1361 | 1361 | | |
1362 | 1362 | | |
1363 | | - | |
| 1363 | + | |
1364 | 1364 | | |
1365 | 1365 | | |
1366 | 1366 | | |
1367 | 1367 | | |
1368 | 1368 | | |
1369 | 1369 | | |
1370 | 1370 | | |
1371 | | - | |
| 1371 | + | |
| 1372 | + | |
1372 | 1373 | | |
1373 | 1374 | | |
1374 | 1375 | | |
| |||
1411 | 1412 | | |
1412 | 1413 | | |
1413 | 1414 | | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
1414 | 1428 | | |
1415 | 1429 | | |
1416 | 1430 | | |
| |||
1422 | 1436 | | |
1423 | 1437 | | |
1424 | 1438 | | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
1425 | 1451 | | |
1426 | 1452 | | |
1427 | 1453 | | |
| |||
1431 | 1457 | | |
1432 | 1458 | | |
1433 | 1459 | | |
1434 | | - | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
1435 | 1467 | | |
1436 | 1468 | | |
1437 | 1469 | | |
1438 | 1470 | | |
1439 | | - | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
1440 | 1481 | | |
1441 | 1482 | | |
1442 | 1483 | | |
| |||
1448 | 1489 | | |
1449 | 1490 | | |
1450 | 1491 | | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
1451 | 1514 | | |
1452 | 1515 | | |
1453 | | - | |
1454 | | - | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
1455 | 1523 | | |
1456 | | - | |
1457 | | - | |
1458 | | - | |
1459 | | - | |
1460 | | - | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
1461 | 1529 | | |
1462 | | - | |
1463 | | - | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
1464 | 1537 | | |
1465 | 1538 | | |
1466 | 1539 | | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
1467 | 1543 | | |
1468 | 1544 | | |
1469 | 1545 | | |
| |||
1477 | 1553 | | |
1478 | 1554 | | |
1479 | 1555 | | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
1480 | 1570 | | |
1481 | 1571 | | |
1482 | 1572 | | |
| |||
1522 | 1612 | | |
1523 | 1613 | | |
1524 | 1614 | | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
1525 | 1622 | | |
1526 | 1623 | | |
1527 | 1624 | | |
| |||
1554 | 1651 | | |
1555 | 1652 | | |
1556 | 1653 | | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
1557 | 1662 | | |
1558 | 1663 | | |
| 1664 | + | |
| 1665 | + | |
1559 | 1666 | | |
1560 | 1667 | | |
1561 | 1668 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1095 | 1095 | | |
1096 | 1096 | | |
1097 | 1097 | | |
| 1098 | + | |
1098 | 1099 | | |
| 1100 | + | |
| 1101 | + | |
1099 | 1102 | | |
1100 | 1103 | | |
1101 | 1104 | | |
| |||
1108 | 1111 | | |
1109 | 1112 | | |
1110 | 1113 | | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
1111 | 1127 | | |
1112 | 1128 | | |
1113 | 1129 | | |
| |||
1126 | 1142 | | |
1127 | 1143 | | |
1128 | 1144 | | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
1129 | 1150 | | |
1130 | 1151 | | |
1131 | 1152 | | |
| |||
1209 | 1230 | | |
1210 | 1231 | | |
1211 | 1232 | | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
1212 | 1247 | | |
1213 | 1248 | | |
1214 | 1249 | | |
| |||
1252 | 1287 | | |
1253 | 1288 | | |
1254 | 1289 | | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
1255 | 1307 | | |
1256 | 1308 | | |
1257 | 1309 | | |
| |||
1279 | 1331 | | |
1280 | 1332 | | |
1281 | 1333 | | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
1282 | 1342 | | |
1283 | 1343 | | |
1284 | 1344 | | |
| |||
1293 | 1353 | | |
1294 | 1354 | | |
1295 | 1355 | | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
1296 | 1373 | | |
1297 | 1374 | | |
1298 | 1375 | | |
| |||
0 commit comments