Changes in / [ff1efc10:ad72c8b]


Ignore:
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/proposals/vtable.md

    rff1efc10 rad72c8b  
    33
    44This is an adaptation of the earlier virtual proposal, updating it with new
    5 ideas, re-framing it and laying out more design decisions. It should
    6 eventually replace the earlier proposal, but not all features and syntax have
    7 been converted to the new design.
     5ideas, reframing it and laying out more design decisions.
    86
    97The basic concept of a virtual table (vtable) is the same here as in most
    108other languages. They will mostly contain function pointers although they
    119should be able to store anything that goes into a trait.
     10
     11This should replace the virtual proposal, although all not all features have
     12been converted to the new design.
    1213
    1314Trait Instances
     
    3839        combine(obj, 5);
    3940
    40 As with `struct` (and `union` and `enum`), `trait` might be optional when
    41 using the trait as a type name. A trait may be used in assertion list as
    42 before.
    43 
    4441Internally a trait object is a pair of pointers. One to an underlying object
    4542and the other to the vtable. All calls on an trait are implemented by looking
     
    4744remaining arguments to it.
    4845
    49 Trait objects can be moved by moving the pointers. Almost all other operations
    50 require some functions to be implemented on the underlying type. Depending on
    51 what is in the virtual table a trait type could be a dtype or otype.
     46Trait objects can be copied and moved by copying and moving the pointers.
     47They should also be able to own or borrow the underlying object.
    5248
    5349Hierarchy
     
    6056tree.
    6157
    62 The hierarchy would be a tree of types, of traits and structs. Currently we do
     58The hierachy would be a tree of types, of traits and structs. Currently we do
    6359not support structural extension, so traits form the internal nodes and
    6460structures the leaf nodes.
     
    6662The syntax is undecided but it will include a clause like `virtual (PARENT)`
    6763on trait and struct definitions. It marks out all types in a hierarchy.
    68 PARENT may be omitted, if it is this type is the root of a hierarchy. Otherwise
     64PARENT may be omitted, if it is this type is the root of a hierachy. Otherwise
    6965it is the name of the type that is this type's parent in the hierarchy.
    7066
     
    7773from a parent type to a child type are conditional, they check to make sure
    7874the underlying instance is an instance of the child type, or an instance of
    79 one of its children. The type then is recoverable at run-time.
     75one of its children. The type then is recoverable at runtime.
    8076
    8177As with regular trait objects, calling a function on a trait object will cause
    82 a look-up on the the virtual table. The casting rules make sure anything that
     78a lookup on the the virtual table. The casting rules make sure anything that
    8379can be cast to a trait type will have all the function implementations for
    8480that trait.
    8581
    86 Converting from a concrete type (structures at the edge of the hierarchy) to
     82Converting from a concrete type (structures at the edge of the hierchy) to
    8783an abstract type works the same as with normal trait objects, the underlying
    88 object is packaged with a virtual table pointer. Converting back to an abstract
     84object is packaged with a virtal table pointer. Converting back to an abstract
    8985type requires confirming the underlying type matches, but then simply extracts
    9086the pointer to it.
     
    9692it is the trait object could be a single pointer.
    9793
    98 It is trivial to do if the field with the virtual table pointer is fixed.
     94It is trival to do if the field with the virtual table pointer is fixed.
    9995Otherwise some trickery with pointing to the field and storing the offset in
    10096the virtual table to recover the main object would have to be used.
     
    118114
    119115The main thing CFA would need to do it this way is some single point where
    120 the type declaration, including the functions that satisfy the trait, are
     116the type declaration, including the functions that satify the trait, are
    121117all defined. Currently there are many points where this can happen, not all
    122118of them will have the same definitions and no way to select one over the
     
    126122time and a single vtable created for each type at compilation time.
    127123
    128 ### Explicit Resolution Points:
    129 Slightly looser than the above, there are explicit points where the vtables
     124### Explicate Resolution Points:
     125Slightly looser than the above, there are explicate points where the vtables
    130126are resolved, but there is no limit on the number of resolution points that
    131127might be provided. Each time a object is bound to a trait, one of the
    132 resolutions is selected. This might be the most flexible option.
     128resolutions is selected. This might be the most flexable option.
    133129
    134130An syntax would have to be provided as above. There may also be the option
    135131to name resolution points so that you can choose between them. This also
    136 could come with the ability to forward declare them.
     132could come with the ablity to forward declare them.
    137133
    138134Especially if they are not named, these resolution points should be able to
     
    145141its own resolution. Syntax-wise this is the simplest as it should be able
    146142to use just the existing declarations and the conversion to trait object.
    147 It also is very close to the current polymorphic resolution rules.
     143It also is very close to the current polymorphic reolution rules.
    148144
    149 This works as the explicit resolution points except the resolution points
    150 are implicit and their would be no selection of which resolution to use. The
     145This works as the explicate resolution points except the resolution points
     146are implicate and their would be no selection of which resolution to use. The
    151147closest (current) resolution is always selected.
    152148
    153 This could easily lead to an explosion of vtables as it has the most fine
     149This could easily lead to an explosition of vtables as it has the most fine
    154150grained resolution the number of bindings in a single scope (that produces
    155151the same binding) could be quite high. Merging identical vtables might help
     
    160156
    161157Vtables interact badly with the thunk issue. Conceptually vtables are static
    162 like type/function data they carry, as those decisions are made by the
     158like type/function data they carry, as those decitions are made by the
    163159resolver at compile time.
    164160
    165161Stack allocated functions interact badly with this because they are not
    166 static. There are several ways to try to resolve this, however without a
     162static. There are serveral ways to try to resolve this, however without a
    167163general solution most can only buy time.
    168164
     
    172168
    173169Dynamically allocated vtables introduces memory management overhead and
    174 requires some way to differentiate between dynamic and statically allocated
     170requires some way to differentate between dynamic and statically allocated
    175171tables. The stale function pointer problem continues unless those becomes
    176172dynamically allocated as well which gives us the same costs again.
     
    179175is now the limiting factor but it should be effectively the same as the
    180176shortest lifetime of a function assigned to it. However this still limits the
    181 lifetime "implicitly" and returns to the original problem with thunks.
     177lifetime "implicately" and returns to the original problem with thunks.
  • libcfa/src/Makefile.am

    rff1efc10 rad72c8b  
    7171)
    7272
    73 -include $(libdeps)
     73include $(libdeps)
     74
     75$(libdeps):
     76        @mkdir -p $(dir $@)
     77        @echo '#dummy' > $@
    7478
    7579prelude.o : prelude.cfa extras.cf gcc-builtins.cf builtins.cf @CFACC@ @CFACPP@
Note: See TracChangeset for help on using the changeset viewer.