From a4ca5508745d7a0d0e5944c5379f4b0f9b48e23f Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Sun, 8 Feb 2009 21:44:46 +0100 Subject: [PATCH] Revert templates to old behavior. While emitting a template instantiation only once is good for compile times and binary sizes, it doesn't work with linkonce linkage as inlined function bodies could be discarded. Since we don't want to inhibit inlining, templates are reverted to the previous behavior, where an instantiation is emitted for each module using it. In the future, a custom inlining pass may allow us to switch back to common/weak linkage and reenable smart template instance emission. --- dmd/template.c | 4 ++++ gen/llvmhelpers.cpp | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dmd/template.c b/dmd/template.c index 7893ed6f..fd39101b 100644 --- a/dmd/template.c +++ b/dmd/template.c @@ -2873,7 +2873,10 @@ TemplateInstance::TemplateInstance(Loc loc, Identifier *ident) this->havetempdecl = 0; this->isnested = NULL; this->errors = 0; + + // LDC this->tinst = NULL; + this->tmodule = NULL; } /***************** @@ -2988,6 +2991,7 @@ void TemplateInstance::semantic(Scope *sc) tmodule = tinst->tmodule; else tmodule = sc->module; + //printf("%s in %s\n", toChars(), tmodule->toChars()); #if LOG printf("\tdo semantic\n"); diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 0b748eba..70d1e229 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -1557,13 +1557,14 @@ void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, s bool mustDefineSymbol(Dsymbol* s) { -#if 0 +#if 1 return s->getModule() == gIR->dmodule || DtoIsTemplateInstance(s) != NULL; #else Module* M = DtoIsTemplateInstance(s); // if it's a template instance, check the instantiating module // not the module that defines the template if (M) { + //Logger::println("TINST %s from %s cur %s", s->toPrettyChars(), M->toChars(), gIR->dmodule->toChars()); return M == gIR->dmodule; } return s->getCompilationModule() == gIR->dmodule; @@ -1574,7 +1575,7 @@ bool mustDefineSymbol(Dsymbol* s) bool needsTemplateLinkage(Dsymbol* s) { -#if 0 +#if 1 return DtoIsTemplateInstance(s) != NULL; #else Module* M = DtoIsTemplateInstance(s);