Skip to content

Commit 392fb69

Browse files
committed
Allow PtrType in vector expressions.
1 parent 0dc16a3 commit 392fb69

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/check.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const Type* TypeChecker::invalid_cast(const Loc& loc, const Type* type, const Ty
8383

8484
const Type* TypeChecker::invalid_simd(const Loc& loc, const Type* elem_type) {
8585
if (should_report_error(elem_type))
86-
error(loc, "expected primitive type for simd type component, but got '{}'", *elem_type);
86+
error(loc, "expected primitive or pointer type for simd type component, but got '{}'", *elem_type);
8787
return type_table.type_error();
8888
}
8989

@@ -489,7 +489,7 @@ const Type* TypeChecker::infer_array(
489489
if (elem_count == 0)
490490
return cannot_infer(loc, msg);
491491
auto elem_type = infer_elems();
492-
if (is_simd && !elem_type->template isa<PrimType>())
492+
if (is_simd && !(elem_type->template isa<PrimType>() || elem_type->template isa<PtrType>()))
493493
return invalid_simd(loc, elem_type);
494494
return type_table.sized_array_type(elem_type, elem_count, is_simd);
495495
}
@@ -509,7 +509,7 @@ const Type* TypeChecker::check_array(
509509
if (is_simd_type(array_type) != is_simd)
510510
return incompatible_type(loc, (is_simd ? "simd " : "non-simd ") + std::string(msg), expected);
511511
auto elem_type = array_type->elem;
512-
if (is_simd && !elem_type->isa<PrimType>())
512+
if (is_simd && !(elem_type->template isa<PrimType>() || elem_type->template isa<PtrType>()))
513513
return invalid_simd(loc, elem_type);
514514
check_elems(elem_type);
515515
if (auto sized_array_type = array_type->isa<artic::SizedArrayType>();
@@ -847,7 +847,7 @@ const artic::Type* TupleType::infer(TypeChecker& checker) {
847847

848848
const artic::Type* SizedArrayType::infer(TypeChecker& checker) {
849849
auto elem_type = checker.infer(*elem);
850-
if (is_simd && !elem_type->isa<artic::PrimType>())
850+
if (is_simd && !(elem_type->template isa<artic::PrimType>() || elem_type->template isa<artic::PtrType>()))
851851
return checker.invalid_simd(loc, elem_type);
852852

853853
if (std::holds_alternative<ast::Path>(size)) {
@@ -1022,7 +1022,7 @@ const artic::Type* ArrayExpr::check(TypeChecker& checker, const artic::Type* exp
10221022

10231023
const artic::Type* RepeatArrayExpr::infer(TypeChecker& checker) {
10241024
auto elem_type = checker.deref(elem);
1025-
if (is_simd && !elem_type->isa<artic::PrimType>())
1025+
if (is_simd && !(elem_type->template isa<artic::PrimType>() || elem_type->template isa<artic::PtrType>()))
10261026
return checker.invalid_simd(loc, elem_type);
10271027

10281028
if (std::holds_alternative<ast::Path>(size)) {

src/emit.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,8 +1885,17 @@ std::string SizedArrayType::stringify(Emitter& emitter) const {
18851885
}
18861886

18871887
const thorin::Type* SizedArrayType::convert(Emitter& emitter) const {
1888-
if (is_simd)
1889-
return emitter.world.prim_type(elem->convert(emitter)->as<thorin::PrimType>()->primtype_tag(), size);
1888+
if (is_simd) {
1889+
auto elem_type = elem->convert(emitter);
1890+
if (auto prim_type = elem_type->isa<thorin::PrimType>())
1891+
return emitter.world.prim_type(prim_type->primtype_tag(), size);
1892+
else if (auto ptr_type = elem_type->isa<thorin::PtrType>())
1893+
return emitter.world.ptr_type(ptr_type->pointee(), size, ptr_type->addr_space());
1894+
1895+
//This should be unreachable after type checking.
1896+
assert(false);
1897+
return nullptr;
1898+
}
18901899
return emitter.world.definite_array_type(elem->convert(emitter), size);
18911900
}
18921901

0 commit comments

Comments
 (0)