Skip to content

Commit

Permalink
fix: use read location for variable source locations, rather than whe…
Browse files Browse the repository at this point in the history
…re the variable was last defined
  • Loading branch information
daniel-makerx committed Nov 7, 2024
1 parent dac51be commit 27e2659
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 253 deletions.
8 changes: 6 additions & 2 deletions examples/amm/out_unoptimized/ConstantProductAMM.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,14 @@ do_asset_transfer:
// asset_receiver=receiver,
// ).submit()
itxn_begin
// amm/contract.py:357
// def do_asset_transfer(*, receiver: Account, asset: Asset, amount: UInt64) -> None:
// amm/contract.py:359
// xfer_asset=asset,
frame_dig -2
// amm/contract.py:360
// asset_amount=amount,
frame_dig -1
// amm/contract.py:361
// asset_receiver=receiver,
frame_dig -3
itxn_field AssetReceiver
itxn_field AssetAmount
Expand Down
8 changes: 4 additions & 4 deletions examples/auction/out_unoptimized/Auction.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ opt_into_asset:
// auction/contract.py:36
// asset_receiver=Global.current_application_address,
global CurrentApplicationAddress
// auction/contract.py:26
// def opt_into_asset(self, asset: Asset) -> None:
// auction/contract.py:37
// xfer_asset=asset,
frame_dig -1
itxn_field XferAsset
itxn_field AssetReceiver
Expand Down Expand Up @@ -525,8 +525,8 @@ claim_asset:
// asset_amount=self.asa_amount,
// ).submit()
itxn_begin
// auction/contract.py:98
// def claim_asset(self, asset: Asset) -> None:
// auction/contract.py:102
// xfer_asset=asset,
frame_dig -1
// auction/contract.py:103
// asset_close_to=self.previous_bidder,
Expand Down
4 changes: 2 additions & 2 deletions examples/voting/out_unoptimized/VotingRoundApp.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,8 @@ close_after_for@14:
bytec 13 // "nft_image_url"
app_global_get_ex
assert // check self.nft_image_url exists
// voting/voting.py:144
// note += "]}}"
// voting/voting.py:153
// note=note,
uncover 2
itxn_field Note
itxn_field ConfigAssetURL
Expand Down
1 change: 1 addition & 0 deletions src/puya/ir/builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ def visit_var_expression(self, expr: awst_nodes.VarExpression) -> TExpression:
variable = self.context.ssa.read_variable(
expr.name, ir_type, self.context.block_builder.active_block
)
variable = attrs.evolve(variable, source_location=expr.source_location)
return variable

