• Keine Ergebnisse gefunden

Unterschiede zwischen τ und ˆ τ

N/A
N/A
Protected

Academic year: 2022

Aktie "Unterschiede zwischen τ und ˆ τ"

Copied!
43
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Typinferenzalgorithmus

Typinferenzalgorithmus

mit Kontrollflussanalyse

Robert Kufner

26.06.2009

(2)

Typinferenzalgorithmus

Inhaltsverzeichnis

1 Der WU L Algorithmus Idee

Beispiel

2 Der UU LAlgorithmus Idee

Beispiel

3 CFA Algorithmus Kontrollflussanalyse Unification

Beispiel

Constraints

(3)

Typinferenzalgorithmus

Unterschiede zwischen τ und ˆ τ

Dekl. Typsystem Algorithmus ULτ Typen:

Keine Variablen od. Annotationen

erweiterte Typen: Variablen aber keine Annotationen CFA ˆτ Annotierte Typen:

keine Variablen aber aber Annotata- tionen

Einfache Typen: Variablen & Annota- tionsvariablen

(4)

Typinferenzalgorithmus

Unterschiede zwischen τ und ˆ τ

Dekl. Typsystem Algorithmus ULτ Typen:

Keine Variablen od. Annotationen

erweiterte Typen:

Variablen aber keine Annotationen CFA ˆτ Annotierte Typen:

keine Variablen aber aber Annotata- tionen

Einfache Typen:

Variablen & Annota- tionsvariablen

(5)

Typinferenzalgorithmus DerWU LAlgorithmus

Idee

Algorithmus erh¨alt Typumgebung Γ und Ausdruck e

Falls erfolgreich: Liefert einen erweiterten Typτ und Substitution θ

(6)

Typinferenzalgorithmus DerWU LAlgorithmus

Idee

Algorithmus erh¨alt Typumgebung Γ und Ausdruck e Falls erfolgreich: Liefert einen erweiterten Typτ und Substitution θ

(7)

Typinferenzalgorithmus DerWU LAlgorithmus

Idee

Auszug aus den Spezifikationen

WU L(Γ, c) = (τc, id) WU L(Γ, x) = (Γ(x), id) WU L(Γ, f nπx⇒e) = let αx be fresh

(τ, θ) =WU L(Γ[x7→αx], e) in ((θαx)→τ, θ) WU L(Γ, f unπf x⇒e0) = let αx, α0 be fresh

0, θ0) =WU L(Γ[f 7→αx →α0][x7→αx], e0) θ1=UU L0, θ0α0)

in (θ10αx)→θ1τ0, θ1◦θ0)

(8)

Typinferenzalgorithmus DerWU LAlgorithmus

Idee

Auszug aus den Spezifikationen

WU L(Γ, e1e2) = let (τ1, θ1) =WU L(Γ, e1) (τ2, θ2) =WU L1Γ, e2) α be fresh

θ3=UU L2τ1, τ2→α) in (θ3α, θ3◦θ2◦θ1)

(9)

Typinferenzalgorithmus DerWU LAlgorithmus

Beispiel

e = (f n X x ⇒ x) ( f n Y y ⇒ y)

Welche Teile vonWU L werden aufgerufen?

1 WU L([ ], (f nX x⇒x) (f nY y⇒ y))

2 WU L([ ], f nX x⇒ x)

3 WU L([ ], f nY y⇒ y)

4 UU L(´a→´a, (´b →´b)→´c)

(10)

Typinferenzalgorithmus DerWU LAlgorithmus

Beispiel

e = (f n X x ⇒ x) ( f n Y y ⇒ y)

Welche Teile vonWU L werden aufgerufen?

1 WU L([ ], (f nX x⇒x) (f nY y⇒ y))

2 WU L([ ], f nX x⇒ x)

3 WU L([ ], f nY y⇒ y)

4 UU L(´a→´a, (´b →´b)→´c)

(11)

Typinferenzalgorithmus DerWU LAlgorithmus

Beispiel

e = (f n X x ⇒ x) ( f n Y y ⇒ y)

Welche Teile vonWU L werden aufgerufen?

1 WU L([ ], (f nX x⇒x) (f nY y⇒ y))

2 WU L([ ], f nX x⇒ x)

3 WU L([ ], f nY y⇒ y)

4 UU L(´a→´a, (´b →´b)→´c)

(12)

Typinferenzalgorithmus DerWU LAlgorithmus

Beispiel

e = (f n X x ⇒ x) ( f n Y y ⇒ y)

Welche Teile vonWU L werden aufgerufen?

1 WU L([ ], (f nX x⇒x) (f nY y⇒ y))

2 WU L([ ], f nX x⇒ x)

3 WU L([ ], f nY y⇒ y)

4 UU L(´a→´a, (´b →´b)→´c)

(13)

Typinferenzalgorithmus DerWU LAlgorithmus

Beispiel

e = (f n X x ⇒ x) ( f n Y y ⇒ y)

Welche Teile vonWU L werden aufgerufen?

1 WU L([ ], (f nX x⇒x) (f nY y⇒ y))

2 WU L([ ], f nX x⇒ x)

3 WU L([ ], f nY y⇒ y)

4 UU L(´a→´a, (´b →´b) →´c)

(14)

Typinferenzalgorithmus DerUU LAlgorithmus

Idee

Algorithmus erh¨alt zwei erweiterte Typen τ1 und τ2

Gibt Art der Substitution zur¨uck falls erfolgreich

Bricht ab bei top-level Konstruktoren (Hier: int, bool, →) oder wenn versucht wird eine Typvariable mit einem Funktionstyp zu vereinigen der die Typvariable enth¨alt

(15)

Typinferenzalgorithmus DerUU LAlgorithmus

Idee

Algorithmus erh¨alt zwei erweiterte Typen τ1 und τ2

Gibt Art der Substitution zur¨uck falls erfolgreich

Bricht ab bei top-level Konstruktoren (Hier: int, bool, →) oder wenn versucht wird eine Typvariable mit einem Funktionstyp zu vereinigen der die Typvariable enth¨alt

(16)

Typinferenzalgorithmus DerUU LAlgorithmus

Idee

Algorithmus erh¨alt zwei erweiterte Typen τ1 und τ2

Gibt Art der Substitution zur¨uck falls erfolgreich

Bricht ab bei top-level Konstruktoren (Hier: int, bool, →) oder wenn versucht wird eine Typvariable mit einem Funktionstyp zu vereinigen der die Typvariable enth¨alt

(17)

Typinferenzalgorithmus DerUU LAlgorithmus

Idee

Auszug aus den Spezifikationen

UU L1 →τ2, τ10 →τ20) = let θ1 =UU L1, τ10) θ2 =UU L1τ2, θ1τ20) inθ2◦θ1

UU L(τ, α) =

( [α7→τ] fallsαnicht inτ auftaucht oderα=τ ist

fail sonst UU L(α, τ) = s.o.

UU L1, τ2) = fail

(18)

Typinferenzalgorithmus DerUU LAlgorithmus

Beispiel

Beispiel von zuvor: e = (f nX x⇒ x) (f nY y⇒ y)

=UU L(´a→´a, ( ´b→´b) →´c)

Welche Teile vonUU L werden aufgerufen und was wird zur¨uckgegeben?

1 UU L(´a→´a, ( ´b →´b) →´c)

2 UU L(´a, ´b→´b) = [´a7→´b→´b]

3 UU L(´b→´b,´c) = [´c7→´b→´b]

Endergebnis: [´a7→ ´b→ ´b][´c7→ ´b→ ´b]

(19)

Typinferenzalgorithmus DerUU LAlgorithmus

Beispiel

Beispiel von zuvor: e = (f nX x⇒ x) (f nY y⇒ y)

=UU L(´a→´a, ( ´b→´b) →´c)

Welche Teile vonUU L werden aufgerufen und was wird zur¨uckgegeben?

1 UU L(´a→´a, ( ´b→´b) →´c)

2 UU L(´a, ´b→´b) = [´a7→´b→´b]

3 UU L(´b→´b,´c) = [´c7→´b→´b]

Endergebnis: [´a7→ ´b→ ´b][´c7→ ´b→ ´b]

(20)

Typinferenzalgorithmus DerUU LAlgorithmus

Beispiel

Beispiel von zuvor: e = (f nX x⇒ x) (f nY y⇒ y)

=UU L(´a→´a, ( ´b→´b) →´c)

Welche Teile vonUU L werden aufgerufen und was wird zur¨uckgegeben?

1 UU L(´a→´a, ( ´b→´b) →´c)

2 UU L(´a, ´b→´b) = [´a7→´b→´b]

3 UU L(´b→´b,´c) = [´c7→´b→´b]

Endergebnis: [´a7→ ´b→ ´b][´c7→ ´b→ ´b]

(21)

Typinferenzalgorithmus DerUU LAlgorithmus

Beispiel

Beispiel von zuvor: e = (f nX x⇒ x) (f nY y⇒ y)

=UU L(´a→´a, ( ´b→´b) →´c)

Welche Teile vonUU L werden aufgerufen und was wird zur¨uckgegeben?

1 UU L(´a→´a, ( ´b→´b) →´c)

2 UU L(´a, ´b→´b) = [´a7→´b→´b]

3 UU L(´b→´b,´c) = [´c7→´b→´b]

Endergebnis: [´a7→ ´b→ ´b][´c7→ ´b→ ´b]

(22)

Typinferenzalgorithmus DerUU LAlgorithmus

Beispiel

Beispiel von zuvor: e = (f nX x⇒ x) (f nY y⇒ y)

=UU L(´a→´a, ( ´b→´b) →´c)

Welche Teile vonUU L werden aufgerufen und was wird zur¨uckgegeben?

1 UU L(´a→´a, ( ´b→´b) →´c)

2 UU L(´a, ´b→´b) = [´a7→´b→´b]

3 UU L(´b→´b,´c) = [´c7→´b→´b]

(23)

Typinferenzalgorithmus CFA Algorithmus

Kontrollflussanalyse

Was ist Kontrollflussanalyse ?

Kontrollflussanalyse stellt folgende Kontrollflussanomalien im Code fest:

nicht erreichbarer Quelltext duplizierter Quelltext GOTO-Anweisungen

(24)

Typinferenzalgorithmus CFA Algorithmus

Kontrollflussanalyse

Was ist Kontrollflussanalyse ?

Kontrollflussanalyse stellt folgende Kontrollflussanomalien im Code fest:

nicht erreichbarer Quelltext duplizierter Quelltext GOTO-Anweisungen

(25)

Typinferenzalgorithmus CFA Algorithmus

Kontrollflussanalyse

Was ist Kontrollflussanalyse ?

Kontrollflussanalyse stellt folgende Kontrollflussanomalien im Code fest:

nicht erreichbarer Quelltext

duplizierter Quelltext GOTO-Anweisungen

(26)

Typinferenzalgorithmus CFA Algorithmus

Kontrollflussanalyse

Was ist Kontrollflussanalyse ?

Kontrollflussanalyse stellt folgende Kontrollflussanomalien im Code fest:

nicht erreichbarer Quelltext duplizierter Quelltext

GOTO-Anweisungen

(27)

Typinferenzalgorithmus CFA Algorithmus

Kontrollflussanalyse

Was ist Kontrollflussanalyse ?

Kontrollflussanalyse stellt folgende Kontrollflussanomalien im Code fest:

nicht erreichbarer Quelltext duplizierter Quelltext GOTO-Anweisungen

(28)

Typinferenzalgorithmus CFA Algorithmus

Kontrollflussanalyse

Wie implementieren wir eine

Kontrollflussanalyse in unseren Algorithmus ?

Bisher :

WU L(f nXx⇒x)(f nYy ⇒y) = [´a7→´b→´b][´c7→´b→´b]

Jetzt :

WU L(f nXx⇒x)(f nYy ⇒y) = [´a7→´b−→´2 ´b][´c7→´b−→´2 ´b]

(29)

Typinferenzalgorithmus CFA Algorithmus

Kontrollflussanalyse

Wie implementieren wir eine

Kontrollflussanalyse in unseren Algorithmus ?

Bisher :

WU L(f nXx⇒x)(f nYy ⇒y) = [´a7→´b→´b][´c7→´b→´b]

Jetzt :

WU L(f nXx⇒x)(f nYy ⇒y) = [´a7→´b−→´2 ´b][´c7→´b−→´2 ´b]

(30)

Typinferenzalgorithmus CFA Algorithmus

Kontrollflussanalyse

Wie implementieren wir eine

Kontrollflussanalyse in unseren Algorithmus ?

Bisher :

WU L(f nXx⇒x)(f nYy⇒y) = [´a7→´b→´b][´c7→´b→´b]

Jetzt :

WU L(f nXx⇒x)(f nYy ⇒y) = [´a7→´b−→´2 ´b][´c7→´b−→´2 ´b]

(31)

Typinferenzalgorithmus CFA Algorithmus

Kontrollflussanalyse

Wie implementieren wir eine

Kontrollflussanalyse in unseren Algorithmus ?

Bisher :

WU L(f nXx⇒x)(f nYy⇒y) = [´a7→´b→´b][´c7→´b→´b]

Jetzt :

WU L(f nXx⇒x)(f nYy ⇒y) = [´a7→´b−→´2 ´b][´c7→´b−→´2 ´b]

(32)

Typinferenzalgorithmus CFA Algorithmus

Kontrollflussanalyse

Wie implementieren wir eine

Kontrollflussanalyse in unseren Algorithmus ?

Bisher :

WU L(f nXx⇒x)(f nYy⇒y) = [´a7→´b→´b][´c7→´b→´b]

Jetzt :

WU L(f nXx⇒x)(f nYy ⇒y) = [´a7→´b−→´2 ´b][´c7→´b−→´2 ´b]

(33)

Typinferenzalgorithmus CFA Algorithmus

Unification

Beispiel: U

CF A

(´ a −

´1

→ ´ a, (´ b −

´2

→ ´ b) −

´3

→´ c)

Aufruf Ergebnis

UCF A(´a−→´´1 a,(´b−→´2 ´b)−→´´3 c) [´37→´1] UCF A(´a,´b−→´2 ´b) [´a,´b−→´2 ´b] UCF A(´b−→´2 ´b,´c) [´c,´b−→´2 ´b]

Endergebnis: [´3 7→ ´1][´ a, ´ b −

´2

→ ´ b][´ c, ´ b −

´2

→ ´ b]

(34)

Typinferenzalgorithmus CFA Algorithmus

Unification

Beispiel: U

CF A

(´ a −

´1

→ ´ a, (´ b −

´2

→ ´ b) −

´3

→´ c)

Aufruf Ergebnis

UCF A(´a−→´´1 a,(´b−→´2 ´b)−→´´3 c) [´37→´1]

UCF A(´a,´b−→´2 ´b) [´a,´b−→´2 ´b]

UCF A(´b−→´2 ´b,´c) [´c,´b−→´2 ´b]

Endergebnis: [´3 7→ ´1][´ a, ´ b −

´2

→ ´ b][´ c, ´ b −

´2

→ ´ b]

(35)

Typinferenzalgorithmus CFA Algorithmus

Unification

Beispiel: U

CF A

(´ a −

´1

→ ´ a, (´ b −

´2

→ ´ b) −

´3

→´ c)

Aufruf Ergebnis

UCF A(´a−→´´1 a,(´b−→´2 ´b)−→´´3 c) [´37→´1]

UCF A(´a,´b−→´2 ´b) [´a,´b−→´2 ´b]

UCF A(´b−→´2 ´b,´c) [´c,´b−→´2 ´b]

Endergebnis: [´3 7→ ´1][´ a, ´ b −

´2

→ ´ b][´ c, ´ b −

´2

→ ´ b]

(36)

Typinferenzalgorithmus CFA Algorithmus

Constraints

Einf¨ uhrung der Constraints - aber warum ?

Problem:

einfache Typen :: = int|bool|τˆ1

−→β τˆ2 |α wobei :β::= ´1 |´2|´3|... annotierte Typen :: = int |bool|τˆ1

−→ϕ τˆ2

wobei :ϕ::={π} | ϕ1∪ϕ2 | ∅ | β

Deswegen: Einf¨uhrung von Constraints der Artβ ⊇ϕ

(37)

Typinferenzalgorithmus CFA Algorithmus

Constraints

Einf¨ uhrung der Constraints - aber warum ?

Problem:

einfache Typen :: = int|bool|τˆ1

−→β τˆ2 |α wobei :β::= ´1 |´2 |´3|...

annotierte Typen :: = int |bool|τˆ1

−→ϕ τˆ2

wobei :ϕ::={π} | ϕ1∪ϕ2 | ∅ | β

Deswegen: Einf¨uhrung von Constraints der Artβ ⊇ϕ

(38)

Typinferenzalgorithmus CFA Algorithmus

Constraints

Einf¨ uhrung der Constraints - aber warum ?

Problem:

einfache Typen :: = int|bool|τˆ1

−→β τˆ2 |α wobei :β::= ´1 |´2 |´3|...

annotierte Typen :: = int |bool|τˆ1

−→ϕ τˆ2

wobei :ϕ::={π} | ϕ1∪ϕ2 | ∅ | β

(39)

Typinferenzalgorithmus CFA Algorithmus

Der Algorithmus

Form: WCF A(ˆΓ, e) = (ˆτ , θ, C) Auszug aus den Spezifikationen

WCF A(ˆΓ, c) = (τc, id,∅) WCF A(ˆΓ, x) = (ˆΓ(x), id,∅) WCF A(ˆΓ, f nπx⇒e0) = let αx be fresh

( ˆτ0, θ0, C0) =WCF A(ˆΓ[x7→αx], e0) β0 be fresh

in ((θ0αx)−→β0 τ0, θ0, C0∪ {β0 ⊇ {π}})

(40)

Typinferenzalgorithmus CFA Algorithmus

