Skip to content

Rework handling of prototypes of built-in types

Yorick Peterse requested to merge rework-prototype-handling into master

This reworks how the prototypes of built-in types, such as ByteArray, are handled. Prior to this commit, various built-in types would use Object as their prototype, followed by the runtime correcting this. This required the use of std::reflection in various places, which would add unnecessary runtime overhead.

Supporting FFI was also made more complicated in this setup. For example, in the FFI API a Pointer should be an instance of std::pointer::Pointer, but the VM has no built-in knowledge of this type, meaning it had to use Object as the prototype. This then required the FFI runtime code to fix the prototype every time a Pointer was created. This complicates the code, and in certain places requires different approaches to fix the prototype.

In this commit, we make sure that all built-in types have a dedicated prototype in the VM. We also merge the various GetFooPrototype instructions into a single GetBuiltinPrototype instruction, reducing the number of instructions necessary. The compiler still exposes separate virtual instructions, though this is mostly to keep the prototype IDs out of the runtime.

Setting object names

This new setup requires that for a few more types we get the prototype and set the object name manually. To make this easier, the compiler now supports the virtual instruction set_object_name. This allows modules to set the correct object name, without having to use the @_object_name instance attribute directly. This in turn means this attribute is now only used in two places:

  1. In the compiler, where it belongs.
  2. In std::mirror, in order to obtain the name of the object.

DefaultHasher is now in a separate module

The DefaultHasher type used to reside in std::hash_map, but this didn't make much sense since it's not tied into the HashMap type. With the various prototype changes being made I decided that now was a good time to move DefaultHasher to its own module: std::hasher. In the future this module might provide hashers using other algorithms, but for now it only defines the DefaultHasher type.

Edited by Yorick Peterse

Merge request reports