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 __traits(initSymbol, <aggregate type>) #3774

Merged
merged 2 commits into from
Jun 28, 2021

Conversation

kinke
Copy link
Member

@kinke kinke commented Jun 27, 2021

A clean way of directly accessing struct and class init symbols. It yields a const(void[]) slice; the length reflecting the struct/class instance size, and the pointer either pointing to the init symbol or being null for zero-initialized structs.

Paves the way for resolving #3773 in druntime as well as accessing class init symbols without TypeInfo_Class.initializer() indirection, and so with -betterC as well.

@thewilsonator
Copy link
Contributor

Please do submit this upstream

@kinke
Copy link
Member Author

kinke commented Jun 27, 2021

I have 0 interest to tackle the DMD glue stuff but it's all prepared for simple upstreaming (that's why it's not in ldctraits.d).

thewilsonator added a commit to thewilsonator/dmd that referenced this pull request Jun 27, 2021
thewilsonator added a commit to thewilsonator/dmd that referenced this pull request Jun 27, 2021
@thewilsonator
Copy link
Contributor

Noted, added upstream PR to reduce frontend diff

@JohanEngelen
Copy link
Member

Nice, much better than the pragma hack indeed.

kinke added 2 commits June 27, 2021 17:30
A clean way of directly accessing struct and class init symbols. It
yields a `const(void[])` slice; the length reflecting the struct/class
instance size, and the pointer either pointing to the init symbol or
being null for zero-initialized structs.

Paves the way for resolving ldc-developers#3773 in druntime as well as accessing class
init symbols without `TypeInfo_Class.initializer()` indirection, and so
with -betterC as well.
@kinke
Copy link
Member Author

kinke commented Jun 27, 2021

Reverted from immutable to const, as class init symbols aren't really immutable (monitor field, plus druntime emplacing some Errors in their init symbols to prevent allocations...).

@kinke kinke merged commit c6096a7 into ldc-developers:master Jun 28, 2021
@kinke kinke deleted the initSymbol branch June 28, 2021 16:40
MoonlightSentinel added a commit to MoonlightSentinel/dmd that referenced this pull request Nov 13, 2021
`__traits(initSymbol, S)` was introduced in ldc-developers/ldc#3774 and
provides access to the initializer symbol of `S` in a way that does not
rely on `TypeInfo` or other hacks.

This commit contains some small adjustments to the initial patch which
improve the user experience:

- generated `VarExp` points to the `TraitsExp` instead of the symbol LoC
- CTFE issues a specific error message
- more extensive tests

Co-authored-by: Nicholas Wilson <iamthewilsonator@hotmail.com>
MoonlightSentinel added a commit to MoonlightSentinel/dmd that referenced this pull request Nov 13, 2021
`__traits(initSymbol, S)` was introduced in ldc-developers/ldc#3774 and
provides access to the initializer symbol of `S` in a way that does not
rely on `TypeInfo` or other hacks.

This commit contains some small adjustments to the initial patch which
improve the user experience:

- generated `VarExp` points to the `TraitsExp` instead of the symbol LoC
- CTFE issues a specific error message
- rejects interfaces because they don't have an initializer symbol and
  hence cause linker failures
- more extensive tests

Co-authored-by: Nicholas Wilson <iamthewilsonator@hotmail.com>
MoonlightSentinel added a commit to MoonlightSentinel/dmd that referenced this pull request Nov 13, 2021
`__traits(initSymbol, S)` was introduced in ldc-developers/ldc#3774 and
provides access to the initializer symbol of `S` in a way that does not
rely on `TypeInfo` or other hacks.

This commit contains some small adjustments to the initial patch which
improve the user experience:

- generated `VarExp` points to the `TraitsExp` instead of the symbol LoC
- CTFE issues a specific error message
- rejects interfaces because they don't have an initializer symbol and
  hence cause linker failures
- more extensive tests

Co-authored-by: Nicholas Wilson <iamthewilsonator@hotmail.com>
MoonlightSentinel added a commit to MoonlightSentinel/dmd that referenced this pull request Nov 13, 2021
`__traits(initSymbol, S)` was introduced in ldc-developers/ldc#3774 and
provides access to the initializer symbol of `S` in a way that does not
rely on `TypeInfo` or other hacks.

This commit contains some small adjustments to the initial patch which
improve the user experience:

- generated `VarExp` points to the `TraitsExp` instead of the symbol LoC
- CTFE issues a specific error message
- rejects interfaces because they don't have an initializer symbol and
  hence cause linker failures
- more extensive tests

Co-authored-by: Nicholas Wilson <iamthewilsonator@hotmail.com>
MoonlightSentinel added a commit to MoonlightSentinel/dmd that referenced this pull request Nov 13, 2021
`__traits(initSymbol, S)` was introduced in ldc-developers/ldc#3774 and
provides access to the initializer symbol of `S` in a way that does not
rely on `TypeInfo` or other hacks.

This commit contains some small adjustments to the initial patch which
improve the user experience:

- generated `VarExp` points to the `TraitsExp` instead of the symbol LoC
- CTFE issues a specific error message
- rejects interfaces because they don't have an initializer symbol and
  hence cause linker failures
- more extensive tests

Co-authored-by: Nicholas Wilson <iamthewilsonator@hotmail.com>
MoonlightSentinel added a commit to MoonlightSentinel/dmd that referenced this pull request Nov 16, 2021
`__traits(initSymbol, S)` was introduced in ldc-developers/ldc#3774 and
provides access to the initializer symbol of `S` in a way that does not
rely on `TypeInfo` or other hacks.

This commit contains some small adjustments to the initial patch which
improve the user experience:

- generated `VarExp` points to the `TraitsExp` instead of the symbol LoC
- CTFE issues a specific error message
- rejects interfaces because they don't have an initializer symbol and
  hence cause linker failures
- more extensive tests

Co-authored-by: Nicholas Wilson <iamthewilsonator@hotmail.com>
dlang-bot pushed a commit to dlang/dmd that referenced this pull request Nov 17, 2021
`__traits(initSymbol, S)` was introduced in ldc-developers/ldc#3774 and
provides access to the initializer symbol of `S` in a way that does not
rely on `TypeInfo` or other hacks.

This commit contains some small adjustments to the initial patch which
improve the user experience:

- generated `VarExp` points to the `TraitsExp` instead of the symbol LoC
- CTFE issues a specific error message
- rejects interfaces because they don't have an initializer symbol and
  hence cause linker failures
- more extensive tests

Co-authored-by: Nicholas Wilson <iamthewilsonator@hotmail.com>
kinke pushed a commit to ldc-developers/dmd-testsuite that referenced this pull request Dec 19, 2021
`__traits(initSymbol, S)` was introduced in ldc-developers/ldc#3774 and
provides access to the initializer symbol of `S` in a way that does not
rely on `TypeInfo` or other hacks.

This commit contains some small adjustments to the initial patch which
improve the user experience:

- generated `VarExp` points to the `TraitsExp` instead of the symbol LoC
- CTFE issues a specific error message
- rejects interfaces because they don't have an initializer symbol and
  hence cause linker failures
- more extensive tests

Co-authored-by: Nicholas Wilson <iamthewilsonator@hotmail.com>
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.

3 participants