
◦ ◦◦◦ TECHNISCHE UNIVERSITAT¨ MUNCHEN¨ ◦◦◦◦ ◦ ◦ ◦◦◦ ◦◦◦◦ ¨ ¨ ◦ ◦◦ FAKULTAT FUR INFORMATIK Linearization in Multiple Inheritance Seminar “Example Talk” Dr. Michael Petter Winter term 2016 Outline Basics of Linearization 1 Linearization vs. Ambiguous Dispatching 2 Resources for Establishing Order DFS Linearizations 1 DFS (w. or w/o. Duplicate Cancellation) 2 Reverse Rightmost DFS 3 Refined DFSs C3 Linearization 1 Basic algorithm 2 Practical example Discussion 1 Linearization vs. Explicit Qualification 2 Language examples Multiple inheritance class diagram A B int f(int) int f(int) int a int b C int c Ambiguities classA{ void f(int); }; classB{ void f(int); }; classC: publicA, public B {}; C* pc; pc->f(42); ! Which method is called? Solution I: Explicit qualification Solution II: Automagical resolution Idea: The Compiler introduces a pc->A::f(42); linear order on the nodes of the pc->B::f(42); inheritance graph Linearization Principle 1: Inheritance Relation Principle 2: Multiplicity Relation Defined by parent-child. Example: Defined by the succession of C(A; B) =) C −BA ^ C −BB multiple parents. Example: C(A; B) =) A ! B In General: 1 Inheritance is a uniform mechanism, and its searches (! total order) apply identically for all object fields or methods 2 In the literature, we also find the set of constraints to create a linearization as Method Resolution Order 3 Linearization is a best-effort approach at best L[A] = ABCW XPrinciple 1 inheritance is fixed L[A] = ABCW V ! Principle 2 multiplicity not fulfillable ! However B ! C =) W ! V ?? L[A] = ABW C ! Principle 1 inheritance is violated Python: classical python objects (≤ 2.1) use LPDFS! LPDFS with Duplicate Cancellation Python: new python objects (2.2) use LPDFS(DC)! LPDFS with Duplicate Cancellation MRO via DFS W Leftmost Preorder Depth-First Search B C A A(B; C) B(W ) C(W ) L[A] = ABCW V ! Principle 2 multiplicity not fulfillable ! However B ! C =) W ! V ?? L[A] = ABCW XPrinciple 1 inheritance is fixed Python: new python objects (2.2) use LPDFS(DC)! LPDFS with Duplicate Cancellation MRO via DFS W Leftmost Preorder Depth-First Search L[A] = ABW C B C ! Principle 1 inheritance is violated Python: classical python objects (≤ 2.1) use LPDFS! LPDFS with Duplicate Cancellation A A(B; C) B(W ) C(W ) L[A] = ABCW V ! Principle 2 multiplicity not fulfillable ! However B ! C =) W ! V ?? MRO via DFS W Leftmost Preorder Depth-First Search L[A] = ABW C B C ! Principle 1 inheritance is violated Python: classical python objects (≤ 2.1) use LPDFS! LPDFS with Duplicate Cancellation A A(B; C) B(W ) C(W ) L[A] = ABCW XPrinciple 1 inheritance is fixed V W Python: new python objects (2.2) use LPDFS(DC)! LPDFS with Duplicate Cancellation B C A A(B; C)B(V; W )C(W; V ) MRO via DFS W Leftmost Preorder Depth-First Search L[A] = ABW C B C ! Principle 1 inheritance is violated Python: classical python objects (≤ 2.1) use LPDFS! LPDFS with Duplicate Cancellation A A(B; C) B(W ) C(W ) L[A] = ABCW XPrinciple 1 inheritance is fixed V W Python: new python objects (2.2) use LPDFS(DC)! LPDFS with Duplicate Cancellation B C L[A] = ABCW V ! Principle 2 multiplicity not fulfillable A ! However B ! C =) W ! V ?? A(B; C)B(V; W )C(W; V ) L[A] = ABCDGEF ! But principle 2 multiplicity is violated! L[A] = ABCDEF G XRefine graph with conflict edge & rerun RPRDFS! L[A] = ABF DCEGHW XLinear extension of inheritance relation RPRDFS FG CLOS: uses Refined RPDFS [3] B D E Refined RPRDFS C A A(B; C) B(F; G) C(D; E) D(G) E(F ) MRO via Refined Postorder DFS W Reverse Postorder Rightmost DFS G D EF H B C A A(B; C) B(F; D) C(E; H) D(G) E(G) F (W ) G(W ) H(W ) L[A] = ABCDEF G XRefine graph with conflict edge & rerun RPRDFS! L[A] = ABCDGEF ! But principle 2 multiplicity is violated! FG CLOS: uses Refined RPDFS [3] B D E Refined RPRDFS C A A(B; C) B(F; G) C(D; E) D(G) E(F ) MRO via Refined Postorder DFS W Reverse Postorder Rightmost DFS G L[A] = ABF DCEGHW D EF H XLinear extension of inheritance relation B C A RPRDFS A(B; C) B(F; D) C(E; H) D(G) E(G) F (W ) G(W ) H(W ) FG B D E C A A(B; C) B(F; G) C(D; E) D(G) E(F ) L[A] = ABCDEF G XRefine graph with conflict edge & rerun RPRDFS! FG CLOS: uses Refined RPDFS [3] B D E Refined RPRDFS C A A(B; C) B(F; G) C(D; E) D(G) E(F ) MRO via Refined Postorder DFS W Reverse Postorder Rightmost DFS G L[A] = ABF DCEGHW D EF H XLinear extension of inheritance relation B C A RPRDFS A(B; C) B(F; D) C(E; H) D(G) E(G) F (W ) G(W ) H(W ) L[A] = ABCDGEF ! But principle 2 multiplicity is violated! FG B D E C A A(B; C) B(F; G) C(D; E) D(G) E(F ) FG CLOS: uses Refined RPDFS [3] B D E L[A] = ABCDEF G C A XRefine graph with conflict edge & rerun RPRDFS! A(B; C) B(F; G) C(D; E) D(G) E(F ) MRO via Refined Postorder DFS W Reverse Postorder Rightmost DFS G L[A] = ABF DCEGHW D EF H XLinear extension of inheritance relation B C A RPRDFS A(B; C) B(F; D) C(E; H) D(G) E(G) F (W ) G(W ) H(W ) L[A] = ABCDGEF ! But principle 2 multiplicity is violated! FG B D E Refined RPRDFS C A A(B; C) B(F; G) C(D; E) D(G) E(F ) FG B D E C A MRO via Refined Postorder DFS W Reverse Postorder Rightmost DFS G L[A] = ABF DCEGHW D EF H XLinear extension of inheritance relation B C A RPRDFS A(B; C) B(F; D) C(E; H) D(G) E(G) F (W ) G(W ) H(W ) L[A] = ABCDGEF ! But principle 2 multiplicity is violated! CLOS: uses Refined RPDFS [3] Refined RPRDFS L[A] = ABCDEF G XRefine graph with conflict edge & rerun RPRDFS! A(B; C) B(F; G) C(D; E) D(G) E(F ) Refined RPRDFS ! Monotonicity is not guaranteed! MRO via Refined Postorder DFS Extension Principle: Monotonicity If C1 ! C2 in C’s linearization, then C1 ! C2 FG for every linearization of C’s children. A(B; C) B(F; G) C(D; E) D(GB) E(F ) D E C A MRO via Refined Postorder DFS Refined RPRDFS ! Monotonicity is not guaranteed! Extension Principle: Monotonicity If C1 ! C2 in C’s linearization, then C1 ! C2 FG for every linearization of C’s children. A(B; C) B(F; G) C(D; E) D(GB) E(F ) D E C A MRO via Refined Postorder DFS Refined RPRDFS ! Monotonicity is not guaranteed! Extension Principle: Monotonicity If C1 ! C2 in C’s linearization, then C1 ! C2 FG for every linearization of C’s children. A(B; C) B(F; G) C(D; E) D(GB) E(F ) D E L[A] = ABCDEFG =) F ! G C L[C] = DGEF =) G ! F A MRO via C3 Linearization A linearization L is an attribute L[C] of a class C. Classes B1;:::;Bn are superclasses to child class C, defined in the local precedence order C(B1 :::Bn). Then G L[C] = C · (L[B1];:::;L[Bn];B1 · ::: · Bn) j C(B1;:::;Bn) L[Object] = Object with ( F G c · ( i(Li n c)) if 9min k8j c = head(Lk) 2= tail(Lj) (Li) = ! i fail else E · F D · G C3 detects and reports a violation of monotonicity with the addition of A(B,C) to the class set. C3 linearization [1]: is used in OpenDylan, Python, and Perl 6 MRO via C3 Linearization L[G] G L[F ] F L[E] L[D] A(B; C) B(F; G) C(D; E) L[B] D(G) E(F ) L[C] L[A] FG B D E C A C3 detects and reports a violation of monotonicity with the addition of A(B,C) to the class set. C3 linearization [1]: is used in OpenDylan, Python, and Perl 6 MRO via C3 Linearization L[G] G L[F ] F L[E] E · F L[D] D · G A(B; C) B(F; G) C(D; E) L[B] D(G) E(F ) L[C] L[A] FG B D E C A C3 detects and reports a violation of monotonicity with the addition of A(B,C) to the class set. C3 linearization [1]: is used in OpenDylan, Python, and Perl 6 MRO via C3 Linearization L[G] G L[F ] F L[E] E · F L[D] D · G A(B; C) B(F; G) C(D; E) L[B] B · (L[F ] t L[G] t (F · G)) D(G) E(F ) L[C] L[A] FG B D E C A C3 detects and reports a violation of monotonicity with the addition of A(B,C) to the class set. C3 linearization [1]: is used in OpenDylan, Python, and Perl 6 MRO via C3 Linearization L[G] G L[F ] F L[E] E · F L[D] D · G A(B; C) B(F; G) C(D; E) L[B] B · (F t G t (F · G)) D(G) E(F ) L[C] L[A] FG B D E C A C3 detects and reports a violation of monotonicity with the addition of A(B,C) to the class set.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages33 Page
-
File Size-