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

Void as a "real" type #20609

Closed
wants to merge 8 commits into from
Closed

Void as a "real" type #20609

wants to merge 8 commits into from

Conversation

SirOlaf
Copy link
Contributor

@SirOlaf SirOlaf commented Oct 20, 2022

Make a bunch of new things possible

type G[T] = object
  x: T
if G[void]().x is void: # true
  echo "It's a void"

proc `$`(x: void): string = "()"
var x: void
echo x # '()'
echo typeof(x) # 'void'

Also an alternative to #20385 and #20603

@Varriount
Copy link
Contributor

So, what is a void-typed variable? How is it represented in backend code?

@SirOlaf
Copy link
Contributor Author

SirOlaf commented Oct 20, 2022

Should stay as tyVoid until it disappears in cgen

@beef331
Copy link
Collaborator

beef331 commented Oct 20, 2022

Does this have any repercussions on offsetOf or sizeOf magics?

@SirOlaf
Copy link
Contributor Author

SirOlaf commented Oct 20, 2022

If I do it right by some miracle, it's just a compiletime construct, so doesn't do anything but let you compare types (or use them in weird ways).
Best case I make it work, worst case it's out there so someone else might get inspired to try as well.

Edit:
addr for this says x and z are 8 bytes apart (64bit system), so it's like y doesn't exist while letting you "use" it

type H = object
    x: int
    y: void
    z: int

@Araq
Copy link
Member

Araq commented Oct 21, 2022

This is covered by nim-lang/RFCs#437

However it says

"Void type" -- We should optimize away the "empty tuple" type in the backend and remove this feature.

But fixing it instead is the better solution surely.

@SirOlaf
Copy link
Contributor Author

SirOlaf commented Nov 6, 2022

Probably a controversial thing, these all work. Void gets treated as so optional you can skip it entirely

proc foo(voidparam: void, intparam: int) = echo intparam
foo(intparam=2)
foo(55)
var x: void
foo(x, 22)
foo(x, intparam=33)
foo(voidparam=x, 44)

@Varriount Varriount requested a review from Araq November 10, 2022 20:40
@Varriount Varriount added the Requires Araq To Merge PR should only be merged by Araq label Nov 10, 2022
@ringabout ringabout removed the Requires Araq To Merge PR should only be merged by Araq label Dec 9, 2022
@SirOlaf SirOlaf closed this Mar 1, 2023
@Araq Araq reopened this Mar 2, 2023
Copy link
Contributor

github-actions bot commented Mar 3, 2024

This pull request is stale because it has been open for 1 year with no activity. Contribute more commits on the pull request and rebase it on the latest devel, or it will be closed in 30 days. Thank you for your contributions.

@github-actions github-actions bot added the stale Staled PR/issues; remove the label after fixing them label Mar 3, 2024
Copy link
Contributor

github-actions bot commented Apr 5, 2024

This pull request has been marked as stale and closed due to inactivity after 395 days.

@github-actions github-actions bot closed this Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Staled PR/issues; remove the label after fixing them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants