a rewriting logic approach to type inference
play

A Rewriting Logic Approach to Type Inference , erb , Chucky - PowerPoint PPT Presentation

Introduction Exp and W Proof Techniques Conclusion A Rewriting Logic Approach to Type Inference , erb , Chucky Ellison, Traian Florin S anut a, and Grigore Ros , u University of Illinois at Urbana-Champaign June 14, 2008 Chucky


  1. Introduction Exp and W Proof Techniques Conclusion A Rewriting Logic Approach to Type Inference , erb˘ , ˘ Chucky Ellison, Traian Florin S anut a, and Grigore Ros , u University of Illinois at Urbana-Champaign June 14, 2008 Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

  2. Introduction Exp and W Overview Proof Techniques Background Conclusion Outline Introduction Overview Description of K Background Exp and W Exp W Inferencer Efficiency Proof Techniques Motivation Morphism α Abstract Type Inferencer Type Preservation Proof Overview Conclusion Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

  3. Introduction Exp and W Overview Proof Techniques Background Conclusion What We Have Done ◮ K, a rewriting-logic inspired framework for language development ◮ Shown how the K can also encompass type systems ◮ Works on both imperative and functional languages ◮ Can define as both type checkers and inferencers ◮ Executable! ◮ Formally analyzable – proofs of soundness for type systems Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

  4. Introduction Exp and W Overview Proof Techniques Background Conclusion What We Are Going to Talk About ◮ Short overview of K framework ◮ How we use K to define Milner’s Type Inferencer W ◮ Proof techniques developed to analyze the inferencer ◮ Morphism from language configurations to type configurations ◮ Abstract type system Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

  5. Introduction Exp and W Overview Proof Techniques Background Conclusion Introducing K: Rules ◮ Structural rules (reversible transitions, heating/cooling rules): LHS = RHS ✱ ♦r LHS ⇋ RHS ; ◮ Semantic rules (configuration-modifying transitions): LHS − → RHS . ◮ Contextual rewriting style: Use C [ L 1 ] instead of C [ L 1 , . . . , L N ] − → C [ R 1 , . . . , R N ] , . . . , L N R 1 R N ◮ List and set comprehension ◮ Match middle – � | X | � , prefix – � X | � , suffix – � | X � ◮ Works well with contextual rewriting. E.g., stating idempotency: � | XX � , where · means the identity for sets. | · Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

  6. Introduction Exp Exp and W W Inferencer Proof Techniques Efficiency Conclusion Outline Introduction Overview Description of K Background Exp and W Exp W Inferencer Efficiency Proof Techniques Motivation Morphism α Abstract Type Inferencer Type Preservation Proof Overview Conclusion Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

  7. Introduction Exp Exp and W W Inferencer Proof Techniques Efficiency Conclusion Exp Syntax ::= Var st❛♥❞❛r❞ ✐❞❡♥t✐✜❡rs ::= Var | . . . ❛❞❞ ❜❛s✐❝ ✈❛❧✉❡s ✭❇♦♦❧s✱ ✐♥ts✱ ❡t❝✳✮ Exp | λ Var . Exp | [ strict ] Exp Exp | µ Var . Exp | [ strict ( 1 )] if Exp then Exp else Exp | let Var = Exp in Exp [ strict ( 2 )] | letrec Var Var = Exp in Exp [ letrec f x = e in e ′ ⇌ let = f µ f . ( λ x . e ) in e ′ ] Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

  8. Introduction Exp Exp and W W Inferencer Proof Techniques Efficiency Conclusion Desugaring Strictness Rules ◮ Strictness attributes on language constructs . . . ::= [ strict ] Exp Exp Exp | [ strict ( 1 )] if Exp then Exp else Exp | let Var = Exp in Exp [ strict ( 2 )] ◮ . . . are desugared into “evaluation” operations . . . k 1 k 2 = k 1 � � k 2 k 1 k 2 = k 2 � k 1 � if k then k 1 else k 2 = k � if � then k 1 else k 2 let Var = k in k 1 = k � let Var = � in k 1 ◮ . . . by using “ � ”-based constructs to freeze computations. Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

  9. Introduction Exp Exp and W W Inferencer Proof Techniques Efficiency Conclusion Exp Configuration and Semantics ::= λ Var . Exp | ... ✭❇♦♦❧s✱ ✐♥ts✱ ❡t❝✳✮ Val ::= Result Val ::= KProper µ Var . Exp ::= � K � k ConfigItem ::= Val | � Exp � | Set [ ConfigItem ] Config � ( λ x . e ) v | � k � | � k µ x . e e [ x ← v ] e [ x ← µ x . e ] if true then e 1 else e 2 → e 1 if false then e 1 else e 2 → e 2 Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

  10. Introduction Exp Exp and W W Inferencer Proof Techniques Efficiency Conclusion Let Polymorphism ◮ The following would not work without let polymorphism: let f = λ x . x in if f true then f else ( λ x . 1 ) ◮ Why? Type of f is constrained to both bool → bool and t → int ◮ Solution: ◮ when typing f , make it parametric in unbounded type variables ◮ instantiate them with fresh ones whenever f is later used Thus obtained type of above expression is int → int ◮ Notice: expression evaluates to f , which is polymorphic, thus more general than inferred type Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

  11. Introduction Exp Exp and W W Inferencer Proof Techniques Efficiency Conclusion W Inferencer Syntax ::= Var st❛♥❞❛r❞ ✐❞❡♥t✐✜❡rs ::= Var | . . . ❛❞❞ ❜❛s✐❝ ✈❛❧✉❡s ✭❇♦♦❧s✱ ✐♥ts✱ ❡t❝✳✮ Exp | λ Var . Exp | [ strict ] Exp Exp | µ Var . Exp | [ strict ] if Exp then Exp else Exp | let Var = Exp in Exp [ strict ( 2 )] | letrec Var Var = Exp in Exp [ letrec f x = e in e ′ ⇌ let f = µ f . ( λ x . e ) in e ′ ] Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

  12. Introduction Exp Exp and W W Inferencer Proof Techniques Efficiency Conclusion W Inferencer Configuration Syntax ::= · · · | Type → K [ strict ( 2 )] K ::= Result Type ::= Map [ Name , Type ] TEnv ::= . . . | let ( Type ) Type ConfigItem ::= � K � k | � TEnv � tenv | � Eqns � eqns | � TypeVar � nextType ::= Type | � K � | � Set [ ConfigItem ] � Config ::= . . . | int | bool | Type �→ Type | TypeVar Type ::= Type ≡ Type Eqn ::= Set [ Eqn ] Eqns Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

  13. Introduction Exp Exp and W W Inferencer Proof Techniques Efficiency Conclusion W by Example ◮ � let f = λ x . x in if f true then f else λ x . 1 � k � · � Γ � · � E ◮ � if f true then f else λ x . 1 � k � f = let ( t → t ) � Γ � · � E ◮ � if t 1 then f else λ x . 1 � k � f = let ( t → t ) � Γ � t 1 = bool � E ◮ � if t 1 then t 2 → t 2 else λ x . 1 � k � f = let ( t → t ) � Γ � t 1 = bool � E ◮ � if t 1 then t 2 → t 2 else t 3 → int � k � f = let ( t → t ) � Γ � t 1 = bool � E ◮ � t 2 → t 2 � k � f = let ( t → t ) � Γ � t 1 = bool , t 2 → t 2 = t 3 → int � E ◮ � t 2 → t 2 � k � f = let ( t → t ) � Γ � t 1 = bool , t 2 = t 3 , t 2 = int � E ◮ int → int Let us exemplify W by typing expression above Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

  14. Introduction Exp Exp and W W Inferencer Proof Techniques Efficiency Conclusion W by Example ◮ � let f = λ x . x in if f true then f else λ x . 1 � k � · � Γ � · � E ◮ � if f true then f else λ x . 1 � k � f = let ( t → t ) � Γ � · � E ◮ � if t 1 then f else λ x . 1 � k � f = let ( t → t ) � Γ � t 1 = bool � E ◮ � if t 1 then t 2 → t 2 else λ x . 1 � k � f = let ( t → t ) � Γ � t 1 = bool � E ◮ � if t 1 then t 2 → t 2 else t 3 → int � k � f = let ( t → t ) � Γ � t 1 = bool � E ◮ � t 2 → t 2 � k � f = let ( t → t ) � Γ � t 1 = bool , t 2 → t 2 = t 3 → int � E ◮ � t 2 → t 2 � k � f = let ( t → t ) � Γ � t 1 = bool , t 2 = t 3 , t 2 = int � E ◮ int → int Type λ x . x : bind x to a new type variable t and obtain t → t Bind f to special type let ( t → t ) and begin typing the body Chucky Ellison, Traian Florin S , erb˘ anut , ˘ a, and Grigore Ros , u A Rewriting Logic Approach to Type Inference

Recommend


More recommend