// can't handle ... args yet
if Debug['l'] < 3 {
- for _, t := range fn.Type.Params().Fields().Slice() {
- if t.Isddd {
+ f := fn.Type.Params().Fields()
+ if len := f.Len(); len > 0 {
+ if t := f.Index(len - 1); t.Isddd {
return
}
}
}
const maxBudget = 80
- budget := maxBudget // allowed hairyness
+ budget := int32(maxBudget) // allowed hairyness
if ishairylist(fn.Nbody, &budget) || budget < 0 {
return
}
savefn := Curfn
Curfn = fn
- fn.Func.Nname.Func.Inl.Set(fn.Nbody.Slice())
- fn.Nbody.Set(inlcopylist(fn.Func.Nname.Func.Inl.Slice()))
- inldcl := inlcopylist(fn.Func.Nname.Name.Defn.Func.Dcl)
- fn.Func.Nname.Func.Inldcl.Set(inldcl)
- fn.Func.Nname.Func.InlCost = int32(maxBudget - budget)
+ n := fn.Func.Nname
+
+ n.Func.Inl.Set(fn.Nbody.Slice())
+ fn.Nbody.Set(inlcopylist(n.Func.Inl.Slice()))
+ inldcl := inlcopylist(n.Name.Defn.Func.Dcl)
+ n.Func.Inldcl.Set(inldcl)
+ n.Func.InlCost = maxBudget - budget
// hack, TODO, check for better way to link method nodes back to the thing with the ->inl
// this is so export can find the body of a method
- fn.Type.SetNname(fn.Func.Nname)
+ fn.Type.SetNname(n)
if Debug['m'] > 1 {
- fmt.Printf("%v: can inline %v as: %v { %v }\n", fn.Line(), Nconv(fn.Func.Nname, FmtSharp), Tconv(fn.Type, FmtSharp), Hconv(fn.Func.Nname.Func.Inl, FmtSharp))
+ fmt.Printf("%v: can inline %v as: %v { %v }\n", fn.Line(), Nconv(n, FmtSharp), Tconv(fn.Type, FmtSharp), Hconv(n.Func.Inl, FmtSharp))
} else if Debug['m'] != 0 {
- fmt.Printf("%v: can inline %v\n", fn.Line(), fn.Func.Nname)
+ fmt.Printf("%v: can inline %v\n", fn.Line(), n)
}
Curfn = savefn
}
// Look for anything we want to punt on.
-func ishairylist(ll Nodes, budget *int) bool {
+func ishairylist(ll Nodes, budget *int32) bool {
for _, n := range ll.Slice() {
if ishairy(n, budget) {
return true
return false
}
-func ishairy(n *Node, budget *int) bool {
+func ishairy(n *Node, budget *int32) bool {
if n == nil {
return false
}
switch n.Op {
// Call is okay if inlinable and we have the budget for the body.
case OCALLFUNC:
- if n.Left.Func != nil && n.Left.Func.Inl.Len() != 0 {
- *budget -= int(n.Left.Func.InlCost)
+ if fn := n.Left.Func; fn != nil && fn.Inl.Len() != 0 {
+ *budget -= fn.InlCost
break
}
if n.Left.Op == ONAME && n.Left.Left != nil && n.Left.Left.Op == OTYPE && n.Left.Right != nil && n.Left.Right.Op == ONAME { // methods called as functions
- if n.Left.Sym.Def != nil && n.Left.Sym.Def.Func.Inl.Len() != 0 {
- *budget -= int(n.Left.Sym.Def.Func.InlCost)
+ if d := n.Left.Sym.Def; d != nil && d.Func.Inl.Len() != 0 {
+ *budget -= d.Func.InlCost
break
}
}
// Call is okay if inlinable and we have the budget for the body.
case OCALLMETH:
- if n.Left.Type == nil {
+ t := n.Left.Type
+ if t == nil {
Fatalf("no function type for [%p] %v\n", n.Left, Nconv(n.Left, FmtSign))
}
- if n.Left.Type.Nname() == nil {
- Fatalf("no function definition for [%p] %v\n", n.Left.Type, Tconv(n.Left.Type, FmtSign))
+ if t.Nname() == nil {
+ Fatalf("no function definition for [%p] %v\n", t, Tconv(t, FmtSign))
}
- if n.Left.Type.Nname().Func.Inl.Len() != 0 {
- *budget -= int(n.Left.Type.Nname().Func.InlCost)
+ if inlfn := t.Nname().Func; inlfn.Inl.Len() != 0 {
+ *budget -= inlfn.InlCost
break
}
if Debug['l'] < 4 {