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

Avoid repeated global strings #1377

Merged
merged 1 commit into from
Jun 23, 2023

Conversation

LucasSte
Copy link
Contributor

@LucasSte LucasSte commented Jun 20, 2023

When debugging the issue #1367, I found out that we keep emitting repeated global strings. The LLVM IR for the contract pointed in such an issue had the string math overflow,\0A defined 1008 times.

This PR DOES NOT solve #1367, but it is something that needed a fix.

@LucasSte LucasSte marked this pull request as ready for review June 20, 2023 22:39
@xermicus
Copy link
Contributor

Are these "global strings" guaranteed to be readonly?

@seanyoung
Copy link
Contributor

Are these "global strings" guaranteed to be readonly?

only when constant is set

@LucasSte
Copy link
Contributor Author

Are these "global strings" guaranteed to be readonly?

only when constant is set

I missed that. I should reuse them when they are constant. Let me update the PR.

@LucasSte
Copy link
Contributor Author

Are these "global strings" guaranteed to be readonly?

only when constant is set

Fixed!
The changes worked because presently we do not generate any non-constant global string.

Copy link
Contributor

@seanyoung seanyoung left a comment

Choose a reason for hiding this comment

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

How are we testing this?

src/emit/binary.rs Outdated Show resolved Hide resolved
@LucasSte
Copy link
Contributor Author

How are we testing this?

The test file I added tests/codegen_testcases/solidity/global_strings.sol generates the LLVM-IR file and reads it. It ensures that we only have a single math overflow string there, instead of 1008.

Signed-off-by: Lucas Steuernagel <[email protected]>


constructor(address a, string memory _baseURI)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the contract need all those empty functions for this case?

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 can shorten the contract, but I left it as it is because it used to generate 1008 definitions of math overflow.
What is your opinion in shortening it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, it's not the end of the world. I'll leave that up to you. I just thought that if in the end only 1 single math overflow string instead of 1008 should be generated, the test code could be more to the point.

@LucasSte LucasSte merged commit 8373ae5 into hyperledger:main Jun 23, 2023
17 checks passed
@LucasSte LucasSte deleted the avoid-repeated-strings branch June 23, 2023 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants