semantic

package
v0.44.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2019 License: MIT Imports: 15 Imported by: 21

Documentation

Overview

The semantic package provides a graph structure that represents the meaning of a Flux script. An AST is converted into a semantic graph for use with other systems. Using a semantic graph representation of the Flux, enables highlevel meaning to be specified programatically.

The semantic structures are to be designed to facilitate the interpretation and compilation of Flux.

For example since Flux uses the javascript AST structures, arguments to a function are represented as a single positional argument that is always an object expression. The semantic graph validates that the AST correctly follows these semantics, and use structures that are strongly typed for this expectation.

Index

Constants

View Source
const PackageMain = "main"

Variables

View Source
var EmptyArrayType = NewArrayType(Nil)

TODO(nathanielc): Make empty array types polymorphic over element type?

View Source
var EmptyObject = NewObjectType(nil)

Functions

func SortNodes added in v0.16.0

func SortNodes(nodes []Node)

SortNodes sorts a list of nodes by their source locations.

func Walk

func Walk(v Visitor, node Node)

Types

type Addable

type Addable struct{}

type Annotator

type Annotator struct {
	// contains filtered or unexported fields
}

Annotator implements Visitor to walk the graph.

func Annotate

func Annotate(node Node) Annotator

Annotate walks a graph and assigns each expression a type variable annotation.

func (Annotator) Done

func (v Annotator) Done(node Node)

func (Annotator) Visit

func (v Annotator) Visit(node Node) Visitor

type ArrayExpression

type ArrayExpression struct {
	Elements []Expression `json:"elements"`
	// contains filtered or unexported fields
}

func (*ArrayExpression) Copy

func (e *ArrayExpression) Copy() Node

func (ArrayExpression) Location

func (l ArrayExpression) Location() ast.SourceLocation

func (*ArrayExpression) MarshalJSON

func (e *ArrayExpression) MarshalJSON() ([]byte, error)

func (*ArrayExpression) NodeType

func (*ArrayExpression) NodeType() string

func (*ArrayExpression) UnmarshalJSON

func (e *ArrayExpression) UnmarshalJSON(data []byte) error

type Assignment added in v0.14.0

type Assignment interface {
	Statement
	// contains filtered or unexported methods
}

type BinaryExpression

type BinaryExpression struct {
	Operator ast.OperatorKind `json:"operator"`
	Left     Expression       `json:"left"`
	Right    Expression       `json:"right"`
	// contains filtered or unexported fields
}

func (*BinaryExpression) Copy

func (e *BinaryExpression) Copy() Node

func (BinaryExpression) Location

func (l BinaryExpression) Location() ast.SourceLocation

func (*BinaryExpression) MarshalJSON

func (e *BinaryExpression) MarshalJSON() ([]byte, error)

func (*BinaryExpression) NodeType

func (*BinaryExpression) NodeType() string

func (*BinaryExpression) UnmarshalJSON

func (e *BinaryExpression) UnmarshalJSON(data []byte) error

type Block added in v0.8.0

type Block struct {
	Body []Statement `json:"body"`
	// contains filtered or unexported fields
}

func (*Block) Copy added in v0.8.0

func (s *Block) Copy() Node

func (Block) Location added in v0.8.0

func (l Block) Location() ast.SourceLocation

func (*Block) MarshalJSON added in v0.8.0

func (s *Block) MarshalJSON() ([]byte, error)

func (*Block) NodeType added in v0.8.0

func (*Block) NodeType() string

func (*Block) ReturnStatement added in v0.8.0

func (s *Block) ReturnStatement() *ReturnStatement

func (*Block) UnmarshalJSON added in v0.8.0

func (s *Block) UnmarshalJSON(data []byte) error

type BooleanLiteral

type BooleanLiteral struct {
	Value bool `json:"value"`
	// contains filtered or unexported fields
}

func (*BooleanLiteral) Copy

func (l *BooleanLiteral) Copy() Node

func (BooleanLiteral) Location

func (l BooleanLiteral) Location() ast.SourceLocation

func (*BooleanLiteral) MarshalJSON

func (l *BooleanLiteral) MarshalJSON() ([]byte, error)

func (*BooleanLiteral) NodeType

func (*BooleanLiteral) NodeType() string

type BuiltinStatement added in v0.14.0

type BuiltinStatement struct {
	ID *Identifier `json:"id"`
	// contains filtered or unexported fields
}

func (*BuiltinStatement) Copy added in v0.14.0

func (s *BuiltinStatement) Copy() Node

func (BuiltinStatement) Location added in v0.14.0

func (l BuiltinStatement) Location() ast.SourceLocation

func (*BuiltinStatement) MarshalJSON added in v0.14.0

func (s *BuiltinStatement) MarshalJSON() ([]byte, error)

func (*BuiltinStatement) NodeType added in v0.14.0

func (s *BuiltinStatement) NodeType() string

type CallExpression

type CallExpression struct {
	Callee    Expression        `json:"callee"`
	Arguments *ObjectExpression `json:"arguments"`
	Pipe      Expression        `json:"pipe,omitempty"`
	// contains filtered or unexported fields
}

func (*CallExpression) Copy

func (e *CallExpression) Copy() Node

func (CallExpression) Location

func (l CallExpression) Location() ast.SourceLocation

func (*CallExpression) MarshalJSON

func (e *CallExpression) MarshalJSON() ([]byte, error)

func (*CallExpression) NodeType

func (*CallExpression) NodeType() string

func (*CallExpression) UnmarshalJSON

func (e *CallExpression) UnmarshalJSON(data []byte) error

type Comparable

type Comparable struct{}

type ConditionalExpression

type ConditionalExpression struct {
	Test       Expression `json:"test"`
	Alternate  Expression `json:"alternate"`
	Consequent Expression `json:"consequent"`
	// contains filtered or unexported fields
}

func (*ConditionalExpression) Copy

func (e *ConditionalExpression) Copy() Node

func (ConditionalExpression) Location

func (l ConditionalExpression) Location() ast.SourceLocation

func (*ConditionalExpression) MarshalJSON

func (e *ConditionalExpression) MarshalJSON() ([]byte, error)

func (*ConditionalExpression) NodeType

func (*ConditionalExpression) NodeType() string

func (*ConditionalExpression) UnmarshalJSON

func (e *ConditionalExpression) UnmarshalJSON(data []byte) error

type ConstraintGenerator

type ConstraintGenerator struct {
	// contains filtered or unexported fields
}

ConstraintGenerator implements NestingVisitor and generates constraints as it walks the graph.

func (ConstraintGenerator) Done

func (v ConstraintGenerator) Done(node Node)

Done visits nodes after all children of the node have been visited.

func (ConstraintGenerator) Nest

Nest nests the internal type environment to obey scoping rules.

func (ConstraintGenerator) Visit

func (v ConstraintGenerator) Visit(node Node) Visitor

Visit visits each node, the algorithm is depth first so nothing is performed in Visit except for an error check.

type Constraints

type Constraints struct {
	// contains filtered or unexported fields
}

Constraints is a set of constraints.

func GenerateConstraints

func GenerateConstraints(node Node, annotator Annotator, importer Importer) (*Constraints, error)

GenerateConstraints walks the graph and generates constraints between type vairables provided in the annotations.

func (*Constraints) AddKindConst

func (c *Constraints) AddKindConst(tv Tvar, k Kind)

func (*Constraints) AddTypeConst

func (c *Constraints) AddTypeConst(l, r PolyType, loc ast.SourceLocation)

func (*Constraints) Copy

func (c *Constraints) Copy() *Constraints

func (*Constraints) Instantiate

func (c *Constraints) Instantiate(s Scheme, loc ast.SourceLocation) (t PolyType)

Instantiate produces a new poly type where the free variables from the scheme have been made fresh. This way each new instantiation of a scheme is independent of the other but all have the same constraint structure.

func (*Constraints) String

func (c *Constraints) String() string

type DateTimeLiteral

type DateTimeLiteral struct {
	Value time.Time `json:"value"`
	// contains filtered or unexported fields
}

func (*DateTimeLiteral) Copy

func (l *DateTimeLiteral) Copy() Node

func (DateTimeLiteral) Location

func (l DateTimeLiteral) Location() ast.SourceLocation

func (*DateTimeLiteral) MarshalJSON

func (l *DateTimeLiteral) MarshalJSON() ([]byte, error)

func (*DateTimeLiteral) NodeType

func (*DateTimeLiteral) NodeType() string

type DurationLiteral

type DurationLiteral struct {
	Value time.Duration `json:"value"`
	// contains filtered or unexported fields
}

func (*DurationLiteral) Copy

func (l *DurationLiteral) Copy() Node

func (DurationLiteral) Location

func (l DurationLiteral) Location() ast.SourceLocation

func (*DurationLiteral) MarshalJSON

func (l *DurationLiteral) MarshalJSON() ([]byte, error)

func (*DurationLiteral) NodeType

func (*DurationLiteral) NodeType() string

func (*DurationLiteral) UnmarshalJSON

func (l *DurationLiteral) UnmarshalJSON(data []byte) error

type Env

type Env struct {
	// contains filtered or unexported fields
}

Env is a type environment mapping identifiers in scope to their type schemes.

func NewEnv

func NewEnv() *Env

func (*Env) LocalLookup

func (e *Env) LocalLookup(ident string) (Scheme, bool)

LocalLookup search for the identifier in the local scope only, it does not recurse to parents.

func (*Env) Lookup

func (e *Env) Lookup(ident string) (Scheme, bool)

Lookup searchs for the closest identifier in scope.

func (*Env) Nest

func (e *Env) Nest() *Env

Nest creates a child env.

func (*Env) RangeSet

func (e *Env) RangeSet(f func(k string, v Scheme) Scheme)

RangeSet updates the env recursing through parents.

func (*Env) Set

func (e *Env) Set(ident string, s Scheme)

Set writes the scheme to the scope with the identifier.

type Expression

type Expression interface {
	Node
	// contains filtered or unexported methods
}

func ConjunctionsToExprSlice

func ConjunctionsToExprSlice(expr Expression) []Expression

ConjunctionsToExprSlice finds all children of AndOperators that are not themselves AndOperators, and returns them in a slice. If the root node of expr is not an AndOperator, just returns expr.

    AND
   /   \
  AND   r    =>   {p, q, r}
 /   \
p     q

func ExprsToConjunction

func ExprsToConjunction(exprs ...Expression) Expression

ExprsToConjunction accepts a variable number of expressions and ANDs them together into a single expression.

                     AND
                    /   \
{p, q, r}    =>    AND   r
                  /   \
                 p     q

func PartitionPredicates

func PartitionPredicates(expr Expression, partitionFn func(expression Expression) (bool, error)) (passExpr, failExpr Expression, err error)

PartitionPredicates accepts a predicate expression, separates it into components that have been logically ANDed together, and applies partitionFn to them. Returns two expressions: one AND tree of the expressions for which partitionFn returned true, and an AND tree of expressions for which partitionFn returned false.

