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

Refactor: Use const nodes for const arc4 values #339

Merged
merged 6 commits into from
Nov 12, 2024

Conversation

tristanmenzel
Copy link
Contributor

Proposed Changes

  • Use StringConstant(wtype=arc4_string_wtype, ...) for constant arc4 string values
  • Use BoolConstant(wtype=arc4_bool_wtype, ...) for constant arc4 boolean values
  • Update IR Builder to handle the trivial encoding of these constant values

Why?

This is already how arc4 numeric types are handled. It makes the awst a little clearer to read and cuts down on the number of optimization passes required to output the same Teal.

@tristanmenzel tristanmenzel force-pushed the refactor/use-string-const-for-arc4-string branch from a5bbd9c to 82c3de3 Compare October 30, 2024 20:11
@tristanmenzel tristanmenzel force-pushed the refactor/use-string-const-for-arc4-string branch from 7ae35f8 to 6b30872 Compare October 30, 2024 21:19
Copy link

github-actions bot commented Oct 30, 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.py158895%91–92, 134–137, 157–160, 302, 350
   context.py31197%35
   errors.py35877%40–42, 44–46, 50–51
   log.py1994080%32–35, 69, 89, 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.py2011891%50, 67–68, 77–78, 86–87, 177, 195–197, 204, 212, 226, 249, 251, 274, 309
src/puya/awst
   function_traverser.py285399%76, 367, 373
   nodes.py9824096%100, 104–107, 147, 151–154, 355, 551, 567, 601, 642, 671–672, 722, 749–750, 899, 921, 953, 979, 984, 1139, 1224, 1240, 1289, 1366, 1437, 1491, 1495, 1618, 1763, 1768, 1773, 1781, 1786, 1791
   serialize.py681184%24, 84–89, 95–98
   to_code_visitor.py420898%131, 242, 279, 325, 581, 606, 634, 638
   txn_fields.py98199%48
   wtypes.py3271994%173, 177–180, 194–195, 199, 228, 241, 247, 252, 257–258, 292, 330, 344, 394, 516
src/puya/awst/validation
   base_invoker.py47491%55, 62, 72–76
   immutable.py31294%26, 34
   inner_transactions.py187199%160
   labels.py30873%25–27, 32, 36–41
   scratch_slots.py38489%18, 32, 47, 49
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.py323199%46
   avm_ops_models.py50394%21, 30, 38
   context.py101892%68, 75, 78, 80, 118–119, 129, 135
   main.py2771296%74–80, 90–96, 122, 135, 163, 517
   models.py5302296%74, 182, 189, 338, 408–409, 414, 420–424, 437, 481, 510, 566, 612, 692, 708, 749, 752, 759, 762, 851–852
   ssa.py130398%51–52, 150
   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.py73396%229–231
   arc4.py5272396%166–171, 470, 473, 531–534, 806–807, 1053, 1077, 1158, 1165, 1201, 1249, 1259, 1314, 1359, 1378, 1398, 1459–1466
   assignment.py94793%100, 115, 191, 210, 227–228, 273
   blocks.py140795%55, 92–96, 158, 166, 231
   bytes.py641478%13–45, 129
   callsub.py81594%33–34, 59, 109–110
   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.py5606888%124, 264, 268, 273–292, 297–316, 371, 395, 416, 434–435, 437, 445, 487, 676, 708, 721–722, 778, 803, 840–842, 853, 918, 996, 1009, 1041, 1106, 1109, 1117, 1120, 1128, 1159, 1170, 1179, 1258, 1275, 1318–1328
   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.py30197%28
   compile_reference_validator.py20290%24, 30
   min_avm_version_validator.py15473%16–20
   op_run_mode_validator.py19574%19–29
src/puya/mir
   aligned_writer.py63395%21, 61, 80
   builder.py1571392%71–73, 156, 268–269, 322, 325, 328, 331, 334, 337, 340
   models.py432699%97, 206, 250, 316, 333, 403
