Changes in / [f6cc2096:70284830]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/proposals/virtual.txt

    rf6cc2096 r70284830  
    147147
    148148This gives us an important extra feature, runtime checking of the parent-child
    149 relationship with virtual cast, where a pointer (and maybe a reference) to
    150 a virtual type can be cast to another virtual cast. However the cast is
    151 dynamicly check and only occurs if the underlying type is a child of the type
    152 being cast to. Otherwise null is returned.
    153 
    154 (virtual TYPE)EXPR
    155 
    156 As an extention, the TYPE may be ommitted if it can be determained from
    157 context, for instance if the cast occurs on the right hand side of an
    158 assignment.
     149relationship with a C++ dynamic_cast like operation. Allowing checked
     150conversions from trait references to more particular references, which works
     151if the underlying type is, or is a child of, the new trait type.
    159152
    160153Extension: Multiple Parents
     
    258251autogenerated and often unique.
    259252
    260 It may be worth looking into a way to force the vtable pointer to be in a
    261 particular location, which would save the storage to store the offset and
    262 maybe the offset operation itself (offset = 0). However it may not be worth
    263 introducing a new language feature for.
    264 As of writing, exceptions actually use this system.
    265 
    266253
    267254Keyword Usage:
     
    289276Calling free on a trait reference will free the memory for the object. It will
    290277leave the vtables alone, as those are (always?) statically allocated.
    291 
    292 
    293 Special Traits:
    294 
    295 trait is_virtual_parent(dtype parent, dtype child) { ... };
    296 
    297 There are others but I believe this one to be the most important. The trait
    298 holds if the parent type is a strict virtual ancestor (any number of levels)
    299 of child. It will have to exist at least internally to check for upcasts and
    300 it can also be used to optimize virtual casts into upcasts. Or a null value or
    301 error if the cast would never succeed. Exporting it to a special trait allows
    302 users to express that requirement in their own polymorphic code.
    303 
    304 
    305 Implementation:
    306 
    307 Before we can generate any of the nessasary code, the compiler has to get some
    308 additional information about the code that it currently does not collect.
    309 
    310 First it should establish all child->parent links so that it may travel up the
    311 hierarchy to grab the nessasary information, and create the actual parent
    312 pointers in the strict virtual tables. It should also maintain the connections
    313 between the virtual type (structure or trait), the vtable type and the vtable
    314 instance (or default instance for relaxed virtual if multiple are allowed). To
    315 this end a sub-node should be created with the nessasary pointers. Traits and
    316 structs with virtual can create an instance and store all the nessasary data.
    317 
    318 With the hierarchy in place it can generate the vtable type for each type,
    319 it will generally have a function pointer field for each type assertion in
    320 some consistant order. Strict virtual will also have a pointer to the parent's
    321 vtable and intrusive vtables will also have the offset to recover the original
    322 pointer. Sized types will also carry the size.
    323 
    324 Wheither the vtable is intrusive or not should also be save so that the trait
    325 object/reference/pointer knows if it has to store 1 or 2 pointers. A wrapper
    326 function will have to be generated for each type assertion so that they may
    327 be called on the trait type, these can probably be inlined.
    328 
    329 The virtual parameter will also have to be marked (implicately or explicately)
    330 until code generation so that the wrapper functions know where to go to get
    331 the vtable for the function look up. That could probably be added as a
    332 storageclass, although one that is only valid on type assertions.
    333 
    334 The generated vtable will than have to have a vtable instance created and
    335 filled with all the approprate values. Stricter matching may have to be used
    336 to ensure that the functions used are stable. It will also have to use
    337 ".gnu.linkonce" or equilant to ensure only one copy exists in the final code
    338 base.
Note: See TracChangeset for help on using the changeset viewer.