SlideShare a Scribd company logo
Software Analysis and
Testing
SEC5261
Week 11
Murtaza Munawar Fazal
Type Systems
Type Systems
• Most widely used form of static analysis
• Part of nearly all mainstream languages
• Important for quality
Type
Syste
m
Java
Python
C
C++
ML
Ruby
Motivation
prompt$ javac T.java
T.java:4: error: incompatible types
if (a)
^
required: boolean
found: float
T.java:7: error: incompatible types
return c;
^
required: int
found: int[]
2 errors
1: class T {
2: int f(float a, int b,
3: int[] c) {
4: if (a)
5: return b;
6: else
7: return c;
8: }
9: }
File T.java
Type Systems
• Most widely used form of static analysis
• Part of nearly all mainstream languages
• Important for quality
• Provides notation useful for describing
static analyses:
type checking, dataflow analysis, symbolic
execution, ...
What Is a Type?
• A type is a set of values
• Examples in Java:
•int is the set of all integers between -2^31 and
(2^31)-1
•double is the set of all double-precision floating
point numbers
•boolean is the set {true, false}
More Examples
• Foo is the set of all objects of class Foo
• List<Integer> is the set of all Lists of Integer objects
• List is a type constructor
• List acts as a function from types to types
• int -> int is the set of functions taking an int as
input and returning another int
E.g.: increment, a function that squares a number, etc.
Abstraction
• All static analyses use abstraction
• Represent sets of concrete values as abstract values
• Why?
• Can’t directly reason about infinite sets of
concrete values (wouldn’t guarantee termination)
• Improves performance even in case of (large)
finite sets
• In type systems, the abstractions are called types
What Is a Type?
• A type is an example of an abstract value
• Represents a set of concrete values
• In type systems:
• Every concrete value is an element of some abstract value
=> every concrete value has a type
A Simple Typed Language
(expression) e := v | x | e1 + e2 | e1 e2
(value) v := i | λ x:t => e
(integer) i
(variable) x
(type) t := int | t1 -> t2
(
λ x:int => (x + 1)
) (42)
Example Program:
The Next Steps
• Notation for Type Systems
• Properties of Type Systems
• Describing Other Analyses Using Types
Notation
Notation for Inference Rules
• Inference rules have the following form:
If (hypothesis) is true, then (conclusion) is true
• Type checking computes via reasoning:
If e1 is an int and e2 is a double, then e1*e2 is a double
• We will develop a standard notation for
rules of inference
From English to Inference Rule
• Start with a simplified system and gradually add features
• Building blocks:
• Symbol ∧ is “and”
• Symbol ⇒ is “if-then”
• x : t is “x has type t”
From English to Inference Rule
• If e1 has type int and e2 has type int, then
e1 + e2 has type int
• (e1 has type int ∧ e2 has type int) ⇒
e1 + e2 has type int
• (e1 : int ∧ e2 : int) ⇒ e1 + e2 : int
From English to Inference Rule
The statement
(e1 : int ∧ e2 : int) ⇒ e1 + e2 : int
is a special case of
Hypothesis1 ∧ . . . ∧ HypothesisN ⇒ Conclusion
Notation for Inference Rules
• By tradition, inference rules are written
|- Hypothesis1 . . . |- HypothesisN
|- Conclusion
• Hypotheses and conclusion are type judgments:
|- e : t
• |- means “it is provable that…”
Rules for Integers
|- i : int
|- e1 : int |- e2 : int
|- e1 + e2 : int
[Int]
[Add]
Rules for Integers
• Templates for how to type integers and sums
• Filling in templates produces complete typings
• Note that:
• Hypotheses state facts about sub-expressions
• Conclusions state facts about entire expression
Example: 1 + 2
|- 1 : int
|- 1+2 : int
[Int] [Int]
[Add]
|- 2 : int
A Problem
What is the type of a variable reference?
[Var]
Doesn’t carry enough
information to give x a type
|- e + e : int
Carries type information
for e in hypotheses
|- e : int
|- x : ?
A Solution
• Put more information in the rules!
• An environment gives types for free variables
• A variable is free in an expression if not defined
within the expression; otherwise it is bound
• An environment is a function from variables to types
• May map variables to other abstract values in
different static analyses
[Var]
|- x : ?
Type Environments
• Let A be a function from variables to types
• The sentence A |- e : t means:
“Under the assumption that variables
have types given by A, it is provable that
expression e has type t.”
Modified Rules
• The type environment is added to all rules:
A |- e1 : int A |- e2 : int
A |- e1 + e2 : int
A |- i : int [Int]
[Add]
A New Rule
• And we can write new rules:
A |- x : A(x)
[Var]
Rules for Functions
A |- e : t’
A |- λ x:t => e : t -> t’
A |- e1 : t1 -> t2 A |- e2 : t1
A |- e1 e2 : t2
A[x↦t] means “A modified to map x to type t”
[x↦t]
[Def]
[Call]
All Rules Together
A |- i : int
A [x↦t] |- e : t’
A |- λ x:t => e : t -> t’
[Def]
A |- e1 : int A |- e2 : int
A |- e1 + e2 : int
[Add]
[Int]
A |- x : A(x)
[Var]
A |- e1 : t1 -> t2 A |- e2 : t1
A |- e1 e2 : t2
[Call]
Type Derivations: Example
[x↦int] |- x : int [x↦int] |- 1 : int
[x↦int] |- x + 1 : int
[] |- λ x:int => (x + 1) : int -> int [] |- 42 : int
[] |- (λ x:int => (x + 1)) (42) : int [Call]
[Int]
[Def]
[Var] [Int]
[Add]
Type Derivations: Example
[x↦int] |- x : int [x↦int] |- 1 : int
[x↦int] |- x + 1 : int
[] |- λ x:int => (x + 1) : int -> int [] |- 42 : int
[] |- (λ x:int => (x + 1)) (42) : int [Call]
[Int]
[Def]
[Var] [Int]
[Add]
Back to the Original Example
prompt$ javac T.java
T.java:4: error: incompatible types
if (a)
^
required: boolean
found: float
T.java:7: error: incompatible types
return c;
^
required: int
found: int[]
2 errors
1: class T {
2: int f(float a, int b,
3: int[] c) {
4: if (a)
5: return b;
6: else
7: return c;
8: }
9: }
File T.java
A More Complex Rule
A |- e0 : bool
A |- e1 : t1
A |- e2 : t2
t1 = t2
A |- if e0 then e1 else e2 : t1
[If-Then-Else]
We’ll use this rule to illustrate several ideas . . .
A |- e0 : bool
A |- e1 : t1
A |- e2 : t2
t1 = t2
A |- if e0 then e1 else e2 : t1
Soundness
A type system is sound iff
whenever 1. A |- e : t and
2. If A(x) = t’, then x has a value v’ in t’
then e evaluates to a value v in t
e0 is guaranteed to be a
boolean
e1 and e2 are guaranteed to
be of the same type
Comments on Soundness
• Soundness is extremely useful
• Program type-checks => no errors at runtime
• Verifies absence of a class of errors
• This is a very strong guarantee
• Verified property holds in all executions
• “Well-typed programs cannot go wrong”
Comments on Soundness
• Soundness comes at a price: false positives
• Alternative: use unsound analysis
•Reduces false positives
•Introduces false negatives
• Type systems are sound
•But most bug finding analyses are not sound
Constraints
A |- e0 : bool
A |- e1 : t1
A |- e2 : t2
t1 = t2
A |- if e0 then e1 else e2 : t1
if (a > 1)
then (λ x:int => x)
else (10)
Many analyses have side conditions
• Often constraints to be solved
• All constraints must be satisfied
• A separate algorithmic problem
Side constraints must be solved
Another Example
• Consider a recursive function
f(x) = … f(e) …
• If x : t1 and e : t2 then t2 = t1
•Can be relaxed to t2 ⊆ t1
• Recursive functions yield recursive constraints
•Same with loops
•How hard constraints are to solve depends on
constraint language, details of application

More Related Content

Similar to Software analysis and testing

Python programming
Python programmingPython programming
Python programming
saroja20
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
in computer data structures and algorithms
in computer data structures and algorithmsin computer data structures and algorithms
in computer data structures and algorithms
FIONACHATOLA
 
unit1 python.pptx
unit1 python.pptxunit1 python.pptx
unit1 python.pptx
TKSanthoshRao
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
ssuser492e7f
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
rehanafarheenece
 
Master Thesis Presentation
Master Thesis PresentationMaster Thesis Presentation
Master Thesis Presentation
Mohamed Sobh
 
a581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptxa581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptx
christinamary2620
 
Declarative Semantics Definition - Static Analysis and Error Checking
Declarative Semantics Definition - Static Analysis and Error CheckingDeclarative Semantics Definition - Static Analysis and Error Checking
Declarative Semantics Definition - Static Analysis and Error Checking
Guido Wachsmuth
 
Python
PythonPython
Python
Kumar Gaurav
 
Scala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowScala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To Know
Lightbend
 
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
DrkhanchanaR
 
Ch6
Ch6Ch6
Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"
Ra'Fat Al-Msie'deen
 
Crystal: tipos, peculiaridades y desafios
Crystal: tipos, peculiaridades y desafiosCrystal: tipos, peculiaridades y desafios
Crystal: tipos, peculiaridades y desafios
Brian Cardiff
 
Intro to modelling_wur
Intro to modelling_wurIntro to modelling_wur
Intro to modelling_wur
iGEMWageningenUR
 
Project presentation PPT.pdf this is help for student who doing this complier...
Project presentation PPT.pdf this is help for student who doing this complier...Project presentation PPT.pdf this is help for student who doing this complier...
Project presentation PPT.pdf this is help for student who doing this complier...
AmitSingh395981
 
ppt_pspp.pdf
ppt_pspp.pdfppt_pspp.pdf
ppt_pspp.pdf
ShereenAhmedMohamed
 
Concepts
ConceptsConcepts
Concepts
Ahmed Mohamed
 
Presentation1 (1).pptx
Presentation1 (1).pptxPresentation1 (1).pptx
Presentation1 (1).pptx
BodapatiNagaeswari1
 

Similar to Software analysis and testing (20)

Python programming
Python programmingPython programming
Python programming
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
 
in computer data structures and algorithms
in computer data structures and algorithmsin computer data structures and algorithms
in computer data structures and algorithms
 
unit1 python.pptx
unit1 python.pptxunit1 python.pptx
unit1 python.pptx
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
 
02python.ppt
02python.ppt02python.ppt
02python.ppt
 
Master Thesis Presentation
Master Thesis PresentationMaster Thesis Presentation
Master Thesis Presentation
 
a581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptxa581a6a2cb5778045788f0b1d7da1c0236f.pptx
a581a6a2cb5778045788f0b1d7da1c0236f.pptx
 
Declarative Semantics Definition - Static Analysis and Error Checking
Declarative Semantics Definition - Static Analysis and Error CheckingDeclarative Semantics Definition - Static Analysis and Error Checking
Declarative Semantics Definition - Static Analysis and Error Checking
 
Python
PythonPython
Python
 
Scala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowScala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To Know
 
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
 
Ch6
Ch6Ch6
Ch6
 
Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"
 
Crystal: tipos, peculiaridades y desafios
Crystal: tipos, peculiaridades y desafiosCrystal: tipos, peculiaridades y desafios
Crystal: tipos, peculiaridades y desafios
 
Intro to modelling_wur
Intro to modelling_wurIntro to modelling_wur
Intro to modelling_wur
 
Project presentation PPT.pdf this is help for student who doing this complier...
Project presentation PPT.pdf this is help for student who doing this complier...Project presentation PPT.pdf this is help for student who doing this complier...
Project presentation PPT.pdf this is help for student who doing this complier...
 
ppt_pspp.pdf
ppt_pspp.pdfppt_pspp.pdf
ppt_pspp.pdf
 
Concepts
ConceptsConcepts
Concepts
 
Presentation1 (1).pptx
Presentation1 (1).pptxPresentation1 (1).pptx
Presentation1 (1).pptx
 

More from NishaVatwani

Quality Laggards.pdf
Quality Laggards.pdfQuality Laggards.pdf
Quality Laggards.pdf
NishaVatwani
 
Software Defects.pdf
Software Defects.pdfSoftware Defects.pdf
Software Defects.pdf
NishaVatwani
 
SEC5261_SAT_Week07_Spring22.pdf
SEC5261_SAT_Week07_Spring22.pdfSEC5261_SAT_Week07_Spring22.pdf
SEC5261_SAT_Week07_Spring22.pdf
NishaVatwani
 
SEC5261_SAT_Week08_Spring22.pdf
SEC5261_SAT_Week08_Spring22.pdfSEC5261_SAT_Week08_Spring22.pdf
SEC5261_SAT_Week08_Spring22.pdf
NishaVatwani
 
SEC5 delta debugging
SEC5 delta debugging SEC5 delta debugging
SEC5 delta debugging
NishaVatwani
 
m08mish152006ppwc07-100622022709-phpapp01 (1).pptx
m08mish152006ppwc07-100622022709-phpapp01 (1).pptxm08mish152006ppwc07-100622022709-phpapp01 (1).pptx
m08mish152006ppwc07-100622022709-phpapp01 (1).pptx
NishaVatwani
 

More from NishaVatwani (6)

Quality Laggards.pdf
Quality Laggards.pdfQuality Laggards.pdf
Quality Laggards.pdf
 
Software Defects.pdf
Software Defects.pdfSoftware Defects.pdf
Software Defects.pdf
 
SEC5261_SAT_Week07_Spring22.pdf
SEC5261_SAT_Week07_Spring22.pdfSEC5261_SAT_Week07_Spring22.pdf
SEC5261_SAT_Week07_Spring22.pdf
 
SEC5261_SAT_Week08_Spring22.pdf
SEC5261_SAT_Week08_Spring22.pdfSEC5261_SAT_Week08_Spring22.pdf
SEC5261_SAT_Week08_Spring22.pdf
 
SEC5 delta debugging
SEC5 delta debugging SEC5 delta debugging
SEC5 delta debugging
 
m08mish152006ppwc07-100622022709-phpapp01 (1).pptx
m08mish152006ppwc07-100622022709-phpapp01 (1).pptxm08mish152006ppwc07-100622022709-phpapp01 (1).pptx
m08mish152006ppwc07-100622022709-phpapp01 (1).pptx
 

Recently uploaded

All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
Reetu63
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
Envertis Software Solutions
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
kalichargn70th171
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Peter Caitens
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
kgyxske
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
Yara Milbes
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 

Recently uploaded (20)

All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 

Software analysis and testing

  • 3. Type Systems • Most widely used form of static analysis • Part of nearly all mainstream languages • Important for quality Type Syste m Java Python C C++ ML Ruby
  • 4. Motivation prompt$ javac T.java T.java:4: error: incompatible types if (a) ^ required: boolean found: float T.java:7: error: incompatible types return c; ^ required: int found: int[] 2 errors 1: class T { 2: int f(float a, int b, 3: int[] c) { 4: if (a) 5: return b; 6: else 7: return c; 8: } 9: } File T.java
  • 5. Type Systems • Most widely used form of static analysis • Part of nearly all mainstream languages • Important for quality • Provides notation useful for describing static analyses: type checking, dataflow analysis, symbolic execution, ...
  • 6. What Is a Type? • A type is a set of values • Examples in Java: •int is the set of all integers between -2^31 and (2^31)-1 •double is the set of all double-precision floating point numbers •boolean is the set {true, false}
  • 7. More Examples • Foo is the set of all objects of class Foo • List<Integer> is the set of all Lists of Integer objects • List is a type constructor • List acts as a function from types to types • int -> int is the set of functions taking an int as input and returning another int E.g.: increment, a function that squares a number, etc.
  • 8. Abstraction • All static analyses use abstraction • Represent sets of concrete values as abstract values • Why? • Can’t directly reason about infinite sets of concrete values (wouldn’t guarantee termination) • Improves performance even in case of (large) finite sets • In type systems, the abstractions are called types
  • 9. What Is a Type? • A type is an example of an abstract value • Represents a set of concrete values • In type systems: • Every concrete value is an element of some abstract value => every concrete value has a type
  • 10. A Simple Typed Language (expression) e := v | x | e1 + e2 | e1 e2 (value) v := i | λ x:t => e (integer) i (variable) x (type) t := int | t1 -> t2 ( λ x:int => (x + 1) ) (42) Example Program:
  • 11. The Next Steps • Notation for Type Systems • Properties of Type Systems • Describing Other Analyses Using Types Notation
  • 12. Notation for Inference Rules • Inference rules have the following form: If (hypothesis) is true, then (conclusion) is true • Type checking computes via reasoning: If e1 is an int and e2 is a double, then e1*e2 is a double • We will develop a standard notation for rules of inference
  • 13. From English to Inference Rule • Start with a simplified system and gradually add features • Building blocks: • Symbol ∧ is “and” • Symbol ⇒ is “if-then” • x : t is “x has type t”
  • 14. From English to Inference Rule • If e1 has type int and e2 has type int, then e1 + e2 has type int • (e1 has type int ∧ e2 has type int) ⇒ e1 + e2 has type int • (e1 : int ∧ e2 : int) ⇒ e1 + e2 : int
  • 15. From English to Inference Rule The statement (e1 : int ∧ e2 : int) ⇒ e1 + e2 : int is a special case of Hypothesis1 ∧ . . . ∧ HypothesisN ⇒ Conclusion
  • 16. Notation for Inference Rules • By tradition, inference rules are written |- Hypothesis1 . . . |- HypothesisN |- Conclusion • Hypotheses and conclusion are type judgments: |- e : t • |- means “it is provable that…”
  • 17. Rules for Integers |- i : int |- e1 : int |- e2 : int |- e1 + e2 : int [Int] [Add]
  • 18. Rules for Integers • Templates for how to type integers and sums • Filling in templates produces complete typings • Note that: • Hypotheses state facts about sub-expressions • Conclusions state facts about entire expression
  • 19. Example: 1 + 2 |- 1 : int |- 1+2 : int [Int] [Int] [Add] |- 2 : int
  • 20. A Problem What is the type of a variable reference? [Var] Doesn’t carry enough information to give x a type |- e + e : int Carries type information for e in hypotheses |- e : int |- x : ?
  • 21. A Solution • Put more information in the rules! • An environment gives types for free variables • A variable is free in an expression if not defined within the expression; otherwise it is bound • An environment is a function from variables to types • May map variables to other abstract values in different static analyses [Var] |- x : ?
  • 22. Type Environments • Let A be a function from variables to types • The sentence A |- e : t means: “Under the assumption that variables have types given by A, it is provable that expression e has type t.”
  • 23. Modified Rules • The type environment is added to all rules: A |- e1 : int A |- e2 : int A |- e1 + e2 : int A |- i : int [Int] [Add]
  • 24. A New Rule • And we can write new rules: A |- x : A(x) [Var]
  • 25. Rules for Functions A |- e : t’ A |- λ x:t => e : t -> t’ A |- e1 : t1 -> t2 A |- e2 : t1 A |- e1 e2 : t2 A[x↦t] means “A modified to map x to type t” [x↦t] [Def] [Call]
  • 26. All Rules Together A |- i : int A [x↦t] |- e : t’ A |- λ x:t => e : t -> t’ [Def] A |- e1 : int A |- e2 : int A |- e1 + e2 : int [Add] [Int] A |- x : A(x) [Var] A |- e1 : t1 -> t2 A |- e2 : t1 A |- e1 e2 : t2 [Call]
  • 27. Type Derivations: Example [x↦int] |- x : int [x↦int] |- 1 : int [x↦int] |- x + 1 : int [] |- λ x:int => (x + 1) : int -> int [] |- 42 : int [] |- (λ x:int => (x + 1)) (42) : int [Call] [Int] [Def] [Var] [Int] [Add]
  • 28. Type Derivations: Example [x↦int] |- x : int [x↦int] |- 1 : int [x↦int] |- x + 1 : int [] |- λ x:int => (x + 1) : int -> int [] |- 42 : int [] |- (λ x:int => (x + 1)) (42) : int [Call] [Int] [Def] [Var] [Int] [Add]
  • 29. Back to the Original Example prompt$ javac T.java T.java:4: error: incompatible types if (a) ^ required: boolean found: float T.java:7: error: incompatible types return c; ^ required: int found: int[] 2 errors 1: class T { 2: int f(float a, int b, 3: int[] c) { 4: if (a) 5: return b; 6: else 7: return c; 8: } 9: } File T.java
  • 30. A More Complex Rule A |- e0 : bool A |- e1 : t1 A |- e2 : t2 t1 = t2 A |- if e0 then e1 else e2 : t1 [If-Then-Else] We’ll use this rule to illustrate several ideas . . .
  • 31. A |- e0 : bool A |- e1 : t1 A |- e2 : t2 t1 = t2 A |- if e0 then e1 else e2 : t1 Soundness A type system is sound iff whenever 1. A |- e : t and 2. If A(x) = t’, then x has a value v’ in t’ then e evaluates to a value v in t e0 is guaranteed to be a boolean e1 and e2 are guaranteed to be of the same type
  • 32. Comments on Soundness • Soundness is extremely useful • Program type-checks => no errors at runtime • Verifies absence of a class of errors • This is a very strong guarantee • Verified property holds in all executions • “Well-typed programs cannot go wrong”
  • 33. Comments on Soundness • Soundness comes at a price: false positives • Alternative: use unsound analysis •Reduces false positives •Introduces false negatives • Type systems are sound •But most bug finding analyses are not sound
  • 34. Constraints A |- e0 : bool A |- e1 : t1 A |- e2 : t2 t1 = t2 A |- if e0 then e1 else e2 : t1 if (a > 1) then (λ x:int => x) else (10) Many analyses have side conditions • Often constraints to be solved • All constraints must be satisfied • A separate algorithmic problem Side constraints must be solved
  • 35. Another Example • Consider a recursive function f(x) = … f(e) … • If x : t1 and e : t2 then t2 = t1 •Can be relaxed to t2 ⊆ t1 • Recursive functions yield recursive constraints •Same with loops •How hard constraints are to solve depends on constraint language, details of application