FAQ
Reviewers: rsc,

Message:
Hello rsc@golang.org (cc: golang-dev@googlegroups.com),

I'd like you to review this change to
https://go.googlecode.com/hg/


Description:
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.

Please review this at http://codereview.appspot.com/6600044/

Affected files:
M src/cmd/gc/closure.c
M src/cmd/gc/dcl.c
M src/cmd/gc/fmt.c


Index: src/cmd/gc/closure.c
===================================================================
--- a/src/cmd/gc/closure.c
+++ b/src/cmd/gc/closure.c
@@ -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 @@
}
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));
}
}
Index: src/cmd/gc/dcl.c
===================================================================
--- a/src/cmd/gc/dcl.c
+++ b/src/cmd/gc/dcl.c
@@ -596,25 +596,40 @@
}

// 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) {
+
+ 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
+
+ } else {
+
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);
}
+
+ n->left->ntype = n->right;
+ declare(n->left, PPARAMOUT);
+ n->left->vargen = i++;
}
}

@@ -769,7 +784,8 @@
break;
}

- if(n->left && n->left->op == ONAME) {
+ if(n->left && n->left->op == ONAME && n->left->orig != N) {
+ if (n->left->orig == N) print("nname from synt %+N\n", n->left);
f->nname = n->left;
f->embedded = n->embedded;
f->sym = f->nname->sym;
@@ -1145,7 +1161,7 @@
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;
}
Index: src/cmd/gc/fmt.c
===================================================================
--- a/src/cmd/gc/fmt.c
+++ b/src/cmd/gc/fmt.c
@@ -518,6 +518,8 @@
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 @@
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)

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedOct 18, '12 at 11:16p
activeOct 22, '12 at 8:17a
posts3
users2
websitegolang.org

2 users in discussion

Lvd: 2 posts Rsc: 1 post

People

Translate

site design / logo © 2022 Grokbase