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

Remove unnecessary branches #120

Merged
merged 4 commits into from
Sep 27, 2021
Merged

Conversation

jasonpaulos
Copy link
Contributor

This PR adds additional code to TealBlock.NormalizeBlocks to remove unnecessary intermediate blocks with 0 ops. Blocks like this are added by If and other branching expressions in order to converge divergent branches. They are harmless, but it would be more efficient to get rid of them.

For example, consider the following expression:

If(Int(1)).Then(Int(2)).ElseIf(Int(3)).Then(Int(4)).Else(Int(5))

Before this PR, it compiles to:

#pragma version 2
int 1
bnz main_l5
int 3
bnz main_l4
int 5
main_l3:
b main_l6
main_l4:
int 4
b main_l3
main_l5:
int 2
main_l6:
return

With this PR, it now compiles to:

#pragma version 2
int 1
bnz main_l4
int 3
bnz main_l3
int 5
b main_l5
main_l3:
int 4
b main_l5
main_l4:
int 2
main_l5:
return

Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

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

How do we version this stuff? Since it changes compilation, logicsig authors may be sad. Do you only introduce these in new teal versions?

@jasonpaulos
Copy link
Contributor Author

This change will get released with v0.9.0 of pyteal, which is allowed to introduce breaking changes. In the past we've changed the code generator on releases like this out of necessity (and always with a warning in the changelog), so there is precedence for this.

Copy link
Contributor

@algochoi algochoi left a comment

Choose a reason for hiding this comment

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

Code looks good to me :shipit:
Just had one question about manual list splicing.

@jasonpaulos jasonpaulos merged commit b261fa5 into master Sep 27, 2021
@jasonpaulos jasonpaulos deleted the remove-unnecessary-branches branch September 27, 2021 18:24
@jasonpaulos jasonpaulos mentioned this pull request Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants