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

Conversation

clonker
Copy link
Member

@clonker clonker commented Mar 17, 2025

Builtins are mapped to BuiltinHandles instead of YulNames.

@clonker clonker force-pushed the remove_builtin_check_from_inline_asm_mangling branch from 08c5138 to 7f09a93 Compare March 17, 2025 09:50
@clonker clonker requested a review from aarlt March 19, 2025 11:44
Comment on lines 84 to 88
// 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;
Copy link
Member

@cameel cameel Mar 19, 2025

Choose a reason for hiding this comment

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

Now that we don't handle builtins in this function, the comment is a bit out of context and does not even refer to the code that is below it, because that only handles identifiers. We should put it somewhere else or at least note that it refers to builtins, which are not processed here.

It's still relevant though, just now it's about mapping builtin handles rather than names. And m_dialect no longer exists.

// 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.

The fact that we're not checking this is actually quite dangerous now that we transitioned to handles. Before, it was enough that all builtins from the source dialect existed in the target dialect as well and had matching names, which was relatively easy to ensure in EVMDialect::createBuiltins(). With sequential numeric IDs though the names do not matter and we instead rely on defining them in the same order, which is less visible and can easily be affected by making builtins conditional.

For a moment I was worried that we already broke it with EOF, but looks like it so happened that the builtins unavailable in inline assembly were last, so they weren't shifting other IDs when unevailable. And then #15783 made them all unavailable. This could easily break in the future though - we're planning to enable eofcreate() and it's the middle one there. If we don't change the order while doing that, we'll end up with eofcreate() in inline assembly being translated to returncontract() in full Yul.

We should at least add some big fat warnings in createBuiltins() to be very careful with ordering. But it would be much better if we could have sanity checks.

I guess this goes back to my concern that handles are just plain numbers, not associated with the dialect.

Copy link
Member

@cameel cameel Mar 19, 2025

Choose a reason for hiding this comment

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

Actually, you did secure it a bit with the createIfObjectAccess(), which still reserves the ID even if the builtin does not exist. So enabling eofcreate() should have been safe... but isn't :) The EOF code ignores your helper and uses an ordinary condition. We need to fix that.

So we should still add some warnings in createBuiltins() and mention that we do rely on this property in practice. It's just too easy to violate it by not paying attention.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah you are absolutely right. I will update the comment here and have opened PR #15961 that should improve the situation. Also contains the fix for EOF.

@cameel cameel changed the title IRGeneratorForStatements: Remove builtin check for usr$ prefixing IRGeneratorForStatements: Remove check against usr$ prefixing of builtins Mar 19, 2025
@clonker clonker force-pushed the remove_builtin_check_from_inline_asm_mangling branch from 7f09a93 to 8455f15 Compare March 20, 2025 15:55
@cameel cameel changed the title IRGeneratorForStatements: Remove check against usr$ prefixing of builtins IRGeneratorForStatements: Remove outdated check against usr$ prefixing of builtins Mar 20, 2025
@cameel cameel force-pushed the remove_builtin_check_from_inline_asm_mangling branch from 8455f15 to 098b854 Compare March 20, 2025 22:51
@clonker clonker merged commit 4a93b2a into develop Mar 21, 2025
74 checks passed
@clonker clonker deleted the remove_builtin_check_from_inline_asm_mangling branch March 21, 2025 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants