Changeset: 17151a70823a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=17151a70823a
Modified Files:
        monetdb5/mal/mal.h
        monetdb5/mal/mal_builder.c
        monetdb5/mal/mal_debugger.c
        monetdb5/mal/mal_function.c
        monetdb5/mal/mal_instruction.c
        monetdb5/mal/mal_instruction.h
        monetdb5/mal/mal_interpreter.c
        monetdb5/mal/mal_listing.c
        monetdb5/mal/mal_parser.c
        monetdb5/mal/mal_session.c
        monetdb5/mal/mal_type.c
        monetdb5/mal/mal_type.h
        monetdb5/optimizer/opt_factorize.c
        monetdb5/optimizer/opt_macro.c
        monetdb5/optimizer/opt_querylog.c
        monetdb5/optimizer/opt_remoteQueries.c
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_optimizer.c
Branch: default
Log Message:

Move variable names into VarRecord
To reduce the code complexity and lower the malloc calls,
all variable names are made part of the VarRecord structure.
No more tmpindex, but a simple counter per MAL block to
name temprary variables.

NewVariables are not passed by malloced structure, but
directly using the string and its length.

In passing some old, unused stuff has been removed


diffs (truncated from 980 to 300 lines):

diff --git a/monetdb5/mal/mal.h b/monetdb5/mal/mal.h
--- a/monetdb5/mal/mal.h
+++ b/monetdb5/mal/mal.h
@@ -144,16 +144,15 @@ typedef struct SYMDEF {
 } *Symbol, SymRecord;
 
 typedef struct VARRECORD {
-       str name;                                       /* argname or lexical 
value repr */
+       char id[IDLENGTH];                      /* use the space for the full 
name */
        malType type;                           /* internal type signature */
        int flags;                                      /* see below, reserve 
some space */
-       int tmpindex;                           /* temporary variable */
        ValRecord value;
        int declared;                           /* pc index when it was first 
assigned */
        int updated;                            /* pc index when it was first 
updated */
        int eolife;                                     /* pc index when it 
should be garbage collected */
        int depth;                                      /* scope block depth */
-       int worker;                                     /* tread id of last 
worker producing it */
+       int worker;                                     /* thread id of last 
worker producing it */
        str stc;                                        /* rendering 
schema.table.column */
        BUN rowcnt;                                     /* estimated row count*/
 } *VarPtr, VarRecord;
@@ -198,6 +197,7 @@ typedef struct MALBLK {
        struct MALBLK *alternative;
        int vtop;                                       /* next free slot */
        int vsize;                                      /* size of variable 
arena */
+       int vid;                                        /* generate local 
variable counter */
        VarRecord **var;                        /* Variable table */
        int stop;                                       /* next free slot */
        int ssize;                                      /* byte size of arena */
diff --git a/monetdb5/mal/mal_builder.c b/monetdb5/mal/mal_builder.c
--- a/monetdb5/mal/mal_builder.c
+++ b/monetdb5/mal/mal_builder.c
@@ -128,7 +128,7 @@ newCatchStmt(MalBlkPtr mb, str nme)
                return NULL;
        q->barrier = CATCHsymbol;
        if ( i< 0) {
-               if ((getArg(q,0)= newVariable(mb, GDKstrdup(nme),TYPE_str)) < 
0) {
+               if ((getArg(q,0)= newVariable(mb, nme, strlen(nme),TYPE_str)) < 
0) {
                        freeInstruction(q);
                        return NULL;
                }
@@ -146,7 +146,7 @@ newRaiseStmt(MalBlkPtr mb, str nme)
                return NULL;
        q->barrier = RAISEsymbol;
        if ( i< 0) {
-               if ((getArg(q,0)= newVariable(mb, GDKstrdup(nme),TYPE_str)) < 
0) {
+               if ((getArg(q,0)= newVariable(mb, nme, strlen(nme),TYPE_str)) < 
0) {
                        freeInstruction(q);
                        return NULL;
                }
@@ -165,7 +165,7 @@ newExitStmt(MalBlkPtr mb, str nme)
                return NULL;
        q->barrier = EXITsymbol;
        if ( i< 0) {
-               if ((getArg(q,0)= newVariable(mb, GDKstrdup(nme),TYPE_str)) < 
0) {
+               if ((getArg(q,0)= newVariable(mb, nme,strlen(nme),TYPE_str)) < 
0) {
                        freeInstruction(q);
                        return NULL;
                }
diff --git a/monetdb5/mal/mal_debugger.c b/monetdb5/mal/mal_debugger.c
--- a/monetdb5/mal/mal_debugger.c
+++ b/monetdb5/mal/mal_debugger.c
@@ -1229,18 +1229,11 @@ printBATelm(stream *f, bat i, BUN cnt, B
 void
 printStackHdr(stream *f, MalBlkPtr mb, ValPtr v, int index)
 {
-       str nme;
-       char nmebuf[PATHLENGTH];
        VarPtr n = getVar(mb, index);
 
        if (v == 0 && isVarConstant(mb, index))
                v = &getVarConstant(mb, index);
-       if (n->tmpindex) {
-               snprintf(nmebuf, PATHLENGTH, "%c%d", TMPMARKER, n->tmpindex);
-               nme = nmebuf;
-       } else
-               nme = n->name;
-       mnstr_printf(f, "#[%2d] %5s", index, nme);
+       mnstr_printf(f, "#[%2d] %5s", index, n->id);
        mnstr_printf(f, " (%d,%d,%d) = ", getBeginScope(mb,index), 
getLastUpdate(mb,index),getEndScope(mb, index));
        if (v)
                ATOMprint(v->vtype, VALptr(v), f);
diff --git a/monetdb5/mal/mal_function.c b/monetdb5/mal/mal_function.c
--- a/monetdb5/mal/mal_function.c
+++ b/monetdb5/mal/mal_function.c
@@ -32,7 +32,7 @@ Symbol newFunction(str mod, str nme,int 
        }
        setModuleId(p, mod);
        setFunctionId(p, nme);
-       setDestVar(p, newVariable(s->def,GDKstrdup(nme),TYPE_any));
+       setDestVar(p, newVariable(s->def,nme,strlen(nme),TYPE_any));
        pushInstruction(s->def,p);
        return s;
 }
diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c
--- a/monetdb5/mal/mal_instruction.c
+++ b/monetdb5/mal/mal_instruction.c
@@ -110,6 +110,7 @@ newMalBlk(int maxvars, int maxstmts)
 
        mb->var = v;
        mb->vtop = 0;
+       mb->vid = 0;
        mb->vsize = maxvars;
        mb->help = mb->binding = NULL;
        mb->tag = 0;
@@ -200,6 +201,7 @@ freeMalBlk(MalBlkPtr mb)
                        mb->var[i] = 0;
                }
        mb->vtop = 0;
+       mb->vid = 0;
        GDKfree(mb->stmt);
        mb->stmt = 0;
        GDKfree(mb->var);
@@ -247,6 +249,7 @@ copyMalBlk(MalBlkPtr old)
        mb->vsize = old->vsize;
 
        mb->vtop = 0;
+       mb->vid = old->vid;
        for (i = 0; i < old->vtop; i++) {
                if( copyVariable(mb, getVar(old, i)) == -1){
                        GDKfree(mb->var);
@@ -371,23 +374,6 @@ trimexpand(MalBlkPtr mb, int varsize, in
        mb->ssize = mb->ssize + stmtsize;
 }
 
-void
-expandMalBlk(MalBlkPtr mb, int lines)
-{
-       int newlines = (int) (lines * 1.1);
-
-       if (newlines > mb->ssize || newlines > mb->vsize)
-               trimexpand(mb, newlines, newlines);
-}
-
-void
-trimMalBlk(MalBlkPtr mb)
-{
-       (void) mb;                                      /* fool the compiler */
-       /* printf("safe %d %ld\n", mb->vtop, 
(mb->vsize-mb->vtop)*sizeof(VarPtr));
-          trimexpand(mb, mb->vsize, mb->ssize); */
-}
-
 /* Before compiling a large string, it makes sense to allocate
  * approximately enough space to keep the intermediate
  * code. Otherwise, we end up with a repeated extend on the MAL block,
@@ -409,7 +395,9 @@ prepareMalBlk(MalBlkPtr mb, str s)
                        cnt++;
                }
        }
-       expandMalBlk(mb, cnt);
+       cnt = (int) (cnt * 1.1);
+       if (cnt > mb->ssize || cnt > mb->vsize)
+               trimexpand(mb, cnt, cnt);
 }
 
 InstrPtr
@@ -593,72 +581,7 @@ insertInstruction(MalBlkPtr mb, InstrPtr
 /* Beware that the first argument of a signature is reserved for the
  * function return type , which should be equal to the destination
  * variable type.
- *
- * VarRecords are allocated on the variable stack. Their index is
- * returned for future reference.
- *
- * Use the information that a variable is at least one character wide
- * and terminated by a null-byte. This means that we can speed up
- * search when the variables differ in the first two characters
- *
- * Furthermore, temporary variables are already assigned to a specific
- * position in the variable table. This information can only be used
- * under the assumption that the code base is not modified on the
- * fly. Then the expensive search is started anyway. It also means
- * that input which does not comply with the intended location of a
- * temporary variable should be flagged as an error. */
-/* Unsafe routine when called in parallel to materialise temporary variables */
-inline str
-getVarName(MalBlkPtr mb, int i)
-{
-       str nme;
-       char buf[IDLENGTH];
-
-       nme = mb->var[i]->name;
-
-       if (nme == 0 || *nme =='_') {
-               GDKfree(nme);
-               snprintf(buf, IDLENGTH, "%c_%d", refMarker(mb,i), 
mb->var[i]->tmpindex);
-               nme = mb->var[i]->name = GDKstrdup(buf);
-       }
-       return nme;
-}
-
-inline void
-setVarName(MalBlkPtr mb, int i, str nme)
-{
-       char buf[IDLENGTH];
-
-       if ( mb->var[i]->name){
-               GDKfree(mb->var[i]->name);
-               mb->var[i]->name = NULL;
-       }
-
-       if (nme == 0) {
-               snprintf(buf, IDLENGTH, "%c%d", TMPMARKER, 
mb->var[i]->tmpindex);
-               nme = buf;
-       }
-       mb->var[i]->name = GDKstrdup(nme);
-}
-
-inline void
-resetVarName(MalBlkPtr mb, int i)
-{
-       str nme;
-       char buf[IDLENGTH];
-
-       nme = mb->var[i]->name;
-       if (mb->var[i]->tmpindex && nme) {
-               GDKfree(nme);
-               mb->var[i]->name = NULL;
-               nme = 0;
-       }
-
-       if (nme == 0) {
-               snprintf(buf, IDLENGTH, "%c%d", TMPMARKER, 
mb->var[i]->tmpindex);
-               mb->var[i]->name = GDKstrdup(buf);
-       }
-}
+ */
 
 int
 findVariable(MalBlkPtr mb, const char *name)
@@ -667,30 +590,8 @@ findVariable(MalBlkPtr mb, const char *n
 
        if (name == NULL)
                return -1;
-       if (isTmpName(name)) {
-               int j;
-               i = atol(name + (*name == TMPMARKER ? 1 : 2));
-               /* quick test validity */
-               if (i < mb->vtop && isTmpVar(mb, i) && getVarTmp(mb, i) == i)
-                       return i;
-               for (j = 0; j < mb->vtop; j++)
-                       if (getVarTmp(mb, j) == i && isTmpVar(mb, j))
-                               return j;
-               return -1;
-       }
        for (i = mb->vtop - 1; i >= 0; i--)
-               if (!isTmpVar(mb, i) && idcmp(name, getVarName(mb, i)) == 0)
-                       return i;
-       return -1;
-}
-
-int
-findTmpVariable(MalBlkPtr mb, int type)
-{
-       int i;
-
-       for (i = 0; i < mb->vtop; i++)
-               if (isTmpVar(mb, i) && getVarType(mb, i) == type)
+               if (idcmp(name, getVarName(mb, i)) == 0)
                        return i;
        return -1;
 }
@@ -706,8 +607,8 @@ findVariableLength(MalBlkPtr mb, str nam
        int j;
 
        for (i = mb->vtop - 1; i >= 0; i--)
-               if (mb->var[i] && mb->var[i]->name && !isTmpVar(mb, i)) {
-                       str s = mb->var[i]->name;
+               if (mb->var[i] && mb->var[i]->id) {
+                       str s = mb->var[i]->id;
 
                        j = 0;
                        if (s)
@@ -717,18 +618,6 @@ findVariableLength(MalBlkPtr mb, str nam
                        if (j == len && s && s[j] == 0)
                                return i;
                }
-       /* most variables are not temporary */
-       if (isTmpName(name)) {
-               int j;
-               i = atol(name + (*name == TMPMARKER ? 1 : 2));
-               /* quick test validity */
-               if (i < mb->vtop && isTmpVar(mb, i) && getVarTmp(mb, i) == i)
-                       return i;
-               for (j = 0; j < mb->vtop; j++)
-                       if (getVarTmp(mb, j) == i && isTmpVar(mb, j))
-                               return j;
-               return -1;
-       }
        return -1;
 }
 
@@ -860,40 +749,30 @@ makeVarSpace(MalBlkPtr mb)
        return 0;
 }
 
-/* swallows name argument */
+/* create and initialize a variable record*/
 int
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to