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

Type getters could automatically unwrap user types #1406

Open
xermicus opened this issue Jun 28, 2023 · 3 comments
Open

Type getters could automatically unwrap user types #1406

xermicus opened this issue Jun 28, 2023 · 3 comments
Labels
enhancement New feature or request under discussion

Comments

@xermicus
Copy link
Contributor

xermicus commented Jun 28, 2023

Currently it's super easy to write code that forgets to unwrap user types. I think that for most cases, we want to work with the actual type and not the user type.

There are many places which this could potentially matter:

src/codegen/cfg.rs
2131:    pub fn storage_type(&self) -> Type {
2140:    pub fn value_type(&self) -> Type {
src/codegen/mod.rs
799:    fn ty(&self) -> Type {

src/sema/ast.rs
125:    fn ty(&self) -> Type;

src/sema/yul/ast.rs
50:    fn ty(&self) -> Type {

src/sema/expression/retrieve_type.rs
6:    fn ty(&self) -> Type {

What we could do is to use unwrap_user_type() in all these fn ty(). However, a consistent solution to this could be to make the enum Type private, and provide a wrapper for it, that explicitly represents the Type in its wrapped or unwrapped form. This would force us to think about this nuance wherever enum Type is currently used.

WDYT?

@xermicus xermicus added enhancement New feature or request under discussion labels Jun 28, 2023
@LucasSte
Copy link
Contributor

LucasSte commented Jul 5, 2023

Ideally, a user type should not exist in codegen. We would unwrap it when building the CFG.

@xermicus
Copy link
Contributor Author

xermicus commented Jul 6, 2023

I agree, however I'm not sure how to enforce this without having two entirely distinct Type types within the two modules.

@seanyoung
Copy link
Contributor

seanyoung commented Jul 7, 2023

Ideally, a user type should not exist in codegen. We would unwrap it when building the CFG.

How would we add correct debug information to types if the higher level user-type information has been thrown away? I don't think removing the user-types from the CFG is the solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request under discussion
Projects
None yet
Development

No branches or pull requests

3 participants