Transcript
Page 1: e Implicit Calculus resolution - Seoul National …rosaec.snu.ac.kr/meet/file/20150128p_f.pdfsyntactic sugar implicit e : in e 1: def=(|e 1:¯ ) |) with e : formalized, but restrictive

1.����������� ������������������  목표

안전성을����������� ������������������  체계적으로����������� ������������������  조절하여����������� ������������������  정확하게����������� ������������������  분석하기허기홍,����������� ������������������  오학주,����������� ������������������  이광근����������� ������������������  

서울대학교

let OrdList = (| · · · : 8A.OrdhAi ) OrdhListhAii|) inlet OrdInt = (| · · · : OrdhInti|) inimplicit {OrdInt ,OrdList} in

sorthListhIntii ?(OrdhListhIntii) [[2, 5], [1, 3]]

http://rosaec.snu.ac.kr

ProgrammingResearch Laboratory

http://ropas.snu.ac.kr

The Implicit Calculus

1Seoul National University 2Universiteit GentBruno C. d. S. Oliveira1 Tom Schrijvers2 Wontae Choi1 Wonchan Lee1 Kwangkeun Yi1

A New Foundation for Generic Programming

2. The Implicit Calculus λ⇒• Calculus of the essence of GP: rules, scoping, and type-directed resolution

In the paper• Type system• Elaboration semantics to System F• Higher-order rules and partial resolution• Source language and its translation to λ⇒

1. Generic Programming

• Decoupling algorithms from types

sort [3,1,2] // [1,2,3]sort [‘c’,’a’,’b’] // [‘a’,’b’,’c’]sort [[2,5],[1,3]] // [[1,3],[2,5]]

• Decoupling by parametrization

• Implicit instantiation

sort<A>: Ord<A> ⇒ List<A> → List<A>

sort< ? > ? [3,1,2]

sort<Int> ? [3,1,2]

sort<Int> OrdInt [3,1,2]

type inference

elements of type A should have order!

• Well-known GP mechanisms: Haskell Type Classes, C++0x Concepts, Scala Implicits

• Queries and Resolution

OrdInt gives order between Ints

resolution

e ::= ?⇢ | (|e : ⇢|) | e with e : ⇢ | · · ·queries rules scoping?⇢ (|e : ⇢|)

OrdInt : OrdhIntiOrdInt

OrdList : 8A.OrdhAi) OrdhListhAii

OrdList

⇢ ::= 8~↵.⇢̄ ) ⌧

rule environment➾ sorthListhIntii (OrdList OrdInt) [[2, 5], [1, 3]]OrdIntOrdList

• Rules and Scoping

OrdList

OrdInt

?(OrdhListhIntii)

(| · · · : 8A.OrdhAi ) OrdhListhAii|)(| · · · : OrdhInti|)

OrdListOrdIntimplicit in

with

• Translation from Source Langauge

sorthInti ?(OrdhInti) [3, 1, 2]?(OrdhInti)➾ sorthInti OrdInt [3, 1, 2]OrdInt

simple case

sorthListhIntii ?(OrdhListhIntii) [[2, 5], [1, 3]]?(OrdhListhIntii)recursive case

sort [[2,5],[1,3]]source language λ⇒

sorthListhIntii with {?(OrdhListhIntii)} [[2, 5], [1, 3]]?(OrdhListhIntii)with;

syntactic sugarimplicit e : ⇢ in e1 : ⌧

def= (|e1 : ⇢̄ ) ⌧ |) with e : ⇢

implicit in

with

formalized, but restrictive general, but never formalized

let OrdList = (| · · · : 8A.OrdhAi ) OrdhListhAii|) inlet OrdInt = (| · · · : OrdhInti|) inimplicit {OrdInt ,OrdList} in

sorthListhIntii ?(OrdhListhIntii) [[2, 5], [1, 3]]

http://rosaec.snu.ac.kr

ProgrammingResearch Laboratory

http://ropas.snu.ac.kr

The Implicit Calculus

1Seoul National University 2Universiteit GentBruno C. d. S. Oliveira1 Tom Schrijvers2 Wontae Choi1 Wonchan Lee1 Kwangkeun Yi1

A New Foundation for Generic Programming

2. The Implicit Calculus λ⇒• Calculus of the essence of GP: rules, scoping, and type-directed resolution

In the paper• Type system• Elaboration semantics to System F• Higher-order rules and partial resolution• Source language and its translation to λ⇒

1. Generic Programming

• Decoupling algorithms from types

sort [3,1,2] // [1,2,3]sort [‘c’,’a’,’b’] // [‘a’,’b’,’c’]sort [[2,5],[1,3]] // [[1,3],[2,5]]

• Decoupling by parametrization

• Implicit instantiation

sort<A>: Ord<A> ⇒ List<A> → List<A>

sort< ? > ? [3,1,2]

sort<Int> ? [3,1,2]

sort<Int> OrdInt [3,1,2]

type inference

elements of type A should have order!

• Well-known GP mechanisms: Haskell Type Classes, C++0x Concepts, Scala Implicits

• Queries and Resolution

OrdInt gives order between Ints

resolution

e ::= ?⇢ | (|e : ⇢|) | e with e : ⇢ | · · ·queries rules scoping?⇢ (|e : ⇢|)

OrdInt : OrdhIntiOrdInt

OrdList : 8A.OrdhAi) OrdhListhAii

OrdList

⇢ ::= 8~↵.⇢̄ ) ⌧

rule environment➾ sorthListhIntii (OrdList OrdInt) [[2, 5], [1, 3]]OrdIntOrdList

• Rules and Scoping

OrdList

OrdInt

?(OrdhListhIntii)

(| · · · : 8A.OrdhAi ) OrdhListhAii|)(| · · · : OrdhInti|)

OrdListOrdIntimplicit in

with

• Translation from Source Langauge

sorthInti ?(OrdhInti) [3, 1, 2]?(OrdhInti)➾ sorthInti OrdInt [3, 1, 2]OrdInt

simple case

sorthListhIntii ?(OrdhListhIntii) [[2, 5], [1, 3]]?(OrdhListhIntii)recursive case

sort [[2,5],[1,3]]source language λ⇒

sorthListhIntii with {?(OrdhListhIntii)} [[2, 5], [1, 3]]?(OrdhListhIntii)with;

syntactic sugarimplicit e : ⇢ in e1 : ⌧

def= (|e1 : ⇢̄ ) ⌧ |) with e : ⇢

implicit in

with

formalized, but restrictive general, but never formalized

let OrdList = (| · · · : 8A.OrdhAi ) OrdhListhAii|) inlet OrdInt = (| · · · : OrdhInti|) inimplicit {OrdInt ,OrdList} in

sorthListhIntii ?(OrdhListhIntii) [[2, 5], [1, 3]]

http://rosaec.snu.ac.kr

ProgrammingResearch Laboratory

http://ropas.snu.ac.kr

The Implicit Calculus

1Seoul National University 2Universiteit GentBruno C. d. S. Oliveira1 Tom Schrijvers2 Wontae Choi1 Wonchan Lee1 Kwangkeun Yi1

A New Foundation for Generic Programming

2. The Implicit Calculus λ⇒• Calculus of the essence of GP: rules, scoping, and type-directed resolution

In the paper• Type system• Elaboration semantics to System F• Higher-order rules and partial resolution• Source language and its translation to λ⇒

1. Generic Programming

• Decoupling algorithms from types

sort [3,1,2] // [1,2,3]sort [‘c’,’a’,’b’] // [‘a’,’b’,’c’]sort [[2,5],[1,3]] // [[1,3],[2,5]]

• Decoupling by parametrization

• Implicit instantiation

sort<A>: Ord<A> ⇒ List<A> → List<A>

sort< ? > ? [3,1,2]

sort<Int> ? [3,1,2]

sort<Int> OrdInt [3,1,2]

type inference

elements of type A should have order!

• Well-known GP mechanisms: Haskell Type Classes, C++0x Concepts, Scala Implicits

• Queries and Resolution

OrdInt gives order between Ints

resolution

e ::= ?⇢ | (|e : ⇢|) | e with e : ⇢ | · · ·queries rules scoping?⇢ (|e : ⇢|)

OrdInt : OrdhIntiOrdInt

OrdList : 8A.OrdhAi) OrdhListhAii

OrdList

⇢ ::= 8~↵.⇢̄ ) ⌧

rule environment➾ sorthListhIntii (OrdList OrdInt) [[2, 5], [1, 3]]OrdIntOrdList

• Rules and Scoping

OrdList

OrdInt

?(OrdhListhIntii)

(| · · · : 8A.OrdhAi ) OrdhListhAii|)(| · · · : OrdhInti|)

OrdListOrdIntimplicit in

with

• Translation from Source Langauge

sorthInti ?(OrdhInti) [3, 1, 2]?(OrdhInti)➾ sorthInti OrdInt [3, 1, 2]OrdInt

simple case

sorthListhIntii ?(OrdhListhIntii) [[2, 5], [1, 3]]?(OrdhListhIntii)recursive case

sort [[2,5],[1,3]]source language λ⇒

sorthListhIntii with {?(OrdhListhIntii)} [[2, 5], [1, 3]]?(OrdhListhIntii)with;

syntactic sugarimplicit e : ⇢ in e1 : ⌧

def= (|e1 : ⇢̄ ) ⌧ |) with e : ⇢

implicit in

with

formalized, but restrictive general, but never formalized

4.����������� ������������������  실험결과

2.����������� ������������������  안전성����������� ������������������  조절����������� ������������������  대상

•과도한����������� ������������������  안전성이����������� ������������������  정확도를����������� ������������������  해치는����������� ������������������  대표적����������� ������������������  사례 ����������� ������������������  ����������� ������������������  ����������� ������������������  ����������� ������������������  :����������� ������������������  loop,����������� ������������������  lib

3.����������� ������������������  안전성����������� ������������������  조절����������� ������������������  방법

버그탐색기

오탐률

미탐률

검증기

선별적으로 정밀한 분석 [PLDI’14]

검증기 버그탐색기

•두����������� ������������������  가지����������� ������������������  정적분석의����������� ������������������  장점을����������� ������������������  결합

*선별적으로 안전한 분석*

•정적����������� ������������������  분석����������� ������������������  :����������� ������������������  세����������� ������������������  가지����������� ������������������  성질의����������� ������������������  끊임없는����������� ������������������  밀/당

loop lib bitwise input

허위경보 원인 조사

while(e){ C;}

if(e){ C;}

A;lib();B;

A;skip;B;

- loop 해체

- lib 삭제

•안전성����������� ������������������  조절����������� ������������������  =����������� ������������������  선별적����������� ������������������  loop����������� ������������������  해체,����������� ������������������  lib����������� ������������������  삭제

학습 데이터 생성 기계 학습 파라미터 예측

DATA

A

⇡̂

•문제 •알고리즘- 안전성 파라미터가 장착된 분석기 , 프로그램

- 분석결과 의 오/탐률을 평가하는 척도

예) 오탐률과 미탐률의 평균

- 이 때, 을 최소로 하는 찾기

A⇡ P

A⇡(P ) M

⇡⇤ = argmin⇡2⇧

M�A⇡(P )

�M

�A⇡(P )

�⇡⇤

•학습한����������� ������������������  특성

0

750

1500

2250

3000

Sound Rand Selective Unsound

0

35

70

105

140

Sound Rand Selective Unsound

경보 개수 발견한 버그 개수

•총����������� ������������������  23개����������� ������������������  프로그램����������� ������������������  (132개����������� ������������������  버그)- loop종료조건에 Null종료조건에 상수종료조건에 배열종료조건에 &&종료조건에 있는 변수가 순환문 안에서 한/여러 배열의 인덱스종료조건에 있는 변수가 순환문 밖에서 인덱스종료조건에 없는 변수가 순환문 안에서 배열의 인덱스순환문 시작하기 전에 인덱스/포인터 초기화나가는 문 개수순환문의 크기순환문에서 접근하는 배열 개수순환문에서 인덱스/포인터++횟수종료조건에 문자열종료조건이 pruning종료조건에 외부 입력종료조건에 전역변수종료조건에 유한 인터벌/배열종료조건에 왼쪽이 닫힌 인터벌/배열종료조건에서 포인터가 가르키는 변수 개수

- lib인자에 상수인자 개수void 리턴 int 리턴인자 중 외부 입력 개수인자 중 전역 변수 존재string.h 에 선언되어 있는가순환문 안에서 호출순환문 안에서 업데이트되는 값을 사용순환문 안에서 사용되는 값을 업데이트인자를 수정리턴값이 함수 밖으로 나가는가인자가 유한 인터벌/배열인자가 가리키는 변수 개수인자가 문자열인가

Top Related