-
Notifications
You must be signed in to change notification settings - Fork 34
Improved overload resolution
prunedtree edited this page Jan 10, 2011
·
25 revisions
Current overloads have two main issues:
- They depend on code position of toplevel definitions (confusing for newbies, manageable for some, unacceptable for others, error-prone for all)
- They depend on module loading order (much more problematic)
various syntaxes are possible....
"overload" [ "(" [ module_list ] ")" ] ( function_definition | "{" [ function_definition ]* "}" )
// vectors.clay
overload () {
Vector(s:'S) | Sequence?('S) {
...
}
Vector(s:'S) | SizedSequence?('S) {
...
}
Vector(rvalue s:Vector['T]) {
...
}
}
// randomaccesssequences.clay
overload (vectors, forwardsequences) {
Vector(s:'S) | RandomAccessSequence?('S) {
...
}
}
// forwardsequences.clay
overload (vectors) Vector(s:'S) | ForwardSequence?('S) {
...
}
// customsequence.clay
overload Vector(s: FooSequence) {
...
}
overload Vector(s: BarSequence) {
...
}
"overload" [ "(" [ module_list ] ")" ] function_definition [ "shadow" function_definition ]*
- overloads are a list of function definitions with a list of the modules whose definition they shadow
- overload lists with empty module lists "()" overload nothing
- overload lists with no specified module list implicitly overload all modules (including itself, thus order is irrelevant)
- each module has at most one overload list with qualified modules per callable (you cannot have a callable in two qualified lists)
- there can be several overload lists with no specified modules
- definitions within one overload list will overload each-other based on list order (current semantics)
- function definitions outside overload lists cannot overload other functions
Overloads form a DAG where every node points to the node(s) it overloads. If two definitions match a call site, but are unordered according the the DAG, then that ambiguity is a static error
Please add comments here.