Skip to content

Commit

Permalink
minor formatting adjustments
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmad Rezaii <[email protected]>
  • Loading branch information
arezaii committed Sep 3, 2024
1 parent d9576b6 commit 9d3eea5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
13 changes: 8 additions & 5 deletions frontend/lib/resolution/can-pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,10 @@ bool CanPassResult::canInstantiateBuiltin(Context* context,
return false;
}

static bool tryConvertClassTypeIntoManagerRecordIfNeeded(Context* context,
const Type*& mightBeManagerRecord,
const Type*& mightBeClass) {
static bool
tryConvertClassTypeIntoManagerRecordIfNeeded(Context* context,
const Type*& mightBeManagerRecord,
const Type*& mightBeClass) {
if (!mightBeManagerRecord || !mightBeClass) return false;

auto mr = mightBeManagerRecord->toRecordType();
Expand All @@ -830,8 +831,10 @@ static bool tryConvertClassTypeIntoManagerRecordIfNeeded(Context* context,
}

// Override the class type to the manager record type
mightBeClass = ct->managerRecordType(context); // mightBeClass used to be `owned` of type ClassType,
// now it's `_owned` of type RecordType
mightBeClass = ct->managerRecordType(context);
// mightBeClass used to be `owned` of type ClassType,
// now it's `_owned` of type RecordType

return true;
}

Expand Down
4 changes: 3 additions & 1 deletion frontend/lib/types/ClassType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ const ClassType* ClassType::withDecorator(Context* context,

const RecordType* ClassType::managerRecordType(Context* context) const {
// for owned and shared, manager is the builtin AnyClassType
// e.g. for `owned C`, produce `_owned(C)`
// for `shared C`, produce `_shared(C)`
if (auto myManager = manager()) {
if (myManager->isAnyOwnedType()) {
return CompositeType::getOwnedRecordType(context, basicClassType()); // for `owned C`, produce `_owned(C)`
return CompositeType::getOwnedRecordType(context, basicClassType());
} else if (myManager->isAnySharedType()) {
return CompositeType::getSharedRecordType(context, basicClassType());
} else if (auto mgr = myManager->toRecordType()) {
Expand Down
23 changes: 16 additions & 7 deletions frontend/lib/types/CompositeType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,25 @@ static const RecordType* tryCreateManagerRecord(Context* context,
const RecordType* instantiatedFrom = nullptr;
SubstitutionsMap subs;
if (bct != nullptr) {
instantiatedFrom = tryCreateManagerRecord(context, moduleName, recordName, nullptr);

auto fields = fieldsForTypeDecl(context, instantiatedFrom, DefaultsPolicy::IGNORE_DEFAULTS);
instantiatedFrom = tryCreateManagerRecord(context,
moduleName,
recordName,
/*bct*/ nullptr);

auto fields = fieldsForTypeDecl(context,
instantiatedFrom,
DefaultsPolicy::IGNORE_DEFAULTS);
for (int i = 0; i < fields.numFields(); i++) {
if (fields.fieldName(i) != "chpl_t") continue;
auto ct = ClassType::get(context, bct, /* manager */ nullptr, ClassTypeDecorator(ClassTypeDecorator::BORROWED_NONNIL));
auto ctd = ClassTypeDecorator(ClassTypeDecorator::BORROWED_NONNIL);
auto ct = ClassType::get(context, bct, /* manager */ nullptr, ctd);

subs[fields.fieldDeclId(i)] = QualifiedType(QualifiedType::TYPE, ct);
break;
}
if (fields.numFields() == 0) {
CHPL_ASSERT(CompositeType::isMissingBundledRecordType(context, instantiatedFrom->id()));
CHPL_ASSERT(CompositeType::isMissingBundledRecordType(context,
instantiatedFrom->id()));
return nullptr;
}
}
Expand All @@ -216,11 +223,13 @@ static const RecordType* tryCreateManagerRecord(Context* context,
std::move(subs));
}

const RecordType* CompositeType::getOwnedRecordType(Context* context, const BasicClassType* bct) {
const RecordType*
CompositeType::getOwnedRecordType(Context* context, const BasicClassType* bct) {
return tryCreateManagerRecord(context, "OwnedObject", "_owned", bct);
}

const RecordType* CompositeType::getSharedRecordType(Context* context, const BasicClassType* bct) {
const RecordType*
CompositeType::getSharedRecordType(Context* context, const BasicClassType* bct) {
return tryCreateManagerRecord(context, "SharedObject", "_shared", bct);
}

Expand Down

0 comments on commit 9d3eea5

Please sign in to comment.