Suppose partitonFn returns true for p and r, and false for q:

    AND           passExpr     failExpr
   /   \
  AND   r    =>     AND           q
 /   \             /   \
p     q           p     r

type ExpressionStatement

type ExpressionStatement struct {
	Expression Expression `json:"expression"`
	// contains filtered or unexported fields
}

func (*ExpressionStatement) Copy

func (s *ExpressionStatement) Copy() Node

func (ExpressionStatement) Location

func (l ExpressionStatement) Location() ast.SourceLocation

func (*ExpressionStatement) MarshalJSON

func (s *ExpressionStatement) MarshalJSON() ([]byte, error)

func (*ExpressionStatement) NodeType

func (*ExpressionStatement) NodeType() string

func (*ExpressionStatement) UnmarshalJSON

func (s *ExpressionStatement) UnmarshalJSON(data []byte) error

type Extern

type Extern struct {
	Assignments []*ExternalVariableAssignment `json:"assignments"`
	Block       *ExternBlock                  `json:"block"`
	// contains filtered or unexported fields
}

Extern is a node that represents a node with a set of external assignments defined.

func (*Extern) Copy

func (e *Extern) Copy() Node

func (Extern) Location

func (l Extern) Location() ast.SourceLocation

func (*Extern) MarshalJSON

func (e *Extern) MarshalJSON() ([]byte, error)

func (*Extern) NodeType

func (*Extern) NodeType() string

type ExternBlock

type ExternBlock struct {
	Node Node
	// contains filtered or unexported fields
}

ExternBlock is a node that represents a node with a set of external declarations defined.

func (*ExternBlock) Copy

func (e *ExternBlock) Copy() Node

func (ExternBlock) Location

func (l ExternBlock) Location() ast.SourceLocation

func (*ExternBlock) MarshalJSON

func (e *ExternBlock) MarshalJSON() ([]byte, error)

func (*ExternBlock) NodeType

func (*ExternBlock) NodeType() string

func (*ExternBlock) UnmarshalJSON

func (e *ExternBlock) UnmarshalJSON(data []byte) error

type ExternalVariableAssignment added in v0.8.0

type ExternalVariableAssignment struct {
	Identifier *Identifier `json:"identifier"`
	ExternType PolyType    `json:""`
	// contains filtered or unexported fields
}

ExternalVariableAssignment represents an externaly defined identifier and its type.

func (*ExternalVariableAssignment) Copy added in v0.8.0

func (s *ExternalVariableAssignment) Copy() Node

func (ExternalVariableAssignment) Location added in v0.8.0

func (l ExternalVariableAssignment) Location() ast.SourceLocation

func (*ExternalVariableAssignment) MarshalJSON added in v0.8.0

func (d *ExternalVariableAssignment) MarshalJSON() ([]byte, error)

func (*ExternalVariableAssignment) NodeType added in v0.8.0

func (*ExternalVariableAssignment) NodeType() string

type File added in v0.13.0

type File struct {
	Package *PackageClause       `json:"package"`
	Imports []*ImportDeclaration `json:"imports"`
	Body    []Statement          `json:"body"`
	// contains filtered or unexported fields
}

func (*File) Copy added in v0.13.0

func (p *File) Copy() Node

func (File) Location added in v0.13.0

func (l File) Location() ast.SourceLocation

func (*File) MarshalJSON added in v0.13.0

func (p *File) MarshalJSON() ([]byte, error)

func (*File) NodeType added in v0.13.0

func (*File) NodeType() string

func (*File) UnmarshalJSON added in v0.13.0

func (p *File) UnmarshalJSON(data []byte) error

type FloatLiteral

type FloatLiteral struct {
	Value float64 `json:"value"`
	// contains filtered or unexported fields
}

func (*FloatLiteral) Copy

func (l *FloatLiteral) Copy() Node

func (FloatLiteral) Location

func (l FloatLiteral) Location() ast.SourceLocation

func (*FloatLiteral) MarshalJSON

func (l *FloatLiteral) MarshalJSON() ([]byte, error)

func (*FloatLiteral) NodeType

func (*FloatLiteral) NodeType() string

type Fresher

type Fresher interface {
	// Fresh produces a new unused type variable.
	Fresh() Tvar
}

Fresher produces fresh type variables.

func NewFresher

func NewFresher() Fresher

type FunctionBlock

type FunctionBlock struct {
	Parameters *FunctionParameters `json:"parameters"`
	Body       Node                `json:"body"`
	// contains filtered or unexported fields
}

FunctionBlock represents the function parameters and the function body.

func (*FunctionBlock) Copy

func (b *FunctionBlock) Copy() Node

func (FunctionBlock) Location

func (l FunctionBlock) Location() ast.SourceLocation

func (*FunctionBlock) MarshalJSON

func (e *FunctionBlock) MarshalJSON() ([]byte, error)

func (*FunctionBlock) NodeType

func (*FunctionBlock) NodeType() string

func (*FunctionBlock) UnmarshalJSON

func (e *FunctionBlock) UnmarshalJSON(data []byte) error

type FunctionExpression

type FunctionExpression struct {
	Defaults *ObjectExpression `json:"defaults,omitempty"`
	Block    *FunctionBlock    `json:"block"`
	// contains filtered or unexported fields
}

FunctionExpression represents the definition of a function

func (*FunctionExpression) Copy

func (e *FunctionExpression) Copy() Node

func (FunctionExpression) Location

func (l FunctionExpression) Location() ast.SourceLocation

func (*FunctionExpression) MarshalJSON

func (e *FunctionExpression) MarshalJSON() ([]byte, error)

