You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To reduce code size of value witness functions we propose to model their
functionality via type layout strings that are to be interpreted by runtime
functions.
Today, say you have a ``Pair<T>`` the value witness function to copy such a
value will contain two function calls to `T->assignWithCopy()``.
(To be clear this paragraph stems from a time before type layout based value witness generation existed i.e it describes what used to happen if IGM.getOptions().UseTypeLayoutValueHandling == false)
Code size, the value witness function require quite a bit of space.
Furthermore, because the above value witness is slow (because it creates the
metadata for stored property members) we create outlined value functions for
concrete instantiations of a type.
lety = Container(first: Pair(1, 1), second: Pair(2, 2))
varx = y
In this code instead of calling the value witness we create a specialized
version that has knowledge of the types involved and therefore does not need
to call getGenericMetadata.
Performance, in order to compute field offsets we instantiate metadata for the
field's type.
Layout strings:
Instead of generating code for the value witness function we propose to compute
a type layout and store a byte string representation of it that is to be
interpreted by the runtime to achieve the copy.
The layout string for the Pair<T> would just be an encoding of:
Single payload enum value witnesses similarly can be implemented, the runtime
will have knowledge of size, alignment, and extra inhabitants of builtin types. The remainder can be
calculated using this information like we do today in IRGen and runtime.
A type layout is a tree of type layout entries. The contents describe the minimal information for generation of IR. We probably will want to make them independent of TypeInfo later.
We'll add APIs to IRGen's TypeInfo to compute type layout (e.g for structs as
part of computing StructLayout). TypeLayouts should be unqiued as part of
building in TypeConverter.
Step 1:
Using this type lowering we will be able to generate value witness functions
that don't instantiate generic metadata except for resilient types.
compute offsets/sizes based on type layouts
copy/destroy non resilient enums based on cases
My hope is that this will allow us to replace the outlined value functions with value witness calls to save code size and that this will improve performance for some witness calls because we can avoid calls to getGenericMetadata.
(This is what happens if IGM.getOptions().UseTypeLayoutValueHandling == true which is the default as of today)
Step 2:
Generate a byte code representation of the type layout. This can be a
serialization of the type layout representation:
Archetypes as indices
Encode paths for things like T.associatedType
Encoding for enums: num empty/payload cases, (no/single/multi)payload/c
Fast paths: {POD128|} {BitwiseTakable128|}
Interpreter in the runtime:
Compute offsets, alignment, extra inhabitants at runtime
Tye metadata access, associated type witness
Optimizations like {POD128|},
Replace value witness entries with functions that reference type layouts.
Backwards deployment: the runtime library to interpret types is not available have to fall back to witnesses. Can we emit witness tables to sections that are not loaded if needed?
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: cd2441f4cd61806767a7a86cd2eb62bc
Issue Description:
To reduce code size of value witness functions we propose to model their
functionality via type layout strings that are to be interpreted by runtime
functions.
Today, say you have a ``Pair<T>`` the value witness function to copy such a
value will contain two function calls to `T->assignWithCopy()``.
(To be clear this paragraph stems from a time before type layout based value witness generation existed i.e it describes what used to happen if IGM.getOptions().UseTypeLayoutValueHandling == false)
This becomes worst as we nest types.
This approach has two drawbacks:
Code size, the value witness function require quite a bit of space.
Furthermore, because the above value witness is slow (because it creates the
metadata for stored property members) we create outlined value functions for
concrete instantiations of a type.
In this code instead of calling the value witness we create a specialized
version that has knowledge of the types involved and therefore does not need
to call getGenericMetadata.
field's type.
Layout strings:
Instead of generating code for the value witness function we propose to compute
a type layout and store a byte string representation of it that is to be
interpreted by the runtime to achieve the copy.
The layout string for the Pair<T> would just be an encoding of:
The runtime would then interpet this string.
Similar for ``Container<T>``.
Value witness functions:
the string.
will have knowledge of size, alignment, and extra inhabitants of builtin types. The remainder can be
calculated using this information like we do today in IRGen and runtime.
Enum only witness can be implemented in terms of layout.
getEnumTag, destructiveProjectEnumData, destructiveInjectEnumTag,
Type layouts:
Basic types.
Integers, boolean, floating point
Reference types:
Fixed layout types aggregate the layout.
Examples of aggregates.
Resilient types:
Generic resilient types:
Computing the layout:
A type layout is a tree of type layout entries. The contents describe the minimal information for generation of IR. We probably will want to make them independent of TypeInfo later.
We'll add APIs to IRGen's TypeInfo to compute type layout (e.g for structs as
part of computing StructLayout). TypeLayouts should be unqiued as part of
building in TypeConverter.
Step 1:
Using this type lowering we will be able to generate value witness functions
that don't instantiate generic metadata except for resilient types.
compute offsets/sizes based on type layouts
copy/destroy non resilient enums based on cases
My hope is that this will allow us to replace the outlined value functions with value witness calls to save code size and that this will improve performance for some witness calls because we can avoid calls to getGenericMetadata.
(This is what happens if IGM.getOptions().UseTypeLayoutValueHandling == true which is the default as of today)
Step 2:
Generate a byte code representation of the type layout. This can be a
serialization of the type layout representation:
Archetypes as indices
Encode paths for things like T.associatedType
Encoding for enums: num empty/payload cases, (no/single/multi)payload/c
Fast paths: {POD128|} {BitwiseTakable128|}
Interpreter in the runtime:
Compute offsets, alignment, extra inhabitants at runtime
Tye metadata access, associated type witness
Optimizations like {POD128|},
Replace value witness entries with functions that reference type layouts.
Backwards deployment: the runtime library to interpret types is not available have to fall back to witnesses. Can we emit witness tables to sections that are not loaded if needed?
The text was updated successfully, but these errors were encountered: