Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't enforce (normal) emission for pragma(inline, true) function templates, and don't cull lambdas #3570

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions gen/declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,28 +371,19 @@ class CodegenVisitor : public Visitor {
return;
}

// Force codegen if this is a templated function with pragma(inline, true).
if ((decl->members->length == 1) &&
((*decl->members)[0]->isFuncDeclaration()) &&
((*decl->members)[0]->isFuncDeclaration()->inlining == PINLINEalways)) {
Logger::println("needsCodegen() == false, but function is marked with "
"pragma(inline, true), so it really does need "
"codegen.");
} else {
// FIXME: This is #673 all over again.
if (!decl->needsCodegen()) {
Logger::println("Does not need codegen, skipping.");
return;
}
// FIXME: This is #673 all over again.
if (!decl->needsCodegen()) {
Logger::println("Does not need codegen, skipping.");
return;
}

if (irs->dcomputetarget && (decl->tempdecl == Type::rtinfo ||
decl->tempdecl == Type::rtinfoImpl)) {
// Emitting object.RTInfo(Impl) template instantiations in dcompute
// modules would require dcompute support for global variables.
Logger::println("Skipping object.RTInfo(Impl) template instantiations "
"in dcompute modules.");
return;
}
if (irs->dcomputetarget && (decl->tempdecl == Type::rtinfo ||
decl->tempdecl == Type::rtinfoImpl)) {
// Emitting object.RTInfo(Impl) template instantiations in dcompute
// modules would require dcompute support for global variables.
Logger::println("Skipping object.RTInfo(Impl) template instantiations "
"in dcompute modules.");
return;
}

for (auto &m : *decl->members) {
Expand Down
3 changes: 3 additions & 0 deletions gen/function-inlining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ bool isInlineCandidate(FuncDeclaration &fdecl) {
} // end anonymous namespace

bool alreadyOrWillBeDefined(FuncDeclaration &fdecl) {
if (fdecl.isFuncLiteralDeclaration()) // emitted into each referencing CU
return true;

for (FuncDeclaration *f = &fdecl; f;) {
if (!f->isInstantiated() && f->inNonRoot()) {
return false;
Expand Down
10 changes: 4 additions & 6 deletions tests/codegen/inlining_templates.d
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ void main()
{
}

// CHECK-NOT: declare{{.*}}_D6inputs10inlinables__T12template_fooTiZQrUNaNbNiNfiZi
// CHECK-NOT: declare{{.*}}_D3std9exception__T7enforce
// CHECK-NOT: declare {{.*}}template_foo

// CHECK-DAG: define{{.*}}_D6inputs10inlinables__T12template_fooTiZQrUNaNbNiNfiZi{{.*}}) #[[ATTR:[0-9]+]]
// CHECK-DAG: define{{.*}}_D3std9exception__T7enforce{{.*}}) #[[ATTR]]

// CHECK-DAG: attributes #[[ATTR]] ={{.*}} alwaysinline
// CHECK-NOT: declare {{.*}}call_enforce_with_default_template_params
// CHECK-NOT: declare {{.*}}__lambda
// CHECK-NOT: declare {{.*}}_D3std9exception__T7enforce