Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 4 additions & 67 deletions internal/interp/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// The storage model is:
//
// - Scalar locals live as immutable value.Value with the appropriate Kind
// stored in fr.cells[ssa.Value].Value.
// stored in the frame slot (Cell.Value) for that ssa.Value.
// - Composite locals are wrapped in a single-element addressable
// reflect.Value (built by reflect.New(rt).Elem() and stored as
// KindReflect). Field/IndexAddr/Slice operate on these reflect
Expand Down Expand Up @@ -314,69 +314,6 @@ func indexAddrRefEligible(v ssa.Value) bool {
return true
}

func fusableIndexAddrConsumer(indexAddr *ssa.IndexAddr, consumer ssa.Instruction) bool {
if indexAddr == nil || consumer == nil {
return false
}
switch instr := consumer.(type) {
case *ssa.Store:
if instr.Addr != indexAddr {
return false
}
case *ssa.UnOp:
if instr.Op != token.MUL || instr.X != indexAddr {
return false
}
default:
return false
}
refs := indexAddr.Referrers()
if refs == nil || len(*refs) == 0 {
return false
}
found := false
for _, ref := range *refs {
if ref == consumer {
found = true
continue
}
if _, ok := ref.(*ssa.DebugRef); ok {
continue
}
return false
}
return found
}

func (p *program) tryRunFusedIndexAddr(fr *frame, indexAddr *ssa.IndexAddr, consumer ssa.Instruction) (bool, error) {
x, err := p.readValue(fr, indexAddr.X)
if err != nil {
return true, err
}
s, ok := x.IntSlice()
if !ok {
return false, nil
}
idxV, err := p.readValue(fr, indexAddr.Index)
if err != nil {
return true, err
}
idx := int(idxV.Int())
switch instr := consumer.(type) {
case *ssa.UnOp:
fr.setCell(instr, value.MakeInt(int64(s[idx])))
return true, nil
case *ssa.Store:
val, err := p.readValue(fr, instr.Val)
if err != nil {
return true, err
}
s[idx] = int(val.Int())
return true, nil
}
return false, nil
}

func isPlainIntSliceType(t types.Type) bool {
s, ok := t.Underlying().(*types.Slice)
if !ok {
Expand Down Expand Up @@ -655,9 +592,9 @@ func (p *program) runRange(fr *frame, instr *ssa.Range) (continuation, []value.V
default:
return contNext, nil, fmt.Errorf("interp: Range over %s not supported", rv.Kind())
}
fr.setCell(instr, value.MakeNil()) // sentinel; the iterator goes through fr.iters
// Stash the iterator in a side-channel keyed by ssa.Value so Next
// can find it. Simpler than packaging it inside value.Value.
// Stash the iterator in a side-channel keyed by ssa.Value so Next can find
// it (the Range value itself is never read). Simpler than packaging it
// inside value.Value.
if fr.iters == nil {
fr.iters = make(map[ssa.Value]*rangeIter)
}
Expand Down
13 changes: 5 additions & 8 deletions internal/interp/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ func (defaultEngine) NewProgram(ctx context.Context, unit frontend.Unit, env hos
if err := p.allocateGlobals(); err != nil {
return nil, err
}
// init() runs once at construction so the Go semantics of
// package-level initialisation are honoured. The vertical slice
// has no globals-with-bodies, so this is currently a no-op for the
// programs we test, but the call site is kept honest.
// init() runs once at construction so the Go semantics of package-level
// initialisation are honoured.
if err := p.runInit(ctx); err != nil {
return nil, err
}
Expand All @@ -76,7 +74,7 @@ type program struct {
maxDepth int
hostFuncs sync.Map // map[*ssa.Function]host.Function
hostMethods sync.Map // map[hostMethodCacheKey]host.Method or missingHostMethod
layouts sync.Map // map[*ssa.Function]*frameLayout
layouts sync.Map // map[*ssa.Function]map[ssa.Value]int
}

// Call resolves the named function and runs it with the given args.
Expand Down Expand Up @@ -132,9 +130,8 @@ func (p *program) allocateGlobals() error {
}

// runInit invokes the package's init() function once at construction.
// Phase 6 vertical slice has nothing meaningful to put through init,
// but a missing function is also fine: SSA only emits init when there
// is something to do.
// runInit runs the package init function if one exists. A missing init is
// fine: SSA only emits init when there is something to do.
func (p *program) runInit(ctx context.Context) error {
fn := p.ssaPkg.Func("init")
if fn == nil {
Expand Down
Loading