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

bytes/string literal concatenation #13661

Closed
axic opened this issue Oct 27, 2022 · 4 comments
Closed

bytes/string literal concatenation #13661

axic opened this issue Oct 27, 2022 · 4 comments
Labels
closed due inactivity The issue/PR was automatically closed due to inactivity. feature language design :rage4: Any changes to the language, e.g. new features stale The issue/PR was marked as stale because it has been open for too long.

Comments

@axic
Copy link
Member

axic commented Oct 27, 2022

In some languages subsequent string literals are concatenated prior to compilation, which proves useful for containing large amounts of verbatim text in source code, while splitting it across multiple lines or logical boundaries.

One good example for Solidity is NFT metadata-JSON and SVG generation, where text is built up programatically. Current best practice is use string.concat and break logical parts.

Here's an excerpt from Uniswap NFT:

                '<path id="text-path-a" d="M40 12 H250 A28 28 0 0 1 278 40 V460 A28 28 0 0 1 250 488 H40 A28 28 0 0 1 12 460 V40 A28 28 0 0 1 40 12 z" />',
                '<path id="minimap" d="M234 444C234 457.949 242.21 463 253 463" />',
                '<filter id="top-region-blur"><feGaussianBlur in="SourceGraphic" stdDeviation="24" /></filter>',
                '<linearGradient id="grad-up" x1="1" x2="0" y1="1" y2="0"><stop offset="0.0" stop-color="white" stop-opacity="1" />',
                '<stop offset=".9" stop-color="white" stop-opacity="0" /></linearGradient>',
                '<linearGradient id="grad-down" x1="0" x2="1" y1="0" y2="1"><stop offset="0.0" stop-color="white" stop-opacity="1" /><stop offset="0.9" stop-color="white" stop-opacity="0" /></linearGradient>',
                '<mask id="fade-up" maskContentUnits="objectBoundingBox"><rect width="1" height="1" fill="url(#grad-up)" /></mask>',
                '<mask id="fade-down" maskContentUnits="objectBoundingBox"><rect width="1" height="1" fill="url(#grad-down)" /></mask>',
                '<mask id="none" maskContentUnits="objectBoundingBox"><rect width="1" height="1" fill="white" /></mask>',
                '<linearGradient id="grad-symbol"><stop offset="0.7" stop-color="white" stop-opacity="1" /><stop offset=".95" stop-color="white" stop-opacity="0" /></linearGradient>',
                '<mask id="fade-symbol" maskContentUnits="userSpaceOnUse"><rect width="290px" height="200px" fill="url(#grad-symbol)" /></mask></defs>',
                '<g clip-path="url(#corners)">',

This results in a bunch of items on the stack and a lot of more runtime overhead.

It would be useful allowing 'hello' 'world' to be compounded as helloworld.

@axic axic added feature language design :rage4: Any changes to the language, e.g. new features labels Oct 27, 2022
@axic axic changed the title bytes/string literla concatenation bytes/string literal concatenation Oct 27, 2022
@hrkrshnn
Copy link
Member

Random comment: we should also be moving these string into code and use codecopy, rather than mstore(...) with 32-byte chunks.

@github-actions
Copy link

github-actions bot commented Apr 1, 2023

This issue has been marked as stale due to inactivity for the last 90 days.
It will be automatically closed in 7 days.

@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Apr 1, 2023
@github-actions
Copy link

github-actions bot commented Apr 8, 2023

Hi everyone! This issue has been automatically closed due to inactivity.
If you think this issue is still relevant in the latest Solidity version and you have something to contribute, feel free to reopen.
However, unless the issue is a concrete proposal that can be implemented, we recommend starting a language discussion on the forum instead.

@github-actions github-actions bot added the closed due inactivity The issue/PR was automatically closed due to inactivity. label Apr 8, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 8, 2023
@cameel
Copy link
Member

cameel commented Apr 10, 2023

Isn't it already implemented? #7524 has been merged ages ago.

Parser already has this covered unless I'm misunderstanding the feature being requested here:

case Token::StringLiteral:
case Token::UnicodeStringLiteral:
case Token::HexStringLiteral:
{
string literal = m_scanner->currentLiteral();
Token firstToken = m_scanner->currentToken();
while (m_scanner->peekNextToken() == firstToken)
{
advance();
literal += m_scanner->currentLiteral();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed due inactivity The issue/PR was automatically closed due to inactivity. feature language design :rage4: Any changes to the language, e.g. new features stale The issue/PR was marked as stale because it has been open for too long.
Projects
None yet
Development

No branches or pull requests

3 participants