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

incomplete importc types should be annotated with incomplete and optional sizeof / alignof pragmas #9250

Open
timotheecour opened this issue Oct 8, 2018 · 3 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Oct 8, 2018

/cc @krux02
this would help with #5664 (implement sizeof and alignof operator) for importc types:

cda1ab4#diff-3ff4bd5c972c5629ed4e7e62596e3b3bR326
# TODO there is no proper way to find out if a type cannot be queried for the size.

as well as here:

cda1ab4#diff-e3317694adf0c30fc5d1562cb85f4d40R2

discard """
errormsg: "cannot evaluate 'sizeof/alignof' because its type is not defined completely"
line: 9
"""
 type
  MyStruct {.importc: "MyStruct".} = object
 const i = sizeof(MyStruct)
 echo i

instead of cannot evaluate 'sizeof/alignof' because its type is not defined completely for all importc types we can restrict this error to cases where type is marked with {.incomplete.}

Furthermore, we can add optional annotations {.sizeof: 32, alignof:32.} pragma for cases of {.incomplete.} types T so that T.sizeof can just use that directly, when available

@timotheecour timotheecour changed the title incomplete importc types should be annotated with incomplete and optional sizeof pragmas incomplete importc types should be annotated with incomplete and optional sizeof pragmas Oct 8, 2018
@mratsim
Copy link
Collaborator

mratsim commented Oct 10, 2018

There is a size pragma for imported types, though it is very restricted at the moment: #7674

@timotheecour timotheecour changed the title incomplete importc types should be annotated with incomplete and optional sizeof pragmas incomplete importc types should be annotated with incomplete and optional sizeof / alignof pragmas Oct 10, 2018
@krux02
Copy link
Contributor

krux02 commented Oct 11, 2018

That is isteresting. But for a recursive calculation of object sizes it is important to know borth size and alignment. Just setting the size does not really help.

@krux02
Copy link
Contributor

krux02 commented Oct 12, 2018

Alignment is often very platform, compiler and compiler flag dependent. you can't just measure alignment and size and set it as a constant. If something goes wrong here, debugging will be horrible.

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

No branches or pull requests

3 participants