migoextract

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Overview

Package migoextract provides session type inference from Go code.

Index

Constants

View Source
const (
	BlockSymbol     = "┝ "
	CallSymbol      = " ↘ "
	ExitSymbol      = " ↙ "
	ChanSymbol      = "ν "
	FuncEnterSymbol = "┌"
	FuncExitSymbol  = "└"
	RecvSymbol      = "❓ "
	SendSymbol      = "❗ "
	SkipSymbol      = "┆ "
	SpawnSymbol     = "┿ "
	JumpSymbol      = " ⇾ "
	ParamSymbol     = "├param "
	MoreSymbol      = "┊ "
	ReturnSymbol    = "⏎ "
	LoopSymbol      = "↻ "
	PhiSymbol       = "φ "
	IfSymbol        = "⨁ "
	SelectSymbol    = "Sel:"
	SplitSymbol     = "分"
	ErrorSymbol     = " ◹ "
	FieldSymbol     = " ↦ "
	NewSymbol       = "新"
	SubSymbol       = "    ▸ "
	ValSymbol       = "├ "
	AssignSymbol    = "≔"
)

Variables

View Source
var (
	ErrEmptyStack      = errors.New("stack: empty")
	ErrNoMainPkg       = errors.New("no main package found")
	ErrNonConstChanBuf = errors.New("MakeChan creates channel with non-const buffer size")
	ErrMakeChanNonChan = errors.New("type error: MakeChan creates non-channel type channel")
	ErrUnitialisedFunc = errors.New("operation on uninitialised function (did you call prepareVisit?)")
	ErrUnknownValue    = errors.New("internal error: unknown SSA value")
	ErrInvalidJumpSucc = errors.New("internal error: wrong number of Succ for Jump (expects 1)")
	ErrInvalidIfSucc   = errors.New("internal error: wrong number of Succ for If (expects 2)")
	ErrUnimplemented   = errors.New("unimplemented")
	ErrWrongArgNum     = errors.New("wrong number of arguments")
	ErrRuntimeLen      = errors.New("length can only be determined at runtime")
	ErrInvalidVarWrite = errors.New("internal error: write to uninitialised variable")
	ErrInvalidVarRead  = errors.New("internal error: read from uninitialised variable")
	ErrIfaceIncomplete = errors.New("interface not fully implemented")
	ErrMethodNotFound  = errors.New("interface method not found")
	ErrPhiUnknownEdge  = errors.New("phi node has edge from unknown block")
	ErrIncompatType    = errors.New("cannot convert incompatible type")
)

Functions

This section is empty.

Types

type Block

type Block struct {
	Function *Function      // Parent function context.
	MigoDef  *migo.Function // MiGo Function for the block.
	Pred     int            // Immediate predecessor trace.
	Index    int            // Current block index.
}

Block captures information about SSA block.

func NewBlock

func NewBlock(parent *Function, block *ssa.BasicBlock, curr int) *Block

NewBlock creates a new block enclosed by the given function.

type Captures

type Captures []Instance

Captures are holders for closure capture variables.

type CommaOk

type CommaOk struct {
	Instr  ssa.Instruction // TypeAssert, Lookup (map access) or UnOp (recv).
	Result Instance        // Result tuple { recvVal:T , recvTest:bool }.
	OkCond Instance        // The comma-ok condition.
}

CommaOK is a struct to capture different kinds of the _, ok := instr syntax where instr can be TypeAssert, map Lookup or recv UnOp

type Const

type Const struct {
	*ssa.Const
}

Const captures a constant value.

This is just a wrapper.

func (*Const) Instance

func (c *Const) Instance() (int, int)

Instance returns the instance identifier pair.

func (*Const) String

func (c *Const) String() string

type Context

type Context struct {
	F *Function // Function context.
	B *Block    // Block context.
	L *Loop     // Loop context.
}

Context is a grouping of different levels of context.

type Elems

type Elems map[ssa.Value]Instance

Elems are maps from array indices (variable) to VarInstances of elements.

type External

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

External captures an external instance of an SSA value.

An external instance is one without ssa.Value, usually if the creating body is in runtime or not built as SSA.

func (*External) Instance

func (i *External) Instance() (int, int)

Instance returns the instance number.

func (*External) String

func (i *External) String() string

type Fields

type Fields []Instance

Fields is a slice of variable instances.

type Function

type Function struct {
	Fn          *ssa.Function           // Function callee (this).
	Caller      *Function               // Function caller (parent).
	Prog        *Program                // Program environment (global).
	Visited     map[*ssa.BasicBlock]int // Visited block tracking.
	Level       int                     // Call level (for indentation).
	FuncDef     *migo.Function          // Function definition.
	ChildBlocks map[int]*Block          // Map from index -> child SSA blocks.

	*Storage // Storage.
	// contains filtered or unexported fields
}

Function captures the function environment.

Function environment stores local variable instances (as reference), return values, if-then-else parent, select-condition.

func NewFunction

func NewFunction(caller *Function) *Function

NewFunction returns a new function call context, and takes the caller's context as parameter.

func NewMainFunction

func NewMainFunction(prog *Program, mainFn *ssa.Function) *Function

NewMainFunction returns a new main() call context.

func (*Function) Call

func (caller *Function) Call(call *ssa.Call, infer *TypeInfer, b *Block, l *Loop)

Call performs call on a given unprepared call context.

func (*Function) Go

func (caller *Function) Go(instr *ssa.Go, infer *TypeInfer)

Go handles Go statements.

func (*Function) HasBody

func (caller *Function) HasBody() bool

HasBody returns true if Function is user-defined or has source code and built in SSA program.

func (*Function) InstanceID