func (*FunctionExpression) NodeType

func (*FunctionExpression) NodeType() string

type FunctionParameter

type FunctionParameter struct {
	Key *Identifier `json:"key"`
	// contains filtered or unexported fields
}

FunctionParameter represents a function parameter.

func (*FunctionParameter) Copy

func (p *FunctionParameter) Copy() Node

func (FunctionParameter) Location

func (l FunctionParameter) Location() ast.SourceLocation

func (*FunctionParameter) MarshalJSON

func (e *FunctionParameter) MarshalJSON() ([]byte, error)

func (*FunctionParameter) NodeType

func (*FunctionParameter) NodeType() string

type FunctionParameters

type FunctionParameters struct {
	List []*FunctionParameter `json:"list"`
	Pipe *Identifier          `json:"pipe"`
	// contains filtered or unexported fields
}

FunctionParameters represents the list of function parameters and which if any parameter is the pipe parameter.

func (*FunctionParameters) Copy

func (p *FunctionParameters) Copy() Node

func (FunctionParameters) Location

func (l FunctionParameters) Location() ast.SourceLocation

func (*FunctionParameters) MarshalJSON

func (e *FunctionParameters) MarshalJSON() ([]byte, error)

func (*FunctionParameters) NodeType

func (*FunctionParameters) NodeType() string

type FunctionPolySignature

type FunctionPolySignature struct {
	Parameters   map[string]PolyType
	Required     LabelSet
	Return       PolyType
	PipeArgument string
}

type FunctionSignature

type FunctionSignature struct {
	Parameters   map[string]Type
	Required     []string
	Return       Type
	PipeArgument string
}

type Identifier

type Identifier struct {
	Name string `json:"name"`
	// contains filtered or unexported fields
}

func (*Identifier) Copy

func (i *Identifier) Copy() Node

func (*Identifier) Key added in v0.12.0

func (n *Identifier) Key() string

func (Identifier) Location

func (l Identifier) Location() ast.SourceLocation

func (*Identifier) MarshalJSON

func (i *Identifier) MarshalJSON() ([]byte, error)

func (*Identifier) NodeType

func (*Identifier) NodeType() string

type IdentifierExpression

type IdentifierExpression struct {
	Name string `json:"name"`
	// contains filtered or unexported fields
}

func (*IdentifierExpression) Copy

func (e *IdentifierExpression) Copy() Node

func (IdentifierExpression) Location

func (l IdentifierExpression) Location() ast.SourceLocation

func (*IdentifierExpression) MarshalJSON

func (e *IdentifierExpression) MarshalJSON() ([]byte, error)

func (*IdentifierExpression) NodeType

func (*IdentifierExpression) NodeType() string

type ImportDeclaration added in v0.8.0

type ImportDeclaration struct {
	As   *Identifier    `json:"as"`
	Path *StringLiteral `json:"path"`
	// contains filtered or unexported fields
}

func (*ImportDeclaration) Copy added in v0.8.0

func (d *ImportDeclaration) Copy() Node

func (ImportDeclaration) Location added in v0.8.0

func (l ImportDeclaration) Location() ast.SourceLocation

func (*ImportDeclaration) MarshalJSON added in v0.8.0

func (p *ImportDeclaration) MarshalJSON() ([]byte, error)

func (*ImportDeclaration) NodeType added in v0.8.0

func (*ImportDeclaration) NodeType() string

type Importer added in v0.8.0

type Importer interface {
	Import(path string) (PackageType, bool)
}

Importer produces a package given an import path.

type IndexExpression added in v0.7.1

type IndexExpression struct {
	Array Expression `json:"array"`
	Index Expression `json:"index"`
	// contains filtered or unexported fields
}

func (*IndexExpression) Copy added in v0.7.1

func (e *IndexExpression) Copy() Node

func (IndexExpression) Location added in v0.7.1

func (l IndexExpression) Location() ast.SourceLocation

func (*IndexExpression) MarshalJSON added in v0.7.1

func (e *IndexExpression) MarshalJSON() ([]byte, error)

func (*IndexExpression) NodeType added in v0.7.1

func (*IndexExpression) NodeType() string

func (*IndexExpression) UnmarshalJSON added in v0.7.1

func (e *IndexExpression) UnmarshalJSON(data []byte) error

type IntegerLiteral

type IntegerLiteral struct {
	Value int64 `json:"value"`
	// contains filtered or unexported fields
}

func (*IntegerLiteral) Copy

func (l *IntegerLiteral) Copy() Node

func (IntegerLiteral) Location

func (l IntegerLiteral) Location() ast.SourceLocation

func (*IntegerLiteral) MarshalJSON

func (l *IntegerLiteral) MarshalJSON() ([]byte, error)

func (*IntegerLiteral) NodeType

func (*IntegerLiteral) NodeType() string

func (*IntegerLiteral) UnmarshalJSON

func (l *IntegerLiteral) UnmarshalJSON(data []byte) error

type InterpolatedPart added in v0.41.0

type InterpolatedPart struct {
	Expression Expression `json:"expression"`
	// contains filtered or unexported fields
}

func (*InterpolatedPart) Copy added in v0.41.0

func (p *InterpolatedPart) Copy() Node

func (InterpolatedPart) Location added in v0.41.0

func (l InterpolatedPart) Location() ast.SourceLocation

func (*InterpolatedPart) MarshalJSON added in v0.41.0

func (e *InterpolatedPart) MarshalJSON() ([]byte, error)

func (*InterpolatedPart) NodeType added in v0.41.0

func (*InterpolatedPart) NodeType() string

