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

AVM: Teal macros #4737

Merged
merged 16 commits into from
Feb 8, 2023
Merged

AVM: Teal macros #4737

merged 16 commits into from
Feb 8, 2023

Conversation

jannotti
Copy link
Contributor

@jannotti jannotti commented Nov 2, 2022

Adds simple:

#define X 10

style constants, and more complex:

#define beq ==; bnz

style macros.

@jannotti jannotti changed the title Teal macros AVM: Teal macros Nov 2, 2022
@jannotti
Copy link
Contributor Author

jannotti commented Nov 2, 2022

I am curious if @fergalwalsh or @jeapostrophe would care to use this in the TEAL they emit to make it more readable / auditable.

@codecov
Copy link

codecov bot commented Nov 2, 2022

Codecov Report

Merging #4737 (9231903) into master (fa77937) will increase coverage by 0.05%.
The diff coverage is 98.87%.

@@            Coverage Diff             @@
##           master    #4737      +/-   ##
==========================================
+ Coverage   54.62%   54.67%   +0.05%     
==========================================
  Files         414      414              
  Lines       53514    53595      +81     
==========================================
+ Hits        29231    29303      +72     
- Misses      21860    21868       +8     
- Partials     2423     2424       +1     
Impacted Files Coverage Δ
data/transactions/logic/assembler.go 87.31% <98.83%> (+0.80%) ⬆️
data/transactions/logic/opcodes.go 84.84% <100.00%> (+0.28%) ⬆️
ledger/blockqueue.go 85.63% <0.00%> (-2.88%) ⬇️
crypto/merkletrie/trie.go 66.42% <0.00%> (-2.19%) ⬇️
agreement/cryptoVerifier.go 67.60% <0.00%> (-2.12%) ⬇️
agreement/proposalManager.go 96.07% <0.00%> (-1.97%) ⬇️
crypto/merkletrie/node.go 91.62% <0.00%> (-1.87%) ⬇️
catchup/service.go 68.14% <0.00%> (-0.75%) ⬇️
network/wsNetwork.go 65.52% <0.00%> (-0.19%) ⬇️
... and 2 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@fergalwalsh
Copy link

I am curious if @fergalwalsh or @jeapostrophe would care to use this in the TEAL they emit to make it more readable / auditable.

This looks interesting indeed. It can certainly be nice for constants. For macro 'ops' it would be nice if we come up with a shared standard library of common macros (I see you have the starts of one in the tests) so that there is some consistency across the space. Otherwise it may actually make things more difficult for auditors. e.g. if my beq is not the same as your beq

I'll try to spend some time playing with this and give feedback if I have any.

@michaeldiamant michaeldiamant linked an issue Dec 2, 2022 that may be closed by this pull request
@@ -31,6 +31,7 @@ import (
"sort"
"strconv"
"strings"
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I suppose so. It's not really a spec change (of the protocol) but since that's where we document some assembler level stuff, it would be the right place to explain these as well. I'll add.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can merge without a spec mod, as they don't actually change the protocol.

@bbroder-algo
Copy link
Contributor

I like it, the testing is good, the recheck is funny. It does feel ripe for getting overlooked if additional reserved strings are added. also I wonder if enforcing some name prefix would lead to improved readability, or maybe it could just be convention.

Copy link
Contributor

@jasonpaulos jasonpaulos left a comment

Choose a reason for hiding this comment

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

Looks correct to me. I did note one concern, but I don't view it as a blocker.

if isTxnType || isOnCompletion {
return fmt.Errorf("Named constants cannot be used as macro names: %s", macroName)
}
if _, ok := pseudoOps[macroName]; ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that if we introduce a new pseudo op that happens to have the same name as an existing program's macro, their code will fail to assemble, regardless of whether they've increased their pragma version or not (since pseudo ops aren't versioned). This also applies to txn and on completion types, but I expect new values for these to be much rarer.

I don't have a suggestion to improve the situation, I just wanted to point out this relationship.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I think we would probably introduce versioning to those names if/when there were newly introduced values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though I suppose we have not versioned pseudo-ops in the past, since they are compiled down to normal opcodes, and thus don't require versioning. We'll just have to keep this in mind and decide what to do then.

Copy link
Contributor

@bbroder-algo bbroder-algo left a comment

Choose a reason for hiding this comment

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

#define LGTM "looksgoodtome"

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.

AVM: Add TEAL macro expansion support
7 participants