Static Analysis for Dynamic Languages | Generated by AI

Home 2025.12

Question: What does the PDF “pysonar-slides.pdf” say?

Answer:

The PDF “pysonar-slides.pdf” appears to be a presentation slide deck titled “Static Analysis of Dynamically Typed Languages made Easy” by Yin Wang from the School of Informatics and Computing at Indiana University. It discusses challenges and solutions for performing static analysis on dynamically typed languages like Python, based on the author’s internships at Google in 2009 and 2010. The work was motivated by Google’s Grok Project, which aimed to statically analyze all code at Google (including C++, Java, JavaScript, Python, Sawzall, and Protobuf). The initial goal was to enable IDE-like code browsing, but it proved difficult for Python, leading to more advanced semantic analysis.

Key Sections and Content

Overview (Pages 1-2)

Achieved Goals (Page 3)

Problems Faced by Static Analysis (Pages 5-23)

The presentation outlines four main problems with solutions:

  1. Problems with Dynamic Typing (Pages 6-9):
    • Dynamic typing complicates name resolution, especially in polymorphic functions (e.g., def h(x): return x.z – where is z defined? It depends on x’s type).
    • Solution: Use a static type system with inter-procedural analysis to infer types.

    Static Type System for Python (Page 10):

    • Mostly standard, with extras like union and dict types.
    • Includes:
      • Primitives: int, str, float, bool.
      • Tuples: (int, float), (A, B, C).
      • Lists: [int], [bool], [(int, bool)].
      • Dicts: {int => str}, {A => B}.
      • Classes: ClassA, ClassB.
      • Unions: {int str}, {A B C}.
      • Recursive: #1(int, +), #2(int -> 2).
      • Functions: int -> bool, A -> B.
  2. Problems with Control-Flow Graph (CFG) (Pages 11-13):
    • CFGs are hard to build for higher-order programs (e.g., functions passed as arguments like def g(f, x): return f(x)).
    • References prior work (Shivers 1988/1991, Might & Shivers 2006/2007, Vardoulakis & Shivers 2010/2011) on complications from CPS (Continuation-Passing Style) and CFG construction.
    • Solution: Avoid CPS and CFG entirely; use a direct-style, recursive abstract interpreter.
  3. Problems with Dynamic Field Creation/Deletion (Pages 14-21):
    • Example: class A: x = 1; obj = A(); obj.y = 3; print obj.x, obj.y.
    • Solution: Create “abstract objects” at constructor calls and modify them when fields are added/deleted. Classes remain unaffected.
  4. Problems with More Powerful Dynamic Features (Pages 22-23):
    • Includes operations on __dict__ (e.g., setattr, delattr), dynamic reparenting, import hacks, eval, etc.
    • Solution: Enforce a “Python Style Guide” to restrict such features.

Pages 4 and 24-28 appear blank or transitional.

Actual Code of Main Interpreter (Pages 29-33)

Pages 34-39 appear blank or transitional.

Recursion Detection (Pages 40-54)

Correctness of Recursion Detection (Pages 55-58)

Connections to Deeper Theories (Page 60)

Limitations (Page 61)

Applicability (Page 62)

Availability (Page 63)

Possible Future Work (Page 64)

Page 65 appears blank.

The slides include code examples, diagrams (e.g., speech bubbles for questions), and references to academic papers. There’s a “Demo Time” slide (Page 4), likely for a live demonstration. Overall, it presents a practical approach to making static analysis feasible for Python by addressing dynamic typing challenges through type inference, abstract interpretation, and recursion handling.


Back

x-ai/grok-4.1-fast

Donate