Saved in:
Bibliographic Details
Main Authors: Hivert, Florent, Thiéry, Nicolas M.
Format: Preprint
Published: 2024
Subjects:
Online Access:https://arxiv.org/abs/2401.12740
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866910306118139904
author Hivert, Florent
Thiéry, Nicolas M.
author_facet Hivert, Florent
Thiéry, Nicolas M.
contents C3 is an algorithm used by several widely used programming languages such as Python to support multiple inheritance in object oriented programming (OOP): for each class, C3 computes recursively a linear extension of the poset of all its super classes (the Method Resolution Order, MRO) from user-provided local information (an ordering of the direct super classes). This algorithm can fail if the local information is not consistent. For large hierarchies of classes, as encountered when modeling hierarchies of concepts from abstract algebra in the SageMath computational system, maintaining consistent local information by hand does not scale and leads to unpredictable C3 failures. This paper reports on the authors' work to analyze and circumvent this maintenance nightmare. First, we discovered through extensive computer exploration that there exists posets admitting no consistent local information; we exhibit the smallest one which has 10 elements. Then, we provide and analyze an algorithm that, given a poset and a linear extension, automatically builds local information for C3 in such a way that guarantees that it will never fail, at the price of a slight relaxation of the hypotheses. This algorithm has been used in production in SageMath since 2013.
format Preprint
id arxiv_https___arxiv_org_abs_2401_12740
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Controlling the C3 super class linearization algorithm
Hivert, Florent
Thiéry, Nicolas M.
Combinatorics
06A06, 68N15
C3 is an algorithm used by several widely used programming languages such as Python to support multiple inheritance in object oriented programming (OOP): for each class, C3 computes recursively a linear extension of the poset of all its super classes (the Method Resolution Order, MRO) from user-provided local information (an ordering of the direct super classes). This algorithm can fail if the local information is not consistent. For large hierarchies of classes, as encountered when modeling hierarchies of concepts from abstract algebra in the SageMath computational system, maintaining consistent local information by hand does not scale and leads to unpredictable C3 failures. This paper reports on the authors' work to analyze and circumvent this maintenance nightmare. First, we discovered through extensive computer exploration that there exists posets admitting no consistent local information; we exhibit the smallest one which has 10 elements. Then, we provide and analyze an algorithm that, given a poset and a linear extension, automatically builds local information for C3 in such a way that guarantees that it will never fail, at the price of a slight relaxation of the hypotheses. This algorithm has been used in production in SageMath since 2013.
title Controlling the C3 super class linearization algorithm
topic Combinatorics
06A06, 68N15
url https://arxiv.org/abs/2401.12740