Documentation ¶
Overview ¶
Package migoextract provides session type inference from Go code.
Index ¶
- Constants
- Variables
- type Block
- type Captures
- type CommaOk
- type Const
- type Context
- type Elems
- type External
- type Fields
- type Function
- func (caller *Function) Call(call *ssa.Call, infer *TypeInfer, b *Block, l *Loop)
- func (caller *Function) Go(instr *ssa.Go, infer *TypeInfer)
- func (caller *Function) HasBody() bool
- func (caller *Function) InstanceID() int
- func (caller *Function) IsRecursiveCall() bool
- func (ctx *Function) Sprintf(format string, a ...interface{}) string
- func (caller *Function) String() string
- type Instance
- type Loop
- type LoopBound
- type LoopStack
- type LoopState
- type Placeholder
- type Program
- type Select
- type Storage
- type Tuples
- type TypeInfer
- type Value
Constants ¶
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 ¶
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.
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 ¶
Const captures a constant value.
This is just a wrapper.
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 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.
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 ¶
NewFunction returns a new function call context, and takes the caller's context as parameter.
func NewMainFunction ¶
NewMainFunction returns a new main() call context.
func (*Function) HasBody ¶
HasBody returns true if Function is user-defined or has source code and built in SSA program.
func (*Function) InstanceID ¶
InstanceID returns the current function instance number (numbers of times function called).
func (*Function) IsRecursiveCall ¶
IsRecursiveCall checks if current function context is a recursive call and marks the context recursive (with pointer to the original context).
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.
type LoopStack ¶
LoopStack is a stack of ssa.BasicBlock
type LoopState ¶
type LoopState int
LoopState indicate the state (in analysis) of loop currently in.
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 ¶
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.
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.