src/puya/mir/stack_allocation
   f_stack.py89298%23, 70
   peephole.py48296%47, 49
   x_stack.py205399%32, 336–340
src/puya/teal
   models.py364299%377, 438
src/puya/teal/optimize
   constant_block.py104496%63, 152, 189, 206
   peephole.py127398%162, 168, 251
   repeated_rotations.py51198%16
   repeated_rotations_search.py90693%35, 41–42, 58, 68–69
src/puya/ussemble
   assemble.py169597%128, 196, 213–214, 254
   models.py23196%16
   op_spec_models.py22195%20
src/puyapy
   __main__.py631773%172, 184–198, 202
   client_gen.py1161587%56–57, 66–70, 74, 166–167, 175–176, 191, 195–196, 205
   compile.py1502285%59–68, 82, 162–163, 174, 181–182, 199–209, 219–221, 226, 242
   models.py99496%65, 77–79
   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.py1042675%46–50, 58, 70, 76, 80, 109, 115–116, 122, 125, 128, 134, 137, 140–145, 148, 151, 154, 157, 160, 163, 166, 169, 172
   arc4_utils.py2824285%42, 45–46, 48, 78, 89–93, 109, 111, 114–115, 138, 181–183, 192, 197, 202–203, 237, 241, 253, 260, 262, 276–277, 280–284, 289–290, 296–299, 307, 325, 337, 345, 446, 451, 470
   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.py2184778%55, 58, 68–69, 87–88, 128, 188, 193, 199–203, 207, 210, 219, 221, 224–226, 228, 235, 237, 248–249, 254–256, 259, 274, 286–287, 299, 313, 316–328
   contract.py3193390%128, 179, 192–196, 236, 238, 242, 246, 254, 262, 264, 284, 339, 342, 354, 362, 365, 368, 371, 374, 377, 380, 383, 386, 389, 449–453, 502–506, 586–590, 661, 684
   intrinsic_models.py49198%55
   main.py36197%31
   module.py4296086%118, 138, 144–148, 163–164, 171, 180–181, 189–193, 215, 244, 264–265, 276, 298–301, 311–313, 319, 336–339, 352, 386, 393, 415–416, 439–444, 498–499, 527, 538, 541, 547, 553, 563, 569, 572, 584, 587, 610, 630, 635, 639, 648–652, 672, 742, 750, 752
   pytypes.py5926090%87, 97–99, 104, 111, 116–118, 122–124, 151–152, 192, 208–214, 237, 257, 299, 337–339, 367, 431, 440, 459, 478, 499–500, 637–639, 653–654, 721–722, 826, 837–838, 887–888, 893, 946–947, 970–971, 1122–1123, 1147, 1175, 1209–1211, 1251, 1261–1262
   subroutine.py6025291%135, 245, 251, 309–312, 318, 369, 374, 377–383, 474, 494, 649, 651–652, 670, 672, 682–683, 692–693, 697, 718, 784, 791, 811–812, 896, 922–923, 940, 956, 980, 988, 999, 1025–1028, 1134–1135, 1155, 1165, 1167, 1176, 1194, 1202, 1216, 1219, 1222, 1225, 1228
   utils.py1612485%30, 47–51, 69, 104–105, 107, 151–152, 203, 211, 216, 229–233, 238–241, 250, 254, 262
