*************************** C3 superclass linearization *************************** =============== ============================================= DEP-Number: 3 Type: Standards Track Affects-DRM: Yes Author: Hannes Mehnert Status: Accepted Created: 09-Jan-2012 Last-Modified: 09-Jan-2012 Post-History: 09-Jan-2012 Target-Version: 2012.1 =============== ============================================= Abstract ======== The Dylan superclass linearization is sometimes counter-intuitive. The C3 superclass linearization algorithm is more intuitive and allows for greater optimization. Copyright ========= This DEP is public domain. Specification ============= The C3 superclass linearization has been proposed in 1996 by Kim Barrett, Bob Cassels, Paul Haahr, David A. Moon, Keith Playford, and P. Tucker Withington in a `paper `_ (`html version `_). A superclass linearization (also known as a class precedence list) is used for resolving conflicts among multiply-inherited superclasses which provide differing definitions of the same method. Unfortunately the algorithm presented in the Dylan Reference Manual (`computing the class precedence list `_) is not consistent with the extended precedence graph, and may lead to counter-intuitive linearizations. To fix that, the C3 linearization was developed. Motivation ========== In order to allow for more optimizations, especially compression of dispatch tables, which requires monotonicity of method orderings, a consistent superclass linearization algorithm is needed. After the C3 linearization was proposed in 1996, it was subsequently adapted in Python 2.3 (`article `__) and Perl 6 (`article `__). Rationale ========= The C3 linearization has been around for a long time, does not break any existing code, and is commonly agreed upon as being the right thing to do (in mailing list discussions). Examples ======== The example from the paper is given here, consider the following Dylan classes: .. code-block:: dylan define class () end; define class () end; define class () end; define class (, ) end; define class (, ) end; define class (, ) end; The Dylan linearization is: .. code-block:: dylan , , , , , , The C3 linearization is: .. code-block:: dylan , , , , , , The difference in the ordering of ```` and ```` and having that match the ordering of ```` and ```` is clearly more intuitive and consistent. Backwards Compatibility ======================= In the first release a serious warning will be issued for superclass linearization which changed, in subsequent releases a warning should be issued (depending on a strict compatibility to DRM switch). Experiments show that there are some differences in existing code; we found so far three, two of them in duim-gadgets, one in win32-duim. According to Scott McKay, the author of DUIM, the first two look better when C3 is used (`mailing list post `_). The latter does not alter behaviour (`post `_). The class precedence list of differ, Dylan: #(, , , , , , , , , , , , , , , , , , ); C3: #(, , , , , , , , , , , , , , , , , , ) The class precedence list of differ, Dylan: #(, , , , , , , , , , , , , , , , , , ); C3: #(, , , , , , , , , , , , , , , , , , ) The class precedence list of differ, Dylan: #(, , , , , , , , , , , , , , , , , , , , , , , , , ); C3: #(, , , , , , , , , , , , , , , , , , , , , , , , , ) Reference Implementation ======================== The `pull request #168 `_ was finally merged into master.