From b37e55f4a5524d4287341f36b66bfde0bdd618b0 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Wed, 5 Feb 2020 17:15:09 +1100 Subject: [PATCH] Increment coroID per-struct, not per-package --- internal/cgen/cgen.go | 3 ++- internal/cgen/func.go | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/cgen/cgen.go b/internal/cgen/cgen.go index 078a80bb..76c38f4e 100644 --- a/internal/cgen/cgen.go +++ b/internal/cgen/cgen.go @@ -499,7 +499,7 @@ type gen struct { currFunk funk funks map[t.QQID]funk - numPublicCoroutines uint32 + numPublicCoroutines map[t.QID]uint32 } func (g *gen) generate() ([]byte, error) { @@ -544,6 +544,7 @@ func (g *gen) generate() ([]byte, error) { } g.structMap = map[t.QID]*a.Struct{} g.privateDataFields = map[t.QQID]struct{}{} + g.numPublicCoroutines = map[t.QID]uint32{} for _, n := range g.structList { qid := n.QID() g.structMap[qid] = n diff --git a/internal/cgen/func.go b/internal/cgen/func.go index c8c81034..8380faa9 100644 --- a/internal/cgen/func.go +++ b/internal/cgen/func.go @@ -199,14 +199,16 @@ func (g *gen) writeFuncImpl(b *buffer, n *a.Func) error { } func (g *gen) gatherFuncImpl(_ *buffer, n *a.Func) error { + coroID := uint32(0) if n.Public() && n.Effect().Coroutine() { - g.numPublicCoroutines++ + g.numPublicCoroutines[n.Receiver()]++ + coroID = g.numPublicCoroutines[n.Receiver()] } g.currFunk = funk{ astFunc: n, cName: g.funcCName(n), - coroID: g.numPublicCoroutines, + coroID: coroID, returnsStatus: n.Effect().Coroutine() || ((n.Out() != nil) && n.Out().IsStatus()),