Use polymorphic variants for phantom types #34
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Instead of declaring a load of unique type names at the start of the file, use polymorphic variants. These don't need to be declared before use.
e.g.
becomes
This simplifies imports (all uses of
Obj.magic
have been removed from the generated code).It also makes it possible to refer to a type before applying the generated code's functor. This might be useful for the RPC system, as it allows it to define a capability as something that takes a request struct, before applying the RPC schema's functor (that defines what a request struct is).
I also switched to formatting the node ID as hex, to make it shorter and to match the format used in the schema files.
Note that there is a slight API change here, because the
$Struct.reader_t
and$Struct.builder_t
types have gone (to avoid confusion with the genericreader_t
andbuilder_t
types). You have to usestruct_t reader_t
andstruct_t builder_t
instead.To make writing generic code simpler, there are two new helpers in
StructStorage
:This required some changes to the benchmark code, but the new code is shorter (
6 files changed, 29 insertions(+), 57 deletions(-)
).