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

Local/GlobalState custom keys & descriptions #111

Merged
merged 40 commits into from
Mar 5, 2024
Merged

Conversation

achidlow
Copy link
Contributor

@achidlow achidlow commented Mar 1, 2024

Add the ability to specify a custom key and/or provide a description for LocalState and GlobalState objects. The resolution of a member name to the key has thus been deferred to the IR phase. To support this, additional nodes have been introduced for dealing with state keys by member name, which has also allowed for an approach that significantly improves the generated code in certain cases.

Solve the issue of requiring module level constructs (such as constants) to come before their usage

scratch_slots reservation fixes:

  • allow module constants args, and in args to urange within
  • handle negatives
  • check for third arg to urange being non-zero to avoid crash
  • allow just a single urange call
  • allow list exprs
  • add tests for the above and tests for failure cases

Fixes a bug where types declared in other modules wouldn't work on import.

Check file encodings and warn if it's not UTF-8.

Fix potential issue with TemporaryAssignmentExpressionBuilder not being picked up as a value.

Add "unknown" bytes encoding for raw bytes. default to hex output, but we can choose a better encoding when e.g. combining constants in optimisation (will be addressed in another PR).

Don't generate code/calls to an empty __init__ function (todo in another PR: remove all empty function calls, and remove unreferenced functions after optimisation).

- allow module constants args, and in args to urange within
- handle negatives
- check for third arg to urange being non-zero to avoid crash
- allow just a single urange call
- allow list exprs
- add tests for the above and tests for failure cases

start on state reservation

add stubs for state key & descriptions
- remove unused `module_asts` on ASTConversionContext
- convert ALLOWED_OCA list to frozenset
- add/remove/address some TODOs
- simplify FunctionASTConverter.visit_assignment_stmt a bit
…t we can choose a better encoding when e.g. combining constants in optimisation
…gnarly to plumb this through everywhere, and given the lack of uproar over ruff's complete lack of handling of non-utf8 files astral-sh/ruff#6791, we can just warn about it instead. the only potential negative effects are that the bytes on disk in the python file for something like a LocalState that takes it's key from the member name, might not match exactly what's in the TEAL file (and thus on chain).

- refactor to slightly reduce mypy dependencies in ParseResult - pull out component orderding and checking to the parse level

- construct read_source directly and add caching at the top level
Copy link

github-actions bot commented Mar 1, 2024

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/puya
   __main__.py30197%110
   arc4_util.py63494%28, 64, 78, 97
   arc32.py66297%87, 98
   compile.py151398%137, 151–154
   errors.py1242977%47–48, 52, 54–57, 82, 124, 144–145, 150–164, 175–178
   logging_config.py1292878%15, 36–39, 45, 47, 50–54, 69, 88, 141–143, 146–148, 150, 163–172, 194
   models.py80298%11–12
   options.py29293%12–13
   parse.py2041891%86, 98, 127, 166, 169, 223, 266, 276, 278, 282, 310–315, 319, 349, 363, 376–377
   utils.py1451987%49, 53, 87, 93, 108, 111–113, 120, 142, 155–156, 160, 164–167, 196, 198, 221
src/puya/awst
   function_traverser.py186398%113, 143–144
   nodes.py9596793%19–28, 44, 53, 87, 93, 97–100, 134, 140, 144–147, 275, 281, 486, 524, 729–730, 750, 762, 800, 806–807, 837, 863, 867–871, 883, 974–975, 980, 995, 1046, 1051, 1109, 1132, 1149, 1328, 1333–1334, 1341–1346, 1458, 1506, 1515, 1543, 1550, 1563, 1612, 1623, 1625, 1630, 1638, 1643, 1648, 1657, 1662, 1667, 1674
   to_code_visitor.py3181496%81–82, 85–88, 112–113, 194, 319–320, 330, 411–412, 483, 511
   visitors.py2147067%7, 15, 19, 23, 27, 31, 35, 39, 43, 47, 53, 59, 65, 69, 73, 77, 83, 87, 91, 95, 99, 105, 109, 113, 117, 121, 125, 129, 133, 139, 143, 147, 153, 159, 163, 169, 173, 177, 181, 185, 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 231, 234, 237, 243, 249, 253, 257, 261, 265, 269, 273, 277, 281, 285, 289, 293, 297, 301, 305, 309
   wtypes.py2833687%21, 64, 176–187, 202–205, 222, 224, 266, 269, 294, 296, 300–301, 304, 328, 348, 384, 387, 414–415, 424–425, 433–434, 445, 448, 507, 514, 530
