Skip to content

Commit

Permalink
Tweak the Dyno builtins to match those in production (chapel-lang#23641)
Browse files Browse the repository at this point in the history
Dyno is missing just a handful of builtins from production; this PR adds
them back in.

The only things that were missing that seemed to be necessary to add
back in eagerly (as opposed to waiting for it to come up as part of
compiler implementation) were those missing from the (collapsed) list at
the bottom of the issue, except `splitInitType`, which seems like an
implementation detail. They are the following:

* `dtObject` -- dyno had `object`, which I changed to `RootClass` to
match the semi-recent rename.
* `dtTaskID` -- dyno had a type, but the name of the type was actually
the runtime value. I changed the name.
* `dtSingleAuxFields` -- added to match `dtSyncAuxFields`.

Overall, very few things were needed for compatibility.

Reviewed by @benharsh -- thanks!

## Testing

- [x] paratest

## Details

<details>
<summary>List prior to this PR</summary>

- [x] dtVoid = createInternalType("void", "void");
- [x] dtNothing = createInternalType ("nothing", "nothing");
- [x] dtInt[INT_SIZE_64] = createPrimitiveType("int", "int64_t");
- [x] dtReal[FLOAT_SIZE_64] = createPrimitiveType("real", "_real64");
- [x] dtStringC = createPrimitiveType("chpl_c_string",
"c_string_rehook");
- [ ] dtObject = new AggregateType(AGGREGATE_CLASS);
- [x] dtBytes = new AggregateType(AGGREGATE_RECORD);
- [x] dtString = new AggregateType(AGGREGATE_RECORD);
- [x] dtLocale = new AggregateType(AGGREGATE_RECORD);
- [x] dtRange = new AggregateType(AGGREGATE_RECORD);
- [x] dtOwned = new AggregateType(AGGREGATE_RECORD);
- [x] dtShared = new AggregateType(AGGREGATE_RECORD);
- [x] dtBool = createPrimitiveType("bool", "chpl_bool");
- [x] gFalse = createSymbol(dtBool, "false");
- [x] gTrue = createSymbol(dtBool, "true");
  - [x] dtNil = createInternalType ("_nilType", "_nilType");
- [ ] dtSplitInitType = createInternalType("_splitInitType",
"_splitInitType");
  - [x] dtUnknown = createInternalType ("_unknown", "_unknown");
  - [x] dtAnyRecord = createInternalType("record", "_anyRecord");
  - [x] INIT_PRIM_IMAG( "imag", 64);            // default size
  - [x] INIT_PRIM_COMPLEX( "complex", 128);       // default size
- [x] dtCVoidPtr = createPrimitiveType("chpl__c_void_ptr",
"raw_c_void_ptr" );
- [x] dtCFnPtr = createPrimitiveType("chpl_c_fn_ptr",
"c_fn_ptr_rehook");
  - [x] dtOpaque = createPrimitiveType("opaque", "chpl_opaque");
- [ ] dtTaskID = createPrimitiveType("chpl_taskID_t", "chpl_taskID_t");
- [x] dtSyncVarAuxFields = createPrimitiveType( "_sync_aux_t",
"chpl_sync_aux_t");
- [ ] dtSingleVarAuxFields = createPrimitiveType( "_single_aux_t",
"chpl_single_aux_t");
  - [x] dtAny = createInternalType ("_any", "_any");
  - [x] dtAnyComplex = createInternalType("chpl_anycomplex", "complex");
  - [x] dtAnyEnumerated = createInternalType ("enum", "enum");
  - [x] dtAnyImag = createInternalType("chpl_anyimag", "imag");
  - [x] dtAnyReal = createInternalType("chpl_anyreal", "real");
  - [x] dtAnyPOD = createInternalType ("chpl_anyPOD", "POD");
  - [x] dtIntegral = createInternalType ("integral", "integral");
  - [x] dtNumeric = createInternalType ("numeric", "numeric");
- [x] dtIteratorRecord = createInternalType("_iteratorRecord",
"_iteratorRecord");
- [x] dtIteratorClass = createInternalType("_iteratorClass",
"_iteratorClass");
  - [x] dtBorrowed = createInternalType("borrowed", "borrowed");
- [x] dtBorrowedNonNilable = createInternalType("_borrowedNonNilable",
"_borrowedNonNilable");
- [x] dtBorrowedNilable = createInternalType("_borrowedNilable",
"_borrowedNilable");
  - [x] dtUnmanaged = createInternalType("unmanaged", "unmanaged");
- [x] dtUnmanagedNonNilable = createInternalType("_unmanagedNonNilable",
"_unmanagedNonNilable");
- [x] dtUnmanagedNilable = createInternalType("_unmanagedNilable",
"_unmanagedNilable");
- [x] dtAnyManagementAnyNilable =
createInternalType("_anyManagementAnyNilable",
"_anyManagementAnyNilable");
- [x] dtAnyManagementNonNilable = createInternalType("class",
"_anyManagementNonNilable");
- [x] dtAnyManagementNilable =
createInternalType("_anyManagementNilable", "_anyManagementNilable");
</details>
  • Loading branch information
DanilaFe authored Oct 13, 2023
2 parents 1c53dea + 629b7bb commit 7c15850
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 18 deletions.
1 change: 1 addition & 0 deletions compiler/passes/convert-uast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4125,6 +4125,7 @@ Type* Converter::convertType(const types::QualifiedType qt) {
case typetags::CVoidPtrType: return dtCVoidPtr;
case typetags::OpaqueType: return dtOpaque;
case typetags::SyncAuxType: return dtSyncVarAuxFields;
case typetags::SingleAuxType: return dtSingleVarAuxFields;
case typetags::TaskIdType: return dtTaskID;

// generic builtin types
Expand Down
1 change: 1 addition & 0 deletions frontend/include/chpl/framework/all-global-strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ X(postinit , "postinit")
X(real_ , "real")
X(reduce , "reduce")
X(reduceAssign , "reduce=")
X(RootClass , "RootClass")
X(scan , "scan")
X(shared , "shared")
X(single , "single")
Expand Down
4 changes: 2 additions & 2 deletions frontend/include/chpl/types/BasicClassType.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BasicClassType final : public ManageableType {
{
// all classes should have a parent type, except for object
// which doesn't.
CHPL_ASSERT(parentType_ || name == USTR("object"));
CHPL_ASSERT(parentType_ || name == USTR("RootClass"));
}

bool contentsMatchInner(const Type* other) const override {
Expand Down Expand Up @@ -74,7 +74,7 @@ class BasicClassType final : public ManageableType {
const BasicClassType* instantiatedFrom,
CompositeType::SubstitutionsMap subs);

static const BasicClassType* getObjectType(Context* context);
static const BasicClassType* getRootClassType(Context* context);

static const BasicClassType* getReduceScanOpType(Context* context);

Expand Down
3 changes: 2 additions & 1 deletion frontend/include/chpl/types/type-classes-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ TYPE_BEGIN_SUBCLASSES(BuiltinType)
BUILTIN_TYPE_NODE(CVoidPtrType, "chpl__c_void_ptr")
BUILTIN_TYPE_NODE(OpaqueType, "opaque")
BUILTIN_TYPE_NODE(SyncAuxType, "_sync_aux_t")
BUILTIN_TYPE_NODE(TaskIdType, "chpl_nullTaskID")
BUILTIN_TYPE_NODE(SingleAuxType, "_single_aux_t")
BUILTIN_TYPE_NODE(TaskIdType, "chpl_taskID_t")

// generic builtin types. AnyComplexType must be the first of these
// (or else adjust BuiltinType::genericity and this comment)
Expand Down
4 changes: 2 additions & 2 deletions frontend/lib/resolution/return-type-inference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ const CompositeType* helpGetTypeForDecl(Context* context,
// OK, It's an interface.
} else {
context->error(inheritExpr, "invalid parent class expression");
parentClassType = BasicClassType::getObjectType(context);
parentClassType = BasicClassType::getRootClassType(context);
}
}

// All the parent expressions could've been interfaces, and we just
// inherit from object.
if (!parentClassType) {
parentClassType = BasicClassType::getObjectType(context);
parentClassType = BasicClassType::getRootClassType(context);
}

const BasicClassType* insnFromBct = nullptr;
Expand Down
6 changes: 3 additions & 3 deletions frontend/lib/types/BasicClassType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ BasicClassType::get(Context* context, ID id, UniqueString name,
}

const BasicClassType*
BasicClassType::getObjectType(Context* context) {
BasicClassType::getRootClassType(Context* context) {
ID emptyId;
auto name = UniqueString::get(context, "object");
auto name = UniqueString::get(context, "RootClass");

return getBasicClassType(context, emptyId, name,
/* parentType */ nullptr,
Expand All @@ -68,7 +68,7 @@ BasicClassType::getReduceScanOpType(Context* context) {
auto symbolPath = UniqueString::get(context, "ChapelReduce.ReduceScanOp");
auto name = UniqueString::get(context, "ReduceScanOp");
auto id = ID(symbolPath, -1, 0);
auto objectType = getObjectType(context);
auto objectType = getRootClassType(context);

return getBasicClassType(context, id, name,
/* parentType */ objectType,
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/types/CompositeType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const ClassType* CompositeType::getErrorType(Context* context) {
auto dec = ClassTypeDecorator(ClassTypeDecorator::GENERIC_NONNIL);
auto bct = BasicClassType::get(context, id,
name,
BasicClassType::getObjectType(context),
BasicClassType::getRootClassType(context),
/* instantiatedFrom */ nullptr,
SubstitutionsMap());
return ClassType::get(context, bct, /* manager */ nullptr, dec);
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/types/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void Type::gatherBuiltins(Context* context,
gatherType(context, map, "nothing", NothingType::get(context));
gatherType(context, map, "void", VoidType::get(context));

gatherType(context, map, "object", BasicClassType::getObjectType(context));
gatherType(context, map, "RootClass", BasicClassType::getRootClassType(context));

gatherType(context, map, "_tuple", TupleType::getGenericTupleType(context));

Expand Down
2 changes: 1 addition & 1 deletion frontend/test/resolution/testCanPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ static void test7() {

auto parentName = UniqueString::get(context, "Parent");
auto childName = UniqueString::get(context, "Child");
auto basicObj = BasicClassType::getObjectType(context);
auto basicObj = BasicClassType::getRootClassType(context);
auto basicParent = BasicClassType::get(context, emptyId, parentName,
basicObj,
/* instantiatedFrom */ nullptr,
Expand Down
14 changes: 7 additions & 7 deletions frontend/test/resolution/testTypeConstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ static void test36() {
auto p = parseTypeAndFieldsOfX(context,
R""""(
class ClassA {
var field: object;
var field: RootClass;
}
var x: owned ClassA;
)"""");
Expand All @@ -1072,8 +1072,8 @@ static void test36() {
assert(fct);
assert(fct->decorator().isUnknownManagement());
assert(fct->decorator().isNonNilable());
assert(fct->basicClassType()->name() == "object");
assert(fct->basicClassType() == BasicClassType::getObjectType(context));
assert(fct->basicClassType()->name() == "RootClass");
assert(fct->basicClassType() == BasicClassType::getRootClassType(context));
}

static void test37() {
Expand Down Expand Up @@ -1123,7 +1123,7 @@ static void test38() {
var parentField:int;
}
class Child : Parent {
var childObject: object;
var childObject: RootClass;
}
var x: owned Child;
)"""");
Expand All @@ -1144,13 +1144,13 @@ static void test38() {
assert(fct);
assert(fct->decorator().isUnknownManagement());
assert(fct->decorator().isNonNilable());
assert(fct->basicClassType()->name() == "object");
assert(fct->basicClassType() == BasicClassType::getObjectType(context));
assert(fct->basicClassType()->name() == "RootClass");
assert(fct->basicClassType() == BasicClassType::getRootClassType(context));

auto pct = bct->parentClassType()->toBasicClassType();
assert(pct);
assert(pct->parentClassType()->isObjectType());
assert(pct->parentClassType() == BasicClassType::getObjectType(context));
assert(pct->parentClassType() == BasicClassType::getRootClassType(context));

auto& parentFields = fieldsForTypeDecl(context, pct, DefaultsPolicy::IGNORE_DEFAULTS);
assert(parentFields.numFields() == 1);
Expand Down

0 comments on commit 7c15850

Please sign in to comment.