Der Algorithmus

Auszug aus den Spezifikationen

WCF A(ˆΓ, f unπf x⇒e0) = letαx, α0, β0 be fresh ( ˆτ0, θ0, C0) =WCF A(ˆΓ[f 7→αx

β0

−→α0][x7→αx], e0) θ1=UCF A( ˆτ0, θ0α0)

in (θ10αx)−−−−−→θ10β0) θ1τˆ0, θ1◦θ0), (θ1C0)∪ {θ10β0)⊇ {π}})

WCF A(ˆΓ, e1e2) = let ( ˆτ1, θ1, C1) =WCF A(ˆΓ, e1) ( ˆτ2, θ2, C2) =WCF A1Γ, eˆ 2)

α, β be fresh

(41)

Typinferenzalgorithmus CFA Algorithmus

Der Algorithmus

W

CF A

([ ], (f n

X

x ⇒ x) ( f n

Y

y ⇒ y))

Aufruf Effekt

WCF A([ ], (f nX x⇒ x)) (´a−→´a,´1 id,{´1⊇ {X}}) WCF A([ ], (f nY y⇒ y)) (´b−→´b,´2 id,{´2⊇ {Y}})

UCF A(´a−→´´1 a,(´b−→´2 ´b)−→´´3 c) [´37→´1][´a7→´b−→´2 ´b][´c7→´b−→´2 ´b]

Endergebnisse = Typ : ´b−→´2 ´b

Substitution : [´37→´1][´a7→´b−→´2 ´b][´c7→´b−→´2 ´b] Set :{´1⊇ {X},´2⊇ {Y}}

(42)

Typinferenzalgorithmus CFA Algorithmus

Der Algorithmus

W

CF A

([ ], (f n

X

x ⇒ x) ( f n

Y

y ⇒ y))

Aufruf Effekt

WCF A([ ], (f nX x⇒ x)) (´a−→´a,´1 id,{´1⊇ {X}}) WCF A([ ], (f nY y⇒y)) (´b−→´b,´2 id,{´2⊇ {Y}})

UCF A(´a−→´´1 a,(´b−→´2 ´b)−→´´3 c) [´37→´1][´a7→´b−→´2 ´b][´c7→´b−→´2 ´b]

Endergebnisse = Typ : ´b−→´2 ´b

Substitution : [´37→´1][´a7→´b−→´2 ´b][´c7→´b−→´2 ´b] Set :{´1⊇ {X},´2⊇ {Y}}

(43)

Typinferenzalgorithmus CFA Algorithmus

Der Algorithmus

W

CF A

([ ], (f n

X

x ⇒ x) ( f n

Y

y ⇒ y))

Aufruf Effekt

WCF A([ ], (f nX x⇒ x)) (´a−→´a,´1 id,{´1⊇ {X}}) WCF A([ ], (f nY y⇒y)) (´b−→´b,´2 id,{´2⊇ {Y}})

UCF A(´a−→´´1 a,(´b−→´2 ´b)−→´´3 c) [´37→´1][´a7→´b−→´2 ´b][´c7→´b−→´2 ´b]

Endergebnisse = Typ : ´b−→´2 ´b

Substitution : [´37→´1][´a7→´b−→´2 ´b][´c7→´b−→´2 ´b]

Set :{´1⊇ {X},´2⊇ {Y}}

Referenzen

ÄHNLICHE DOKUMENTE

should be solved at home and delivered at Wednesday, the 12th December, before the beginning of

Zusammen mit (17) zeigen sie, daß in einer Booleschen Algebra jede der beiden zweistelligen Verkn¨ upfungen zusammen mit der Komplementbildung die andere zweistellige Verkn¨ upfung

Diese Denition kann leiht auf mehrdimensionale Inte- grale ausgedehnt werden und wird bei numerishen Rehnungen gebrauht.. Die meisten Algorithmen beruhen darauf, dass jede glatte

We have measured the mass of the τ lepton from the pseudomass distributions of the hadronic τ decays recorded by the OPAL detector at LEP and obtained a result of. m τ = 1775.1

Finally, the achievable signal significances and exclusion limits for the search for light charged Higgs bosons in the m h -max scenario of the Minimal Supersymmetric Extension of

In order to suppress this background, the search is performed in events where the Higgs boson is produced together with two highly energetic jets emitted in the proton beam

First, the measurement of the inclusive Z → τ τ cross section can confirm the measurements of Z boson production using electron and muon pair decays, providing information of the

Da jedes der beiden Polynome bereits ein maximales Ideal erzeugt, sind die oben angegebenen die einzigen Primideale von R..