Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of and/or where the result is a type union #312

Merged
merged 2 commits into from
Sep 17, 2024

Conversation

achidlow
Copy link
Contributor

@achidlow achidlow commented Sep 13, 2024

Expand handling of literal expressions to allow combining them with binary boolean operators, and improve error messaging when handling of type unions in nested bool contexts (fixes #145)

Also:

  • allow dummy values to be constructed for literal-only pytypes
  • single spot where "unexpected type" error message is defined, which also gives a special message in case of a union, just in case the function actually does support a union argument as is the case with some intrinsics etc
  • prevent parsing function bodies when the return type is invalid, which can cause secondary errors which might be confusing and overshadow the root problem
  • supress "expression result is ignored" warning when using typing.assert_type

Copy link

github-actions bot commented Sep 13, 2024

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/puya_lib
   arc4.py1261260%1–332
   bytes.py990%1–15
   util.py16160%1–33
src/puya
   __main__.py30300%1–42
   arc32.py68297%77, 103
   artifact_sorter.py53198%84
   compile.py147895%89–90, 132–135, 155–158, 288, 309
   context.py31197%35
   errors.py35877%40–42, 44–46, 50–51
   log.py1994179%32–35, 69, 89, 108, 123–124, 166–168, 171–173, 175, 188–197, 219, 288–289, 298, 320–322, 335–349
   main.py36360%1–49
   parse.py87594%31, 40, 50, 56, 87
   utils.py1991891%50, 67–68, 77–78, 86–87, 171, 177, 195–197, 204, 226, 249, 251, 274, 309
src/puya/awst
   function_traverser.py285399%76, 367, 373
   nodes.py9924496%99, 103–106, 146, 150–153, 351, 537, 553, 587, 628, 657–658, 708, 736–737, 886, 908, 940, 968, 976, 981, 1136, 1221, 1237, 1286, 1359, 1430, 1484, 1488, 1734, 1745, 1747, 1752, 1760, 1765, 1770, 1779, 1784, 1789
   serialize.py57198%20
   to_code_visitor.py439798%131, 315, 365, 621, 646, 674, 678
   txn_fields.py98199%48
   wtypes.py2941794%174–178, 188–191, 208, 226, 250, 305, 319, 353, 424, 469
src/puya/awst/validation
   base_invoker.py47491%55, 62, 69–73
   inner_transactions.py181199%160
   labels.py30873%25–27, 32, 36–41
   scratch_slots.py39490%19, 33, 49, 51
src/puya/ir
   arc4_router.py3122094%110, 173, 229, 307, 355, 424, 433, 491–492, 504, 509, 514, 519, 524, 529, 549–553, 737, 762, 799
   avm_ops.py315199%46
   avm_ops_models.py48394%21, 30, 38
   context.py107893%78, 85, 88, 90, 128–129, 141, 147
   main.py2991396%74–80, 90–96, 122, 135, 163, 221, 565
   models.py5292296%74, 182, 189, 338, 408–409, 414, 420–424, 437, 481, 510, 566, 612, 692, 708, 749, 752, 759, 762, 851–852
   ssa.py130596%51–52, 150, 212, 223
   to_text_visitor.py152795%123, 212, 219–224
   types_.py1011090%50, 57, 91–95, 116, 152, 157–159
   visitor.py1291787%145, 193, 205, 220, 223, 236, 239, 245, 248, 259, 262, 265, 268, 271, 274, 277, 280
   visitor_mutator.py105298%174–175
   vla.py72199%87
src/puya/ir/builder
   _utils.py58395%175–177
   arc4.py5042595%93, 129–134, 375, 400, 403, 461–464, 719–720, 966, 990, 1071, 1078, 1114, 1162, 1172, 1227, 1272, 1291, 1311, 1372–1379
   assignment.py83693%51, 98, 112, 188, 206, 222
   blocks.py140795%55, 92–96, 158, 166, 231
   bytes.py641478%13–45, 129
   callsub.py77594%30–31, 51, 101–102
   flow_control.py95199%56
   iteration.py198597%91–92, 107, 144, 206
   itxn.py2761993%124–125, 127, 141, 189, 210, 235–236, 565, 589–590, 603–612
   main.py5456588%106, 247, 251, 256–274, 279–297, 352, 376, 400–401, 439, 627, 649, 662–663, 719, 744, 781–783, 794, 859, 937, 950, 983, 1038, 1041, 1049, 1052, 1060, 1089, 1100, 1109, 1188, 1205, 1248–1258
   storage.py83298%101, 154
src/puya/ir/destructure
   coalesce_locals.py1011981%119, 128–129, 132–135, 138–147, 163–166
   parcopy.py84298%47, 83
src/puya/ir/optimize
   collapse_blocks.py92595%65–69
   compiled_reference.py79594%53, 87, 158–163
   control_op_simplification.py104793%47–48, 171, 245–252
   inner_txn.py36197%38
   intrinsic_simplification.py4833194%76, 166–168, 173, 255, 267, 302, 313–314, 338–339, 363, 430, 617, 619, 634, 674, 697, 727, 733, 735, 737, 742, 744, 746, 748, 750, 802–803, 810
   main.py87298%116–117
src/puya/ir/validation
   _base.py29197%24
   compile_reference_validator.py20385%24, 30, 37
   min_avm_version_validator.py11191%15
   op_run_mode_validator.py19574%19–29
src/puya/mir
   annotaters.py159299%62, 212
   builder.py1401093%139, 248–249, 302, 305, 308, 311, 314, 317, 320
   models.py3281695%40, 52, 68, 77, 88, 99, 110, 150, 260, 291, 328, 340, 365–371
   output.py63297%29, 33
   stack.py2501992%72, 119, 135, 146, 157, 167, 184, 201, 211, 230, 250, 256, 258, 297, 310, 334, 366, 371, 409
src/puya/mir/stack_allocation
   baileys.py205399%31, 330–334
   frame_allocation.py80298%21, 68
   koopmans.py61198%55
   peephole.py100694%75, 89, 99, 101, 103, 145
src/puya/teal/optimize
   peephole.py112298%139, 145
   repeated_rotations.py42198%13
   repeated_rotations_search.py88693%34, 40–41, 57, 67–68
src/puya/ussemble
   build.py731086%37, 52–53, 58–61, 65–68, 85–86, 115
   op_spec_models.py22195%20
   optimize.py76199%77
   output.py115199%71
   validate.py17194%19
src/puyapy
   __main__.py581672%163–177, 181
   client_gen.py1151587%55–56, 65–69, 73, 165–166, 174–175, 190, 194–195, 204
   compile.py1502285%59–68, 81, 161–162, 173, 180–181, 198–208, 218–220, 225, 241
   parse.py1801393%49–50, 86, 158–163, 167, 265, 269–270, 317, 329, 354
   template.py32875%10–11, 18–19, 27–28, 34, 37
   utils.py21576%16–17, 25–28
src/puyapy/awst_build
   arc4_client.py701973%45, 54, 60, 63, 66, 72, 75, 78–83, 86, 89, 92, 95, 98, 101, 104, 107, 110
   arc4_utils.py3184686%45, 48–49, 51, 92, 104–106, 133, 144–148, 164, 166, 169–170, 193, 234–236, 245, 250, 255–256, 280, 284, 296, 303, 305, 319–320, 323–327, 332–333, 339–342, 350, 368, 380, 391, 399, 500, 524
   arc32_client_gen.py68297%34, 130
   base_mypy_visitor.py1273969%70–76, 94, 102–115, 129, 131, 133, 145, 150, 154, 157, 160, 166, 188, 191, 194, 201, 205, 208, 211, 215, 233, 237, 241, 245, 249, 253, 257, 261, 265, 269, 273, 277, 281
   context.py2314780%65, 95, 98, 108–109, 127–128, 168, 228, 233, 239–243, 248, 257, 259, 262–264, 266, 273, 275, 286–287, 292–294, 297, 312, 336–337, 349, 363, 366–378
   contract.py2382789%182, 224–225, 227–230, 242, 254, 345, 349, 371, 374, 386, 394, 397, 400, 403, 406, 409, 412, 415, 418, 421, 435, 458–464
   contract_data.py58198%37
   intrinsic_factory.py32391%47, 56, 65
   intrinsic_models.py40198%49
   main.py51198%34
   module.py4025786%115, 129–131, 146–147, 154, 163–164, 172–176, 194–198, 207, 245–246, 257, 279–282, 292–294, 300, 317–320, 333, 367, 374, 396–397, 420–425, 479–480, 508, 519, 522, 528, 534, 544, 550, 553, 565, 568, 590, 610, 615, 619, 623–626, 651, 694, 702, 704
   pytypes.py5165290%85–87, 101–102, 142, 158–164, 187, 207, 312, 321, 340, 359, 363, 379–380, 419, 512–514, 528–529, 598–599, 729, 740–741, 786–787, 792, 841–842, 863–864, 993–994, 1018, 1046, 1080–1082, 1108, 1135, 1145–1146, 1182–1184
   subroutine.py6035491%134, 249, 255, 313–316, 322, 374, 381, 384–390, 455, 610, 612–613, 631, 633, 643–644, 653–654, 658, 679, 752, 759, 779–780, 862, 888–889, 906, 922, 946, 954, 965, 990, 1095–1096, 1116, 1126, 1133, 1142, 1158, 1168–1169, 1177, 1196, 1199, 1202, 1205, 1208, 1228–1230
   utils.py1842487%34, 51–55, 73, 108–109, 111, 155–156, 207, 215, 220, 233–237, 242–245, 287, 295, 338
src/puyapy/awst_build/eb
   _base.py1311985%53, 58–60, 65, 72, 77, 82–84, 143, 154, 184, 189, 194, 199, 210, 225, 230–232
   _bytes_backed.py48296%30–31
   _expect.py1222183%26, 37, 87–90, 102–105, 108, 160–161, 219–222, 232–235
   _literals.py1442980%44, 73, 92, 121, 138, 152, 156, 160–166, 176–190, 195
   _type_registry.py40490%250–251, 263–264
   utils.py47394%29–31, 100
   array.py26965%23, 28–33, 43, 49
   biguint.py96694%56, 98, 135, 150–151, 153
   binary_bool_op.py104397%152, 160, 170
   bool.py56984%39–43, 59, 70, 85, 99
   bytes.py1681889%103–104, 131–132, 137–138, 144–145, 148, 156, 199, 234, 266, 270, 287–288, 303–304
   compiled.py1121388%56, 61, 67–68, 165–169, 206–210, 233
   conditional_literal.py1293176%100, 104, 164, 168–171, 180–182, 205–208, 217, 221, 225–228, 243–255, 264–265
   contracts.py83693%58, 64, 76, 101, 122, 126
   dict.py27581%25, 33–35, 39
   ensure_budget.py31197%47
   interface.py84396%311–313, 317
   intrinsics.py97694%43, 62, 69, 82, 89, 160
   log.py43491%46–47, 52, 61
   logicsig.py15193%26
   none.py27196%38
   string.py1441391%72, 116–117, 136, 140, 183, 190, 194, 206, 280–282, 302
   struct.py16569%14–16, 25, 31
   subroutine.py801680%46, 50–53, 68, 71–78, 93, 101–102, 104–107, 112
   template_variables.py37295%30, 58
   tuple.py2871395%75, 147, 153, 188–189, 201, 278–279, 398, 426, 437–438, 501
   uint64.py110595%57, 118–119, 167–168
   uint64_enums.py40295%41, 46
   unsigned_builtins.py1552286%74, 81, 105, 129, 133, 137, 141, 149, 153, 157, 161, 165, 175, 179, 185, 196, 202, 208, 247, 279, 291, 303
src/puyapy/awst_build/eb/arc4
   _base.py91397%186–189, 200
   _utils.py1311092%78–79, 106, 111, 124, 164–167, 207, 211, 225
   abi_call.py3212094%122, 128, 132, 156, 226, 243–244, 325, 342, 400, 428, 458, 481–482, 540, 577, 649, 734–735, 752
   address.py77396%57, 117–118
   bool.py57395%44, 86–87
   dynamic_array.py1271092%57, 126–127, 147, 149, 154, 228, 249, 255–258
   dynamic_bytes.py68396%97–99
   emit.py36197%38
   static_array.py66198%45
   string.py100793%54–55, 103, 126, 131–134
   struct.py49198%49
   tuple.py941584%50–52, 92–95, 98–99, 135–138, 143, 147–148, 158, 168
   ufixed.py70297%43, 102
src/puyapy/awst_build/eb/reference_types
   account.py81298%65, 176
   application.py45198%40
   asset.py65198%48
src/puyapy/awst_build/eb/storage
   _common.py69396%107, 122–123
   _storage.py1031883%77, 85, 89, 93, 97, 101, 105, 109, 113, 123, 127, 131, 135, 141, 152, 158, 164, 176
   _value_proxy.py55787%38, 42, 50, 54, 91, 99, 103
   box_map.py143199%186
   global_state.py138596%108–109, 115, 171–172
   local_state.py1481193%103–104, 108, 157, 161, 165, 175, 179, 203, 290, 314
src/puyapy/awst_build/eb/transaction
   base.py39295%23, 43
   group.py58198%51
   inner.py49296%89–90
   inner_params.py81594%69, 79, 83, 143, 145
   itxn_args.py60198%72
TOTAL21570168192% 

Tests Skipped Failures Errors Time
1267 2 💤 0 ❌ 0 🔥 6m 43s ⏱️

@achidlow achidlow force-pushed the fix-nested-bool-contexts branch 4 times, most recently from cf541c1 to 64941de Compare September 17, 2024 04:12
@achidlow achidlow marked this pull request as ready for review September 17, 2024 04:16
@achidlow achidlow changed the title Fix handling of type unions in nested bool contexts Improve handling of and/or where the result is a type union Sep 17, 2024
@achidlow achidlow enabled auto-merge (rebase) September 17, 2024 04:22
…with binary boolean operators, and improve error messaging when handling of type unions in nested bool contexts

---------

also:
- allow dummy values to be constructed for literal-only pytypes
- single spot where "unexpected type" error message is defined, which also gives a special message in case of a union, just in case the function actually does support a union argument as is the case with some intrinsics etc
- prevent parsing function bodies when the return type is invalid, which can cause secondary errors which might be confusing and overshadow the root problem
- supress "expression result is ignored" warning when using `typing.assert_type`
@achidlow achidlow merged commit 738a008 into main Sep 17, 2024
4 checks passed
@achidlow achidlow deleted the fix-nested-bool-contexts branch September 17, 2024 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nested bool contexts give unexpected results
2 participants