src/puya/awst_build
   base_mypy_visitor.py1334467%39, 59, 71–77, 95, 106–121, 135, 139, 143, 154, 158, 166, 172, 178, 196, 202, 207, 210, 213, 222, 226, 231, 236, 242, 247, 253, 260, 264, 268, 272, 276, 280, 284, 288, 292, 296, 300, 304, 308
   context.py1402086%124–129, 137, 139–144, 147–148, 168, 173, 177, 190, 202–203
   contract.py3349372%133–134, 136–139, 147–148, 151, 163, 174, 196, 214, 220, 222, 233, 243, 252, 280, 284, 300–304, 312–313, 318, 321, 324, 327, 332–333, 336, 339, 342, 345, 348, 351, 354, 357, 360, 363, 366, 380, 394–401, 410–417, 424–425, 451, 461, 490, 492, 495, 507, 536–537, 552, 556, 559, 565, 568, 571, 574, 582, 590, 593, 596–608, 611, 620, 623, 640, 650–651, 658, 664, 686–692
   intrinsic_models.py32584%21, 26–29
   main.py47394%32, 44, 54
   module.py3708078%67, 115, 133–134, 141, 149, 155, 161–165, 174, 198–199, 210, 240, 266–267, 290, 297, 305–318, 331–332, 355–360, 414–415, 426, 450, 453, 459, 467, 470, 477, 483, 495, 498, 519, 538–539, 556–587, 615–616, 630–632, 634, 636–637, 669–676, 688, 690
   subroutine.py6127588%214, 225, 280, 348, 352, 366, 374, 407–408, 545–559, 567, 575, 578, 590, 619–620, 625, 630, 666, 686–687, 717–723, 743, 776–777, 782, 798, 801, 804, 812–818, 841, 873, 877–878, 882–883, 899, 901, 904–906, 933–934, 942, 977–985, 1020, 1048, 1052, 1083, 1180, 1187, 1197, 1208–1212, 1221, 1224, 1227, 1230, 1233, 1238, 1243, 1250, 1257
   utils.py1852487%50–51, 66, 103, 118–119, 121, 141–142, 162, 176, 187, 192, 199, 211, 233–246, 267, 338–339
src/puya/awst_build/eb
   app_account_state.py1282878%51–54, 62, 79, 81, 114–115, 136–143, 165–166, 171, 178–179, 181, 198–199, 206–207, 236, 241–242
   app_state.py1202282%47–54, 76–77, 82, 92–93, 98, 115–116, 123–124, 165–166, 190, 209
   array.py684534%26–27, 30–32, 37–44, 57–73, 78–80, 83, 86–89, 94–96, 101–103, 113–125
   base.py2076171%24–31, 103, 107, 111, 117, 121, 127–132, 143–149, 154–160, 166, 172, 182, 193, 197, 201, 211, 214, 217, 220, 223, 226, 231, 234, 256, 277, 280, 285, 288, 291, 294, 297, 302, 305, 316, 329, 340, 343, 356, 377, 382, 392, 395, 399, 405, 408, 411, 416, 421, 426, 432
   biguint.py932276%35–39, 64–65, 79, 94, 104–107, 129–132, 149–154, 184–192, 195–196
   bool.py401270%27–31, 48–55, 73
   bytes.py1432384%56–60, 83–84, 95–96, 117–118, 122, 126, 131, 133–134, 154, 176, 251–255, 269–270, 363–364
   bytes_backed.py29486%38–39, 48–49
   ensure_budget.py481569%25–29, 50–51, 71–72, 80, 92, 98–103
   intrinsics.py1564372%32–34, 56–57, 65–66, 72–73, 90–91, 98, 128, 137, 139–163, 170–171, 215, 223, 235–236, 238, 255–256, 268, 273, 280, 283
   log.py591181%26–30, 85–95, 105, 107
   named_int_constants.py20290%23–24
   struct.py321553%21–22, 25, 36–42, 47–49, 52–57
   subroutine.py35294%52, 72
   temporary_assignment.py41783%27, 30, 41, 47, 50, 53, 58
   tuple.py1002377%38–39, 46, 57, 59–60, 82–83, 92–93, 106, 112, 130–131, 136–137, 149, 157–163, 171, 203
   type_registry.py27293%138–139
   uint64.py791581%37–41, 63–64, 85, 103, 126, 145–148, 162–170, 173–174
   unsigned_builtins.py701184%30–34, 52, 59, 94, 97–98, 129, 132–133
   value_proxy.py391269%24, 27, 30, 33, 36, 41, 56, 66, 75, 85, 88, 91
src/puya/awst_build/eb/arc4
   arrays.py2223186%58–62, 75–76, 104, 135, 155–156, 192, 194, 228, 260, 277–278, 291, 334–335, 341, 346, 401–402, 424, 434–435, 443, 473, 493–494, 502, 549
   base.py1121785%34–38, 68–69, 90–91, 159, 180, 197–198, 212–213, 230–231, 237, 242
   bool.py28679%26–33, 59–60
   numeric.py821878%26–30, 42, 57, 88–89, 91, 94–95, 112, 119–120, 138, 152–153, 158, 163
   string.py651282%31–35, 65–66, 101, 120–121, 146–147, 165–166
   struct.py601083%26–33, 69, 72, 107–108, 114, 119
   tuple.py832175%30–34, 49, 53–54, 79, 84–86, 95, 106, 115, 128, 132–133, 145, 161–162, 171–172
src/puya/awst_build/eb/reference_types
   account.py46883%24–26, 44, 53–57
   application.py31487%17–19, 41–42
   asset.py52688%27–29, 51–52, 89–90
   base.py44491%25–27, 61, 87