func (*InterpolatedPart) UnmarshalJSON added in v0.41.0

func (e *InterpolatedPart) UnmarshalJSON(data []byte) error

type KClass

type KClass struct{}

func (KClass) MonoType

func (k KClass) MonoType() (Type, bool)

type Kind

type Kind interface {
	TypeExpression
	// contains filtered or unexported methods
}

Kind is a constraint in the kind domain.

type KindConstrainter

type KindConstrainter interface {
	KindConstraint() Kind
}

type LabelSet

type LabelSet []string

LabelSet is a set of string labels.

func AllLabels

func AllLabels() LabelSet

AllLabels returns a label set that represents the infinite set of all possible string labels.

func (LabelSet) String

func (s LabelSet) String() string

type Literal

type Literal interface {
	Expression
	// contains filtered or unexported methods
}

type LogicalExpression

type LogicalExpression struct {
	Operator ast.LogicalOperatorKind `json:"operator"`
	Left     Expression              `json:"left"`
	Right    Expression              `json:"right"`
	// contains filtered or unexported fields
}

func (*LogicalExpression) Copy

func (e *LogicalExpression) Copy() Node

func (LogicalExpression) Location

func (l LogicalExpression) Location() ast.SourceLocation

func (*LogicalExpression) MarshalJSON

func (e *LogicalExpression) MarshalJSON() ([]byte, error)

func (*LogicalExpression) NodeType

func (*LogicalExpression) NodeType() string

func (*LogicalExpression) UnmarshalJSON

func (e *LogicalExpression) UnmarshalJSON(data []byte) error

type MemberAssignment added in v0.14.0

type MemberAssignment struct {
	Member *MemberExpression `json:"member"`
	Init   Expression        `json:"init"`
	// contains filtered or unexported fields
}

func (*MemberAssignment) Copy added in v0.14.0

func (s *MemberAssignment) Copy() Node

func (MemberAssignment) Location added in v0.14.0

func (l MemberAssignment) Location() ast.SourceLocation

func (*MemberAssignment) MarshalJSON added in v0.14.0

func (s *MemberAssignment) MarshalJSON() ([]byte, error)

func (*MemberAssignment) NodeType added in v0.14.0

func (*MemberAssignment) NodeType() string

func (*MemberAssignment) UnmarshalJSON added in v0.14.0

func (s *MemberAssignment) UnmarshalJSON(data []byte) error

type MemberExpression

type MemberExpression struct {
	Object   Expression `json:"object"`
	Property string     `json:"property"`
	// contains filtered or unexported fields
}

func (*MemberExpression) Copy

func (e *MemberExpression) Copy() Node

func (MemberExpression) Location

func (l MemberExpression) Location() ast.SourceLocation

func (*MemberExpression) MarshalJSON

func (e *MemberExpression) MarshalJSON() ([]byte, error)

func (*MemberExpression) NodeType

func (*MemberExpression) NodeType() string

func (*MemberExpression) UnmarshalJSON

func (e *MemberExpression) UnmarshalJSON(data []byte) error

type NativeVariableAssignment added in v0.8.0

type NativeVariableAssignment struct {
	Identifier *Identifier `json:"identifier"`
	Init       Expression  `json:"init"`
	// contains filtered or unexported fields
}

func (*NativeVariableAssignment) Copy added in v0.8.0

func (s *NativeVariableAssignment) Copy() Node

func (NativeVariableAssignment) Location added in v0.8.0

func (l NativeVariableAssignment) Location() ast.SourceLocation

func (*NativeVariableAssignment) MarshalJSON added in v0.8.0

func (d *NativeVariableAssignment) MarshalJSON() ([]byte, error)

func (*NativeVariableAssignment) NodeType added in v0.8.0

func (*NativeVariableAssignment) NodeType() string

func (*NativeVariableAssignment) UnmarshalJSON added in v0.8.0

func (d *NativeVariableAssignment) UnmarshalJSON(data []byte) error

type Nature

type Nature int

Nature is the primitive description of a type.

const (
	Invalid Nature = iota
	Nil
	String
	Bytes
	Int
	UInt
	Float
	Bool
	Time
	Duration
	Regexp
	Array
	Object
	Function
)

func (Nature) ElementType

func (n Nature) ElementType() Type

func (Nature) Equal

func (n Nature) Equal(t PolyType) bool

func (Nature) FunctionSignature

func (n Nature) FunctionSignature() FunctionSignature

func (Nature) MonoType

func (n Nature) MonoType() (Type, bool)

func (Nature) Nature

func (n Nature) Nature() Nature

func (Nature) PolyType

func (n Nature) PolyType() PolyType

func (Nature) Properties

func (n Nature) Properties() map[string]Type

func (Nature) PropertyType

func (n Nature) PropertyType(name string) Type

func (Nature) String

func (n Nature) String() string

type NestingVisitor

type NestingVisitor interface {
	Visitor
	Nest() NestingVisitor
}

type Node

type Node interface {
	NodeType() string
	Copy() Node

	Location() ast.SourceLocation

	json.Marshaler
	// contains filtered or unexported methods
}

func UnmarshalNode

func UnmarshalNode(data []byte) (Node, error)

type NullableKind added in v0.33.0

type NullableKind struct {
	T PolyType
}

NullableKind indicates that it is possible for this variable to be the null type if no other type is more appropriate.

func (NullableKind) MonoType added in v0.33.0

func (n NullableKind) MonoType() (Type, bool)

type NullableTvar added in v0.40.0

type NullableTvar struct {
	Tvar
}

