1
Review of Static Program Analysis and Co/Contra-variance
Ras Bodik, Thibaud Hottelier, James IdeUC Berkeley
CS164: Introduction to Programming Languages and Compilers Fall 2010
Improve the course (we need your feedback)
Office hours with Pizzathis Wed, Nov 17, 5pm, in La Val’s
HKN surveys: Next Monday, Nov 22
2
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
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
Announcements
Contest 1: Fastest 164 Parserworkload: large files + many tiny files (onclick handlers)
Contest 2: Most Impressive 164 Browser Demo
goal: combine bQuery with Rx, potentially extending themsimplicity: future 164 students must be able to build it
Prizes: iPod nanos
Deadline: a few days after the second midterm
5
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
Prolog program for Andersen algorithm
new(o1,x). % x=new_1 Foo()new(o2,z). % z=new_2 Bar()assign(x,y). % y=xassign(x,w). % w=xpf(z,y,f). % y.f=zgf(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
Computing pointsTo and alias relations
o2
y
z new
w
v
assign
x
o1
new
assign
pf[f]gf[f]
8
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 intofoo_retval = foo_x.fr = new T; s = foo_retval; foo_x = r.g
9
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
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
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