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

Add an is_reference_type::<T>() builtin. #1121

Merged
merged 1 commit into from
Apr 2, 2022
Merged

Conversation

otrho
Copy link
Contributor

@otrho otrho commented Mar 31, 2022

Returns false for copy types (unit, bool, byte, uint), true otherwise.

This is a temporary measure to assist in getting the stdlib richer now, i.e., to make decisions regarding ASM block instructions based on generic types, but isn't reliable once we have optimisations which could invalidate compile time assertions like this. A 'reference type' may not always be used by reference if optimisations allow a value to be passed by value.

is_reference_type::<T>() closely resembles size_of::<T>() in both syntax and semantics and so I've combined them into a builtin 'type property' expression and split the size_of_value(expr) expression
into its own thing.

Closes #1119.
Closes #1120.

@otrho otrho added enhancement New feature or request compiler General compiler. Should eventually become more specific as the issue is triaged labels Mar 31, 2022
@otrho otrho self-assigned this Mar 31, 2022
@otrho otrho force-pushed the otrho/1119_is_reference_type branch from 0cc886f to 547ec0c Compare April 1, 2022 07:20
@otrho otrho marked this pull request as ready for review April 1, 2022 07:21
Returns false for copy types (unit, bool, byte, uint), true otherwise.

This is a temporary measure to assist in getting the stdlib richer now,
i.e., to make decisions regarding ASM block instructions based on
generic types, but isn't reliable once we have optimisations which could
invalidate compile time assertions like this.  A 'reference type' may
not always be used by reference if optimisations allow a value to be
passed by value.

`is_reference_type::<T>()` closely resembles `size_of::<T>()` in both
syntax and semantics and so I've combined them into a builtin 'type
property' expression and split the `size_of_value(expr)` expression
into its own thing.
@otrho otrho force-pushed the otrho/1119_is_reference_type branch from 547ec0c to ab6b7e9 Compare April 1, 2022 07:26
Copy link
Contributor

@mohammadfawaz mohammadfawaz left a comment

Choose a reason for hiding this comment

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

Looks reasonable.

Copy link
Contributor

@adlerjohn adlerjohn left a comment

Choose a reason for hiding this comment

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

Can you file an issue so we remember about the unit type? How is it represented in a register anyways?

@otrho
Copy link
Contributor Author

otrho commented Apr 2, 2022

Unit is definitely a copy type at the moment (the test is passing) and should stay that way. I've updated the code to reflect this everywhere, like in is_copy_type() and in codegen it's represented by a zero, though in practice it shouldn't need to be anything.

@otrho otrho merged commit d6bfac2 into master Apr 2, 2022
@otrho otrho deleted the otrho/1119_is_reference_type branch April 2, 2022 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Monomorphisation is still sometimes incomplete. Add is_reference_type()
3 participants