Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Review of Static Program Analysis and Co/Contra-variance Ras Bodik, Thibaud Hottelier, James Ide UC Berkeley CS164: Introduction to Programming Languages.

Similar presentations


Presentation on theme: "1 Review of Static Program Analysis and Co/Contra-variance Ras Bodik, Thibaud Hottelier, James Ide UC Berkeley CS164: Introduction to Programming Languages."— Presentation transcript:

1 1 Review of Static Program Analysis and Co/Contra-variance Ras Bodik, Thibaud Hottelier, James Ide UC Berkeley CS164: Introduction to Programming Languages and Compilers Fall 2010

2 Improve the course (we need your feedback) Office hours with Pizza this Wed, Nov 17, 5pm, in La Val’s HKN surveys: Next Monday, Nov 22 2

3 HW8: Static analysis (types and flow analysis) Three problems, one for each lecture L18-20 Preparation for the exam. Some reading Due in two weeks (Two days before exam) Today’s lecture and Thursday recitation will review the material 3

4 HW9: Final Project Design Document Main goal: Flesh out HW7. Include details for implementation and evaluation. What programs you want to write in your language? –if you are building a tool, answer “What programs do you want to analyze with your debugger / …?” –be specific, write down these programs What implementation steps will you follow? –finish your design before you submit the document –break down the implementation into ~6 steps –say what data structures and modules you’ll implement 4

5 Announcements Contest 1: Fastest 164 Parser workload: large files + many tiny files (onclick handlers) Contest 2: Most Impressive 164 Browser Demo goal: combine bQuery with Rx, potentially extending them simplicity: future 164 students must be able to build it Prizes: iPod nanos Deadline: a few days after the second midterm 5

6 Paid 164 Courseware Developer Job Do you want to improve 164? Some of the tasks where we need your help: Improve the browser, the language, the parser. Rewrite the handouts with creative technical writing. Develop homeworks that prepare for PAs (like HW4). Talk to Ras if interested. 6

7 Prolog program for Andersen algorithm new(o1,x). % x=new_1 Foo() new(o2,z). % z=new_2 Bar() assign(x,y). % y=x assign(x,w). % w=x pf(z,y,f). % y.f=z gf(w,v,f). % v=w.f flowsTo(O,X) :- new(O,X). flowsTo(O,X) :- assign(Y,X), flowsTo(O,Y). flowsTo(O,X) :- pf(Y,P,F), gf(R,X,F), aliasP,R), flowsTo(O,Y). alias(X,Y) :- flowsTo(O,X), flowsTo(O,Y). 7

8 Computing pointsTo and alias relations o2o2 y z new w v assign x o1o1 new assign pf[f]gf[f] 8

9 Handling of method calls Issue 1: Arguments and return values: –these are translated into assignments of the form p=r Example: Object foo(T x) { return x.f } r = new T; s = foo(r.g) is translated into foo_retval = foo_x.f r = new T; s = foo_retval; foo_x = r.g 9

10 Imprecision in modeling of function calls Example where our modeling leads to imprecision: def id(x) { return x } a = id(new Foo()) b = id(new Bar()) Let’s draw our inference graph: 10

11 Handling of method calls Issue 2: targets of virtual calls –call p.f() may call many possible methods –to do the translation shown on previous slide, must determine what these targets are Suggest two simple methods: – 11

12 Nominal type systems: co/contra-variance Assume: C extends B extends A. class B has method B foo(B). class C also has method foo. Assume you are designing the type system for this language. What types of C’s foo should you allow? B-->B, A-->A, C-->A, A-->C, … How do we decide? Want some statements to be type safe. What does type safety mean? 12


Download ppt "1 Review of Static Program Analysis and Co/Contra-variance Ras Bodik, Thibaud Hottelier, James Ide UC Berkeley CS164: Introduction to Programming Languages."

Similar presentations


Ads by Google