def visit_intrinsic_call(self, call: awst_nodes.IntrinsicCall) -> TExpression:
Expand Down
63 changes: 8 additions & 55 deletions test_cases/compile/out_unoptimized/HelloFactory.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ test_compile_contract:
extract 6 2
bytec_3 // "world"
concat
// compile/factory.py:35
// hello_app = (
// compile/factory.py:49
// app_id=hello_app,
swap
itxn_field ApplicationID
// compile/factory.py:48
Expand Down Expand Up @@ -550,8 +550,8 @@ test_compile_contract_tmpl:
extract 6 2
bytec_3 // "world"
concat
// compile/factory.py:67
// hello_app = (
// compile/factory.py:84
// app_id=hello_app,
swap
itxn_field ApplicationID
// compile/factory.py:83
Expand Down Expand Up @@ -715,8 +715,8 @@ test_compile_contract_prfx:
extract 6 2
bytec_3 // "world"
concat
// compile/factory.py:103
// hello_app = (
// compile/factory.py:117
// app_id=hello_app,
swap
itxn_field ApplicationID
// compile/factory.py:116
Expand Down Expand Up @@ -992,14 +992,8 @@ test_arc4_create:
extract 6 2
bytec_3 // "world"
concat
// compile/factory.py:163-164
// # create app
// hello_app = arc4.arc4_create(Hello.create, "hello").created_app
swap
itxn_field ApplicationID
// compile/factory.py:166-167
// # call the new app
// result, _txn = arc4.abi_call(Hello.greet, "world", app_id=hello_app)
bytec 5 // method "greet(string)string"
itxn_field ApplicationArgs
itxn_field ApplicationArgs
Expand Down Expand Up @@ -1101,13 +1095,8 @@ test_arc4_create_tmpl:
extract 6 2
bytec_3 // "world"
concat
// compile/factory.py:182
// hello_app = arc4.arc4_create(
swap
itxn_field ApplicationID
// compile/factory.py:187-188
// # call the new app
// result, _txn = arc4.abi_call(HelloTmpl.greet, "world", app_id=hello_app)
bytec 5 // method "greet(string)string"
itxn_field ApplicationArgs
itxn_field ApplicationArgs
Expand Down Expand Up @@ -1211,13 +1200,8 @@ test_arc4_create_prfx:
extract 6 2
bytec_3 // "world"
concat
// compile/factory.py:205
// hello_app = arc4.arc4_create(
swap
itxn_field ApplicationID
// compile/factory.py:210-211
// # call the new app
// result, _txn = arc4.abi_call(HelloPrfx.greet, "world", app_id=hello_app)
bytec 5 // method "greet(string)string"
itxn_field ApplicationArgs
itxn_field ApplicationArgs
Expand Down Expand Up @@ -1448,12 +1432,8 @@ test_arc4_create_modified_compiled:
extract 6 2
bytec 6 // "there"
concat
// compile/factory.py:246
// app = arc4.arc4_create(
swap
itxn_field ApplicationID
// compile/factory.py:257
// result, _txn = arc4.abi_call(Hello.greet, "there", app_id=app)
bytec 5 // method "greet(string)string"
itxn_field ApplicationArgs
itxn_field ApplicationArgs
Expand Down Expand Up @@ -1589,14 +1569,8 @@ test_arc4_update:
extract 6 2
bytec 6 // "there"
concat
// compile/factory.py:266-267
// # create app
// app = arc4.arc4_create(
swap
itxn_field ApplicationID
// compile/factory.py:280-281
// # call the new app
// result, _txn = arc4.abi_call(HelloTmpl.greet, "there", app_id=app)
bytec 5 // method "greet(string)string"
itxn_field ApplicationArgs
itxn_field ApplicationArgs
Expand All @@ -1623,13 +1597,7 @@ test_arc4_update:
// # update the app
// arc4.arc4_update(Hello, app_id=app)
itxn_begin
// compile/factory.py:266-267
// # create app
// app = arc4.arc4_create(
frame_dig 0
// compile/factory.py:284-285
// # update the app
// arc4.arc4_update(Hello, app_id=app)
bytec_2 // base64(CoEBQw==)
itxn_field ClearStateProgramPages
bytec_0 // 0x
Expand All @@ -1656,14 +1624,8 @@ test_arc4_update:
extract 6 2
bytec 6 // "there"
concat
// compile/factory.py:266-267
// # create app
// app = arc4.arc4_create(
frame_dig 0
itxn_field ApplicationID
// compile/factory.py:287-288
// # call the updated app
// result, _txn = arc4.abi_call(Hello.greet, "there", app_id=app)
bytec 5 // method "greet(string)string"
itxn_field ApplicationArgs
itxn_field ApplicationArgs
Expand Down Expand Up @@ -1694,9 +1656,8 @@ test_arc4_update:
// # on_complete is inferred from Hello.delete ARC4 definition
// )
itxn_begin
// compile/factory.py:266-267
// # create app
// app = arc4.arc4_create(
// compile/factory.py:294
// app_id=app,
frame_dig 0
// compile/factory.py:291-296
// # delete the app
Expand Down Expand Up @@ -1805,12 +1766,8 @@ test_other_constants:
extract 6 2
bytec 21 // "Johnny"
concat
// compile/factory.py:300
// app = arc4.arc4_create(
swap
itxn_field ApplicationID
// compile/factory.py:315
// result, _txn = arc4.abi_call(HelloOtherConstants.greet, "Johnny", app_id=app)
pushbytes 0x5b0c2375 // method "greet(string)byte[]"
itxn_field ApplicationArgs
itxn_field ApplicationArgs
Expand Down Expand Up @@ -1940,12 +1897,8 @@ test_abi_call_create_params:
extract 6 2
bytec 6 // "there"
concat
// compile/factory.py:327
// app = arc4.abi_call(
swap
itxn_field ApplicationID
// compile/factory.py:339
// result, _txn = arc4.abi_call(Hello.greet, "there", app_id=app)
bytec 5 // method "greet(string)string"
itxn_field ApplicationArgs
itxn_field ApplicationArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,8 @@ create_and_transfer:
// inner_transactions/asset_transfer.py:30
// asset_receiver=Global.current_application_address,
global CurrentApplicationAddress
// inner_transactions/asset_transfer.py:13-14
// # create
// new_asset = (
// inner_transactions/asset_transfer.py:32
// xfer_asset=new_asset,
swap
itxn_field XferAsset
// inner_transactions/asset_transfer.py:31
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,9 @@ log_greetings:
bytec_0 // "hello_app"
app_global_get_ex
assert // check self.hello_app exists
// inner_transactions/c2c.py:24
// def log_greetings(self, name: arc4.String) -> None:
frame_dig -1
// inner_transactions/c2c.py:27
// app_args=(arc4.arc4_signature("hello(string)string"), name),
frame_dig -1
pushbytes 0x02bece11 // method "hello(string)string"
itxn_field ApplicationArgs
itxn_field ApplicationArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,8 @@ test4:
// + Bytes(b"\x48") # pop
// )
dupn 3
// inner_transactions/contract.py:230
// approval_2 = (
// inner_transactions/contract.py:239
// approval_program=(approval_1, approval_2, approval_2, approval_2),
cover 2
cover 2
// inner_transactions/contract.py:245
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,21 @@ main_for_header@1:
b main_switch_case_default@6

main_switch_case_0@3:
// inner_transactions/itxn_loop.py:28
// i_note = op.extract(note, 0, i)
dig 3
bury 3
// inner_transactions/itxn_loop.py:31
// app_params.set(note=i_note, app_args=(Bytes(b"1"),))
dig 3
bury 3
bytec_0 // 0x31
bury 7
intc_0 // 1
bury 2
b main_switch_case_next@7

main_switch_case_1@4:
// inner_transactions/itxn_loop.py:28
// i_note = op.extract(note, 0, i)
dig 3
bury 3
// inner_transactions/itxn_loop.py:33
// app_params.set(note=i_note, app_args=(Bytes(b"2"), Bytes(b"1")))
dig 3
bury 3
bytec_1 // 0x32
bury 7
bytec_0 // 0x31
Expand All @@ -88,8 +84,8 @@ main_switch_case_1@4:
b main_switch_case_next@7

main_switch_case_2@5:
// inner_transactions/itxn_loop.py:28
// i_note = op.extract(note, 0, i)
// inner_transactions/itxn_loop.py:36
// note=i_note,
dig 3
bury 3
// inner_transactions/itxn_loop.py:37
Expand Down
Loading

0 comments on commit 27e2659

Please sign in to comment.