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

File-level inline assembly blocks #9282

Open
chriseth opened this issue Jul 1, 2020 · 9 comments
Open

File-level inline assembly blocks #9282

chriseth opened this issue Jul 1, 2020 · 9 comments
Labels
low effort There is not much implementation work to be done. The task is very easy or tiny. medium impact Default level of impact must have eventually Something we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.

Comments

@chriseth
Copy link
Contributor

chriseth commented Jul 1, 2020

Just like free functions, inline assembly blocks could be allowed at file level. This would make it possible to write helper functions in yul that can be called from any inline assembly block. Maybe we could even import these yul functions using import statements.

@ekpyron
Copy link
Member

ekpyron commented Jul 3, 2020

Importing should work nicely now that we reserved dots in identifiers!

@chriseth
Copy link
Contributor Author

chriseth commented Jul 8, 2020

Shadowing: if there is a file-level inline-assembly function f, then no contract can be named f.

@axic
Copy link
Member

axic commented Jul 8, 2020

Some relevant issues from the past:

@chriseth
Copy link
Contributor Author

chriseth commented Jul 8, 2020

Exactly, this is a solution to the problem in #1319.

@ekpyron
Copy link
Member

ekpyron commented Jul 8, 2020

To be more precise about importing: Namespaces could be introduced using import statements to get qualified functions like A.f (using import f from file.sol as A). This won't cause conflicts now, since dots are now reserved in inline assembly and have to refer to things in the solidity scope anyways.

To be more precise about the shadowing: yul functions in file-level blocks would occupy the same namespace as solidity objects (be proper Declarations for the compiler) - just referring to them from outside inline assembly would be an error.
[Note: it could even make sense at some point in the future to make such functions callable from solidity in some way, but that'd be quite a separate issue.]

We could reserve one special identifier in Yul, in case we ever decide to expose compiler generated functions in any way (to use it as namespace for those e.g. std and have std.require(...) etc.). This could expose e.g. abi encoding/decoding functions. Again a separate issue though, but maybe also worth keeping in mind for this.

@chriseth
Copy link
Contributor Author

chriseth commented Sep 2, 2020

Discussion: Pretty clear how to do it, only question is whether it is useful.

@cameel
Copy link
Member

cameel commented Sep 2, 2020

While working on the yul-phaser I compiled a list of a few publicly available contracts with more substantial assembly blocks to use as input in experiments (#7806 (comment)). It might come in handy if we want to gain more insight into how people organize assembly-heavy contracts in practice:

Source repository Direct link to .sol file
AztecProtocol/AZTEC Swap.sol
GNSPS/solidity-bytes-utils AssertBytes.sol
GNSPS/solidity-bytes-utils BytesLib.sol
likecoin/likecoin-contracts LikeChainRelayLogic.sol
Loopring/protocols LzDecompressor.sol
NutBerry/stack GatedComputing.sol
NutBerry/stack LEVM.sol
pvienhage/ghost-wallet p256.sol
rynobey/multi-exponent EcOperations.sol
vaporns/solsha1 SHA1.sol
zcoinofficial/solidity-BigNumber BigNumber.sol

@axic
Copy link
Member

axic commented Nov 12, 2020

@cameel cameel added feature language design :rage4: Any changes to the language, e.g. new features labels Nov 22, 2020
@ekpyron
Copy link
Member

ekpyron commented Sep 2, 2022

Not sure why we were wondering if this is useful - at the moment I'd say it rather clearly is and we just had a similar request in #13472, so I'd say we can consider this as "nice-to-have" at least. And I don't see any open design questions or blockers on this.

I'll actually even move it to "must have eventually".

@ekpyron ekpyron added low effort There is not much implementation work to be done. The task is very easy or tiny. medium impact Default level of impact must have eventually Something we consider essential but not enough to prevent us from releasing Solidity 1.0 without it. and removed language design :rage4: Any changes to the language, e.g. new features labels Sep 2, 2022
@ekpyron ekpyron moved this to Triage in Solidity Focus Board Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low effort There is not much implementation work to be done. The task is very easy or tiny. medium impact Default level of impact must have eventually Something we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.
Projects
None yet
Development

No branches or pull requests

5 participants