NullableTvar is a type variable that might be null. If a type variable is constrained to be nullable (via the NullableKind), in order to preserve that constraint when resolving the type, we return a NullableTvar.

TODO: This is a temporary type that will be removed once kind constraints can be expressed in the language of types. Unfortunately right now, external packages like the compiler don't have any notion of kind constraints.

func (NullableTvar) Equal added in v0.40.0

func (t NullableTvar) Equal(p PolyType) bool

func (NullableTvar) MonoType added in v0.40.0

func (NullableTvar) MonoType() (Type, bool)

func (NullableTvar) Nature added in v0.40.0

func (NullableTvar) Nature() Nature

func (NullableTvar) String added in v0.40.0

func (t NullableTvar) String() string

type Number

type Number struct{}

type ObjectExpression

type ObjectExpression struct {
	With       *IdentifierExpression `json:"with,omitempty"`
	Properties []*Property           `json:"properties"`
	// contains filtered or unexported fields
}

func (*ObjectExpression) Copy

func (e *ObjectExpression) Copy() Node

func (ObjectExpression) Location

func (l ObjectExpression) Location() ast.SourceLocation

func (*ObjectExpression) MarshalJSON

func (e *ObjectExpression) MarshalJSON() ([]byte, error)

func (*ObjectExpression) NodeType

func (*ObjectExpression) NodeType() string

type ObjectKind added in v0.7.1

type ObjectKind struct {
	// contains filtered or unexported fields
}

func (ObjectKind) MonoType added in v0.7.1

func (k ObjectKind) MonoType() (Type, bool)

func (ObjectKind) String added in v0.7.1

func (k ObjectKind) String() string

type OptionStatement

type OptionStatement struct {
	Assignment Assignment `json:"assignment"`
	// contains filtered or unexported fields
}

func (*OptionStatement) Copy

func (s *OptionStatement) Copy() Node

func (OptionStatement) Location

func (l OptionStatement) Location() ast.SourceLocation

func (*OptionStatement) MarshalJSON

func (s *OptionStatement) MarshalJSON() ([]byte, error)

func (*OptionStatement) NodeType

func (s *OptionStatement) NodeType() string

func (*OptionStatement) UnmarshalJSON

func (s *OptionStatement) UnmarshalJSON(data []byte) error

type Package added in v0.8.0

type Package struct {
	Package string  `json:"package"`
	Files   []*File `json:"files"`
	// contains filtered or unexported fields
}

func New

func New(pkg *ast.Package) (*Package, error)

New creates a semantic graph from the provided AST

func (*Package) Copy added in v0.13.0

func (p *Package) Copy() Node

func (Package) Location added in v0.13.0

func (l Package) Location() ast.SourceLocation

func (*Package) MarshalJSON added in v0.13.0

func (p *Package) MarshalJSON() ([]byte, error)

func (*Package) NodeType added in v0.13.0

func (*Package) NodeType() string

type PackageClause added in v0.8.0

type PackageClause struct {
	Name *Identifier `json:"name"`
	// contains filtered or unexported fields
}

func (*PackageClause) Copy added in v0.8.0

func (p *PackageClause) Copy() Node

func (PackageClause) Location added in v0.8.0

func (l PackageClause) Location() ast.SourceLocation

func (*PackageClause) MarshalJSON added in v0.8.0

func (p *PackageClause) MarshalJSON() ([]byte, error)

func (*PackageClause) NodeType added in v0.8.0

func (*PackageClause) NodeType() string

type PackageType added in v0.13.0

type PackageType struct {
	Name string
	Type PolyType
}

PackageType represents the type and name of a package.

func CreatePackage added in v0.8.0

func CreatePackage(n Node, importer Importer) (PackageType, error)

CreatePackage constructs a Package from the node. The node must contain a Program node with a valid PackageClause

type PolyType

type PolyType interface {
	TypeExpression

	// Equal reports if two types are the same.
	Equal(PolyType) bool

	// Nature reports the primitive description of the type.
	Nature() Nature
	// contains filtered or unexported methods
}

PolyType represents a polymorphic type, meaning that the type may have multiple free type variables.

func NewArrayPolyType

func NewArrayPolyType(elementType PolyType) PolyType

func NewEmptyObjectPolyType

func NewEmptyObjectPolyType() PolyType

func NewFunctionPolyType

func NewFunctionPolyType(sig FunctionPolySignature) PolyType

func NewObjectPolyType

func NewObjectPolyType(properties map[string]PolyType, lower, upper LabelSet) PolyType

NewObjectPolyType creates a PolyType representing an object. A map of properties and their types may be provided. Lower is a set of labels that must exist on the object, and upper is a set of labels that may exist on the object. Upper must be a superset of lower. The map must contain an entry for all lables in the lower set. Use AllLabels() to represent the infinite set of all possible labels.

type Property

type Property struct {
	Key   PropertyKey `json:"key"`
	Value Expression  `json:"value"`
	// contains filtered or unexported fields
}

func (*Property) Copy

func (p *Property) Copy() Node

func (Property) Location

func (l Property) Location() ast.SourceLocation

func (*Property) MarshalJSON

func (p *Property) MarshalJSON() ([]byte, error)

func (*Property) NodeType

func (*Property) NodeType() string

func (*Property) UnmarshalJSON

func (p *Property) UnmarshalJSON(data []byte) error

type PropertyKey added in v0.12.0

type PropertyKey interface {
	Node
	Key() string
}

type RegexpLiteral

type RegexpLiteral struct {
	Value *regexp.Regexp `json:"value"`
	// contains filtered or unexported fields
}

