Skip to content

IRGeneratorForStatements: Remove outdated check against usr$ prefixing of builtins #15952

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

Merged
merged 1 commit into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions libsolidity/codegen/ir/IRGeneratorForStatements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ struct CopyTranslate: public yul::ASTCopier
{
using ExternalRefsMap = std::map<yul::Identifier const*, InlineAssemblyAnnotation::ExternalIdentifierInfo>;

CopyTranslate(yul::Dialect const& _dialect, IRGenerationContext& _context, ExternalRefsMap const& _references):
m_dialect(_dialect), m_context(_context), m_references(_references) {}
CopyTranslate(IRGenerationContext& _context, ExternalRefsMap const& _references):
m_context(_context), m_references(_references) {}

using ASTCopier::operator();

Expand All @@ -80,14 +80,11 @@ struct CopyTranslate: public yul::ASTCopier

yul::YulName translateIdentifier(yul::YulName _name) override
{
// Strictly, the dialect used by inline assembly (m_dialect) could be different
// from the Yul dialect we are compiling to. So we are assuming here that the builtin
// functions are identical. This should not be a problem for now since everything
// is EVM anyway.
if (m_dialect.findBuiltin(_name.str()))
return _name;
else
return yul::YulName{"usr$" + _name.str()};
// Strictly, the dialect used by inline assembly could be different
// from the Yul dialect we are compiling to. By only translating `YulName`s which correspond to Identifiers,
// we are implicitly excluding builtins together with the assumption, that numerical builtin handles
// stay identical. Special care has to be taken, that these numerical handles stay consistent.
return yul::YulName{"usr$" + _name.str()};
}

yul::Identifier translate(yul::Identifier const& _identifier) override
Expand Down Expand Up @@ -209,8 +206,6 @@ struct CopyTranslate: public yul::ASTCopier
return yul::Identifier{_identifier.debugData, yul::YulName{value}};
}


yul::Dialect const& m_dialect;
IRGenerationContext& m_context;
ExternalRefsMap const& m_references;
};
Expand Down Expand Up @@ -2294,7 +2289,7 @@ bool IRGeneratorForStatements::visit(InlineAssembly const& _inlineAsm)
setLocation(_inlineAsm);
if (*_inlineAsm.annotation().hasMemoryEffects && !_inlineAsm.annotation().markedMemorySafe)
m_context.setMemoryUnsafeInlineAssemblySeen();
CopyTranslate bodyCopier{_inlineAsm.dialect(), m_context, _inlineAsm.annotation().externalReferences};
CopyTranslate bodyCopier{m_context, _inlineAsm.annotation().externalReferences};

yul::Statement modified = bodyCopier(_inlineAsm.operations().root());

Expand Down
11 changes: 3 additions & 8 deletions libsolidity/experimental/codegen/IRGeneratorForStatements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ struct CopyTranslate: public yul::ASTCopier
{
CopyTranslate(
IRGenerationContext const& _context,
yul::Dialect const& _dialect,
std::map<yul::Identifier const*, InlineAssemblyAnnotation::ExternalIdentifierInfo> _references
): m_context(_context), m_dialect(_dialect), m_references(std::move(_references)) {}
): m_context(_context), m_references(std::move(_references)) {}

using ASTCopier::operator();

Expand All @@ -72,10 +71,7 @@ struct CopyTranslate: public yul::ASTCopier

yul::YulName translateIdentifier(yul::YulName _name) override
{
if (m_dialect.findBuiltin(_name.str()))
return _name;
else
return yul::YulName{"usr$" + _name.str()};
return yul::YulName{"usr$" + _name.str()};
}

yul::Identifier translate(yul::Identifier const& _identifier) override
Expand Down Expand Up @@ -106,7 +102,6 @@ struct CopyTranslate: public yul::ASTCopier
}

IRGenerationContext const& m_context;
yul::Dialect const& m_dialect;
std::map<yul::Identifier const*, InlineAssemblyAnnotation::ExternalIdentifierInfo> m_references;
};

Expand All @@ -129,7 +124,7 @@ bool IRGeneratorForStatements::visit(TupleExpression const& _tupleExpression)

bool IRGeneratorForStatements::visit(InlineAssembly const& _assembly)
{
CopyTranslate bodyCopier{m_context, _assembly.dialect(), _assembly.annotation().externalReferences};
CopyTranslate bodyCopier{m_context, _assembly.annotation().externalReferences};
yul::Statement modified = bodyCopier(_assembly.operations().root());
solAssert(std::holds_alternative<yul::Block>(modified));
m_code << yul::AsmPrinter(_assembly.dialect())(std::get<yul::Block>(modified)) << "\n";
Expand Down