Skip to content

Commit

Permalink
Implement prim 'scalar promotion type'
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Rift <[email protected]>
  • Loading branch information
riftEmber committed Dec 20, 2024
1 parent fc566e4 commit ed1773b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
14 changes: 13 additions & 1 deletion frontend/lib/resolution/prims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,18 @@ static QualifiedType primTypeof(Context* context, PrimitiveTag prim, const CallI
return QualifiedType(QualifiedType::TYPE, typePtr);
}

static QualifiedType primPromotionType(Context* context, const CallInfo& ci) {
if (ci.numActuals() != 1) return QualifiedType();
auto actualQt = ci.actual(0).type();

auto promoTy = getPromotionType(context, actualQt).type();

// We want a type result, even if the prim was passed a value.
auto promoQt = QualifiedType(QualifiedType::TYPE, promoTy);

return promoQt;
}

static QualifiedType primGetSvecMember(Context* context, PrimitiveTag prim,
const CallInfo& ci) {
CHPL_ASSERT(prim == PRIM_GET_SVEC_MEMBER ||
Expand Down Expand Up @@ -1688,7 +1700,7 @@ CallResolutionResult resolvePrimCall(ResolutionContext* rc,
break;

case PRIM_SCALAR_PROMOTION_TYPE:
CHPL_UNIMPL("misc primitives");
type = primPromotionType(context, ci);
break;
case PRIM_STATIC_FIELD_TYPE:
type = staticFieldType(context, ci);
Expand Down
19 changes: 19 additions & 0 deletions frontend/test/resolution/testResolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,23 @@ static void testInfiniteCycleBug() {
std::ignore = resolveQualifiedTypeOfX(context, program1);
}

static void testPromotionPrim() {
Context* context = buildStdContext();
ErrorGuard guard(context);

std::string prog =
R"""(
var d : domain(1);
type t = __primitive("scalar promotion type", d);
param x = t == int;
)""";

auto x = resolveTypeOfXInit(context, prog);
ensureParamBool(x, true);

assert(guard.realizeErrors() == 0);
}

int main() {
test1();
test2();
Expand Down Expand Up @@ -1770,5 +1787,7 @@ int main() {

testInfiniteCycleBug();

testPromotionPrim();

return 0;
}

0 comments on commit ed1773b

Please sign in to comment.