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 std/rtti and getDynamicTypeInfo #16963

Closed
wants to merge 10 commits into from

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Feb 8, 2021

use cases

notes

  • std/rtti is a new module and hidden behind -d:nimExperimentalTypeInfoCore so this module can more freely evolve until it stabilizes, while at same time allowing people to try it as opt-in, refs nimExperimentalFoo for experimental modules/APIs timotheecour/Nim#575
  • I intentionally didn't add that API inside typeinfo which is about the Any type, whereas getDynamicTypeInfo is about runtime type information (in particular for polymorphic types, but also useful for non polymorphic ones), but both can be combined
  • the diff in sytem.nim is to avoid Error: system module needs: programResult for tests/dll/nimhcr_integration.nim
  • turned hti include module into a private import module std/private/hti to avoid it being included more than once (and because imports are cleaner in general)

future work

  • move definition of TNimTypeV2 to hti.nim now that hti is a proper import module, so that it can be deduplicated from system.nim and std/rtti (alternatively, I could do this in this PR)
  • see whether lib/system/cyclebreaker.nim can reuse this proc instead of it defining its own proc getDynamicTypeInfo[T](x: T): PNimTypeV2 {.magic: "GetTypeInfoV2", noSideEffect, locks: 0.}
  • maybe also expose a common API in std/rtti that would work with both gc:refc and gc:arc, eg via getters getSize, gteAlign, getName etc

@timotheecour timotheecour changed the title getDynamicTypeInfo add std/rrti and getDynamicTypeInfo Feb 8, 2021
@timotheecour timotheecour changed the title add std/rrti and getDynamicTypeInfo add std/rtti and getDynamicTypeInfo Feb 8, 2021
@timotheecour timotheecour marked this pull request as ready for review February 8, 2021 05:33
@Araq
Copy link
Member

Araq commented Feb 8, 2021

This should be opt-in, the type names might not always be available (I can think of v2 implementations that use integers and modulo operations for the of operator). Also, the type names are generally of little use -- you cannot construct objects via the type name and the runtime reflection capabilities of Nim are weak.

@Varriount
Copy link
Contributor

Is there any plan for the design of this module? I'm assuming users are going to want more functionality than just the single function retrieving and comparing type information objects for equality.

@Araq
Copy link
Member

Araq commented Feb 15, 2021

This needs an RFC.

@Araq
Copy link
Member

Araq commented Mar 24, 2021

As I said, this needs an RFC first.

@Araq Araq closed this Mar 24, 2021
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.

rtti: getDynamicTypeInfo
3 participants