Skip to content

Commit

Permalink
Remove more redundant hardcoded symbol names of special types
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Rift <[email protected]>
  • Loading branch information
riftEmber committed Jul 31, 2024
1 parent 4bbb82f commit 71d92dd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
4 changes: 2 additions & 2 deletions frontend/lib/types/ArrayType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ ArrayType::getArrayTypeQuery(Context* context, ID id, UniqueString name,

const ArrayType*
ArrayType::getGenericArrayType(Context* context) {
auto name = UniqueString::get(context, "_array");
auto id = getArrayID(context);
auto name = id.symbolName(context);
SubstitutionsMap subs;
const ArrayType* instantiatedFrom = nullptr;
return getArrayTypeQuery(context, id, name, instantiatedFrom, subs).get();
Expand All @@ -75,8 +75,8 @@ ArrayType::getArrayType(Context* context,
SubstitutionsMap subs;
subs.emplace(ArrayType::domainId, domainType);
subs.emplace(ArrayType::eltTypeId, eltType);
auto name = UniqueString::get(context, "_array");
auto id = getArrayID(context);
auto name = id.symbolName(context);
auto instantiatedFrom = getGenericArrayType(context);
return getArrayTypeQuery(context, id, name, instantiatedFrom, subs).get();
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/types/BasicClassType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ BasicClassType::getRootClassType(Context* context) {

const BasicClassType*
BasicClassType::getReduceScanOpType(Context* context) {
auto name = UniqueString::get(context, "ReduceScanOp");
auto id = parsing::getSymbolFromTopLevelModule(context, "ChapelReduce", "ReduceScanOp");
auto name = id.symbolName(context);
auto objectType = getRootClassType(context);

return getBasicClassType(context, id, name,
Expand Down
30 changes: 14 additions & 16 deletions frontend/lib/types/CompositeType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,40 +135,40 @@ void CompositeType::stringify(std::ostream& ss,
}

const RecordType* CompositeType::getStringType(Context* context) {
auto name = UniqueString::get(context, "string");
auto id = parsing::getSymbolFromTopLevelModule(context, "String", "_string");
auto name = UniqueString::get(context, "string");
return RecordType::get(context, id, name,
/* instantiatedFrom */ nullptr,
SubstitutionsMap());
}

const RecordType* CompositeType::getRangeType(Context* context) {
auto name = UniqueString::get(context, "_range");
auto id = parsing::getSymbolFromTopLevelModule(context, "ChapelRange", "_range");
auto name = id.symbolName(context);
return RecordType::get(context, id, name,
/* instantiatedFrom */ nullptr,
SubstitutionsMap());
}

const RecordType* CompositeType::getBytesType(Context* context) {
auto name = UniqueString::get(context, "bytes");
auto id = parsing::getSymbolFromTopLevelModule(context, "Bytes", "_bytes");
auto name = UniqueString::get(context, "bytes");
return RecordType::get(context, id, name,
/* instantiatedFrom */ nullptr,
SubstitutionsMap());
}

const RecordType* CompositeType::getLocaleType(Context* context) {
auto name = UniqueString::get(context, "locale");
auto id = parsing::getSymbolFromTopLevelModule(context, "ChapelLocale", "_locale");
auto name = UniqueString::get(context, "locale");
return RecordType::get(context, id, name,
/* instantiatedFrom */ nullptr,
SubstitutionsMap());
}

const RecordType* CompositeType::getLocaleIDType(Context* context) {
auto name = UniqueString::get(context, "chpl_localeID_t");
auto id = ID();
auto name = UniqueString::get(context, "chpl_localeID_t");
return RecordType::get(context, id, name,
/* instantiatedFrom */ nullptr,
SubstitutionsMap());
Expand All @@ -182,11 +182,10 @@ bool CompositeType::isMissingBundledType(Context* context, ID id) {
bool CompositeType::isMissingBundledRecordType(Context* context, ID id) {
bool noLibrary = parsing::bundledModulePath(context).isEmpty();
if (noLibrary) {
auto path = id.symbolPath();
return path == "String._string" ||
path == "ChapelRange._range" ||
path == "ChapelTuple._tuple" ||
path == "Bytes._bytes";
return id == CompositeType::getStringType(context)->id() ||
id == CompositeType::getRangeType(context)->id() ||
id == TupleType::getGenericTupleType(context)->id() ||
id == CompositeType::getBytesType(context)->id();
}

return false;
Expand All @@ -195,19 +194,18 @@ bool CompositeType::isMissingBundledRecordType(Context* context, ID id) {
bool CompositeType::isMissingBundledClassType(Context* context, ID id) {
bool noLibrary = parsing::bundledModulePath(context).isEmpty();
if (noLibrary) {
auto path = id.symbolPath();
return path == "ChapelReduce.ReduceScanOp" ||
path == "Errors.Error" ||
path == "CTypes.c_ptr" ||
path == "CTypes.c_ptrConst";
return id == BasicClassType::getReduceScanOpType(context)->id() ||
id == CompositeType::getErrorType(context)->basicClassType()->id() ||
id == CPtrType::getId(context) ||
id == CPtrType::getConstId(context);
}

return false;
}

const ClassType* CompositeType::getErrorType(Context* context) {
auto name = UniqueString::get(context, "Error");
auto id = parsing::getSymbolFromTopLevelModule(context, "Errors", "Error");
auto name = id.symbolName(context);
auto dec = ClassTypeDecorator(ClassTypeDecorator::GENERIC_NONNIL);
auto bct = BasicClassType::get(context, id,
name,
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/types/DomainType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ DomainType::getDomainType(Context* context, ID id, UniqueString name,

const DomainType*
DomainType::getGenericDomainType(Context* context) {
auto name = UniqueString::get(context, "_domain");
auto id = getDomainID(context);
auto name = id.symbolName(context);
SubstitutionsMap subs;
const DomainType* instantiatedFrom = nullptr;
return getDomainType(context, id, name, instantiatedFrom, subs).get();
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/types/TupleType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ TupleType::getTupleType(Context* context, const TupleType* instantiatedFrom,
QUERY_BEGIN(getTupleType, context, instantiatedFrom, subs,
isVarArgTuple);

auto name = UniqueString::get(context, "_tuple");
auto id = parsing::getSymbolFromTopLevelModule(context, "ChapelTuple", "_tuple");
auto name = id.symbolName(context);
auto result = toOwned(new TupleType(id, name, instantiatedFrom,
std::move(subs), isVarArgTuple));

Expand Down

0 comments on commit 71d92dd

Please sign in to comment.