From 8ffd144c9a57f3c7a5f8fc27da0c37e8d045c4a3 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Tue, 22 Nov 2022 11:07:29 -0500 Subject: [PATCH 1/4] CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2efdc526..f1d3bc5ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,14 @@ # Unreleased +# Added +* Added frame pointer support for subroutine arguments, to substitute excessive use of scratch slots. ([#562](https://github.com/algorand/pyteal/pull/562)) + # Fixed * Allowing the `MethodCall` and `ExecuteMethodCall` to be passed `None` as app_id argument in the case of an app create transaction ([#592](https://github.com/algorand/pyteal/pull/592)) +# Changed +* Introducing `AbstractVar` to abstract value access: store, load, and stack type. ([#584](https://github.com/algorand/pyteal/pull/584)) + * NOTE: a backwards incompatable change was imposed in this PR: previous ABI value's public member `stored_value` with type `ScratchVar`, is now changed to protected member `_stored_value` with type `AbstractVar`. # 0.20.1 From 5e9e47f68c47d03c1e0ddd450dcaf6cd859157dd Mon Sep 17 00:00:00 2001 From: Hang Su <87964331+ahangsu@users.noreply.github.com> Date: Fri, 2 Dec 2022 13:51:10 -0500 Subject: [PATCH 2/4] CHANGELOG Co-authored-by: Zeph Grunschlag --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1d3bc5ad..1c9265ab2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Unreleased # Added -* Added frame pointer support for subroutine arguments, to substitute excessive use of scratch slots. ([#562](https://github.com/algorand/pyteal/pull/562)) +* Added frame pointer support for subroutine arguments, replacing the previous usage of scratch. ([#562](https://github.com/algorand/pyteal/pull/562)) # Fixed * Allowing the `MethodCall` and `ExecuteMethodCall` to be passed `None` as app_id argument in the case of an app create transaction ([#592](https://github.com/algorand/pyteal/pull/592)) From ede265850b85c832aa72d57e6902a4fa8c469e75 Mon Sep 17 00:00:00 2001 From: Hang Su <87964331+ahangsu@users.noreply.github.com> Date: Fri, 2 Dec 2022 13:51:52 -0500 Subject: [PATCH 3/4] per review comments Co-authored-by: Zeph Grunschlag --- pyteal/ast/frame.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyteal/ast/frame.py b/pyteal/ast/frame.py index 1abd6949c..904885f66 100644 --- a/pyteal/ast/frame.py +++ b/pyteal/ast/frame.py @@ -89,9 +89,7 @@ def __init__( f"be greater than local allocations {len(local_stack_types)}." ) - if not all( - map(lambda t: t != TealType.none, arg_stack_types + local_stack_types) - ): + if any(t == TealType.none for t in arg_stack_types + local_stack_types): raise TealInternalError("Variables in frame memory layout must be typed.") self.num_return_allocs: int = num_return_allocs From 22856549e4e0ac895b49e696434c1097a2170a87 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Fri, 2 Dec 2022 17:57:07 -0500 Subject: [PATCH 4/4] per PR comments --- pyteal/ast/subroutine_test.py | 9 +++++++-- pyteal/compiler/compiler_test.py | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pyteal/ast/subroutine_test.py b/pyteal/ast/subroutine_test.py index 26c1d9a7a..32c426b09 100644 --- a/pyteal/ast/subroutine_test.py +++ b/pyteal/ast/subroutine_test.py @@ -1,5 +1,6 @@ from itertools import product from typing import Callable, Literal, Optional, cast +from inspect import signature import pytest from dataclasses import dataclass @@ -1326,6 +1327,11 @@ def mySubroutine_arg_10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10): assert len(declaration.body.args) == 2 assert isinstance(declaration.body.args[0], Proto) + + proto_expr = declaration.body.args[0] + assert proto_expr.num_returns == int(return_type != pt.TealType.none) + assert proto_expr.num_args == len(signature(subr).parameters) + assert isinstance(declaration.body.args[1], type(return_value)) options_v8.setSubroutine(definition) @@ -1335,8 +1341,7 @@ def mySubroutine_arg_10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10): actual, _ = declaration.__teal__(options_v8) options_v8.setSubroutine(None) - with pt.TealComponent.Context.ExprEqualityContext(): - assert actual == expected + assert actual == expected def test_docstring_parsing_with_different_format(): diff --git a/pyteal/compiler/compiler_test.py b/pyteal/compiler/compiler_test.py index 3016b8254..d4852bd73 100644 --- a/pyteal/compiler/compiler_test.py +++ b/pyteal/compiler/compiler_test.py @@ -2347,6 +2347,13 @@ def approve_if_odd(condition_encoding: pt.abi.Uint32) -> pt.Expr: clear_state=pt.OnCompleteAction.call_only(pt.Approve()), ) + with pytest.raises(pt.TealInputError) as e: + pt.Router("will-error", on_completion_actions).compile_program( + version=6, frame_pointers=True + ) + + assert "Try to use frame pointer with an insufficient version 6" in str(e) + _router_with_oc = pt.Router( "ASimpleQuestionablyRobustContract", on_completion_actions )