src/puyapy/awst_build/eb
   _base.py1281886%52, 57–59, 64, 71, 76, 81–83, 142, 153, 183, 188, 193, 198, 209, 223–225
   _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, 101
   array.py26965%23, 28–33, 43, 49
   biguint.py101694%56, 100, 139, 155–156, 158
   binary_bool_op.py105397%154, 162, 172
   bool.py55984%39–43, 59, 70, 83, 97
   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.py1343475%99, 103, 163, 167–170, 179–181, 204–207, 216, 220, 224–227, 242–254, 263–264, 275–278
   contracts.py77890%55, 61, 63, 73, 99, 109, 111, 116
   dict.py27581%25, 33–35, 39
   ensure_budget.py31197%47
   interface.py90397%314–316, 320
   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, 141, 184, 191, 195, 207, 281–283, 303
   struct.py16569%14–16, 25, 31
   subroutine.py801680%47, 51–54, 69, 72–79, 94, 102–103, 105–108, 113
   template_variables.py37295%30, 58
   tuple.py3391396%86, 134, 150, 240–241, 253, 346–347, 466, 535, 546–547, 610
   uint64.py108694%57, 118–119, 167–168, 200
   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.py92397%185–188, 199
   _utils.py141795%121, 129, 140, 180–183, 254, 258
   abi_call.py3171994%118, 124, 145, 215, 228–229, 310, 321, 379, 402, 433, 452–453, 512, 548, 622, 707–708, 725
   address.py73297%57, 116
   bool.py58395%42, 87–88
   dynamic_array.py120992%56, 123–124, 145, 221, 241–242, 245–248
   dynamic_bytes.py68396%99–101
   emit.py36197%38
   static_array.py62198%44
   string.py98793%54–55, 103, 124, 129–132
   struct.py49198%49
   tuple.py931683%45–47, 70, 88–91, 94–95, 134–137, 142, 146–147, 157, 167
   ufixed.py70297%43, 102
src/puyapy/awst_build/eb/reference_types
   account.py79297%65, 175
   application.py45198%40
   asset.py65198%48
src/puyapy/awst_build/eb/storage
   _common.py69396%107, 120–121
   _storage.py1082081%58, 66, 70, 74, 78, 82, 86, 90, 94, 104, 108, 112, 116, 122, 133, 139, 145, 157–159
   _value_proxy.py55787%38, 42, 50, 54, 91, 99, 103
   box_map.py147199%194
   global_state.py127695%104–105, 114–115, 165–166
   local_state.py1371192%99–100, 104, 151, 155, 159, 169, 173, 197, 254, 278
src/puyapy/awst_build/eb/transaction
   base.py39295%23, 43
   group.py53198%48
   inner.py48296%91–92
   inner_params.py77594%64, 74, 78, 138, 140
   itxn_args.py60198%72
TOTAL22109169592% 

Tests Skipped Failures Errors Time
873 2 💤 0 ❌ 0 🔥 5m 59s ⏱️

…onst-for-arc4-string

# Conflicts:
#	examples/sizes.txt
#	src/puya/ir/builder/main.py
#	test_cases/arc4_types/out/Arc4MutableParamsContract.approval.mir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.ir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.opt_pass_1.ir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.opt_pass_10.ir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.opt_pass_11.ir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.opt_pass_12.ir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.opt_pass_13.ir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.opt_pass_2.ir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.opt_pass_3.ir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.opt_pass_4.ir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.opt_pass_5.ir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.opt_pass_6.ir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.opt_pass_7.ir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.opt_pass_8.ir
#	test_cases/arc4_types/out/Arc4MutableParamsContract.ssa.opt_pass_9.ir
#	test_cases/arc4_types/out/module.awst
#	test_cases/arc4_types/out/mutable_params.O0.log
#	test_cases/arc4_types/out/tuples.O0.log
#	test_cases/arc4_types/out_unoptimized/Arc4MutableParamsContract.approval.teal
#	test_cases/arc4_types/out_unoptimized/Arc4MutableParamsContract.destructured.ir
#	test_cases/arc4_types/puya.log
#	test_cases/compile/out_unoptimized/HelloFactory.approval.teal
#	test_cases/typed_abi_call/out_unoptimized/Greeter.approval.teal
@tristanmenzel tristanmenzel force-pushed the refactor/use-string-const-for-arc4-string branch from 352aaf9 to 66acced Compare November 11, 2024 21:27
@tristanmenzel tristanmenzel merged commit 363aff4 into main Nov 12, 2024
4 checks passed
@tristanmenzel tristanmenzel deleted the refactor/use-string-const-for-arc4-string branch November 12, 2024 00:56
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.

2 participants