func (*RegexpLiteral) Copy

func (l *RegexpLiteral) Copy() Node

func (RegexpLiteral) Location

func (l RegexpLiteral) Location() ast.SourceLocation

func (*RegexpLiteral) MarshalJSON

func (l *RegexpLiteral) MarshalJSON() ([]byte, error)

func (*RegexpLiteral) NodeType

func (*RegexpLiteral) NodeType() string

func (*RegexpLiteral) UnmarshalJSON

func (l *RegexpLiteral) UnmarshalJSON(data []byte) error

type ReturnStatement

type ReturnStatement struct {
	Argument Expression `json:"argument"`
	// contains filtered or unexported fields
}

func (*ReturnStatement) Copy

func (s *ReturnStatement) Copy() Node

func (ReturnStatement) Location

func (l ReturnStatement) Location() ast.SourceLocation

func (*ReturnStatement) MarshalJSON

func (s *ReturnStatement) MarshalJSON() ([]byte, error)

func (*ReturnStatement) NodeType

func (*ReturnStatement) NodeType() string

func (*ReturnStatement) UnmarshalJSON

func (s *ReturnStatement) UnmarshalJSON(data []byte) error

type Scheme

type Scheme struct {
	T    PolyType
	Free TvarSet
}

func (Scheme) Substitute

func (s Scheme) Substitute(tv Tvar, t PolyType) Scheme

type ScopedVisitor

type ScopedVisitor struct {
	// contains filtered or unexported fields
}

ScopedVisitor will nest the given visitor when the scope changes.

func NewScopedVisitor

func NewScopedVisitor(v NestingVisitor) ScopedVisitor

func (ScopedVisitor) Done

func (v ScopedVisitor) Done(node Node)

func (ScopedVisitor) Visit

func (v ScopedVisitor) Visit(node Node) Visitor

type Solution

type Solution struct {
	// contains filtered or unexported fields
}

Solution implement TypeSolution and solves the unification problem.

func (*Solution) AddConstraint

func (s *Solution) AddConstraint(l, r PolyType) error

func (*Solution) Fresh

func (s *Solution) Fresh() Tvar

func (*Solution) FreshSolution

func (s *Solution) FreshSolution() TypeSolution

func (*Solution) PolyTypeOf

func (s *Solution) PolyTypeOf(n Node) (PolyType, error)

func (*Solution) TypeOf

func (s *Solution) TypeOf(n Node) (Type, error)

type SolutionMap added in v0.16.0

type SolutionMap map[Node]PolyType

SolutionMap represents a mapping of nodes to their poly types.

func CreateSolutionMap added in v0.16.0

func CreateSolutionMap(node Node, sol TypeSolution) SolutionMap

CreateSolutionMap constructs a new solution map from the nodes and type solution. Any type errors in the type solution are ignored.

func (SolutionMap) String added in v0.16.0

func (s SolutionMap) String() string

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

type StringExpression added in v0.41.0

type StringExpression struct {
	Parts []StringExpressionPart `json:"parts"`
	// contains filtered or unexported fields
}

func (*StringExpression) Copy added in v0.41.0

func (e *StringExpression) Copy() Node

func (StringExpression) Location added in v0.41.0

func (l StringExpression) Location() ast.SourceLocation

func (*StringExpression) MarshalJSON added in v0.41.0

func (e *StringExpression) MarshalJSON() ([]byte, error)

func (*StringExpression) NodeType added in v0.41.0

func (*StringExpression) NodeType() string

func (*StringExpression) UnmarshalJSON added in v0.41.0

func (e *StringExpression) UnmarshalJSON(data []byte) error

type StringExpressionPart added in v0.41.0

type StringExpressionPart interface {
	Node
	// contains filtered or unexported methods
}

type StringLiteral

type StringLiteral struct {
	Value string `json:"value"`
	// contains filtered or unexported fields
}

func (*StringLiteral) Copy

func (l *StringLiteral) Copy() Node

func (*StringLiteral) Key added in v0.12.0

func (n *StringLiteral) Key() string

func (StringLiteral) Location

func (l StringLiteral) Location() ast.SourceLocation

func (*StringLiteral) MarshalJSON

func (l *StringLiteral) MarshalJSON() ([]byte, error)

func (*StringLiteral) NodeType

func (*StringLiteral) NodeType() string

type Substitution

type Substitution map[Tvar]PolyType

Substitution is a mapping of type variables to a poly type.

func (Substitution) ApplyEnv

func (s Substitution) ApplyEnv(env *Env) *Env

func (Substitution) ApplyKind

func (s Substitution) ApplyKind(k Kind) Kind

func (Substitution) ApplyScheme

func (s Substitution) ApplyScheme(ts Scheme) Scheme

func (Substitution) ApplyTvar

func (s Substitution) ApplyTvar(tv Tvar) Tvar

func (Substitution) ApplyType

func (s Substitution) ApplyType(t PolyType) PolyType

func (Substitution) Merge

func (l Substitution) Merge(r Substitution)

Merge r into l.

func (Substitution) String

func (s Substitution) String() string

type TestStatement added in v0.19.0

type TestStatement struct {
	Assignment *NativeVariableAssignment `json:"assignment"`
	// contains filtered or unexported fields
}

func (*TestStatement) Copy added in v0.19.0

func (s *TestStatement) Copy() Node

func (TestStatement) Location added in v0.19.0

func (l TestStatement) Location() ast.SourceLocation

func (*TestStatement) MarshalJSON added in v0.19.0

func (s *TestStatement) MarshalJSON() ([]byte, error)

func (*TestStatement) NodeType added in v0.19.0

