Skip to content

Commit

Permalink
CTFE: Remove the hack for foreach ref variables
Browse files Browse the repository at this point in the history
The hack was complicated and probably not correct.
Actually the only thing that's needed is to recognize D2 AAs when inlining.
Even that is probably a bug in the inliner.
  • Loading branch information
Don Clugston committed Jan 12, 2012
1 parent 1acc274 commit 40160a5
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/interpret.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ Expression *findKeyInAA(AssocArrayLiteralExp *ae, Expression *e2);
Expression *evaluateIfBuiltin(InterState *istate, Loc loc,
FuncDeclaration *fd, Expressions *arguments, Expression *pthis);
Expression *scrubReturnValue(Loc loc, Expression *e);
bool isAssocArray(Type *t);

// CTFE only expressions
#define TOKclassreference ((TOK)(TOKMAX+1))
Expand Down Expand Up @@ -3357,7 +3358,7 @@ Expression *BinExp::interpretAssignCommon(InterState *istate, CtfeGoal goal, fp_
}
bool wantRef = false;
if (!fp && this->e1->type->toBasetype() == this->e2->type->toBasetype() &&
(e1->type->toBasetype()->ty == Tarray || e1->type->toBasetype()->ty == Taarray)
(e1->type->toBasetype()->ty == Tarray || isAssocArray(e1->type))
// e = *x is never a reference, because *x is always a value
&& this->e2->op != TOKstar
)
Expand Down Expand Up @@ -3392,16 +3393,6 @@ Expression *BinExp::interpretAssignCommon(InterState *istate, CtfeGoal goal, fp_
{
wantRef = true;
}
/* This happens inside compiler-generated foreach statements.
* It's another case where we need a reference
* Note that a similar case, where e2 = 'this', occurs in
* construction of a struct with an invariant().
*/
if (op==TOKconstruct && this->e1->op==TOKvar && this->e2->op != TOKthis
&& this->e2->op != TOKcomma
&& ((VarExp*)this->e1)->var->storage_class & STCref)
wantRef = true;

if (fp)
{
while (e1->op == TOKcast)
Expand Down Expand Up @@ -5232,18 +5223,19 @@ Expression *CatExp::interpret(InterState *istate, CtfeGoal goal)
return e;
}

#if DMDV2
// Return true if t is an AA, or AssociativeArray!(key, value)
bool isAssocArray(Type *t)
{
t = t->toBasetype();
if (t->ty == Taarray)
return true;
#if DMDV2
if (t->ty != Tstruct)
return false;
StructDeclaration *sym = ((TypeStruct *)t)->sym;
if (sym->ident == Id::AssociativeArray)
return true;
#endif
return false;
}

Expand All @@ -5253,14 +5245,18 @@ TypeAArray *toBuiltinAAType(Type *t)
t = t->toBasetype();
if (t->ty == Taarray)
return (TypeAArray *)t;
#if DMDV2
assert(t->ty == Tstruct);
StructDeclaration *sym = ((TypeStruct *)t)->sym;
assert(sym->ident == Id::AssociativeArray);
TemplateInstance *tinst = sym->parent->isTemplateInstance();
assert(tinst);
return new TypeAArray((Type *)(tinst->tiargs->tdata()[1]), (Type *)(tinst->tiargs->tdata()[0]));
}
#else
assert(0);
return NULL;
#endif
}

Expression *CastExp::interpret(InterState *istate, CtfeGoal goal)
{ Expression *e;
Expand Down

1 comment on commit 40160a5

@kennytm
Copy link
Contributor

@kennytm kennytm commented on 40160a5 Feb 1, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit caused bug 7419.

Please sign in to comment.