Skip to content

Conversation

@ThomasHaas
Copy link
Collaborator

@ThomasHaas ThomasHaas commented May 1, 2025

This PR gives makes VoidType a unit type with a single value unit.
This allows for a uniform treatment (and thus less code) of function calls with return value and without return values.
In fact, there are no functions without return values anymore, a void function returns the unit value. The class VoidFunctionCall becomes obsolete.
The callsite now has to assign the return value to a register of void type:

call myFunc(...);  // void functions
// ... becomes
void _ <- myFunc(...); // "_" is a register of void type.

Issues/Possible TODOs:

  • The SPIRV parser does not like to reuse the same register for multiple operations, so I had to hack in an exception to this rule for the unit/void register (a reason why this is a draft).
  • We should also choose a uniform name for this kind of register that cannot collide with user-provided names. For LLVM, the name _ is fine, but it might not be for SPIRV?
  • We might also want to rename VoidType to UnitType, or even replace it entirely by an empty aggregate type.
  • There are currently no restrictions to ensure that void types are not stored into memory, but we will likely throw exceptions in the backend if that happens.
  • We might need an equality expression on VoidType if we want to use it as a proper unit type.
  • [DONE] Now that VoidFunctionCall is gone, we can merge ValueFunctionCall into the base class FunctionCall.
  • There are likely still code places left that can be made more uniform now.

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.

2 participants