Class Extents
If i is a variable of type int then one approximation is
the set of all 232 values of the int data type. (Every
data type, primitive data types and those built using sum (datatype)
or product (record and tuple), has a finite set of values, but the set is
usually too large to iterate over.)
There is often a better approximation that can be deduced from the uses of the variable. For example,
let fun isOdd i = i % 2 = 0 in from e in emps, i suchthat isOdd i andalso i < 100 where i = e.deptno end
we can deduce a better extent for i, namely
from e in emps yield e.deptno where deptno % 2 = 0 andalso deptno < 100
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprivate static class(package private) static classA "suchthat" expression split into an extent and filters. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Extents.Analysiscreate(TypeSystem typeSystem, Core.Pat pat, SortedMap<Core.NamedPat, Core.Exp> boundPats, Core.Exp exp) private static List<Core.IdPat> Converts a singleton id pattern "x" or tuple pattern "(x, y)" to a list of id patterns.static Core.Expgenerator(TypeSystem typeSystem, Core.Pat pat, Core.Exp exp) Returns an expression that generates the extent of a pattern.
-
Constructor Details
-
Extents
private Extents()
-
-
Method Details
-
generator
Returns an expression that generates the extent of a pattern.For example, given the program
let fun f i = i elem [1, 2, 4] in from x suchthat f x endwe can deduce that the extent of "x" is "[1, 2, 4]".
We can also compute the extent of tuples. For the program
let val edges = [(1, 2), (2, 3), (1, 4), (4, 2), (4, 3)] fun edge (i, j) = (i, j) elem edges in from (x, y, z) suchthat edge (x, y) andalso edge (y, z) andalso x <> z endwe could deduce that "x" has extent "from e in edges group e.i", "y" has extent "from e in edges group e.j" ("from e in edges group e.i" is also valid), "z" has extent "from e in edges group e.j", and therefore "(x, y, z)" has extent
from x in (from e in edges group e.i), y in (from e in edges group e.j), z in (from e in edges group e.j)but we can do better by computing the extent of (x, y) simultaneously:
from (x, y) in (from e in edges), z in (from e in edges group e.j) -
create
public static Extents.Analysis create(TypeSystem typeSystem, Core.Pat pat, SortedMap<Core.NamedPat, Core.Exp> boundPats, Core.Exp exp) -
flatten
Converts a singleton id pattern "x" or tuple pattern "(x, y)" to a list of id patterns.
-