Skip to content

Commit

Permalink
Use makeParam* convenience functions (almost) everywhere
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Rift <[email protected]>
  • Loading branch information
riftEmber committed Jan 16, 2025
1 parent 9c7eb35 commit 25769e4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 92 deletions.
4 changes: 1 addition & 3 deletions compiler/passes/convert-typed-uast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,9 +1098,7 @@ void TConverter::createMainFunctions() {

// TODO: add converter or QualifiedType methods to more
// easily construct a QualifiedType for common values like param false.
auto falseQt = types::QualifiedType(types::QualifiedType::PARAM,
types::BoolType::get(context),
types::BoolParam::get(context, false));
auto falseQt = types::QualifiedType::makeParamBool(context, false);
auto ci = resolution::CallInfo(UniqueString::get(context, "_endCountAlloc"),
/* calledType */ types::QualifiedType(),
/* isMethodCall */ false,
Expand Down
25 changes: 7 additions & 18 deletions frontend/lib/resolution/Resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,7 @@ void Resolver::resolveTypeQueries(const AstNode* formalTypeExpr,
if (isNonStarVarArg) {
varArgTypeQueryError(context, call->actual(0), resolvedWidth);
} else {
auto p = IntParam::get(context, pt->bitwidth());
auto it = IntType::get(context, 0);
auto qt = QualifiedType(QualifiedType::PARAM, it, p);
auto qt = QualifiedType::makeParamInt(context, pt->bitwidth());
resolvedWidth.setType(qt);
}
}
Expand Down Expand Up @@ -1218,10 +1216,8 @@ void Resolver::resolveTypeQueriesFromFormalType(const VarLikeDecl* formal,

// args...?n
if (auto countQuery = varargs->count()) {
auto intType = IntType::get(context, 0);
auto val = IntParam::get(context, tuple->numElements());
ResolvedExpression& result = byPostorder.byAst(countQuery);
result.setType(QualifiedType(QualifiedType::PARAM, intType, val));
result.setType(QualifiedType::makeParamInt(context, tuple->numElements()));
}

if (auto typeExpr = formal->typeExpression()) {
Expand Down Expand Up @@ -2453,8 +2449,7 @@ bool Resolver::resolveSpecialPrimitiveCall(const Call* call) {
resultBool = false;
}

result = QualifiedType(QualifiedType::PARAM, BoolType::get(context),
BoolParam::get(context, resultBool));
result = QualifiedType::makeParamBool(context, resultBool);
}

byPostorder.byAst(primCall).setType(result);
Expand Down Expand Up @@ -2748,9 +2743,7 @@ QualifiedType Resolver::typeForId(const ID& id, bool localGenericToUnknown) {
if (field && field->name() == USTR("size")) {
// Tuples don't store a 'size' in their substitutions map, so
// manually take care of things here.
auto intType = IntType::get(context, 0);
auto val = IntParam::get(context, tup->numElements());
return QualifiedType(QualifiedType::PARAM, intType, val);
return QualifiedType::makeParamInt(context, val);
}
}

Expand Down Expand Up @@ -4174,10 +4167,8 @@ void Resolver::exit(const uast::Domain* decl) {

// Add definedConst actual if appropriate
if (decl->usedCurlyBraces()) {
actuals.emplace_back(
QualifiedType(QualifiedType::PARAM, BoolType::get(context),
BoolParam::get(context, true)),
UniqueString());
actuals.emplace_back(QualifiedType::makeParamBool(context, true)),
UniqueString();
}

auto ci = CallInfo(/* name */ UniqueString::get(context, domainBuilderProc),
Expand Down Expand Up @@ -4235,9 +4226,7 @@ types::QualifiedType Resolver::typeForBooleanOp(const uast::OpCall* op) {
// preserve param-ness
// this case is only hit when the result is false (for &&)
// or when the result is true (for ||), so return !isAnd.
return QualifiedType(QualifiedType::PARAM,
BoolType::get(context),
BoolParam::get(context, !isAnd));
return QualifiedType::makeParamBool(context, !isAnd);
} else {
// otherwise just return a Bool value
return QualifiedType(QualifiedType::CONST_VAR,
Expand Down
60 changes: 17 additions & 43 deletions frontend/lib/resolution/prims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ static QualifiedType primNumFields(Context* context, const CallInfo& ci) {
auto firstActual = ci.actual(0).type();
if (auto fields = toCompositeTypeActualFields(context, firstActual)) {
int64_t numFields = fields->numFields();
type = QualifiedType(QualifiedType::PARAM,
IntType::get(context, 64),
IntParam::get(context, numFields));
type = QualifiedType::makeParamInt(context, numFields);
}
return type;
}
Expand All @@ -154,9 +152,7 @@ static QualifiedType primFieldNumToName(Context* context, const CallInfo& ci) {
if (fieldNum > fields->numFields() || fieldNum < 1) return type;

auto fieldName = fields->fieldName(fieldNum - 1);
type = QualifiedType(QualifiedType::PARAM,
RecordType::getStringType(context),
StringParam::get(context, fieldName));
type = QualifiedType::makeParamString(context, fieldName);
}
return type;
}
Expand Down Expand Up @@ -184,9 +180,7 @@ static QualifiedType primFieldNameToNum(Context* context, const CallInfo& ci) {
}

if (!foundField) return type;
type = QualifiedType(QualifiedType::PARAM,
IntType::get(context, 64),
IntParam::get(context, field));
type = QualifiedType::makeParamInt(context, field);
}
return type;
}
Expand Down Expand Up @@ -263,9 +257,7 @@ static QualifiedType primCallResolves(ResolutionContext* rc,
}
}

return QualifiedType(QualifiedType::PARAM,
BoolType::get(context),
BoolParam::get(context, callAndFnResolved));
return QualifiedType::makeParamBool(context, callAndFnResolved);
}

static QualifiedType primImplementsInterface(Context* context,
Expand Down Expand Up @@ -516,9 +508,7 @@ static QualifiedType primGatherTests(Context* context, const CallInfo& ci) {
QUERY_STORE_INPUT_RESULT(gatheredTestsQuery, context, finder.fns);
auto numFoundFns = (int) gatheredTestsQuery(context).size();

return QualifiedType(QualifiedType::PARAM,
IntType::get(context, 0),
IntParam::get(context, numFoundFns));
return QualifiedType::makeParamInt(context, numFoundFns);
}

static QualifiedType primIsTuple(Context* context,
Expand All @@ -528,9 +518,7 @@ static QualifiedType primIsTuple(Context* context,
if (actualType.kind() != QualifiedType::TYPE) return QualifiedType();

bool isTupleType = actualType.type() && actualType.type()->isTupleType();
return QualifiedType(QualifiedType::PARAM,
BoolType::get(context),
BoolParam::get(context, isTupleType));
return QualifiedType::makeParamBool(context, isTupleType);
}

static QualifiedType primCast(Context* context,
Expand Down Expand Up @@ -715,8 +703,7 @@ static QualifiedType primFamilyIsSubtype(Context* context,
}
}

return QualifiedType(QualifiedType::PARAM, BoolType::get(context),
BoolParam::get(context, result));
return QualifiedType::makeParamBool(context, result);
}

static QualifiedType primToNilableClass(Context* context,
Expand Down Expand Up @@ -844,8 +831,7 @@ static QualifiedType primFamilyCopyableAssignable(Context* context,
const bool isCopyableOrAssignable =
info.isFromConst() || (info.isFromRef() && isFromRefOk);

return QualifiedType(QualifiedType::PARAM, BoolType::get(context),
BoolParam::get(context, isCopyableOrAssignable));
return QualifiedType::makeParamBool(context, isCopyableOrAssignable);
}

// TODO: What should be done for 'MAYBE_GENERIC', if anything?
Expand Down Expand Up @@ -1280,9 +1266,7 @@ CallResolutionResult resolvePrimCall(ResolutionContext* rc,
if (auto tt = t->toTupleType())
result = tt->isStarTuple();

type = QualifiedType(QualifiedType::PARAM,
BoolType::get(context),
BoolParam::get(context, result));
type = QualifiedType::makeParamBool(context, result);
}
break;

Expand Down Expand Up @@ -1379,9 +1363,7 @@ CallResolutionResult resolvePrimCall(ResolutionContext* rc,
if (toParamStringActual(actualType, sParam)||
toParamBytesActual(actualType, sParam)) {
const size_t s = sParam.length();
type = QualifiedType(QualifiedType::PARAM,
IntType::get(context, 0),
IntParam::get(context, s));
type = QualifiedType::makeParamInt(context, s);
break;
} else if (actualType.type()->isStringType() ||
actualType.type()->isBytesType() ||
Expand All @@ -1406,7 +1388,7 @@ CallResolutionResult resolvePrimCall(ResolutionContext* rc,
auto lstr = lhs.param()->toStringParam()->value();
auto rstr = rhs.param()->toStringParam()->value();
auto concat = UniqueString::getConcat(context, lstr.c_str(), rstr.c_str());
type = QualifiedType(QualifiedType::PARAM, lhs.type(), StringParam::get(context, concat));
type = QualifiedType::makeParamString(context, concat);
}
}
break;
Expand All @@ -1423,9 +1405,7 @@ CallResolutionResult resolvePrimCall(ResolutionContext* rc,
case PRIM_EQUAL:
if (ci.actual(0).type().isType() && ci.actual(1).type().isType()) {
bool isEqual = ci.actual(0).type().type() == ci.actual(1).type().type();
type = QualifiedType(QualifiedType::PARAM,
BoolType::get(context),
BoolParam::get(context, isEqual));
type = QualifiedType::makeParamBool(context, isEqual);
break;
}
case PRIM_IS_WIDE_PTR:
Expand Down Expand Up @@ -1598,9 +1578,7 @@ CallResolutionResult resolvePrimCall(ResolutionContext* rc,
auto it = chplenv->find(varName);
auto ret = (it != chplenv->end()) ? it->second : "";

auto st = CompositeType::getStringType(context);
auto sp = StringParam::get(context, UniqueString::get(context, ret));
type = QualifiedType(QualifiedType::PARAM, st, sp);
type = QualifiedType::makeParamString(context, ret);
}
break;
/* primitives that return real parts from a complex */
Expand Down Expand Up @@ -1777,18 +1755,15 @@ CallResolutionResult resolvePrimCall(ResolutionContext* rc,
break;

case PRIM_VERSION_MAJOR:
type = QualifiedType(QualifiedType::PARAM, IntType::get(context, 0),
IntParam::get(context, getMajorVersion()));
type = QualifiedType::makeParamInt(context, getMajorVersion());
break;

case PRIM_VERSION_MINOR:
type = QualifiedType(QualifiedType::PARAM, IntType::get(context, 0),
IntParam::get(context, getMinorVersion()));
type = QualifiedType::makeParamInt(context, getMinorVersion());
break;

case PRIM_VERSION_UPDATE:
type = QualifiedType(QualifiedType::PARAM, IntType::get(context, 0),
IntParam::get(context, getUpdateVersion()));
type = QualifiedType::makeParamInt(context, getUpdateVersion());
break;

case PRIM_VERSION_SHA: {
Expand All @@ -1797,8 +1772,7 @@ CallResolutionResult resolvePrimCall(ResolutionContext* rc,
versionHash = UniqueString::get(context, getCommitHash());
}

type = QualifiedType(QualifiedType::PARAM, RecordType::getStringType(context),
StringParam::get(context, versionHash));
type = QualifiedType::getParamString(context, versionHash);
break;
}

Expand Down
32 changes: 8 additions & 24 deletions frontend/lib/resolution/resolution-queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1804,9 +1804,7 @@ computeNumericValuesOfEnumElements(Context* context, ID node) {
Resolver res = Resolver::createForEnumElements(context, enumNode, byPostorder);

// The constant 'one' for adding
auto one = QualifiedType(QualifiedType::PARAM,
IntType::get(context, 0),
IntParam::get(context, 1));
auto one = QualifiedType::makeParamInt(context, 1);

// A type to track what kind of signedness a value needs.
enum RequiredSignedness {
Expand Down Expand Up @@ -1944,9 +1942,7 @@ computeNumericValuesOfEnumElements(Context* context, ID node) {
UintType::get(context, 0),
UintParam::get(context, (uint64_t) *signedValue));
} else {
resultType = QualifiedType(QualifiedType::PARAM,
IntType::get(context, 0),
IntParam::get(context, *signedValue));
resultType = QualifiedType::makeParamInt(context, *signedValue);
}
}

Expand Down Expand Up @@ -3966,10 +3962,7 @@ static bool resolveFnCallSpecial(Context* context,
if (srcQtEnumType && dstTy->isStringType()) {
std::ostringstream oss;
srcQt.param()->stringify(oss, chpl::StringifyKind::CHPL_SYNTAX);
auto ustr = UniqueString::get(context, oss.str());
exprTypeOut = QualifiedType(QualifiedType::PARAM,
RecordType::getStringType(context),
StringParam::get(context, ustr));
exprTypeOut = QualifiedType::makeParamString(context, oss.str());
return true;
}

Expand All @@ -3994,10 +3987,7 @@ static bool resolveFnCallSpecial(Context* context,
// handle casting a type name to a string
std::ostringstream oss;
srcTy->stringify(oss, chpl::StringifyKind::CHPL_SYNTAX);
auto ustr = UniqueString::get(context, oss.str());
exprTypeOut = QualifiedType(QualifiedType::PARAM,
RecordType::getStringType(context),
StringParam::get(context, ustr));
exprTypeOut = QualifiedType::makeParamString(context, oss.str());
return true;
} else if (srcTy->isClassType() && dstTy->isClassType()) {
// cast (borrowed class) : unmanaged
Expand Down Expand Up @@ -4043,8 +4033,7 @@ static bool resolveFnCallSpecial(Context* context,
if (bothType || bothParam) {
bool result = lhs == rhs;
result = ci.name() == USTR("==") ? result : !result;
exprTypeOut = QualifiedType(QualifiedType::PARAM, BoolType::get(context),
BoolParam::get(context, result));
exprTypeOut = QualifiedType::makeParamBool(result);
return true;
}
} else if (ci.numActuals() == 1 && ci.hasQuestionArg()) {
Expand All @@ -4063,9 +4052,7 @@ static bool resolveFnCallSpecial(Context* context,
}
result = ci.name() == USTR("==") ? result : !result;
if (haveResult) {
exprTypeOut =
QualifiedType(QualifiedType::PARAM, BoolType::get(context),
BoolParam::get(context, result));
exprTypeOut = QualifiedType::makeParamBool(result);
return true;
}
}
Expand Down Expand Up @@ -4095,8 +4082,7 @@ static bool resolveFnCallSpecial(Context* context,
}
auto got = canPassScalar(context, ci.actual(0).type(), ci.actual(1).type());
bool result = got.passes();
exprTypeOut = QualifiedType(QualifiedType::PARAM, BoolType::get(context),
BoolParam::get(context, result));
exprTypeOut = QualifiedType::makeParamBool(result);
return true;
}

Expand Down Expand Up @@ -6101,9 +6087,7 @@ QualifiedType paramTypeFromValue(Context* context, T value);

template <>
QualifiedType paramTypeFromValue<bool>(Context* context, bool value) {
return QualifiedType(QualifiedType::PARAM,
BoolType::get(context),
BoolParam::get(context, value));
return QualifiedType::makeParamBool(value);
}

const std::unordered_map<UniqueString, QualifiedType>&
Expand Down
6 changes: 2 additions & 4 deletions frontend/lib/resolution/return-type-inference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,8 +1205,7 @@ static bool helpComputeCompilerGeneratedReturnType(Context* context,
auto ast = parsing::idToAst(context, enumType->id())->toEnum();
CHPL_ASSERT(ast);
int numElts = ast->numElements();
result = QualifiedType(QualifiedType::PARAM, IntType::get(context, 0),
IntParam::get(context, numElts));
result = QualifiedType::makeParamInt(context, numElts);
return true;
}
CHPL_ASSERT(false && "unhandled compiler-generated enum method");
Expand Down Expand Up @@ -1299,8 +1298,7 @@ static bool helpComputeReturnType(ResolutionContext* rc,
} else if (untyped->isMethod() && sig->formalType(0).type()->isTupleType() &&
untyped->name() == "size") {
auto tup = sig->formalType(0).type()->toTupleType();
result = QualifiedType(QualifiedType::PARAM, IntType::get(context, 0),
IntParam::get(context, tup->numElements()));
result = QualifiedType::makeParamInt(context, tup->numElements());
return true;

// if method call and the receiver points to a composite type definition,
Expand Down

0 comments on commit 25769e4

Please sign in to comment.