Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add is_reference_type() #1119

Closed
adlerjohn opened this issue Mar 31, 2022 · 3 comments · Fixed by #1121
Closed

Add is_reference_type() #1119

adlerjohn opened this issue Mar 31, 2022 · 3 comments · Fixed by #1121
Assignees
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged enhancement New feature or request language feature Core language features visible to end users team:compiler Compiler Team

Comments

@adlerjohn
Copy link
Contributor

adlerjohn commented Mar 31, 2022

Similar to #818, add a is_reference_type::<T>() function that is replaced by true or false at compile time depending on if the type is a reference type or not. This is needed so that the stdlib can do different run time logic depending on whether a type is a pointer to data vs data in a register.

Note that currently structs with a single single-word field are actually reference types, so the stdlib cannot use size_of::<T>() against the word size exclusively for such runtime checks.

@adlerjohn adlerjohn added enhancement New feature or request compiler General compiler. Should eventually become more specific as the issue is triaged language feature Core language features visible to end users labels Mar 31, 2022
@adlerjohn adlerjohn moved this to Todo in Fuel Network Mar 31, 2022
@otrho otrho self-assigned this Mar 31, 2022
@mohammadfawaz
Copy link
Contributor

mohammadfawaz commented Mar 31, 2022

In the near future, we won't really know if a type is going to be implemented in registers or not. It is very reasonable for the IR to decide to unwrap a local struct of 2 ints into 2 two separate ints, or an array into its individual elements (if the array accesses have fixed indices), in which case the result of is_reference_type::<T>() becomes incorrect. Where a variable is implemented is really just an implementation detail. We can imagine a (legal but really horrible) compiler that implements everything in storage!

That being said, I may have to catch up on some Slack message to understand the context better. I imagine this has something to do with asm blocks.

@otrho
Copy link
Contributor

otrho commented Mar 31, 2022

Correct. This isn't something we want to keep once we add intrinsics and remove the ASM blocks from the stdlib. But until then we need something to help out.

@adlerjohn
Copy link
Contributor Author

adlerjohn commented Mar 31, 2022

To add some context here for permanence: store is the most obvious example of this. It needs to know if something is a reference or not so that it can know its size, which it needs to know if it should use SWW or SWWQ.

Currently, store assumes all T are one-word primitives.

pub fn store<T>(key: b256, value: T) {
asm(r1: key, r2: value) {
sww r1 r2;
};
}

Repository owner moved this from Todo to Done in Fuel Network Apr 2, 2022
@IGI-111 IGI-111 added the team:compiler Compiler Team label Feb 10, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged enhancement New feature or request language feature Core language features visible to end users team:compiler Compiler Team
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants