From 70b169090dcb66bb6470b225e9356549572b1bd8 Mon Sep 17 00:00:00 2001 From: arezaii Date: Tue, 5 Dec 2023 16:52:15 -0700 Subject: [PATCH 1/7] feat(dyno): implement various primitive call resolution Signed-off-by: arezaii --- frontend/lib/resolution/prims.cpp | 51 +++++++++++-------- .../test/resolution/testFunctionCalls.cpp | 30 +++++++++++ 2 files changed, 60 insertions(+), 21 deletions(-) diff --git a/frontend/lib/resolution/prims.cpp b/frontend/lib/resolution/prims.cpp index a5f7a2f489fc..5b5671900bc2 100644 --- a/frontend/lib/resolution/prims.cpp +++ b/frontend/lib/resolution/prims.cpp @@ -725,11 +725,8 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_IS_CONST_COPYABLE: case PRIM_IS_ASSIGNABLE: case PRIM_IS_CONST_ASSIGNABLE: - case PRIM_HAS_DEFAULT_VALUE: - case PRIM_NEEDS_AUTO_DESTROY: CHPL_UNIMPL("various primitives"); break; - case PRIM_CALL_RESOLVES: case PRIM_CALL_AND_FN_RESOLVES: case PRIM_METHOD_CALL_AND_FN_RESOLVES: @@ -886,6 +883,9 @@ CallResolutionResult resolvePrimCall(Context* context, BoolParam::get(context, isEqual)); break; } + case PRIM_IS_WIDE_PTR: + case PRIM_HAS_DEFAULT_VALUE: + case PRIM_NEEDS_AUTO_DESTROY: case PRIM_NOTEQUAL: case PRIM_LESSOREQUAL: case PRIM_GREATEROREQUAL: @@ -930,12 +930,23 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_POW: case PRIM_MIN: case PRIM_MAX: + case PRIM_STEAL: if (ci.numActuals() > 0) { type = QualifiedType(QualifiedType::CONST_VAR, ci.actual(0).type().type()); } break; - + /* primitives that return default int */ + case PRIM_GATHER_TESTS: + case PRIM_GET_UNION_ID: + type = QualifiedType(QualifiedType::CONST_VAR, + IntType::get(context, 0)); + break; + /* primitives that return an int32 */ + case PRIM_GETCID: + type = QualifiedType(QualifiedType::CONST_VAR, + IntType::get(context, 32)); + break; /* primitives that return void */ case PRIM_NOOP: case PRIM_MOVE: @@ -992,6 +1003,17 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_INVARIANT_START: case PRIM_GET_TEST_BY_NAME: case PRIM_GET_TEST_BY_INDEX: + case PRIM_ARRAY_SET: + case PRIM_ARRAY_SET_FIRST: + case PRIM_INIT_FIELDS: + case PRIM_CHPL_COMM_GET: + case PRIM_CHPL_COMM_PUT: + case PRIM_CHPL_COMM_ARRAY_GET: + case PRIM_CHPL_COMM_ARRAY_PUT: + case PRIM_CHPL_COMM_REMOTE_PREFETCH: + case PRIM_CHPL_COMM_GET_STRD: + case PRIM_CHPL_COMM_PUT_STRD: + case PRIM_ARRAY_SHIFT_BASE_POINTER: type = QualifiedType(QualifiedType::CONST_VAR, VoidType::get(context)); break; @@ -1016,11 +1038,13 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_GET_IMAG: type = primComplexGetComponent(context, ci); break; + case PRIM_WIDE_GET_ADDR: + type = QualifiedType(QualifiedType::CONST_VAR, + CPtrType::getCVoidPtrType(context)); + break; /* primitives that are not yet handled in dyno */ case PRIM_ACTUALS_LIST: case PRIM_REF_TO_STRING: - case PRIM_GETCID: - case PRIM_GET_UNION_ID: case PRIM_GET_MEMBER: case PRIM_GET_MEMBER_VALUE: case PRIM_NEW: @@ -1059,7 +1083,6 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_GPU_ELIGIBLE: case PRIM_SIZEOF_BUNDLE: case PRIM_SIZEOF_DDATA_ELEMENT: - case PRIM_INIT_FIELDS: case PRIM_LIFETIME_OF: CHPL_UNIMPL("misc primitives"); break; @@ -1079,17 +1102,7 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_USED_MODULES_LIST: case PRIM_REFERENCED_MODULES_LIST: case PRIM_TUPLE_EXPAND: - case PRIM_CHPL_COMM_GET: - case PRIM_CHPL_COMM_PUT: - case PRIM_CHPL_COMM_ARRAY_GET: - case PRIM_CHPL_COMM_ARRAY_PUT: - case PRIM_CHPL_COMM_REMOTE_PREFETCH: - case PRIM_CHPL_COMM_GET_STRD: - case PRIM_CHPL_COMM_PUT_STRD: case PRIM_ARRAY_GET: - case PRIM_ARRAY_SHIFT_BASE_POINTER: - case PRIM_ARRAY_SET: - case PRIM_ARRAY_SET_FIRST: case PRIM_MAYBE_LOCAL_THIS: case PRIM_MAYBE_LOCAL_ARR_ELEM: case PRIM_MAYBE_AGGREGATE_ASSIGN: @@ -1111,8 +1124,6 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_WIDE_MAKE: case PRIM_WIDE_GET_LOCALE: case PRIM_WIDE_GET_NODE: - case PRIM_WIDE_GET_ADDR: - case PRIM_IS_WIDE_PTR: case PRIM_ON_LOCALE_NUM: case PRIM_GET_REQUESTED_SUBLOC: case PRIM_REGISTER_GLOBAL_VAR: @@ -1130,7 +1141,6 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_VIRTUAL_METHOD_CALL: case PRIM_END_OF_STATEMENT: case PRIM_CURRENT_ERROR: - case PRIM_STEAL: case PRIM_AUTO_DESTROY_RUNTIME_TYPE: case PRIM_GET_RUNTIME_TYPE_FIELD: case PRIM_LOOKUP_FILENAME: @@ -1140,7 +1150,6 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_NO_ALIAS_SET: case PRIM_COPIES_NO_ALIAS_SET: case PRIM_OPTIMIZATION_INFO: - case PRIM_GATHER_TESTS: CHPL_UNIMPL("misc primitives"); break; diff --git a/frontend/test/resolution/testFunctionCalls.cpp b/frontend/test/resolution/testFunctionCalls.cpp index 55109a047746..b2d7b2d6df55 100644 --- a/frontend/test/resolution/testFunctionCalls.cpp +++ b/frontend/test/resolution/testFunctionCalls.cpp @@ -228,6 +228,34 @@ static void test9() { assert(realPtr->bitwidth()==32); } +static void test10() { + // check that prim_gather_tests returns an int + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var x = __primitive("gather tests"); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); +} + +static void test11() { + // check that prim_is_wide_pointer returns a bool + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var x = __primitive("is wide pointer"); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isBoolType()); +} + int main() { test1(); @@ -240,6 +268,8 @@ int main() { test7(); test8(); test9(); + test10(); + test11(); return 0; } From 3c17c40553f683b657d8d3572502a543058822f0 Mon Sep 17 00:00:00 2001 From: arezaii Date: Tue, 5 Dec 2023 20:38:45 -0700 Subject: [PATCH 2/7] add tests for new primitive resolution in dyno Signed-off-by: arezaii --- .../test/resolution/testFunctionCalls.cpp | 202 ++++++++++++++++++ 1 file changed, 202 insertions(+) diff --git a/frontend/test/resolution/testFunctionCalls.cpp b/frontend/test/resolution/testFunctionCalls.cpp index b2d7b2d6df55..563092c4a956 100644 --- a/frontend/test/resolution/testFunctionCalls.cpp +++ b/frontend/test/resolution/testFunctionCalls.cpp @@ -256,6 +256,189 @@ static void test11() { assert(typePtr->isBoolType()); } +// test for primitive "_wide_get_addr", which should return a void ptr +static void test12() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var x = __primitive("_wide_get_addr"); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + auto cPtrType = typePtr->toCPtrType(); + assert(cPtrType); + assert(cPtrType->isVoidPtr()); +} + +// test for primitive "steal", which should return the type of the argument +static void test13() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var a = 1; + var x = __primitive("steal", a); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); +} + +// test for primitive "is wide pointer", which should return a bool +static void test14() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var x = __primitive("is wide pointer"); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isBoolType()); +} + +// test for primitive "type has default value", which should return a bool +static void test15() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var x = __primitive("type has default value"); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isBoolType()); +} + +// test for primitive "needs auto destroy", which should return a bool +static void test16() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var x = __primitive("needs auto destroy"); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isBoolType()); +} + +// test for primitive "getcid", which should return an int32 +static void test17() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var x = __primitive("getcid"); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 32); +} + +// test for primitive "gather tests", which should return a default int +static void test18() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var x = __primitive("gather tests"); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 64); +} + +// test for primitive "get_union_id", which should return a default int +static void test19() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var x = __primitive("get_union_id"); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 64); +} + +static void voidTypeTestHelper(std::string program) { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, program); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isVoidType()); +} + +// test for primitive "chpl_init_record", which should return void +static void test20() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_init_record");)"""); +} + +// test for primitive "chpl_comm_get", which should return void +static void test21() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_get");)"""); +} + +// test for primitive "chpl_comm_put", which should return void +static void test22() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_put");)"""); +} + +// test for primitive "chpl_comm_array_get", which should return void +static void test23() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_array_get");)"""); +} + +// test for primitive "chpl_comm_array_put", which should return void +static void test24() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_array_put");)"""); +} + +// test for primitive "chpl_comm_remote_prefetch", which should return void +static void test25() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_remote_prefetch");)"""); +} + +// test for primitive "chpl_comm_get_strd", which should return void +static void test26() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_get_strd");)"""); +} + + +// test for primitive "chpl_comm_put_strd", which should return void +static void test27() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_put_strd");)"""); +} + +// test for primitive "shift_base_pointer", which should return void +static void test28() { + voidTypeTestHelper(R"""(var x = __primitive("shift_base_pointer");)"""); +} + +// test for primitive "array_set", which should return void +static void test29() { + voidTypeTestHelper(R"""(var x = __primitive("array_set");)"""); +} + +// test for primitive "array_set_first", which should return void +static void test30() { + voidTypeTestHelper(R"""(var x = __primitive("array_set_first");)"""); +} int main() { test1(); @@ -270,6 +453,25 @@ int main() { test9(); test10(); test11(); + test12(); + test13(); + test14(); + test15(); + test16(); + test17(); + test18(); + test19(); + test20(); + test21(); + test22(); + test23(); + test24(); + test25(); + test26(); + test27(); + test28(); + test29(); + test30(); return 0; } From 82a36e89af0b4d21bc0b28ca3a9541dddb877c67 Mon Sep 17 00:00:00 2001 From: arezaii Date: Wed, 6 Dec 2023 15:04:24 -0700 Subject: [PATCH 3/7] update test comments Signed-off-by: arezaii --- frontend/test/resolution/testFunctionCalls.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/test/resolution/testFunctionCalls.cpp b/frontend/test/resolution/testFunctionCalls.cpp index 563092c4a956..40a9af10ec17 100644 --- a/frontend/test/resolution/testFunctionCalls.cpp +++ b/frontend/test/resolution/testFunctionCalls.cpp @@ -229,7 +229,7 @@ static void test9() { } static void test10() { - // check that prim_gather_tests returns an int + // check that primitive "gather tests" returns an int Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -243,7 +243,7 @@ static void test10() { } static void test11() { - // check that prim_is_wide_pointer returns a bool + // check that primitive "is wide pointer" returns a bool Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, From 05994c43005ddb6177baada1cdb1ab8159716f40 Mon Sep 17 00:00:00 2001 From: arezaii Date: Fri, 8 Dec 2023 12:51:08 -0700 Subject: [PATCH 4/7] implement resolution of more prim return types Signed-off-by: arezaii --- frontend/lib/resolution/prims.cpp | 23 ++- .../test/resolution/testFunctionCalls.cpp | 186 ++++++++++++++++++ 2 files changed, 200 insertions(+), 9 deletions(-) diff --git a/frontend/lib/resolution/prims.cpp b/frontend/lib/resolution/prims.cpp index 5b5671900bc2..55631435a299 100644 --- a/frontend/lib/resolution/prims.cpp +++ b/frontend/lib/resolution/prims.cpp @@ -705,7 +705,6 @@ CallResolutionResult resolvePrimCall(Context* context, type = primFieldByNum(context, ci); break; - case PRIM_CLASS_NAME_BY_ID: case PRIM_ITERATOR_RECORD_FIELD_VALUE_BY_FORMAL: case PRIM_IS_GENERIC_TYPE: case PRIM_IS_CLASS_TYPE: @@ -939,11 +938,15 @@ CallResolutionResult resolvePrimCall(Context* context, /* primitives that return default int */ case PRIM_GATHER_TESTS: case PRIM_GET_UNION_ID: + case PRIM_GET_REQUESTED_SUBLOC: + case PRIM_SIZEOF_BUNDLE: // TODO: this should be sizeType + case PRIM_SIZEOF_DDATA_ELEMENT: // TODO: this should be sizeType type = QualifiedType(QualifiedType::CONST_VAR, IntType::get(context, 0)); break; /* primitives that return an int32 */ case PRIM_GETCID: + case PRIM_WIDE_GET_NODE: // TODO: should be nodeIdType type = QualifiedType(QualifiedType::CONST_VAR, IntType::get(context, 32)); break; @@ -1014,6 +1017,8 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_CHPL_COMM_GET_STRD: case PRIM_CHPL_COMM_PUT_STRD: case PRIM_ARRAY_SHIFT_BASE_POINTER: + case PRIM_AUTO_DESTROY_RUNTIME_TYPE: + case PRIM_CREATE_FN_TYPE: type = QualifiedType(QualifiedType::CONST_VAR, VoidType::get(context)); break; @@ -1042,9 +1047,16 @@ CallResolutionResult resolvePrimCall(Context* context, type = QualifiedType(QualifiedType::CONST_VAR, CPtrType::getCVoidPtrType(context)); break; + /* primitives that return a c_string*/ + case PRIM_LOOKUP_FILENAME: + case PRIM_CLASS_NAME_BY_ID: + case PRIM_REF_TO_STRING:{ + type = QualifiedType(QualifiedType::CONST_VAR, + CStringType::get(context)); + break; + } /* primitives that are not yet handled in dyno */ case PRIM_ACTUALS_LIST: - case PRIM_REF_TO_STRING: case PRIM_GET_MEMBER: case PRIM_GET_MEMBER_VALUE: case PRIM_NEW: @@ -1081,8 +1093,6 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_GPU_SET_BLOCKSIZE: case PRIM_ASSERT_ON_GPU: case PRIM_GPU_ELIGIBLE: - case PRIM_SIZEOF_BUNDLE: - case PRIM_SIZEOF_DDATA_ELEMENT: case PRIM_LIFETIME_OF: CHPL_UNIMPL("misc primitives"); break; @@ -1123,15 +1133,12 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_LOGICAL_FOLDER: case PRIM_WIDE_MAKE: case PRIM_WIDE_GET_LOCALE: - case PRIM_WIDE_GET_NODE: case PRIM_ON_LOCALE_NUM: - case PRIM_GET_REQUESTED_SUBLOC: case PRIM_REGISTER_GLOBAL_VAR: case PRIM_BROADCAST_GLOBAL_VARS: case PRIM_PRIVATE_BROADCAST: case PRIM_CAPTURE_FN: case PRIM_CAPTURE_FN_TO_CLASS: - case PRIM_CREATE_FN_TYPE: case PRIM_GET_USER_LINE: case PRIM_GET_USER_FILE: case PRIM_RESOLUTION_POINT: @@ -1141,9 +1148,7 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_VIRTUAL_METHOD_CALL: case PRIM_END_OF_STATEMENT: case PRIM_CURRENT_ERROR: - case PRIM_AUTO_DESTROY_RUNTIME_TYPE: case PRIM_GET_RUNTIME_TYPE_FIELD: - case PRIM_LOOKUP_FILENAME: case PRIM_GET_VISIBLE_SYMBOLS: case PRIM_STACK_ALLOCATE_CLASS: case PRIM_ZIP: diff --git a/frontend/test/resolution/testFunctionCalls.cpp b/frontend/test/resolution/testFunctionCalls.cpp index 40a9af10ec17..1b602b8f4dd1 100644 --- a/frontend/test/resolution/testFunctionCalls.cpp +++ b/frontend/test/resolution/testFunctionCalls.cpp @@ -440,6 +440,176 @@ static void test30() { voidTypeTestHelper(R"""(var x = __primitive("array_set_first");)"""); } +// test for primitive "auto destroy runtime type", which should return void +static void test31() { + voidTypeTestHelper(R"""(var x = __primitive("auto destroy runtime type");)"""); +} + +// test for primitive "create fn type", which should return void +static void test32() { + voidTypeTestHelper(R"""(var x = __primitive("create fn type");)"""); +} + +// "chpl_task_getRequestedSubloc", which should return int 64 +static void test33() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("chpl_task_getRequestedSubloc");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 64); +} + +// "sizeof_ddata_element", which should return int 64 (actually sizeType) +static void test34() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("sizeof_ddata_element");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 64); +} + +// "_wide_get_node", which should return int 32 (actually nodeIdType) +static void test35() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("_wide_get_node");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 32); +} + +// "class name by id", which should return a cString +static void test36() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("class name by id");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isCStringType()); +} + +// "ref to string", which should return a cString +static void test37() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("ref to string");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isCStringType()); +} + +// "chpl_lookupFilename", which should return a cString +static void test38() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("chpl_lookupFilename");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isCStringType()); +} + +// test for primitive "auto destroy runtime type", which should return void +static void test39() { + voidTypeTestHelper(R"""(var x = __primitive("auto destroy runtime type");)"""); +} + +// test for primitive "create fn type", which should return void +static void test40() { + voidTypeTestHelper(R"""(var x = __primitive("create fn type");)"""); +} + +// "chpl_task_getRequestedSubloc", which should return int 64 +static void test41() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("chpl_task_getRequestedSubloc");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 64); +} + +// "sizeof_ddata_element", which should return int 64 (actually sizeType) +static void test42() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("sizeof_ddata_element");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 64); +} + +// "_wide_get_node", which should return int 32 (actually nodeIdType) +static void test43() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("_wide_get_node");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 32); +} + +// "class name by id", which should return a cString +static void test44() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("class name by id");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isCStringType()); +} + +// "ref to string", which should return a cString +static void test45() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("ref to string");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isCStringType()); +} + +// "chpl_lookupFilename", which should return a cString +static void test46() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("chpl_lookupFilename");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isCStringType()); +} + int main() { test1(); test2(); @@ -472,6 +642,22 @@ int main() { test28(); test29(); test30(); + test31(); + test32(); + test33(); + test34(); + test35(); + test36(); + test37(); + test38(); + test39(); + test40(); + test41(); + test42(); + test43(); + test44(); + test45(); + test46(); return 0; } From 88b2647e32dc5ff5869ea9ea31e47fa25fe452b2 Mon Sep 17 00:00:00 2001 From: arezaii Date: Tue, 12 Dec 2023 11:54:44 -0700 Subject: [PATCH 5/7] fix-up primitive tests after merge collisions Signed-off-by: arezaii --- .../test/resolution/testFunctionCalls.cpp | 162 +++--------------- 1 file changed, 27 insertions(+), 135 deletions(-) diff --git a/frontend/test/resolution/testFunctionCalls.cpp b/frontend/test/resolution/testFunctionCalls.cpp index 1b602b8f4dd1..9557312a90ad 100644 --- a/frontend/test/resolution/testFunctionCalls.cpp +++ b/frontend/test/resolution/testFunctionCalls.cpp @@ -243,7 +243,7 @@ static void test10() { } static void test11() { - // check that primitive "is wide pointer" returns a bool + // test for primitive "is wide pointer", which should return a bool Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -287,22 +287,9 @@ static void test13() { assert(typePtr->isIntType()); } -// test for primitive "is wide pointer", which should return a bool -static void test14() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var x = __primitive("is wide pointer"); - )""""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isBoolType()); -} // test for primitive "type has default value", which should return a bool -static void test15() { +static void test14() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -316,7 +303,7 @@ static void test15() { } // test for primitive "needs auto destroy", which should return a bool -static void test16() { +static void test15() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -330,7 +317,7 @@ static void test16() { } // test for primitive "getcid", which should return an int32 -static void test17() { +static void test16() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -344,23 +331,8 @@ static void test17() { assert(typePtr->toIntType()->bitwidth() == 32); } -// test for primitive "gather tests", which should return a default int -static void test18() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var x = __primitive("gather tests"); - )""""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isIntType()); - assert(typePtr->toIntType()->bitwidth() == 64); -} - // test for primitive "get_union_id", which should return a default int -static void test19() { +static void test17() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -385,73 +357,73 @@ static void voidTypeTestHelper(std::string program) { } // test for primitive "chpl_init_record", which should return void -static void test20() { +static void test18() { voidTypeTestHelper(R"""(var x = __primitive("chpl_init_record");)"""); } // test for primitive "chpl_comm_get", which should return void -static void test21() { +static void test19() { voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_get");)"""); } // test for primitive "chpl_comm_put", which should return void -static void test22() { +static void test20() { voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_put");)"""); } // test for primitive "chpl_comm_array_get", which should return void -static void test23() { +static void test21() { voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_array_get");)"""); } // test for primitive "chpl_comm_array_put", which should return void -static void test24() { +static void test22() { voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_array_put");)"""); } // test for primitive "chpl_comm_remote_prefetch", which should return void -static void test25() { +static void test23() { voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_remote_prefetch");)"""); } // test for primitive "chpl_comm_get_strd", which should return void -static void test26() { +static void test24() { voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_get_strd");)"""); } // test for primitive "chpl_comm_put_strd", which should return void -static void test27() { +static void test25() { voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_put_strd");)"""); } // test for primitive "shift_base_pointer", which should return void -static void test28() { +static void test26() { voidTypeTestHelper(R"""(var x = __primitive("shift_base_pointer");)"""); } // test for primitive "array_set", which should return void -static void test29() { +static void test27() { voidTypeTestHelper(R"""(var x = __primitive("array_set");)"""); } // test for primitive "array_set_first", which should return void -static void test30() { +static void test28() { voidTypeTestHelper(R"""(var x = __primitive("array_set_first");)"""); } // test for primitive "auto destroy runtime type", which should return void -static void test31() { +static void test29() { voidTypeTestHelper(R"""(var x = __primitive("auto destroy runtime type");)"""); } // test for primitive "create fn type", which should return void -static void test32() { +static void test30() { voidTypeTestHelper(R"""(var x = __primitive("create fn type");)"""); } // "chpl_task_getRequestedSubloc", which should return int 64 -static void test33() { +static void test31() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -464,7 +436,7 @@ static void test33() { } // "sizeof_ddata_element", which should return int 64 (actually sizeType) -static void test34() { +static void test32() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -477,7 +449,7 @@ static void test34() { } // "_wide_get_node", which should return int 32 (actually nodeIdType) -static void test35() { +static void test33() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -490,7 +462,7 @@ static void test35() { } // "class name by id", which should return a cString -static void test36() { +static void test34() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -502,7 +474,7 @@ static void test36() { } // "ref to string", which should return a cString -static void test37() { +static void test35() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -514,7 +486,7 @@ static void test37() { } // "chpl_lookupFilename", which should return a cString -static void test38() { +static void test36() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -525,35 +497,12 @@ static void test38() { assert(typePtr->isCStringType()); } -// test for primitive "auto destroy runtime type", which should return void -static void test39() { - voidTypeTestHelper(R"""(var x = __primitive("auto destroy runtime type");)"""); -} - -// test for primitive "create fn type", which should return void -static void test40() { - voidTypeTestHelper(R"""(var x = __primitive("create fn type");)"""); -} - -// "chpl_task_getRequestedSubloc", which should return int 64 -static void test41() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R"""(var x = __primitive("chpl_task_getRequestedSubloc");)"""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isIntType()); - assert(typePtr->toIntType()->bitwidth() == 64); -} - -// "sizeof_ddata_element", which should return int 64 (actually sizeType) -static void test42() { +// "sizeof_bundle", which should return int 64 (actually sizeType) +static void test37() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, - R"""(var x = __primitive("sizeof_ddata_element");)"""); + R"""(var x = __primitive("sizeof_bundle");)"""); assert(qt.kind() == QualifiedType::CONST_VAR); auto typePtr = qt.type(); assert(typePtr); @@ -561,54 +510,6 @@ static void test42() { assert(typePtr->toIntType()->bitwidth() == 64); } -// "_wide_get_node", which should return int 32 (actually nodeIdType) -static void test43() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R"""(var x = __primitive("_wide_get_node");)"""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isIntType()); - assert(typePtr->toIntType()->bitwidth() == 32); -} - -// "class name by id", which should return a cString -static void test44() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R"""(var x = __primitive("class name by id");)"""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isCStringType()); -} - -// "ref to string", which should return a cString -static void test45() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R"""(var x = __primitive("ref to string");)"""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isCStringType()); -} - -// "chpl_lookupFilename", which should return a cString -static void test46() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R"""(var x = __primitive("chpl_lookupFilename");)"""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isCStringType()); -} int main() { test1(); @@ -649,15 +550,6 @@ int main() { test35(); test36(); test37(); - test38(); - test39(); - test40(); - test41(); - test42(); - test43(); - test44(); - test45(); - test46(); return 0; } From d6c87c048cc9e6131fca77194a7148cab286d0c6 Mon Sep 17 00:00:00 2001 From: arezaii Date: Tue, 12 Dec 2023 12:57:18 -0700 Subject: [PATCH 6/7] refactor prim tests into new file, remove param and prims without proper types Signed-off-by: arezaii --- frontend/lib/resolution/prims.cpp | 12 +- frontend/test/resolution/CMakeLists.txt | 1 + .../test/resolution/testFunctionCalls.cpp | 413 ------------------ .../test/resolution/testRuntimePrimitives.cpp | 352 +++++++++++++++ 4 files changed, 359 insertions(+), 419 deletions(-) create mode 100644 frontend/test/resolution/testRuntimePrimitives.cpp diff --git a/frontend/lib/resolution/prims.cpp b/frontend/lib/resolution/prims.cpp index 55631435a299..b552662ff21b 100644 --- a/frontend/lib/resolution/prims.cpp +++ b/frontend/lib/resolution/prims.cpp @@ -724,6 +724,8 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_IS_CONST_COPYABLE: case PRIM_IS_ASSIGNABLE: case PRIM_IS_CONST_ASSIGNABLE: + case PRIM_HAS_DEFAULT_VALUE: // param uses in module code + case PRIM_NEEDS_AUTO_DESTROY: // param uses in module code CHPL_UNIMPL("various primitives"); break; case PRIM_CALL_RESOLVES: @@ -883,8 +885,6 @@ CallResolutionResult resolvePrimCall(Context* context, break; } case PRIM_IS_WIDE_PTR: - case PRIM_HAS_DEFAULT_VALUE: - case PRIM_NEEDS_AUTO_DESTROY: case PRIM_NOTEQUAL: case PRIM_LESSOREQUAL: case PRIM_GREATEROREQUAL: @@ -936,17 +936,13 @@ CallResolutionResult resolvePrimCall(Context* context, } break; /* primitives that return default int */ - case PRIM_GATHER_TESTS: case PRIM_GET_UNION_ID: case PRIM_GET_REQUESTED_SUBLOC: - case PRIM_SIZEOF_BUNDLE: // TODO: this should be sizeType - case PRIM_SIZEOF_DDATA_ELEMENT: // TODO: this should be sizeType type = QualifiedType(QualifiedType::CONST_VAR, IntType::get(context, 0)); break; /* primitives that return an int32 */ case PRIM_GETCID: - case PRIM_WIDE_GET_NODE: // TODO: should be nodeIdType type = QualifiedType(QualifiedType::CONST_VAR, IntType::get(context, 32)); break; @@ -1093,6 +1089,8 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_GPU_SET_BLOCKSIZE: case PRIM_ASSERT_ON_GPU: case PRIM_GPU_ELIGIBLE: + case PRIM_SIZEOF_BUNDLE: // TODO: this should be sizeType + case PRIM_SIZEOF_DDATA_ELEMENT: // TODO: this should be sizeType case PRIM_LIFETIME_OF: CHPL_UNIMPL("misc primitives"); break; @@ -1133,6 +1131,7 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_LOGICAL_FOLDER: case PRIM_WIDE_MAKE: case PRIM_WIDE_GET_LOCALE: + case PRIM_WIDE_GET_NODE: // TODO: this should be nodeIdType (int32) case PRIM_ON_LOCALE_NUM: case PRIM_REGISTER_GLOBAL_VAR: case PRIM_BROADCAST_GLOBAL_VARS: @@ -1155,6 +1154,7 @@ CallResolutionResult resolvePrimCall(Context* context, case PRIM_NO_ALIAS_SET: case PRIM_COPIES_NO_ALIAS_SET: case PRIM_OPTIMIZATION_INFO: + case PRIM_GATHER_TESTS: // param uses in module code CHPL_UNIMPL("misc primitives"); break; diff --git a/frontend/test/resolution/CMakeLists.txt b/frontend/test/resolution/CMakeLists.txt index b19c14e2c09f..d80dd073be28 100644 --- a/frontend/test/resolution/CMakeLists.txt +++ b/frontend/test/resolution/CMakeLists.txt @@ -64,6 +64,7 @@ comp_unit_test(testReflection) comp_unit_test(testResolve) comp_unit_test(testResolverVerboseErrors) comp_unit_test(testReturnTypes) +comp_unit_test(testRuntimePrimitives) comp_unit_test(testScopeResolve) comp_unit_test(testScopeTypes) comp_unit_test(testSplitInit) diff --git a/frontend/test/resolution/testFunctionCalls.cpp b/frontend/test/resolution/testFunctionCalls.cpp index 9557312a90ad..b80c24e48789 100644 --- a/frontend/test/resolution/testFunctionCalls.cpp +++ b/frontend/test/resolution/testFunctionCalls.cpp @@ -132,424 +132,11 @@ static void test3b() { helpTest3(theFunction); } -// test that we can handle non-param string for string_length_bytes -static void test4() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var s:string; - var x = __primitive("string_length_bytes", s); - )""""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isIntType()); - assert(typePtr->toIntType()->bitwidth() == 64); -} - -// test that we can handle non-param bytes for string_length_bytes -static void test5() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var b:bytes; - var x = __primitive("string_length_bytes", b); - )""""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isIntType()); - assert(typePtr->toIntType()->bitwidth() == 64); -} - -static void test6() { - // test for primitive return type for get real/imag - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var a: complex(128); - var x = __primitive("complex_get_real", a); - )""""); - assert(qt.kind() == QualifiedType::REF); - auto typePtr = qt.type(); - assert(typePtr); - auto realPtr = typePtr->toRealType(); - assert(realPtr->bitwidth()==64); -} - -static void test7() { - // test for primitive return type for get real/imag - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var a: complex(64); - var x = __primitive("complex_get_real", a); - )""""); - assert(qt.kind() == QualifiedType::REF); - auto typePtr = qt.type(); - assert(typePtr); - auto realPtr = typePtr->toRealType(); - assert(realPtr->bitwidth()==32); -} - -static void test8() { - // test for primitive return type for get real/imag - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var a: complex(128); - var x = __primitive("complex_get_imag", a); - )""""); - assert(qt.kind() == QualifiedType::REF); - auto typePtr = qt.type(); - assert(typePtr); - auto realPtr = typePtr->toRealType(); - assert(realPtr->bitwidth()==64); -} - -static void test9() { - // test for primitive return type for get real/imag - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var a: complex(64); - var x = __primitive("complex_get_imag", a); - )""""); - assert(qt.kind() == QualifiedType::REF); - auto typePtr = qt.type(); - assert(typePtr); - auto realPtr = typePtr->toRealType(); - assert(realPtr->bitwidth()==32); -} - -static void test10() { - // check that primitive "gather tests" returns an int - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var x = __primitive("gather tests"); - )""""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isIntType()); -} - -static void test11() { - // test for primitive "is wide pointer", which should return a bool - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var x = __primitive("is wide pointer"); - )""""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isBoolType()); -} - -// test for primitive "_wide_get_addr", which should return a void ptr -static void test12() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var x = __primitive("_wide_get_addr"); - )""""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - auto cPtrType = typePtr->toCPtrType(); - assert(cPtrType); - assert(cPtrType->isVoidPtr()); -} - -// test for primitive "steal", which should return the type of the argument -static void test13() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var a = 1; - var x = __primitive("steal", a); - )""""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isIntType()); -} - - -// test for primitive "type has default value", which should return a bool -static void test14() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var x = __primitive("type has default value"); - )""""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isBoolType()); -} - -// test for primitive "needs auto destroy", which should return a bool -static void test15() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var x = __primitive("needs auto destroy"); - )""""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isBoolType()); -} - -// test for primitive "getcid", which should return an int32 -static void test16() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var x = __primitive("getcid"); - )""""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isIntType()); - assert(typePtr->toIntType()->bitwidth() == 32); -} - -// test for primitive "get_union_id", which should return a default int -static void test17() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R""""( - var x = __primitive("get_union_id"); - )""""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isIntType()); - assert(typePtr->toIntType()->bitwidth() == 64); -} - -static void voidTypeTestHelper(std::string program) { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, program); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isVoidType()); -} - -// test for primitive "chpl_init_record", which should return void -static void test18() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_init_record");)"""); -} - -// test for primitive "chpl_comm_get", which should return void -static void test19() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_get");)"""); -} - -// test for primitive "chpl_comm_put", which should return void -static void test20() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_put");)"""); -} - -// test for primitive "chpl_comm_array_get", which should return void -static void test21() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_array_get");)"""); -} - -// test for primitive "chpl_comm_array_put", which should return void -static void test22() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_array_put");)"""); -} - -// test for primitive "chpl_comm_remote_prefetch", which should return void -static void test23() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_remote_prefetch");)"""); -} - -// test for primitive "chpl_comm_get_strd", which should return void -static void test24() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_get_strd");)"""); -} - - -// test for primitive "chpl_comm_put_strd", which should return void -static void test25() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_put_strd");)"""); -} - -// test for primitive "shift_base_pointer", which should return void -static void test26() { - voidTypeTestHelper(R"""(var x = __primitive("shift_base_pointer");)"""); -} - -// test for primitive "array_set", which should return void -static void test27() { - voidTypeTestHelper(R"""(var x = __primitive("array_set");)"""); -} - -// test for primitive "array_set_first", which should return void -static void test28() { - voidTypeTestHelper(R"""(var x = __primitive("array_set_first");)"""); -} - -// test for primitive "auto destroy runtime type", which should return void -static void test29() { - voidTypeTestHelper(R"""(var x = __primitive("auto destroy runtime type");)"""); -} - -// test for primitive "create fn type", which should return void -static void test30() { - voidTypeTestHelper(R"""(var x = __primitive("create fn type");)"""); -} - -// "chpl_task_getRequestedSubloc", which should return int 64 -static void test31() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R"""(var x = __primitive("chpl_task_getRequestedSubloc");)"""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isIntType()); - assert(typePtr->toIntType()->bitwidth() == 64); -} - -// "sizeof_ddata_element", which should return int 64 (actually sizeType) -static void test32() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R"""(var x = __primitive("sizeof_ddata_element");)"""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isIntType()); - assert(typePtr->toIntType()->bitwidth() == 64); -} - -// "_wide_get_node", which should return int 32 (actually nodeIdType) -static void test33() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R"""(var x = __primitive("_wide_get_node");)"""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isIntType()); - assert(typePtr->toIntType()->bitwidth() == 32); -} - -// "class name by id", which should return a cString -static void test34() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R"""(var x = __primitive("class name by id");)"""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isCStringType()); -} - -// "ref to string", which should return a cString -static void test35() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R"""(var x = __primitive("ref to string");)"""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isCStringType()); -} - -// "chpl_lookupFilename", which should return a cString -static void test36() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R"""(var x = __primitive("chpl_lookupFilename");)"""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isCStringType()); -} - -// "sizeof_bundle", which should return int 64 (actually sizeType) -static void test37() { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, - R"""(var x = __primitive("sizeof_bundle");)"""); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isIntType()); - assert(typePtr->toIntType()->bitwidth() == 64); -} - - int main() { test1(); test2(); test3a(); test3b(); - test4(); - test5(); - test6(); - test7(); - test8(); - test9(); - test10(); - test11(); - test12(); - test13(); - test14(); - test15(); - test16(); - test17(); - test18(); - test19(); - test20(); - test21(); - test22(); - test23(); - test24(); - test25(); - test26(); - test27(); - test28(); - test29(); - test30(); - test31(); - test32(); - test33(); - test34(); - test35(); - test36(); - test37(); return 0; } diff --git a/frontend/test/resolution/testRuntimePrimitives.cpp b/frontend/test/resolution/testRuntimePrimitives.cpp new file mode 100644 index 000000000000..bfe5b3a183f6 --- /dev/null +++ b/frontend/test/resolution/testRuntimePrimitives.cpp @@ -0,0 +1,352 @@ +/* + * Copyright 2021-2023 Hewlett Packard Enterprise Development LP + * Other additional copyright holders may be indicated within. + * + * The entirety of this work is licensed under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "test-resolution.h" + +#include "chpl/types/all-types.h" + +// test that we can handle non-param string for string_length_bytes +static void test1() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var s:string; + var x = __primitive("string_length_bytes", s); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 64); +} + +// test that we can handle non-param bytes for string_length_bytes +static void test2() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var b:bytes; + var x = __primitive("string_length_bytes", b); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 64); +} + +static void test3() { + // test for primitive return type for get real/imag + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var a: complex(128); + var x = __primitive("complex_get_real", a); + )""""); + assert(qt.kind() == QualifiedType::REF); + auto typePtr = qt.type(); + assert(typePtr); + auto realPtr = typePtr->toRealType(); + assert(realPtr->bitwidth()==64); +} + +static void test4() { + // test for primitive return type for get real/imag + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var a: complex(64); + var x = __primitive("complex_get_real", a); + )""""); + assert(qt.kind() == QualifiedType::REF); + auto typePtr = qt.type(); + assert(typePtr); + auto realPtr = typePtr->toRealType(); + assert(realPtr->bitwidth()==32); +} + +static void test5() { + // test for primitive return type for get real/imag + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var a: complex(128); + var x = __primitive("complex_get_imag", a); + )""""); + assert(qt.kind() == QualifiedType::REF); + auto typePtr = qt.type(); + assert(typePtr); + auto realPtr = typePtr->toRealType(); + assert(realPtr->bitwidth()==64); +} + +static void test6() { + // test for primitive return type for get real/imag + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var a: complex(64); + var x = __primitive("complex_get_imag", a); + )""""); + assert(qt.kind() == QualifiedType::REF); + auto typePtr = qt.type(); + assert(typePtr); + auto realPtr = typePtr->toRealType(); + assert(realPtr->bitwidth()==32); +} + +static void test7() { + // test for primitive "is wide pointer", which should return a bool + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var x = __primitive("is wide pointer"); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isBoolType()); +} + +// test for primitive "_wide_get_addr", which should return a void ptr +static void test8() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var x = __primitive("_wide_get_addr"); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + auto cPtrType = typePtr->toCPtrType(); + assert(cPtrType); + assert(cPtrType->isVoidPtr()); +} + +// test for primitive "steal", which should return the type of the argument +static void test9() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var a = 1; + var x = __primitive("steal", a); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); +} + +// test for primitive "getcid", which should return an int32 +static void test10() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var x = __primitive("getcid"); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 32); +} + +// test for primitive "get_union_id", which should return a default int +static void test11() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R""""( + var x = __primitive("get_union_id"); + )""""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 64); +} + +static void voidTypeTestHelper(std::string program) { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, program); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isVoidType()); +} + +// test for primitive "chpl_init_record", which should return void +static void test12() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_init_record");)"""); +} + +// test for primitive "chpl_comm_get", which should return void +static void test13() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_get");)"""); +} + +// test for primitive "chpl_comm_put", which should return void +static void test14() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_put");)"""); +} + +// test for primitive "chpl_comm_array_get", which should return void +static void test15() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_array_get");)"""); +} + +// test for primitive "chpl_comm_array_put", which should return void +static void test16() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_array_put");)"""); +} + +// test for primitive "chpl_comm_remote_prefetch", which should return void +static void test17() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_remote_prefetch");)"""); +} + +// test for primitive "chpl_comm_get_strd", which should return void +static void test18() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_get_strd");)"""); +} + + +// test for primitive "chpl_comm_put_strd", which should return void +static void test19() { + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_put_strd");)"""); +} + +// test for primitive "shift_base_pointer", which should return void +static void test20() { + voidTypeTestHelper(R"""(var x = __primitive("shift_base_pointer");)"""); +} + +// test for primitive "array_set", which should return void +static void test21() { + voidTypeTestHelper(R"""(var x = __primitive("array_set");)"""); +} + +// test for primitive "array_set_first", which should return void +static void test22() { + voidTypeTestHelper(R"""(var x = __primitive("array_set_first");)"""); +} + +// test for primitive "auto destroy runtime type", which should return void +static void test23() { + voidTypeTestHelper(R"""(var x = __primitive("auto destroy runtime type");)"""); +} + +// test for primitive "create fn type", which should return void +static void test24() { + voidTypeTestHelper(R"""(var x = __primitive("create fn type");)"""); +} + +// "chpl_task_getRequestedSubloc", which should return int 64 +static void test25() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("chpl_task_getRequestedSubloc");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isIntType()); + assert(typePtr->toIntType()->bitwidth() == 64); +} + +// "class name by id", which should return a cString +static void test26() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("class name by id");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isCStringType()); +} + +// "ref to string", which should return a cString +static void test27() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("ref to string");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isCStringType()); +} + +// "chpl_lookupFilename", which should return a cString +static void test28() { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, + R"""(var x = __primitive("chpl_lookupFilename");)"""); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isCStringType()); +} + + +int main() { + test1(); + test2(); + test3(); + test4(); + test5(); + test6(); + test7(); + test8(); + test9(); + test10(); + test11(); + test12(); + test13(); + test14(); + test15(); + test16(); + test17(); + test18(); + test19(); + test20(); + test21(); + test22(); + test23(); + test24(); + test25(); + test26(); + test27(); + test28(); + + return 0; +} From f45d77d7a4af517aa2498246570fd226ed890703 Mon Sep 17 00:00:00 2001 From: arezaii Date: Tue, 12 Dec 2023 13:53:57 -0700 Subject: [PATCH 7/7] cleanup runtime prim test file Signed-off-by: arezaii --- .../test/resolution/testRuntimePrimitives.cpp | 150 +++++++----------- 1 file changed, 58 insertions(+), 92 deletions(-) diff --git a/frontend/test/resolution/testRuntimePrimitives.cpp b/frontend/test/resolution/testRuntimePrimitives.cpp index bfe5b3a183f6..1c9475505be7 100644 --- a/frontend/test/resolution/testRuntimePrimitives.cpp +++ b/frontend/test/resolution/testRuntimePrimitives.cpp @@ -21,6 +21,59 @@ #include "chpl/types/all-types.h" + +static void voidTypeTestHelper(std::string program) { + Context ctx; + auto context = &ctx; + QualifiedType qt = resolveTypeOfXInit(context, program); + assert(qt.kind() == QualifiedType::CONST_VAR); + auto typePtr = qt.type(); + assert(typePtr); + assert(typePtr->isVoidType()); +} + +// tests for primitives that should return void +static void testVoidPrims() { + // test for primitive "chpl_init_record" + voidTypeTestHelper(R"""(var x = __primitive("chpl_init_record");)"""); + + // test for primitive "chpl_comm_get" + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_get");)"""); + + // test for primitive "chpl_comm_put" + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_put");)"""); + + // test for primitive "chpl_comm_array_get" + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_array_get");)"""); + + // test for primitive "chpl_comm_array_put" + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_array_put");)"""); + + // test for primitive "chpl_comm_remote_prefetch" + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_remote_prefetch");)"""); + + // test for primitive "chpl_comm_get_strd" + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_get_strd");)"""); + + // test for primitive "chpl_comm_put_strd" + voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_put_strd");)"""); + + // test for primitive "shift_base_pointer" + voidTypeTestHelper(R"""(var x = __primitive("shift_base_pointer");)"""); + + // test for primitive "array_set" + voidTypeTestHelper(R"""(var x = __primitive("array_set");)"""); + + // test for primitive "array_set_first" + voidTypeTestHelper(R"""(var x = __primitive("array_set_first");)"""); + + // test for primitive "auto destroy runtime type" + voidTypeTestHelper(R"""(var x = __primitive("auto destroy runtime type");)"""); + + // test for primitive "create fn type" + voidTypeTestHelper(R"""(var x = __primitive("create fn type");)"""); +} + // test that we can handle non-param string for string_length_bytes static void test1() { Context ctx; @@ -192,84 +245,9 @@ static void test11() { assert(typePtr->toIntType()->bitwidth() == 64); } -static void voidTypeTestHelper(std::string program) { - Context ctx; - auto context = &ctx; - QualifiedType qt = resolveTypeOfXInit(context, program); - assert(qt.kind() == QualifiedType::CONST_VAR); - auto typePtr = qt.type(); - assert(typePtr); - assert(typePtr->isVoidType()); -} - -// test for primitive "chpl_init_record", which should return void -static void test12() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_init_record");)"""); -} - -// test for primitive "chpl_comm_get", which should return void -static void test13() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_get");)"""); -} - -// test for primitive "chpl_comm_put", which should return void -static void test14() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_put");)"""); -} - -// test for primitive "chpl_comm_array_get", which should return void -static void test15() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_array_get");)"""); -} - -// test for primitive "chpl_comm_array_put", which should return void -static void test16() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_array_put");)"""); -} - -// test for primitive "chpl_comm_remote_prefetch", which should return void -static void test17() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_remote_prefetch");)"""); -} - -// test for primitive "chpl_comm_get_strd", which should return void -static void test18() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_get_strd");)"""); -} - - -// test for primitive "chpl_comm_put_strd", which should return void -static void test19() { - voidTypeTestHelper(R"""(var x = __primitive("chpl_comm_put_strd");)"""); -} - -// test for primitive "shift_base_pointer", which should return void -static void test20() { - voidTypeTestHelper(R"""(var x = __primitive("shift_base_pointer");)"""); -} - -// test for primitive "array_set", which should return void -static void test21() { - voidTypeTestHelper(R"""(var x = __primitive("array_set");)"""); -} - -// test for primitive "array_set_first", which should return void -static void test22() { - voidTypeTestHelper(R"""(var x = __primitive("array_set_first");)"""); -} - -// test for primitive "auto destroy runtime type", which should return void -static void test23() { - voidTypeTestHelper(R"""(var x = __primitive("auto destroy runtime type");)"""); -} - -// test for primitive "create fn type", which should return void -static void test24() { - voidTypeTestHelper(R"""(var x = __primitive("create fn type");)"""); -} // "chpl_task_getRequestedSubloc", which should return int 64 -static void test25() { +static void test12() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -282,7 +260,7 @@ static void test25() { } // "class name by id", which should return a cString -static void test26() { +static void test13() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -294,7 +272,7 @@ static void test26() { } // "ref to string", which should return a cString -static void test27() { +static void test14() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -306,7 +284,7 @@ static void test27() { } // "chpl_lookupFilename", which should return a cString -static void test28() { +static void test15() { Context ctx; auto context = &ctx; QualifiedType qt = resolveTypeOfXInit(context, @@ -319,6 +297,7 @@ static void test28() { int main() { + testVoidPrims(); test1(); test2(); test3(); @@ -334,19 +313,6 @@ int main() { test13(); test14(); test15(); - test16(); - test17(); - test18(); - test19(); - test20(); - test21(); - test22(); - test23(); - test24(); - test25(); - test26(); - test27(); - test28(); return 0; }