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 where isOdd i andalso i < 100 andalso 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 classResult of analyzing the variables in a query, pulling filters into the extent expression for each variable, so that no variable is over an infinite extent.private static class(package private) static class(package private) static interface -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Extents.Analysiscreate(TypeSystem typeSystem, Core.Pat pat, SortedMap<Core.NamedPat, Core.Exp> boundPats, Iterable<? extends Core.FromStep> followingSteps, PairList<Core.IdPat, Core.Exp> idPats) Analyzes the extent of a pattern in an expression and creates anExtents.Analysis.private static List<Core.IdPat> Converts a singleton id pattern "x" or tuple pattern "(x, y)" to a list of id patterns.static Core.DeclinfinitePats(TypeSystem typeSystem, Core.Decl node) static <C extends Comparable<C>>
Map<String, com.google.common.collect.ImmutableRangeSet<C>> Intersects a collection of range set maps (maps from prefix toRangeSet) into one.private static <C extends Comparable<C>>
com.google.common.collect.ImmutableRangeSet<C> intersectRangeSets(Collection<com.google.common.collect.ImmutableRangeSet<C>> rangeSets) Intersects a collection ofRangeSetinto one.static booleanisInfinite(Core.Exp exp) Returns whether an expression is an infinite extent.reduceAnd(TypeSystem typeSystem, PairList<Core.Exp, Core.Exp> extentFilters) Reduces a list of extent-filter pairs [e0, f0, e1, f1, ...]reduceOr(TypeSystem typeSystem, PairList<Core.Exp, Core.Exp> extentFilters) Reduces a list of extent-filter pairs [e0, f0, e1, f1, ...]static <C extends Comparable<C>>
Map<String, com.google.common.collect.ImmutableRangeSet<C>> Unions a collection of range set maps (maps from prefix toRangeSet) into one.private static <C extends Comparable<C>>
com.google.common.collect.ImmutableRangeSet<C> unionRangeSets(Collection<com.google.common.collect.ImmutableRangeSet<C>> rangeSets) Unions a collection ofRangeSetinto one.
-
Constructor Details
-
Extents
private Extents()
-
-
Method Details
-
create
public static Extents.Analysis create(TypeSystem typeSystem, Core.Pat pat, SortedMap<Core.NamedPat, Core.Exp> boundPats, Iterable<? extends Core.FromStep> followingSteps, PairList<Core.IdPat, Core.Exp> idPats) Analyzes the extent of a pattern in an expression and creates anExtents.Analysis.For example, given the program
let fun f i = i elem [1, 2, 4] in from x where 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 where 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) -
flatten
Converts a singleton id pattern "x" or tuple pattern "(x, y)" to a list of id patterns. -
isInfinite
Returns whether an expression is an infinite extent. -
infinitePats
-
intersect
public static <C extends Comparable<C>> Map<String,com.google.common.collect.ImmutableRangeSet<C>> intersect(List<Map<String, com.google.common.collect.ImmutableRangeSet<C>>> rangeSetMaps) Intersects a collection of range set maps (maps from prefix toRangeSet) into one. -
union
public static <C extends Comparable<C>> Map<String,com.google.common.collect.ImmutableRangeSet<C>> union(List<Map<String, com.google.common.collect.ImmutableRangeSet<C>>> rangeSetMaps) Unions a collection of range set maps (maps from prefix toRangeSet) into one. -
intersectRangeSets
private static <C extends Comparable<C>> com.google.common.collect.ImmutableRangeSet<C> intersectRangeSets(Collection<com.google.common.collect.ImmutableRangeSet<C>> rangeSets) Intersects a collection ofRangeSetinto one.- See Also:
-
unionRangeSets
private static <C extends Comparable<C>> com.google.common.collect.ImmutableRangeSet<C> unionRangeSets(Collection<com.google.common.collect.ImmutableRangeSet<C>> rangeSets) Unions a collection ofRangeSetinto one.- See Also:
-
reduceAnd
static Pair<Core.Exp,Core.Exp> reduceAnd(TypeSystem typeSystem, PairList<Core.Exp, Core.Exp> extentFilters) Reduces a list of extent-filter pairs [e0, f0, e1, f1, ...] to an extent-filter pair [e0 intersect e1 ..., f0 andalso f1 ...].If any of the ei are calls to
extent, merges them into a single extent. For example, in[extent "int: (0, inf)", x > 0, x elem primes, isPrime x, extent "int: (-inf, 10)", x < 10]the extents for "(0, inf)" and "(-inf, 10)" are merged into extent "(0, 10)":
(extent "int: (0, 10)" intersect primes, x > 0 andalso isPrime x andalso x < 10) -
reduceOr
static Pair<Core.Exp,Core.Exp> reduceOr(TypeSystem typeSystem, PairList<Core.Exp, Core.Exp> extentFilters) Reduces a list of extent-filter pairs [e0, f0, e1, f1, ...] to an extent-filter pair [e0 union e1 ..., f0 orelse f1 ...].
-