Documentation
¶
Overview ¶
Package symbols contains symbols for built-in functions and predicates.
Index ¶
- Variables
- func CheckAndDesugar(decls map[ast.PredicateSym]ast.Decl) (map[ast.PredicateSym]*ast.Decl, error)
- func CheckFunTypeExpression(ctx map[ast.Variable]ast.BaseTerm, expr ast.ApplyFn) error
- func CheckSetExpression(expr ast.BaseTerm) error
- func CheckTypeExpression(ctx map[ast.Variable]ast.BaseTerm, expr ast.BaseTerm) error
- func CreateListType(bound ast.Constant) ast.ApplyFn
- func FunTypeArgs(tpe ast.BaseTerm) ([]ast.BaseTerm, error)
- func FunTypeResult(tpe ast.BaseTerm) (ast.BaseTerm, error)
- func IsBaseTypeExpression(c ast.Constant) bool
- func IsFunTypeExpression(tpe ast.BaseTerm) bool
- func IsListTypeExpression(tpe ast.BaseTerm) bool
- func IsMapTypeExpression(tpe ast.BaseTerm) bool
- func IsOptional(structElem ast.BaseTerm) bool
- func IsRelTypeExpression(tpe ast.BaseTerm) bool
- func IsStructTypeExpression(tpe ast.BaseTerm) bool
- func IsUnionTypeExpression(tpe ast.BaseTerm) bool
- func ListTypeArg(tpe ast.BaseTerm) (ast.BaseTerm, error)
- func LowerBound(typeExprs []ast.BaseTerm) ast.BaseTerm
- func MapTypeArgs(tpe ast.BaseTerm) (ast.BaseTerm, ast.BaseTerm, error)
- func NewFunType(res ast.BaseTerm, args ...ast.BaseTerm) ast.ApplyFn
- func NewListType(elem ast.BaseTerm) ast.ApplyFn
- func NewMapType(keyType, valueType ast.BaseTerm) ast.ApplyFn
- func NewOpt(label, tpe ast.BaseTerm) ast.ApplyFn
- func NewOptionType(elem ast.BaseTerm) ast.ApplyFn
- func NewPairType(left, right ast.BaseTerm) ast.ApplyFn
- func NewRelType(args ...ast.BaseTerm) ast.ApplyFn
- func NewStructType(args ...ast.BaseTerm) ast.ApplyFn
- func NewTupleType(parts ...ast.BaseTerm) ast.ApplyFn
- func NewUnionType(elems ...ast.BaseTerm) ast.ApplyFn
- func RelTypeAlternatives(relTypeExpr ast.BaseTerm) []ast.BaseTerm
- func RelTypeArgs(tpe ast.BaseTerm) ([]ast.BaseTerm, error)
- func RelTypeExprFromDecl(decl ast.Decl) (ast.BaseTerm, error)
- func RelTypeFromAlternatives(alternatives []ast.BaseTerm) ast.BaseTerm
- func RemoveFromUnionType(tpeToRemove, unionTpe ast.BaseTerm) (ast.BaseTerm, error)
- func SetConforms(left ast.BaseTerm, right ast.BaseTerm) bool
- func StructTypeField(tpe ast.BaseTerm, field ast.Constant) (ast.BaseTerm, error)
- func StructTypeOptionaArgs(tpe ast.BaseTerm) ([]ast.BaseTerm, error)
- func StructTypeRequiredArgs(tpe ast.BaseTerm) ([]ast.BaseTerm, error)
- func TypeConforms(ctx map[ast.Variable]ast.BaseTerm, left ast.BaseTerm, right ast.BaseTerm) bool
- func UnionTypeArgs(tpe ast.BaseTerm) ([]ast.BaseTerm, error)
- func UpperBound(typeExprs []ast.BaseTerm) ast.BaseTerm
- type NameTrie
- type NameTrieNode
- type TypeHandle
Constants ¶
This section is empty.
Variables ¶
var ( // MatchPrefix matches name constants that have a given prefix. MatchPrefix = ast.PredicateSym{":match_prefix", 2} // StartsWith matches string constants that have a given prefix. StartsWith = ast.PredicateSym{":string:starts_with", 2} // EndsWith matches string constants that have a given suffix. EndsWith = ast.PredicateSym{":string:ends_with", 2} // Contains matches string constants that contain the given string. Contains = ast.PredicateSym{":string:contains", 2} // Lt is the less-than relation on numbers. Lt = ast.PredicateSym{":lt", 2} // Le is the less-than-or-equal relation on numbers. Le = ast.PredicateSym{":le", 2} // Gt is the greater-than relation on numbers. Gt = ast.PredicateSym{":gt", 2} // Ge is the greater-than-or-equal relation on numbers. Ge = ast.PredicateSym{":ge", 2} // MatchPair mode(+, -, -) matches a pair to its elements. MatchPair = ast.PredicateSym{":match_pair", 3} // MatchCons mode(+, -, -) matches a list to head and tail. MatchCons = ast.PredicateSym{":match_cons", 3} // MatchNil matches the empty list. MatchNil = ast.PredicateSym{":match_nil", 1} // MatchEntry mode(+, +, -) matches an entry in a map. MatchEntry = ast.PredicateSym{":match_entry", 3} // MatchField mode(+, +, -) matches a field in a struct. MatchField = ast.PredicateSym{":match_field", 3} // ListMember mode(+, -) either checks membership or binds var to every element. ListMember = ast.PredicateSym{":list:member", 2} // WithinDistance is a relation on numbers X, Y, Z satisfying |X - Y| < Z. WithinDistance = ast.PredicateSym{":within_distance", 3} // Div is a family of functions mapping integer division: X,Y1,.. to (X / Y1) / Y2 ... DIV(X) is 1/x. Div = ast.FunctionSym{"fn:div", -1} // FloatDiv is a family of functions mapping division: X,Y1,.. to (X / Y1) / Y2 ... FloatDiv(X) is 1/x. FloatDiv = ast.FunctionSym{"fn:float:div", -1} // Mult is a family of functions mapping X,Y1,.. to (X * Y1) * Y2 ... MULT(x) is x. Mult = ast.FunctionSym{"fn:mult", -1} // Plus is a family of functions mapping X,Y1,.. to (X + Y1) + Y2 ... PLUS(x) is x. Plus = ast.FunctionSym{"fn:plus", -1} // Minus is a family of functions mapping X,Y1,.. to (X - Y1) - Y2 ...MINUS(x) is -X. Minus = ast.FunctionSym{"fn:minus", -1} // Collect turns a collection { tuple_1,...tuple_n } into a list [tuple_1, ..., tuple_n]. Collect = ast.FunctionSym{"fn:collect", -1} // CollectDistinct turns a collection { tuple_1,...tuple_n } into a list with distinct elements [tuple_1, ..., tuple_n]. CollectDistinct = ast.FunctionSym{"fn:collect_distinct", -1} // PickAny reduces a set { x_1,...x_n } to a single { x_i }, PickAny = ast.FunctionSym{"fn:pick_any", 1} // Max reduces a set { x_1,...x_n } to { x_i } that is maximal. Max = ast.FunctionSym{"fn:max", 1} // FloatMax reduces a set of float64 { x_1,...x_n } to { x_i } that is maximal. FloatMax = ast.FunctionSym{"fn:float:max", 1} // Min reduces a set { x_1,...x_n } to { x_i } that is minimal. Min = ast.FunctionSym{"fn:min", 1} // FloatMin reduces a set of float64 { x_1,...x_n } to { x_i } that is minimal. FloatMin = ast.FunctionSym{"fn:float:min", 1} // Sum reduces a set { x_1,...x_n } to { x_1 + ... + x_n }. Sum = ast.FunctionSym{"fn:sum", 1} // FloatSum reduces a set of float64 { x_1,...x_n } to { x_1 + ... + x_n }. FloatSum = ast.FunctionSym{"fn:float:sum", 1} // Count reduces a set { x_1,...x_n } to { n }. Count = ast.FunctionSym{"fn:count", 0} // GroupBy groups all tuples by the values of key variables, e.g. 'group_by(X)'. // An empty group_by() treats the whole relation as a group. GroupBy = ast.FunctionSym{"fn:group_by", -1} // Append appends a element to a list. Append = ast.FunctionSym{"fn:list:append", 2} // ListGet is a function (List, Number) which returns element at index 'Number'. ListGet = ast.FunctionSym{"fn:list:get", 2} // ListContains is a function (List, Member) which returns /true if Member is contained in list. ListContains = ast.FunctionSym{"fn:list:contains", 2} // Len returns length of a list. Len = ast.FunctionSym{"fn:list:len", 1} // Cons constructs a pair. Cons = ast.FunctionSym{"fn:list:cons", 2} // Pair constructs a pair. Pair = ast.FunctionSym{"fn:pair", 2} // MapGet is a function (Map, Key) which returns element at key. MapGet = ast.FunctionSym{"fn:map:get", 2} // StructGet is a function (Struct, Field) which returns specified field. StructGet = ast.FunctionSym{"fn:struct:get", 2} // Tuple acts either as identity (one argument), pair (two arguments) or nested pair (more). Tuple = ast.FunctionSym{"fn:tuple", -1} // Some constructs an element of an option type. Some = ast.FunctionSym{"fn:some", 1} // List constructs a list. List = ast.FunctionSym{"fn:list", -1} // Map constructs a map. Map = ast.FunctionSym{"fn:map", -1} // Struct constructs a struct. Struct = ast.FunctionSym{"fn:struct", -1} // FunType is a constructor for a function type. // fn:Fun(Res, Arg1, ..., ArgN) is Res <= Arg1, ..., ArgN FunType = ast.FunctionSym{"fn:Fun", -1} // RelType is a constructor for a relation type. RelType = ast.FunctionSym{"fn:Rel", -1} // NumberToString converts from ast.NumberType to ast.StringType NumberToString = ast.FunctionSym{"fn:number:to_string", 1} // Float64ToString converts from ast.Float64Type to ast.StringType Float64ToString = ast.FunctionSym{"fn:float64:to_string", 1} // NameToString converts from ast.NameType to ast.StringType NameToString = ast.FunctionSym{"fn:name:to_string", 1} // StringConcatenate concatenates the arguments into a single string constant. StringConcatenate = ast.FunctionSym{"fn:string:concat", -1} // PairType is a constructor for a pair type. PairType = ast.FunctionSym{"fn:Pair", 2} // TupleType is a type-level function that returns a tuple type out of pair types. TupleType = ast.FunctionSym{"fn:Tuple", -1} // OptionType is a constructor for an option type. // A value of fn:Option(T) is either fn:some(c) for c:T, or fn:none(). // TODO: Implement runtime representation. OptionType = ast.FunctionSym{"fn:Option", 1} // ListType is a constructor for a list type. ListType = ast.FunctionSym{"fn:List", 1} // MapType is a constructor for a map type. MapType = ast.FunctionSym{"fn:Map", 2} // StructType is a constructor for a struct type. StructType = ast.FunctionSym{"fn:Struct", -1} // UnionType is a constructor for a union type. UnionType = ast.FunctionSym{"fn:Union", -1} // Optional may appear inside StructType to indicate optional fields. Optional = ast.FunctionSym{"fn:opt", -1} // Package is an improper symbol, used to represent package declaration. Package = ast.PredicateSym{"Package", 0} // Use is an improper symbol, used to represent use declaration. Use = ast.PredicateSym{"Use", 0} // TypeConstructors is a list of function symbols used in structured type expressions. // Each name is mapped to the corresponding type constructor (a function at the level of types). TypeConstructors = map[string]ast.FunctionSym{ UnionType.Symbol: UnionType, ListType.Symbol: ListType, OptionType.Symbol: OptionType, PairType.Symbol: PairType, TupleType.Symbol: TupleType, MapType.Symbol: MapType, StructType.Symbol: StructType, FunType.Symbol: FunType, RelType.Symbol: RelType, } // EmptyType is a type without members. // TODO: replace with /bot EmptyType = ast.ApplyFn{UnionType, nil} // BuiltinRelations maps each builtin predicate to its argument range list BuiltinRelations = map[ast.PredicateSym]ast.BaseTerm{ MatchPrefix: NewRelType(ast.NameBound, ast.NameBound), StartsWith: NewRelType(ast.StringBound, ast.StringBound), EndsWith: NewRelType(ast.StringBound, ast.StringBound), Contains: NewRelType(ast.StringBound, ast.StringBound), Lt: NewRelType(ast.NumberBound, ast.NumberBound), Le: NewRelType(ast.NumberBound, ast.NumberBound), MatchNil: NewRelType(NewListType(ast.Variable{"X"})), MatchCons: NewRelType( NewListType(ast.Variable{"X"}), ast.Variable{"X"}, NewListType(ast.Variable{"X"})), MatchPair: NewRelType( NewPairType(ast.Variable{"X"}, ast.Variable{"Y"}), ast.Variable{"X"}, ast.Variable{"Y"}), MatchEntry: NewRelType( NewMapType(ast.AnyBound, ast.AnyBound), ast.AnyBound), MatchField: NewRelType( ast.AnyBound, ast.NameBound, ast.AnyBound), ListMember: NewRelType(ast.Variable{"X"}, NewListType(ast.Variable{"X"})), } )
Functions ¶
func CheckAndDesugar ¶
func CheckAndDesugar(decls map[ast.PredicateSym]ast.Decl) (map[ast.PredicateSym]*ast.Decl, error)
CheckAndDesugar rewrites a complete set of decls so that bound declarations contain only type bounds and unary predicate references are added to inclusion constraints.
func CheckFunTypeExpression ¶
CheckFunTypeExpression checks a function type expression.
func CheckSetExpression ¶
CheckSetExpression returns an error if expr is not a valid type expression. expr is by convention a type expression that talks about sets (no type variables, no function type subexpressions, no reltype).
func CheckTypeExpression ¶
CheckTypeExpression returns an error if expr is not a valid type expression. expr is by convention not a reltype.
func CreateListType ¶
CreateListType applies given type to a list.
func FunTypeArgs ¶
FunTypeArgs returns function arguments of function type.
func FunTypeResult ¶
FunTypeResult returns result type of function type.
func IsBaseTypeExpression ¶
IsBaseTypeExpression returns true if c is a base type expression. A name constant is /foo is not a base type expression.
func IsFunTypeExpression ¶
IsFunTypeExpression returns true if tpe is a UnionType.
func IsListTypeExpression ¶
IsListTypeExpression returns true if tpe is a ListType.
func IsMapTypeExpression ¶
IsMapTypeExpression returns true if tpe is a MapType.
func IsOptional ¶
IsOptional returns true if an argument of fn:Struct is an optional field.
func IsRelTypeExpression ¶
IsRelTypeExpression returns true if tpe is a RelType.
func IsStructTypeExpression ¶
IsStructTypeExpression returns true if tpe is a StructType.
func IsUnionTypeExpression ¶
IsUnionTypeExpression returns true if tpe is a UnionType.
func ListTypeArg ¶
ListTypeArg returns the type argument of a ListType.
func LowerBound ¶
LowerBound returns a lower bound of set expressions.
func MapTypeArgs ¶
MapTypeArgs returns the type arguments of a MapType.
func NewFunType ¶
NewFunType returns a new function type. Res <- Arg1, ..., ArgN
func NewListType ¶
NewListType returns a new ListType.
func NewMapType ¶
NewMapType returns a new MapType.
func NewOptionType ¶
NewOptionType returns a new ListType.
func NewPairType ¶
NewPairType returns a new PairType.
func NewRelType ¶
NewRelType returns a new relation type.
func NewStructType ¶
NewStructType returns a new StructType.
func NewTupleType ¶
NewTupleType returns a new TupleType.
func NewUnionType ¶
NewUnionType returns a new UnionType.
func RelTypeAlternatives ¶
RelTypeAlternatives converts a relation type expression to a list of alternatives relTypes.
func RelTypeArgs ¶
RelTypeArgs returns type arguments of a RelType.
func RelTypeExprFromDecl ¶
RelTypeExprFromDecl converts bounds to relation type expression.
func RelTypeFromAlternatives ¶
RelTypeFromAlternatives converts list of rel types bounds to union of relation types. It is assumed that each alternatives is a RelType. An empty list of alternatives corresponds to the empty type fn:Union().
func RemoveFromUnionType ¶
RemoveFromUnionType given T, removes S from a union type {..., S, ...} if S<:T.
func SetConforms ¶
SetConforms returns true if |- left <: right for set expression.
func StructTypeField ¶
StructTypeField returns field type for given field.
func StructTypeOptionaArgs ¶
StructTypeOptionaArgs returns type arguments of a StructType.
func StructTypeRequiredArgs ¶
StructTypeRequiredArgs returns type arguments of a StructType.
func TypeConforms ¶
TypeConforms returns true if ctx |- left <: right. The arguments left and right cannot be RelType or UnionType
func UnionTypeArgs ¶
UnionTypeArgs returns type arguments of a UnionType.
Types ¶
type NameTrie ¶
type NameTrie = *NameTrieNode
NameTrie is a trie for looking up name constants. Every node represents a unique part of a name. Note that the trie for {"/foo", "/foo/bar"} is different from {"/foo/bar"}: the former would map a constant "/foo/baz" to the type "/foo", whereas the latter would map it to type "/name". "/foo" appears as a node in both, but only the former treats it as a terminal node.
func NewNameTrie ¶
func NewNameTrie() NameTrie
NewNameTrie constructs a new NameTrie (representing empty prefix).
func (NameTrie) Collect ¶
Collect traverses a type expression and extracts names. Base type expressions are ignored.
func (NameTrie) LongestPrefix ¶
LongestPrefix returns index of the last element of longest prefix.
func (NameTrie) PrefixName ¶
PrefixName returns, for a given name constant, the longest prefix contained in the trie.
type NameTrieNode ¶
type NameTrieNode struct {
// contains filtered or unexported fields
}
NameTrieNode is a node in NameTrie.
type TypeHandle ¶
type TypeHandle struct {
// contains filtered or unexported fields
}
TypeHandle provides functionality related to type expression.
func NewSetHandle ¶
func NewSetHandle(expr ast.BaseTerm) (TypeHandle, error)
NewSetHandle constructs a TypeHandle for a (simple) monotype.
func NewTypeHandle ¶
NewTypeHandle constructs a TypeHandle.
func (TypeHandle) HasType ¶
func (t TypeHandle) HasType(c ast.Constant) bool
HasType returns true if c has type represented by this TypeHandle.
func (TypeHandle) String ¶
func (t TypeHandle) String() string
String returns a string represented of this type expression.