Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Bug6701 #396

Merged
merged 2 commits into from

2 participants

@MartinNowak
Collaborator

No description provided.

src/template.c
@@ -3509,9 +3521,10 @@ void *TemplateValueParameter::dummyArg()
if (!e)
{
// Create a dummy value
- if (!edummy)
- edummy = valType->defaultInit();
- e = edummy;
+ if (!dummyArgs)
+ dummyArgs = new Array();
+ e = valType->defaultInit();
+ dummyArgs->push((void *)e);
@WalterBright Owner

There's a problem here. Values are inserted into this list, but never removed. The list is searched linearly. It potentially could get very large and slow. An improvement would be to check if the defaultInit is already in dummyArgs, or at least if valType is (if defaultInit keeps creating new e's).

@MartinNowak Collaborator

It is reseted directly after using them in leastAsSpecialized.
I deliberately did not use a set for the typical 2-5 template parameters.

I would agree though that bouncing this info over a global state is prone to break in future.
Maybe adding a boolean out parameter in dummyArg() and using a bitvector is a better solution (O(K) at least).

@WalterBright Owner

Ah, I missed that reset. But I can see disastrous problems with nested templates being instantiated, and the inner one resetting the global variable. A better way is to sneak a flag into Expression, and simply flag an expression as being a dummy. Look ma, no global state!

Would have to be careful that such an Expression instance wouldn't be shared with any others, or more disaster will ensue.

Or back to my idea of using one edummy per type, there won't be that many types in a program.

@MartinNowak Collaborator

Your right about the nested templates.
The latter sounds like a good idea. I will set up a static AA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@MartinNowak
Collaborator

BUMP.
Sorry, but I'm not sure if you get notified about changes of commits in a pull requests.

@WalterBright
Owner
MartinNowak added some commits
@MartinNowak MartinNowak regression test for bug6701 75553e3
@MartinNowak MartinNowak replace global edummy Expression * with AA
 - gather unique init expressions by type
 - identify dummy arguments by type and lookup
f457e9d
@WalterBright WalterBright merged commit 32dc803 into D-Programming-Language:master
@braddr braddr referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 17, 2012
  1. @MartinNowak
  2. @MartinNowak

    replace global edummy Expression * with AA

    MartinNowak authored
     - gather unique init expressions by type
     - identify dummy arguments by type and lookup
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 6 deletions.
  1. +7 −5 src/template.c
  2. +1 −1  src/template.h
  3. +15 −0 test/runnable/template4.d
View
12 src/template.c
@@ -14,6 +14,7 @@
#include <assert.h>
#include "root.h"
+#include "aav.h"
#include "rmem.h"
#include "stringtable.h"
@@ -3582,7 +3583,7 @@ Object *TemplateAliasParameter::defaultArg(Loc loc, Scope *sc)
// value-parameter
-Expression *TemplateValueParameter::edummy = NULL;
+AA *TemplateValueParameter::edummies = NULL;
TemplateValueParameter::TemplateValueParameter(Loc loc, Identifier *ident, Type *valType,
Expression *specValue, Expression *defaultValue)
@@ -3732,7 +3733,7 @@ MATCH TemplateValueParameter::matchArg(Scope *sc, Objects *tiargs,
if (specValue)
{
- if (!ei || ei == edummy)
+ if (!ei || _aaGetRvalue(edummies, ei->type) == ei)
goto Lnomatch;
Expression *e = specValue;
@@ -3815,9 +3816,10 @@ void *TemplateValueParameter::dummyArg()
if (!e)
{
// Create a dummy value
- if (!edummy)
- edummy = valType->defaultInit();
- e = edummy;
+ Expression **pe = (Expression **)_aaGet(&edummies, valType);
+ if (!*pe)
+ *pe = valType->defaultInit();
+ e = *pe;
}
return (void *)e;
}
View
2  src/template.h
@@ -203,7 +203,7 @@ struct TemplateValueParameter : TemplateParameter
Expression *specValue;
Expression *defaultValue;
- static Expression *edummy;
+ static AA *edummies;
TemplateValueParameter(Loc loc, Identifier *ident, Type *valType, Expression *specValue, Expression *defaultValue);
View
15 test/runnable/template4.d
@@ -1035,6 +1035,20 @@ void test39()
}
/*********************************************************/
+// 6701
+
+uint foo_6701(uint v:0)() { return 1; }
+uint foo_6701(uint v)() { return 0; }
+uint foo2_6701(uint v:0, string op)() { return 1; }
+uint foo2_6701(uint v, string op)() { return 0; }
+
+void test6701()
+{
+ assert(foo_6701!(0u)() == 1);
+ assert(foo2_6701!(0u, "+")() == 1);
+}
+
+/*********************************************************/
int main()
{
@@ -1077,6 +1091,7 @@ int main()
test37();
test38();
test39();
+ test6701();
printf("Success\n");
return 0;
Something went wrong with that request. Please try again.