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

Named tuple support #331

Merged
merged 8 commits into from
Oct 23, 2024
Merged

Named tuple support #331

merged 8 commits into from
Oct 23, 2024

Conversation

tristanmenzel
Copy link
Contributor

Proposed Changes

  • Adds support for using native named tuples
  • Named tuples are automatically encoded as ARC4 Structs when used on ABI boundaries

… the same for structs)

- introduce pytypes.TupleLikeType that captures both native and ARC4Tuples
- make a NamedTupleType subclass of TupleType that exposes a `fields` property which is easier to create & consume
- use NamedTuple for pre-compiled data structures
- correct implicit arc4 conversion to use iterate_static, which also ensure single evaluation
- introduce pytype for NamedTupleBaseType - this is somewhat of a lie, since typing.NamedTuple is not actually part of MRO at runtime due to Python magic, but it's a good lie because it allows resolving expression and type builders for NamedTuple without any hackery
- fixing some error messages to start with lower case
- expose concrete types on WType and PyType classes, this simplifies some things and Sequence/Mapping was mostly used as shorthand
- add some negative tests for NamedTuple scenarios
- general refactoring of new NamedTuple feature
Copy link

github-actions bot commented Oct 22, 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, 326–328, 341–355
   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.py9884396%99, 103–106, 146, 150–153, 351, 536, 552, 586, 627, 656–657, 707, 734–735, 884, 906, 938, 964, 969, 1124, 1209, 1225, 1274, 1347, 1418, 1472, 1476, 1722, 1733, 1735, 1740, 1748, 1753, 1758, 1767, 1772, 1777
   serialize.py64494%24, 95–97
   to_code_visitor.py439798%131, 315, 365, 621, 646, 674, 678
   txn_fields.py98199%48
   wtypes.py3231994%170–173, 187–188, 192, 210, 223, 229, 234, 239–240, 274, 328, 342, 392, 463, 514
src/puya/awst/validation
   base_invoker.py47491%55, 62, 69–73
   inner_transactions.py187199%160
   labels.py30873%25–27, 32, 36–41
   scratch_slots.py39490%19, 33, 49, 51
src/puya/ir
   arc4_router.py2831993%110, 173, 229, 307, 355, 426, 439, 497–498, 510, 515, 520, 525, 530, 535, 555–559, 699, 736
   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.py5302595%103, 164–169, 449, 474, 477, 535–538, 803–804, 1050, 1074, 1155, 1162, 1198, 1246, 1256, 1311, 1356, 1375, 1395, 1456–1463
   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.py3233789%139–140, 142, 156, 164–169, 197, 204, 226–227, 560, 579–597, 666, 670, 684, 693–706
   main.py5476588%106, 244, 248, 253–271, 276–294, 349, 373, 397–398, 436, 624, 656, 669–670, 726, 751, 788–790, 801, 866, 944, 957, 990, 1045, 1048, 1056, 1059, 1067, 1096, 1107, 1116, 1195, 1212, 1255–1265
   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.py3281595%40, 52, 68, 77, 88, 99, 110, 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.py100595%75, 89, 103, 105, 149
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, 82, 162–163, 174, 181–182, 199–209, 219–221, 226, 242
   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.py3244785%45, 48–49, 51, 92, 104–106, 133, 144–148, 164, 166, 169–170, 193, 234–236, 245, 250, 255–256, 284, 288, 300, 307, 309, 323–324, 327–331, 336–337, 343–346, 354, 372, 384, 395, 403, 510, 515, 534
   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.py2334780%65, 95, 98, 108–109, 127–128, 168, 228, 233, 239–243, 250, 259, 261, 264–266, 268, 275, 277, 288–289, 294–296, 299, 314, 338–339, 351, 365, 368–380
   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.py50198%33
   module.py4135886%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, 652, 700, 720, 728, 730
   pytypes.py5275190%85–87, 101–102, 142, 158–164, 187, 207, 249, 357, 366, 385, 404, 424–425, 464, 557–559, 573–574, 643–644, 750, 761–762, 807–808, 813, 862–863, 884–885, 1014–1015, 1039, 1067, 1101–1103, 1143, 1153–1154, 1190–1192
   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%252–253, 265–266
   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.py70987%86–90, 127–131, 154
   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.py3051296%76, 124, 225–226, 238, 324–325, 444, 472, 483–484, 547
   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.py1491093%102–103, 132, 137, 150, 190–193, 264, 268, 282
   abi_call.py3212094%126, 132, 136, 160, 230, 247–248, 329, 346, 404, 432, 463, 486–487, 545, 582, 654, 739–740, 757
   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.py921683%46–48, 72, 90–93, 96–97, 133–136, 141, 145–146, 156, 166
   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
TOTAL21677169792% 

Tests Skipped Failures Errors Time
1298 2 💤 0 ❌ 0 🔥 7m 29s ⏱️

@daniel-makerx daniel-makerx merged commit eaf2700 into main Oct 23, 2024
4 checks passed
@daniel-makerx daniel-makerx deleted the feat/named-tuples branch October 23, 2024 04:31
@tristanmenzel tristanmenzel linked an issue Oct 31, 2024 that may be closed by this pull request
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.

Support typing.NamedTuple
3 participants