func (s *TestStatement) NodeType() string

type TextPart added in v0.41.0

type TextPart struct {
	Value string `json:"value"`
	// contains filtered or unexported fields
}

func (*TextPart) Copy added in v0.41.0

func (p *TextPart) Copy() Node

func (TextPart) Location added in v0.41.0

func (l TextPart) Location() ast.SourceLocation

func (*TextPart) MarshalJSON added in v0.41.0

func (e *TextPart) MarshalJSON() ([]byte, error)

func (*TextPart) NodeType added in v0.41.0

func (*TextPart) NodeType() string

func (*TextPart) UnmarshalJSON added in v0.41.0

func (e *TextPart) UnmarshalJSON(data []byte) error

type Tvar

type Tvar int

Tvar represents a type variable meaning its type could be any possible type.

func (Tvar) Equal

func (tv Tvar) Equal(t PolyType) bool

func (Tvar) MonoType

func (tv Tvar) MonoType() (Type, bool)

func (Tvar) Nature

func (tv Tvar) Nature() Nature

func (Tvar) String

func (tv Tvar) String() string

type TvarSet

type TvarSet []Tvar

TvarSet is a set of type variables.

type Type

type Type interface {
	// Nature returns the specific primitive description of this type.
	Nature() Nature

	// PropertyType returns the type of a given property.
	// It panics if the type's Kind is not Object
	PropertyType(name string) Type

	// Properties returns a map of all property types.
	// It panics if the type's Kind is not Object
	Properties() map[string]Type

	// ElementType return the type of elements in the array.
	// It panics if the type's Kind is not Array.
	ElementType() Type

	// FunctionSignature returns the function signature of this type.
	// It panics if the type's Kind is not Function.
	FunctionSignature() FunctionSignature

	PolyType() PolyType
	// contains filtered or unexported methods
}

Type is the representation of a Flux type. Type is a monomorphic, meaning that it represents a single type and is not polymorphic. See PolyType for polymorphic types.

Type values are comparable and as such can be used as map keys and directly comparison using the == operator. Two types are equal if they represent identical types.

Do NOT embed this type into other interfaces or structs as that will invalidate the comparison properties of the interface.

func NewArrayType

func NewArrayType(elementType Type) Type

func NewFunctionType

func NewFunctionType(sig FunctionSignature) (t Type)

func NewObjectType

func NewObjectType(propertyTypes map[string]Type) Type

type TypeConstraint

type TypeConstraint struct {
	// contains filtered or unexported fields
}

TypeConstraint states that the left and right types must be equal.

func (TypeConstraint) String

func (tc TypeConstraint) String() string

type TypeExpression

type TypeExpression interface {
	// MonoType produces a monotype of the expression.
	MonoType() (Type, bool)
	// contains filtered or unexported methods
}

TypeExpression represents an expression describing a type.

type TypeSolution

type TypeSolution interface {
	// TypeOf reports the monotype of the node or an error.
	TypeOf(n Node) (Type, error)
	// TypeOf reports the polytype of the node or an error.
	PolyTypeOf(n Node) (PolyType, error)

	// FreshSolution creates a copy of the solution with fresh type variables
	FreshSolution() TypeSolution

	// Fresh creates a new type variable within the solution.
	Fresh() Tvar

	// AddConstraint adds a new constraint and solves again reporting any errors.
	AddConstraint(l, r PolyType) error
}

TypeSolution is a mapping of Nodes to their types.

func InferTypes

func InferTypes(n Node, importer Importer) (TypeSolution, error)

InferTypes produces a solution to type inference for a given semantic graph.

func SolveConstraints

func SolveConstraints(cs *Constraints) (TypeSolution, error)

SolveConstraints solves the type inference problem defined by the constraints.

type UnaryExpression

type UnaryExpression struct {
	Operator ast.OperatorKind `json:"operator"`
	Argument Expression       `json:"argument"`
	// contains filtered or unexported fields
}

func (*UnaryExpression) Copy

func (e *UnaryExpression) Copy() Node

func (UnaryExpression) Location

func (l UnaryExpression) Location() ast.SourceLocation

func (*UnaryExpression) MarshalJSON

func (e *UnaryExpression) MarshalJSON() ([]byte, error)

func (*UnaryExpression) NodeType

func (*UnaryExpression) NodeType() string

func (*UnaryExpression) UnmarshalJSON

func (e *UnaryExpression) UnmarshalJSON(data []byte) error

type UnsignedIntegerLiteral

type UnsignedIntegerLiteral struct {
	Value uint64 `json:"value"`
	// contains filtered or unexported fields
}

func (*UnsignedIntegerLiteral) Copy

func (l *UnsignedIntegerLiteral) Copy() Node

func (UnsignedIntegerLiteral) Location

func (l UnsignedIntegerLiteral) Location() ast.SourceLocation

func (*UnsignedIntegerLiteral) MarshalJSON

func (l *UnsignedIntegerLiteral) MarshalJSON() ([]byte, error)

func (*UnsignedIntegerLiteral) NodeType

func (*UnsignedIntegerLiteral) NodeType() string

func (*UnsignedIntegerLiteral) UnmarshalJSON

func (l *UnsignedIntegerLiteral) UnmarshalJSON(data []byte) error

type Visitor

type Visitor interface {
	Visit(node Node) Visitor
	Done(node Node)
}

func CreateVisitor

func CreateVisitor(f func(Node)) Visitor

Directories

Path Synopsis
Package semantictest contains utilities for testing the semantic package.
Package semantictest contains utilities for testing the semantic package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL