1
0
mirror of https://github.com/golang/go synced 2024-11-20 05:04:43 -07:00

cmd/gc: track parameter flow, step 0: synthesize name nodes for anonymous PPARAMOUTs without breaking anything.

further work on parameter flow tracking for escape analysis depends on this.

R=rsc
CC=golang-dev
https://golang.org/cl/6600044
This commit is contained in:
Luuk van Dijk 2012-10-22 10:09:52 +02:00
parent e7f89fcb1c
commit 976ca1a47d
3 changed files with 42 additions and 20 deletions

View File

@ -13,7 +13,7 @@
void
closurehdr(Node *ntype)
{
Node *n, *name, *a;
Node *n, *name, *a, *orig;
NodeList *l;
n = nod(OCLOSURE, N, N);
@ -43,8 +43,11 @@ closurehdr(Node *ntype)
}
for(l=n->rlist; l; l=l->next) {
name = l->n->left;
if(name)
if(name) {
orig = name->orig; // preserve the meaning of orig == N (anonymous PPARAMOUT)
name = newname(name->sym);
name->orig = orig;
}
ntype->rlist = list(ntype->rlist, nod(ODCLFIELD, name, l->n->right));
}
}

View File

@ -596,25 +596,38 @@ funcargs(Node *nt)
}
// declare the out arguments.
gen = 0;
gen = count(nt->list);
int i = 0;
for(l=nt->rlist; l; l=l->next) {
n = l->n;
if(n->op != ODCLFIELD)
fatal("funcargs out %O", n->op);
if(n->left != N) {
n->left->op = ONAME;
n->left->ntype = n->right;
if(isblank(n->left)) {
// Give it a name so we can assign to it during return.
// preserve the original in ->orig
nn = nod(OXXX, N, N);
*nn = *n->left;
n->left = nn;
snprint(namebuf, sizeof(namebuf), ".anon%d", gen++);
n->left->sym = lookup(namebuf);
}
declare(n->left, PPARAMOUT);
if(n->left == N) {
// give it a name so escape analysis has nodes to work with
snprint(namebuf, sizeof(namebuf), ".anon%d", gen++);
n->left = newname(lookup(namebuf));
n->left->orig = N; // signal that the original was absent
}
n->left->op = ONAME;
if(isblank(n->left)) {
// Give it a name so we can assign to it during return.
// preserve the original in ->orig
nn = nod(OXXX, N, N);
*nn = *n->left;
n->left = nn;
snprint(namebuf, sizeof(namebuf), ".anon%d", gen++);
n->left->sym = lookup(namebuf);
}
n->left->ntype = n->right;
declare(n->left, PPARAMOUT);
n->left->vargen = i++;
}
}
@ -769,7 +782,7 @@ structfield(Node *n)
break;
}
if(n->left && n->left->op == ONAME) {
if(n->left && n->left->op == ONAME && n->left->orig != N) {
f->nname = n->left;
f->embedded = n->embedded;
f->sym = f->nname->sym;
@ -1145,7 +1158,7 @@ functype(Node *this, NodeList *in, NodeList *out)
t->thistuple = 1;
t->outtuple = count(out);
t->intuple = count(in);
t->outnamed = t->outtuple > 0 && out->n->left != N;
t->outnamed = t->outtuple > 0 && out->n->left != N && out->n->left->orig != N;
return t;
}

View File

@ -518,6 +518,8 @@ symfmt(Fmt *fp, Sym *s)
return fmtprint(fp, "%s.%s", s->pkg->name, s->name); // dcommontype, typehash
return fmtprint(fp, "%s.%s", s->pkg->prefix, s->name); // (methodsym), typesym, weaksym
case FExp:
if(s->name && s->name[0] == '.')
fatal("exporting synthetic symbol %s", s->name);
if(s->pkg != builtinpkg)
return fmtprint(fp, "@\"%Z\".%s", s->pkg->path, s->name);
}
@ -713,9 +715,13 @@ typefmt(Fmt *fp, Type *t)
case TFIELD:
if(!(fp->flags&FmtShort)) {
s = t->sym;
// Take the name from the original, lest we substituted it with .anon%d
if (t->nname && (fmtmode == FErr || fmtmode == FExp))
s = t->nname->orig->sym;
if ((fmtmode == FErr || fmtmode == FExp) && t->nname != N)
if(t->nname->orig != N)
s = t->nname->orig->sym;
else
s = S;
if(s != S && !t->embedded) {
if(fp->flags&FmtLong)