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

ABI Encode Unit Type #671

Closed
wants to merge 1 commit into from
Closed

Conversation

Maltby
Copy link
Contributor

@Maltby Maltby commented Feb 18, 2022

What was wrong?

closes #442

How was it fixed?

To-Do

  • OPTIONAL: Update Spec if applicable

  • Add entry to the release notes (may forgo for trivial changes)

  • Clean up commit history

@sbillig
Copy link
Collaborator

sbillig commented Feb 21, 2022

@Maltby I went down this road once, and abandoned it because our compiler pipeline wasn't powerful enough to solve this in a satisfactory way. In yul, functions that don't return anything really don't return anything, so they can't be used in a position that expects some kind of value. There's no concept of a zero-sized value (everything is a u256).

Fe code like this:

fn f(a: u256, b: ()) -> u256:  return a
fn g():  pass
f(10, g())

is currently compiled to something like this in yul:

function f($a, $b) -> return_val {
    return_val := $a
    leave
}
function g() -> return_val {
    return_val := 0x0
    leave
}
pop(f(10, g()))

which only works because g returns a value. If we get rid of g's return value, we can't use g() as an argument to f. We could modify the current yulgen so that it calls g() first, then calls f(10, 0) or something, but I think that the ideal solution here would be for all zero-sized types (including unit) to not exist at all by the time we reach the code generation (yulgen) phase. In a pre-yul optimization, we could eliminate all unit-type fn args, all unit-type struct fields, and zero-sized structs altogether.

The "middle" of the compiler is currently being revamped (#661, and a follow-up pr that'll generate yul from mir). My tentative suggestion is that unit types could be eliminated in an optimization pass on mir, and the mir-to-yul codegen could assume that unit types don't exist. Thoughts, @Y-Nak?

@Y-Nak
Copy link
Member

Y-Nak commented Feb 22, 2022

Yeah, I agree with the opinion. We should/could remove unit types from both function call-sites and def-sites.
Also, I assume the removal would be done in the legalization pass because its removal would be specific for EVM and should be independent of MIR.
So the compilation passes in my mind currently would look like the below.
graphviz (2)

Of course, Target agnostic transformations are optional.

@Maltby
Copy link
Contributor Author

Maltby commented Mar 2, 2022

@sbillig @Y-Nak thanks for the feedback and info! I'll look into removing the unit type within MIR.

@Y-Nak
Copy link
Member

Y-Nak commented Mar 2, 2022

@Maltby I think it'd be better to fix this issue in codegen crate, which will be introduced in #676.
I'm still working on it, and I could finish it within a week if there are not so many problems. So could you wait for its completion, please?

@Maltby
Copy link
Contributor Author

Maltby commented Mar 3, 2022

@Y-Nak Ok, I'll wait for #676 to be merged. No rush at all! Thanks again for the guidance.

@Y-Nak Y-Nak mentioned this pull request May 19, 2022
3 tasks
@Y-Nak
Copy link
Member

Y-Nak commented May 19, 2022

Hi @Maltby, I'm so sorry for the late response.
I've struggled so much through #676. Also, I fixed this issue in #676.
I should have let you know about this, I'm really sorry for my rudeness.

@Maltby
Copy link
Contributor Author

Maltby commented May 24, 2022

@Y-Nak No worries! #676 looks like a challenging PR!

@Y-Nak Y-Nak closed this in #676 May 25, 2022
@Maltby Maltby deleted the abi-encode-unit-type branch May 25, 2022 13:03
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.

unit type is not abi encodable at analyzer/src/namespace/types.rs:542:27
3 participants