src/puya/awst_build/eb/transaction
   base.py33779%16, 24, 28, 33–34, 41, 50
   group.py57984%32–36, 87–88, 97, 147, 150–151
   inner.py56984%28–31, 64–65, 101–102, 116, 144
   inner_params.py981189%29–33, 46–47, 69, 105, 141, 166, 183, 215
src/puya/awst_build/validation
   arc4_copy.py28196%37
   inner_transactions.py931188%92, 100, 111, 121, 125, 128, 133, 141, 151, 164, 169
   scratch_slots.py37489%17, 30, 46, 48
src/puya/ir
   arc4_router.py2702192%171, 275, 293, 301, 457, 537, 583, 650–651, 665, 705–706, 718, 723, 728, 733, 738, 743, 763–768
   avm_ops.py316299%44–45
   avm_ops_models.py34294%18, 26
   context.py971288%18, 59–60, 62, 80–86, 91, 102, 109, 119
   main.py165696%111, 114, 218, 220, 282, 293
   models.py4332694%29, 45, 63, 79, 186, 196, 200, 342, 416, 458, 538, 554, 595, 598, 605, 608, 655, 664, 672, 678, 689–691, 701, 713, 750
   ssa.py136993%43, 51–52, 99, 105, 141, 145, 166, 170
   to_text_visitor.py132795%82, 87, 169–174
   types_.py40685%26–27, 52–55
   visitor.py1643678%10–12, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 167, 179, 194, 197, 200, 203, 206, 212, 215, 218, 221, 224, 227, 230, 233
   visitor_mutator.py91298%134–135
   vla.py73297%50, 87
src/puya/ir/builder
   _utils.py71889%33, 44, 57, 79–80, 157, 203–204
   arc4.py4185088%75–76, 125, 149–155, 219, 227, 450, 462, 465, 621–635, 964–978, 1004–1028, 1037–1053, 1076, 1177–1178, 1223–1240, 1279–1280, 1333, 1366–1367, 1389–1396, 1517–1518, 1581
   assignment.py46589%67, 83, 110, 141–142
   blocks.py931089%61, 71, 75, 111, 119, 123, 147–149, 155–157
   flow_control.py98496%63, 118, 142, 156
   iteration.py190597%46, 66, 95, 176–177
   itxn.py2251792%109–110, 119–122, 132–133, 141, 166, 445–446, 451–452, 458, 474–475
   main.py4765289%87, 104, 133, 182–183, 198–199, 226, 234, 241–242, 312, 340–341, 356, 368, 385, 406, 413, 447, 491, 504–505, 532, 593–594, 616, 664, 692, 700, 730–731, 746, 806, 809, 815, 822–823, 853–854, 869, 915–916, 932–933, 967, 982–984, 993, 996–997
src/puya/ir/destructure
   coalesce_locals.py941584%33, 36, 118, 127–128, 131–134, 137–139, 153–156
   parcopy.py84298%47, 83
src/puya/ir/optimize
   arithmetic.py2393386%137, 199, 203, 205, 207, 209, 212–213, 229, 275, 277, 284, 316, 320, 322, 325–326, 341, 343, 345, 347, 349, 355, 357, 359, 361, 363, 365, 367, 370–371, 374–375
   collapse_blocks.py92595%65–69
   control_op_simplification.py108794%155–161, 231, 252
   dead_code_elimination.py119298%288, 324
   intrinsic_simplification.py62592%25–26, 41, 118–119
   main.py86397%108–109, 125
src/puya/mir
   annotaters.py173796%57, 63, 99, 103, 136, 140, 217
   builder.py122695%82, 132, 138, 145, 252–253
   context.py39197%35
   models.py3172293%13–18, 30, 41, 53, 64, 75, 86, 116, 226, 257, 294, 306, 323, 331–337, 343
   output.py61297%29, 31
   stack.py2502291%68, 72, 105, 109, 115, 125, 136, 147, 157, 172, 189, 199, 218, 236, 242, 244, 283, 294, 318, 350, 355, 393
   visitor.py732368%7, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, 71, 75, 79, 83, 87, 91, 95, 99
src/puya/mir/stack_allocation
   baileys.py208697%31, 103, 123, 330–334, 359
   frame_allocation.py78396%21, 57–58
   koopmans.py61198%55
   peephole.py100694%75, 89, 99, 101, 103, 145
src/puya/teal
   models.py220399%181, 280, 286
src/puya/teal/optimize
   peephole.py106496%64, 147–157
   repeated_rotations.py30197%13
   repeated_rotations_search.py88693%34, 40–41, 57, 67–68
TOTAL14917167389% 

Tests Skipped Failures Errors Time
233 2 💤 0 ❌ 0 🔥 2m 32s ⏱️

Copy link
Contributor

@tristanmenzel tristanmenzel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@achidlow achidlow merged commit e9d5084 into main Mar 5, 2024
4 checks passed
@achidlow achidlow deleted the state-info-take-2 branch March 5, 2024 06:49
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.

3 participants