translation validation via linear recursion schemes
DESCRIPTION
Translation Validation via Linear Recursion Schemes. Master Seminar Tobias Tebbi. Translation Validation. Goal Verified Compiler Method Implement Validator that checks if input and output of compiler pass are equivalent. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/1.jpg)
Translation Validation via
Linear Recursion Schemes
Master SeminarTobias Tebbi
![Page 2: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/2.jpg)
Translation Validation
• Goal Verified Compiler• Method Implement Validator that checks if
input and output of compiler pass are equivalent.
• Needs Decidable sufficient criterion for program equivalence
![Page 3: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/3.jpg)
CPSControl Flow Graph Continuation Passing Style
𝑥≔10
return 𝑦
𝑥>0
𝑥≤0
𝑃1
𝑃2
𝑃3
![Page 4: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/4.jpg)
𝑃2(10 , 𝑦 )
Unfolding the Procedures
if
10>0 if return (2∗ 𝑦 )
10−1>0 return (2∗2∗𝑦 )if
10−1−1>0 ⋮ return (2∗2∗2∗ 𝑦)
𝑃1(𝑥 , 𝑦 )
𝑃2(10−1 ,2∗ 𝑦)𝑃3(10−1,2∗ 𝑦 )
![Page 5: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/5.jpg)
Program Equivalence
• If trees equal, then programs equivalent.• This is decidable! [Sabelfeld2000]• Many optimizations do not change the tree.• It does not matter– which arguments/variables/registers are used.– when values are computed.
• But the branching structure does matter, e.g. which test is done first.
![Page 6: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/6.jpg)
𝑃 (𝑥 , 𝑦 ,𝑧 )≔ 𝑓 (𝑔 (𝑥 , 𝑦 ) ,𝑃 ′ (h (𝑧 )) ,𝑃 ′ (𝑃 ′ (𝑥 )))
Linear Recursion Scheme
• Restriction with polynomial equivalence check
uninterpreted functionse.g. +, <, if-then-else, return, …
interpreted procedures
linear: nesting forbidden
![Page 7: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/7.jpg)
Simplifications for this Talk• Just one uninterpreted function/operator • Simple terms• Terms• Only procedures of the form
• Thus– All procedures produce infinite trees– Only binary trees where all inner nodes are labelled with and
leaves are labelled with variables or constants– Every subtree is described by a term or
![Page 8: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/8.jpg)
⋮ ⋮
Equality of Infinite Trees• Binary infinite trees equal All subtrees at same position and
with infinite parent-subtrees are both infinite or equal
![Page 9: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/9.jpg)
Equality of Infinite Trees• Binary infinite trees equal All subtrees at same position
and with infinite parent-subtrees are both infinite or equal• To check equivalence of and , we generate all such pairs of
subtrees with the inductively defined relation :
– If with and , then and
• is consistent if for all , both and are procedure calls or .• iff is consistent.
𝑆0
⋮ ⋮
𝑇 0
⋮ ⋮⋮ ⋮⋮ ⋮
𝑃 (𝑠)
𝑆1[𝑠 /𝑥 ]𝑆2[𝑠 /𝑥 ]
𝑄 (𝑡)⋮ ⋮
𝑇 1[𝑡 /𝑥 ]𝑇 2[𝑡 /𝑥]
![Page 10: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/10.jpg)
Substitutions
• A substitution is a function from variables to simple terms.
• S is the term where every occurrence of a variable is replaced by .
• The instantiation pre-order on terms:
And on pairs of terms:
A
![Page 11: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/11.jpg)
Finite Equivalence Proofs• If there is a consistent superset of , then .• We want to construct a finite representation of such a set to serve as an
equivalence proof.• Consider a finite, consistent relation such that
– for some – If with and , then for , is a simple termor for some
Lemma:
• The constraint on is decidable. Thus we have a method to prove equivalence.
• If with and , then and
![Page 12: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/12.jpg)
Unification
• is unifier of and if • We write for Lemma: • Thus, is consistent iff is consistent iff– for all simple pairs , – all other pairs consist of procedure calls only
• This is a classical first-order unification problem• Thus we have most general unifiers (MGUs) :
For every other unifier , we have
• If with and , then and
![Page 13: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/13.jpg)
Universal Finite Equivalence Proofs
• Consider an MGU of and . Then iff where
• Then is a finite equivalence proof for all equivalent terms and .
• Thus equivalence of terms is semi-decidable.
• for some • If
with and , then for , is a simple termor for some
![Page 14: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/14.jpg)
Decidability of Equivalence
• Equivalence of terms is semi-decidable.• Non-equivalence is semi-decidable too: the
trees must differ at some finite level.• Thus equivalence is decidable.• In the next talks, I will present an efficient
procedure to decide equivalence by reducing the problem to a fragment of semi-unification.
![Page 15: Translation Validation via Linear Recursion Schemes](https://reader036.vdocuments.us/reader036/viewer/2022062501/56816194550346895dd138c1/html5/thumbnails/15.jpg)
Literature
Fokkink, W. Unification for infinite sets of equations between finite terms.
Information processing letters 62, 4 (1997), 183–188.
Sabelfeld, V. The tree equivalence of linear recursion schemes.
Theoretical Computer Science 238, 1–2 (2000), 1–29.