Skip to content

Commit

Permalink
Introspection (part 6) (#113)
Browse files Browse the repository at this point in the history
Following on from #112, this PR adds a `reflect`-like API for inspecting
durable coroutine state.

I've opted for a reflect-like API — rather than using `reflect.Type` and
`reflect.StructField` directly — because it's not currently possible to
map serialized named types back into a `reflect.Type` that has the same
properties and same identity. The serialization layer handles this
problem by tracking the offset of a `reflect.Type` in memory relative to
a known anchor point (see
[1](https://github.com/stealthrocket/coroutine/blob/f768d76b2a41ff2256ca7f049cb1fb457a077149/types/unsafe.go#L66-L84)
and
[2](https://github.com/stealthrocket/coroutine/blob/f768d76b2a41ff2256ca7f049cb1fb457a077149/types/types.go#L50-L52))
. This means that it's only possible to get the associated
`reflect.Type` values in the build that generated the state. It's
possible to create `reflect.Type`'s that are somewhat equivalent (e.g.
via `reflect.StructOf([]reflect.StructField)`), but it's not possible to
set certain properties such as the name or package path. I opted to use
a custom API rather than return incomplete/invalid information.

A notable omission and the subject of a follow-up PR is the ability to
walk the object graph. With this PR we can inspect the regions (the
length and type) but we can't unpack the encoded data within them.
  • Loading branch information
chriso authored Nov 21, 2023
2 parents f768d76 + e5ca637 commit 03fcabb
Showing 1 changed file with 549 additions and 0 deletions.
Loading

0 comments on commit 03fcabb

Please sign in to comment.