Skip to content

Commit

Permalink
Revert hasNestedArgs change, and instead tweak apppendToModuleMembers
Browse files Browse the repository at this point in the history
Sadly today, `TemplateInstance::enclosing == NULL` is not equivalent with "the template instance is not nested".
Because of the inconsistency, setting enclosing will break processes in other places.
  • Loading branch information
9rnsr committed Sep 9, 2015
1 parent e7898a6 commit a77a2e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -7167,11 +7167,13 @@ bool TemplateInstance::hasNestedArgs(Objects *args, bool isstatic)
int nested = 0;
//printf("TemplateInstance::hasNestedArgs('%s')\n", tempdecl->ident->toChars());

#if 0
if (!enclosing)
{
if (TemplateInstance *ti = tempdecl->isInstantiated())
enclosing = ti->enclosing;
}
#endif

/* A nested instance happens when an argument references a local
* symbol that is on the stack.
Expand Down Expand Up @@ -7312,9 +7314,22 @@ Dsymbols *TemplateInstance::appendToModuleMember()
* - codegen pass will get a selection chance to do/skip it.
*/

struct N
{
static Dsymbol *getStrictEnclosing(TemplateInstance *ti)
{
if (ti->enclosing)
return ti->enclosing;
if (TemplateInstance *tix = ti->tempdecl->isInstantiated())
return getStrictEnclosing(tix);
return NULL;
}
};
Dsymbol *enc = N::getStrictEnclosing(this);

// insert target is made stable by using the module
// where tempdecl is declared.
mi = (enclosing ? enclosing : tempdecl)->getModule();
mi = (enc ? enc : tempdecl)->getModule();
if (!mi->isRoot())
mi = mi->importedFrom;
assert(mi->isRoot());
Expand Down
4 changes: 2 additions & 2 deletions test/runnable/ice15030.d
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).F
function b.__unittestL5_2.__lambda1.__lambda2.FilterResult!(__lambda2, int[]).FilterResult.__xtoHash
function b.__unittestL5_2.__lambda1.__lambda2.__lambda2
Another problem is in TemplateInstance::hasNestedArgs. By inheriting 'enclosing' of instantiated scope,
now 'filter!(int[])' also becomes a nested template, and then FilterResult!(...) goes into the module b.
By the tweak in TemplateInstance::appendToModuleMember(), all the code of
(implicitly) nested instances are stored into corresponding module object file.
+/

0 comments on commit a77a2e3

Please sign in to comment.