func (caller *Function) InstanceID() int

InstanceID returns the current function instance number (numbers of times function called).

func (*Function) IsRecursiveCall

func (caller *Function) IsRecursiveCall() bool

IsRecursiveCall checks if current function context is a recursive call and marks the context recursive (with pointer to the original context).

func (*Function) Sprintf

func (ctx *Function) Sprintf(format string, a ...interface{}) string

Sprintf in current function context.

func (*Function) String

func (caller *Function) String() string

type Instance

type Instance interface {
	Instance() (int, int)
	String() string
}

Instance is an interface for an instance of a defined value.

type Loop

type Loop struct {
	Parent *Function // Enclosing function.
	Bound  LoopBound // Loop bound type.
	State  LoopState // Loop/Body/Done.

	IndexVar  ssa.Value // Variable holding the index (phi).
	CondVar   ssa.Value // Variable holding the cond expression.
	Index     int64     // Current index value.
	Start     int64     // Lower bound of index.
	Step      int64     // Increment (can be negative).
	End       int64     // Upper bound of index.
	LoopBlock int       // Block number of loop (with for.loop label).
}

Loop captures information about loop.

A Loop context exists within a function, inside the scope of a for loop. Nested loops should be captured externally.

func (*Loop) HasNext

func (l *Loop) HasNext() bool

HasNext returns true if the loop should continue.

func (*Loop) Next

func (l *Loop) Next()

Next performs an index increment (e.g. i++) if possible.

func (*Loop) SetCond

func (l *Loop) SetCond(cond ssa.Value, max int64)

SetCond sets the loop exit condition (int).

func (*Loop) SetInit

func (l *Loop) SetInit(index ssa.Value, init int64)

SetInit sets the loop index initial value (int).

func (*Loop) SetStep

func (l *Loop) SetStep(step int64)

SetStep sets the loop index step value (int).

func (*Loop) String

func (l *Loop) String() string

type LoopBound

type LoopBound int

LoopBound indicates if a loop is bounded or not.

const (
	Unknown LoopBound = iota
	Static            // Static loop.
	Dynamic           // Dynamic loop.
)

func (LoopBound) String

func (i LoopBound) String() string

type LoopStack

type LoopStack struct {
	sync.Mutex
	// contains filtered or unexported fields
}

LoopStack is a stack of ssa.BasicBlock

func NewLoopStack

func NewLoopStack() *LoopStack

NewLoopStack creates a new LoopStack.

func (*LoopStack) IsEmpty

func (s *LoopStack) IsEmpty() bool

IsEmpty returns true if stack is empty.

func (*LoopStack) Pop

func (s *LoopStack) Pop() (*Loop, error)

Pop removes a BasicBlock from top of stack.

func (*LoopStack) Push

func (s *LoopStack) Push(l *Loop)

Push adds a new LoopContext to the top of stack.

type LoopState

type LoopState int

LoopState indicate the state (in analysis) of loop currently in.

const (
	NonLoop LoopState = iota
	Enter             // Loop initialisation and condition checking
	Body              // Loop body (repeat)
	Exit              // Loop exit
)

func (LoopState) String

func (i LoopState) String() string

type Placeholder

type Placeholder struct {
}

Placeholder is a temporary stand in for actual SSA Value.

func (*Placeholder) Instance

func (i *Placeholder) Instance() (int, int)

Instance returns the instance number.

func (*Placeholder) String

func (i *Placeholder) String() string

type Program

type Program struct {
	FuncInstance map[*ssa.Function]int // Count number of function instances.
	InitPkgs     map[*ssa.Package]bool // Initialised packages.
	Infer        *TypeInfer            // Reference to inference.
	MigoProg     *migo.Program         // Core calculus of program.

	*Storage // Storage.
	// contains filtered or unexported fields
}

Program captures the program environment.

A single inference has exactly one Program, and it contains all global data (and metadata) in the program.

func NewProgram

func NewProgram(infer *TypeInfer) *Program

NewProgram creates a program for a type inference.

type Select

type Select struct {
	Instr    *ssa.Select           // Select SSA instruction.
	MigoStmt *migo.SelectStatement // Select statement in MiGo.
	Index    Instance              // Index (extracted from Select instruction).
}

Select keeps track of select statement and its branches.

type Storage

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

Storage is a grouping of auxiliary extra storage.

func NewStorage

func NewStorage() *Storage

NewStorage creates a new storage.

type Tuples

type Tuples []Instance

Tuples are return values for function that returns multiple. Can be extracted by ssa.Extract.

type TypeInfer

type TypeInfer struct {
	SSA    *ssabuilder.SSAInfo // SSA IR of program.
	Env    *Program            // Analysed program.
	GQueue []*Function         // Goroutines to be analysed.

	Time   time.Duration
	Logger *log.Logger
	Done   chan struct{}
	Error  chan error
}

TypeInfer contains the metadata for a type inference.

func New

func New(ssainfo *ssabuilder.SSAInfo, inferlog io.Writer) (*TypeInfer, error)

New creates a new session type infer analysis.

func (*TypeInfer) Run

func (infer *TypeInfer) Run()

Run executes the analysis.

func (*TypeInfer) RunQueue

func (infer *TypeInfer) RunQueue()

RunQueue executes the analysis on spawned (queued) goroutines.

type Value

type Value struct {
	ssa.Value // Storing the ssa.Value this instance is for.
	// contains filtered or unexported fields
}

Value captures a specific instance of a SSA value by counting the number of instantiations.

func (*Value) Instance

func (i *Value) Instance() (int, int)

Instance returns the instance identifier pair.

func (*Value) String

func (i *Value) String() string

Jump to

Keyboard shortcuts

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