From fc1062031ee4db9adc63d4f2b924ae2e61bdbf1a Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Wed, 27 Sep 2023 13:15:04 +0800 Subject: [PATCH 1/6] [Dcompute] don't give error for calling template function --- gen/semantic-dcompute.cpp | 2 ++ tests/semantic/dcompute_template.d | 11 +++++++++++ tests/semantic/inputs/notatcompute.d | 2 ++ 3 files changed, 15 insertions(+) create mode 100644 tests/semantic/dcompute_template.d diff --git a/gen/semantic-dcompute.cpp b/gen/semantic-dcompute.cpp index 157656a02f..86c8f3baea 100644 --- a/gen/semantic-dcompute.cpp +++ b/gen/semantic-dcompute.cpp @@ -44,6 +44,8 @@ struct DComputeSemanticAnalyser : public StoppableVisitor { return true; if (currentFunction == nullptr) return false; + if (f->isInstantiated()) + return true; TemplateInstance *inst = currentFunction->isInstantiated(); if (!inst) return false; diff --git a/tests/semantic/dcompute_template.d b/tests/semantic/dcompute_template.d new file mode 100644 index 0000000000..59307e87c1 --- /dev/null +++ b/tests/semantic/dcompute_template.d @@ -0,0 +1,11 @@ +// RUN: %ldc -o- -mdcompute-targets=cuda-350 %s -I%S +// REQUIRES: target_NVPTX +@compute(CompileFor.deviceOnly) module tests.semaintic.dcompute_template; +import ldc.dcompute; +import inputs.notatcompute : identity; + +@kernel void test()() +{ + auto x = identity(42); +} +alias realtest = test!(); diff --git a/tests/semantic/inputs/notatcompute.d b/tests/semantic/inputs/notatcompute.d index b204bb818c..684c8ba086 100644 --- a/tests/semantic/inputs/notatcompute.d +++ b/tests/semantic/inputs/notatcompute.d @@ -1,3 +1,5 @@ module tests.semantic.inputs.notatcompute; void somefunc() {} + +auto identity()(uint x1) => x1; From cfcabbaaab4f37be11c0f589d2ce80a1e44b2fcc Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Wed, 27 Sep 2023 13:24:45 +0800 Subject: [PATCH 2/6] Add failure case --- tests/semantic/dcompute_template.d | 5 +++++ tests/semantic/dcompute_template_fail.d | 11 +++++++++++ tests/semantic/inputs/notatcompute.d | 5 +++++ 3 files changed, 21 insertions(+) create mode 100644 tests/semantic/dcompute_template_fail.d diff --git a/tests/semantic/dcompute_template.d b/tests/semantic/dcompute_template.d index 59307e87c1..4262d823b7 100644 --- a/tests/semantic/dcompute_template.d +++ b/tests/semantic/dcompute_template.d @@ -9,3 +9,8 @@ import inputs.notatcompute : identity; auto x = identity(42); } alias realtest = test!(); + +@kernel void test2() +{ + auto x = identity(42); +} diff --git a/tests/semantic/dcompute_template_fail.d b/tests/semantic/dcompute_template_fail.d new file mode 100644 index 0000000000..b6f6ad0f43 --- /dev/null +++ b/tests/semantic/dcompute_template_fail.d @@ -0,0 +1,11 @@ +// RUN: not %ldc -o- -mdcompute-targets=cuda-350 -I%S %s 2>&1 | FileCheck %s +// REQUIRES: target_NVPTX +@compute(CompileFor.deviceOnly) module tests.semaintic.dcompute_template_fail; +import ldc.dcompute; +import inputs.notatcompute : callsSomeFunc; + +//CHECK: inputs/notatcompute.d(9): Error: can only call functions from other `@compute` modules in `@compute` code +@kernel void test() +{ + callsSomeFunc(); +} diff --git a/tests/semantic/inputs/notatcompute.d b/tests/semantic/inputs/notatcompute.d index 684c8ba086..82e1d034da 100644 --- a/tests/semantic/inputs/notatcompute.d +++ b/tests/semantic/inputs/notatcompute.d @@ -3,3 +3,8 @@ module tests.semantic.inputs.notatcompute; void somefunc() {} auto identity()(uint x1) => x1; + +void callsSomeFunc()() +{ + somefunc(); +} From f2705c59ca5a2fd0541cf2d4f1c2a52fdd3e7966 Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Wed, 27 Sep 2023 13:37:35 +0800 Subject: [PATCH 3/6] Add struct test case --- tests/semantic/dcompute_template.d | 8 +++++++- tests/semantic/inputs/notatcompute.d | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/semantic/dcompute_template.d b/tests/semantic/dcompute_template.d index 4262d823b7..e7e9e95bf7 100644 --- a/tests/semantic/dcompute_template.d +++ b/tests/semantic/dcompute_template.d @@ -2,7 +2,7 @@ // REQUIRES: target_NVPTX @compute(CompileFor.deviceOnly) module tests.semaintic.dcompute_template; import ldc.dcompute; -import inputs.notatcompute : identity; +import inputs.notatcompute : identity, A; @kernel void test()() { @@ -14,3 +14,9 @@ alias realtest = test!(); { auto x = identity(42); } + +@kernel void test3() +{ + A a; + a.foo(); +} diff --git a/tests/semantic/inputs/notatcompute.d b/tests/semantic/inputs/notatcompute.d index 82e1d034da..f4f47c199e 100644 --- a/tests/semantic/inputs/notatcompute.d +++ b/tests/semantic/inputs/notatcompute.d @@ -8,3 +8,8 @@ void callsSomeFunc()() { somefunc(); } + +struct A +{ + int foo()() { return 0; } +} From 6764a664c4e65a9e3d2998ed611a43eeb6597229 Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Wed, 27 Sep 2023 13:40:02 +0800 Subject: [PATCH 4/6] more tests --- tests/semantic/dcompute_template.d | 9 ++++++++- tests/semantic/inputs/notatcompute.d | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/semantic/dcompute_template.d b/tests/semantic/dcompute_template.d index e7e9e95bf7..4c2f53f738 100644 --- a/tests/semantic/dcompute_template.d +++ b/tests/semantic/dcompute_template.d @@ -2,7 +2,7 @@ // REQUIRES: target_NVPTX @compute(CompileFor.deviceOnly) module tests.semaintic.dcompute_template; import ldc.dcompute; -import inputs.notatcompute : identity, A; +import inputs.notatcompute : identity, A, B; @kernel void test()() { @@ -20,3 +20,10 @@ alias realtest = test!(); A a; a.foo(); } + +@kernel void test4() +{ + B!() b; + b.foo(); +} + diff --git a/tests/semantic/inputs/notatcompute.d b/tests/semantic/inputs/notatcompute.d index f4f47c199e..51615b2f91 100644 --- a/tests/semantic/inputs/notatcompute.d +++ b/tests/semantic/inputs/notatcompute.d @@ -13,3 +13,8 @@ struct A { int foo()() { return 0; } } + +struct B() +{ + int foo() { return 0; } +} From 71e5eb44a74e13b731d3034e0863e31d240636cc Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Thu, 28 Sep 2023 18:09:23 +0200 Subject: [PATCH 5/6] fix typo dcompute_template_fail.d --- tests/semantic/dcompute_template_fail.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/semantic/dcompute_template_fail.d b/tests/semantic/dcompute_template_fail.d index b6f6ad0f43..e8ea3e6b5b 100644 --- a/tests/semantic/dcompute_template_fail.d +++ b/tests/semantic/dcompute_template_fail.d @@ -1,6 +1,6 @@ // RUN: not %ldc -o- -mdcompute-targets=cuda-350 -I%S %s 2>&1 | FileCheck %s // REQUIRES: target_NVPTX -@compute(CompileFor.deviceOnly) module tests.semaintic.dcompute_template_fail; +@compute(CompileFor.deviceOnly) module tests.semantic.dcompute_template_fail; import ldc.dcompute; import inputs.notatcompute : callsSomeFunc; From 484cc28bb68f31f423cac66316fd85ebd81d1a75 Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Thu, 28 Sep 2023 18:11:12 +0200 Subject: [PATCH 6/6] fix typo dcompute_template.d --- tests/semantic/dcompute_template.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/semantic/dcompute_template.d b/tests/semantic/dcompute_template.d index 4c2f53f738..443b163ee7 100644 --- a/tests/semantic/dcompute_template.d +++ b/tests/semantic/dcompute_template.d @@ -1,6 +1,6 @@ // RUN: %ldc -o- -mdcompute-targets=cuda-350 %s -I%S // REQUIRES: target_NVPTX -@compute(CompileFor.deviceOnly) module tests.semaintic.dcompute_template; +@compute(CompileFor.deviceOnly) module tests.semantic.dcompute_template; import ldc.dcompute; import inputs.notatcompute : identity, A, B;