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

sizeof default in type section fails with concept #12720

Closed
mratsim opened this issue Nov 24, 2019 · 1 comment · Fixed by #24028
Closed

sizeof default in type section fails with concept #12720

mratsim opened this issue Nov 24, 2019 · 1 comment · Fixed by #24028

Comments

@mratsim
Copy link
Collaborator

mratsim commented Nov 24, 2019

In a similar vein to #12714 and #12636

const CacheLineSize = 128

type
  Enqueueable = concept x, type T
    x is ptr
    x.next is Atomic[pointer]

  MyChannel*[T: Enqueueable] = object
    pad: array[CacheLineSize - sizeof(default(T)[]), byte]
    dummy: typeof(default(T)[])
.../bug_sizeof.nim(9, 46) template/generic instantiation of `default` from here
../.choosenim/toolchains/nim-1.0.2/lib/system.nim(1818, 16) Error: invalid type: 'T: Enqueueable' in this context: 'proc (T: type T: Enqueueable): T: Enqueueable{.noSideEffect.}' for proc

Unfortunately there is no workaround since typedesc are now NimNode in macros (nim-lang/RFCs#148 and #11400) and there is no way to convert in NimNode back into a typedesc (#6785)

Otherwise somehing like this would probably work

macro sizeofDeref(T: typedesc): untyped =
  let x = default(T)[]
  result = newLit sizeof(x)
mratsim added a commit to mratsim/weave that referenced this issue Nov 24, 2019
Rename to WV_CacheLinePadding

Unfortunately nim-lang/Nim#12722 broke Nim devel in the past 3 days, commit nim-lang/Nim@1b2c1bc is good.

Also C proc signatures changed to csize_t nim-lang/Nim#12497
@metagn
Copy link
Collaborator

metagn commented Aug 29, 2024

Seems to compile now with import std/atomics but no idea if just the code in the issue is a sufficient test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants