This document discusses changes made to the semantics of short-circuit operators in OCL. Originally, short-circuit operators like "and" and "or" allowed for 4-valued logic and were commutative. However, this led to inconsistencies. The changes introduce distinct short-circuit operators that enforce 2-valued truths and are not commutative. Behind the scenes, types are modeled as inflated types to represent null and invalid values while maintaining compatibility with legacy code.
How to Troubleshoot Apps for the Modern Connected Worker
Commutative Short Circuit Operators
1. Made available under EPL 1.0
Commutative Short Circuit Operators
Edward D. Willink
Willink Transformations Ltd
Eclipse Foundation
MMT Component co-Lead
OCL Project Lead
QVTd Project Lead
QVTo Committer
OMG (Model Driven Solutions)
OCL 2.3, 2.4, 2.5 RTF Chair
QVT 1.2, 1.3, 1.4 RTF Chair
OCL 2017 @ STAF2017
20th
July 2017
2. 20 July 2017 Commutative Short Circuits 2Made available under EPL 1.0
Recreated OCL Design Decisions
Truths - true, false
commutative and/or : x and y = y and x
Expressions should be modeled
OCLExpression -> UML TypedElement => Types
=> BooleanType
Functional => no Exceptions
'the' invalid value for bad returns
Unspecified values / UML multiplicity 0
null value for undefined values
=> N+2 value inflated types, 4-valued logic
Short circuits for awkward combinations
x = null or x.doSomething()
3. 20 July 2017 Commutative Short Circuits 3Made available under EPL 1.0
Commutative Short Circuits
x = null or x.doSomething()
short circuit: when x is null
true or invalid
=> 4-valued logic
commutative
x.doSomething() or x = null
commutative short circuit: when x is null
invalid or true
implementation
must evaluate the invalid to index 4x4 Karnaugh map
design intent
implementation should not evaluate garbage
4. 20 July 2017 Commutative Short Circuits 4Made available under EPL 1.0
Where did it go wrong?
Truths - true, false
commutative and/or : x and y = y and x
Expressions should be modeled
OCLExpression -> UML TypedElement => Types
=> BooleanType
Functional => no Exceptions
'the' invalid value for bad returns
Unspecified values / UML multiplicity 0
null value for undefined values
=> N+2 value inflated types, 4-valued truths/logic
Short circuits for awkward combinations
x = null or x.doSomething()
5. 20 July 2017 Commutative Short Circuits 5Made available under EPL 1.0
Where did it go wrong?
Truths - true, false
commutative and/or : x and y = y and x
Expressions should be modeled
OCLExpression -> UML TypedElement => Types
=> BooleanType
Functional => no Exceptions
'the' invalid value for bad returns
Unspecified values / UML multiplicity 0
null value for undefined values
=> N+2 value inflated types, 4-valued truths/logic
Short circuits for awkward combinations
x = null or x.doSomething()
6. 20 July 2017 Commutative Short Circuits 6Made available under EPL 1.0
2-valued truths, 4-valued logic
old: short circuit and/or operators are Boolean
old: Boolean and/or operators are commutative
=> short circuit operators are commutative
new: short circuit operators are NOT commutative
no-change: x implies y uses 4-valued logic
change: x and y uses 2-valued truths
new: x requires y uses 4-valued logic
change: x or y uses 2-valued truths
new: x obviates y uses 4-valued logic
legacy compatability can offer 4-valued and/or
7. 20 July 2017 Commutative Short Circuits 7Made available under EPL 1.0
2-valued truths, Inflated types
2-valued truths enforced by static analysis
no null values - safe navigation analysis
no invalid values - invalidity analysis
enforcement must be controlable
parsing / source text
e.g. Integer[1] - can only be an Integer
Integer[?] - may be null
new Integer[/] - may be null, may be invalid
model inflated types, N, N+1, N+2 values
Integer[1] conformsTo Integer[?] conformsTo Integer[/]
8. 20 July 2017 Commutative Short Circuits 8Made available under EPL 1.0
Summary
old: 4-valued commutative short circuits
inadvertent conflict between design decisions
new: distinct short circuit operators
2-valued Boolean truths
3/4-valued Booleans - legacy/bad code
behind the scenes: model inflated types
e.g. Boolean[1], Boolean[?], Boolean[/]