Adapt to new _d_arraysetlengthT template lowering

This commit is contained in:
Martin Kinkelin 2023-07-16 11:38:20 +02:00
parent 8151a5f65c
commit a6dc3fa73a
6 changed files with 10 additions and 49 deletions

View file

@ -748,34 +748,6 @@ DSliceValue *DtoNewMulDimDynArray(const Loc &loc, Type *arrayType,
return getSlice(arrayType, newptr);
}
////////////////////////////////////////////////////////////////////////////////
DSliceValue *DtoResizeDynArray(const Loc &loc, Type *arrayType, DValue *array,
LLValue *newdim) {
IF_LOG Logger::println("DtoResizeDynArray : %s", arrayType->toChars());
LOG_SCOPE;
assert(array);
assert(newdim);
assert(arrayType);
assert(arrayType->toBasetype()->ty == TY::Tarray);
// decide on what runtime function to call based on whether the type is zero
// initialized
bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit();
// call runtime
LLFunction *fn =
getRuntimeFunction(loc, gIR->module, zeroInit ? "_d_arraysetlengthT"
: "_d_arraysetlengthiT");
LLValue *newArray = gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(loc, arrayType), newdim,
DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(2)),
".gc_mem");
return getSlice(arrayType, newArray);
}
////////////////////////////////////////////////////////////////////////////////
static LLValue *DtoSlicePtr(DValue *dval) {

View file

@ -64,8 +64,6 @@ DSliceValue *DtoNewDynArray(const Loc &loc, Type *arrayType, DValue *dim,
bool defaultInit = true);
DSliceValue *DtoNewMulDimDynArray(const Loc &loc, Type *arrayType,
DValue **dims, size_t ndims);
DSliceValue *DtoResizeDynArray(const Loc &loc, Type *arrayType, DValue *array,
llvm::Value *newdim);
DSliceValue *DtoCatArrays(const Loc &loc, Type *type, Expression *e1,
Expression *e2);

View file

@ -606,12 +606,6 @@ static void buildRuntimeModule() {
createFwdDecl(LINK::c, voidArrayTy, {"_d_newarraymTX", "_d_newarraymiTX"},
{typeInfoTy, sizeTy->arrayOf()}, {STCconst, 0});
// void[] _d_arraysetlengthT (const TypeInfo ti, size_t newlength, void[]* p)
// void[] _d_arraysetlengthiT(const TypeInfo ti, size_t newlength, void[]* p)
createFwdDecl(LINK::c, voidArrayTy,
{"_d_arraysetlengthT", "_d_arraysetlengthiT"},
{typeInfoTy, sizeTy, voidArrayPtrTy}, {STCconst, 0, 0});
// void[] _d_arrayappendcd(ref byte[] x, dchar c)
// void[] _d_arrayappendwd(ref byte[] x, dchar c)
createFwdDecl(LINK::c, voidArrayTy, {"_d_arrayappendcd", "_d_arrayappendwd"},

View file

@ -456,6 +456,14 @@ public:
//////////////////////////////////////////////////////////////////////////////
void visit(LoweredAssignExp *e) override {
IF_LOG Logger::print("LoweredAssignExp::toElem: %s @ %s\n", e->toChars(),
e->type->toChars());
LOG_SCOPE;
result = toElem(e->lowering);
}
void visit(AssignExp *e) override {
IF_LOG Logger::print("AssignExp::toElem: %s | (%s)(%s = %s)\n",
e->toChars(), e->type->toChars(),
@ -463,17 +471,6 @@ public:
e->e2->type ? e->e2->type->toChars() : nullptr);
LOG_SCOPE;
if (auto ale = e->e1->isArrayLengthExp()) {
Logger::println("performing array.length assignment");
DLValue arrval(ale->e1->type, DtoLVal(ale->e1));
DValue *newlen = toElem(e->e2);
DSliceValue *slice =
DtoResizeDynArray(e->loc, arrval.type, &arrval, DtoRVal(newlen));
DtoStore(DtoRVal(slice), DtoLVal(&arrval));
result = newlen;
return;
}
// Initialization of ref variable?
// Can't just override ConstructExp::toElem because not all EXP::construct
// operations are actually instances of ConstructExp... Long live the DMD

View file

@ -36,7 +36,7 @@ template _d_arraysetlengthTImpl(Tarr : T[], T)
*/
size_t _d_arraysetlengthT(return scope ref Tarr arr, size_t newlength) @trusted pure nothrow
{
pragma(inline, false);
version (DigitalMars) pragma(inline, false);
version (D_TypeInfo)
{
auto ti = typeid(Tarr);

View file

@ -29,7 +29,7 @@ void func()
//CHECK: dcompute.d([[@LINE+1]]): Error: {{.*}} interfaces and classes not allowed in `@compute` code
C cc;
int[] quux;
//CHECK: dcompute.d([[@LINE+1]]): Error: can only call functions from other `@compute` modules in `@compute` code
//CHECK: dcompute.d([[@LINE+1]]): Error: setting `length` in `@compute` code not allowed
quux.length = 1;
//CHECK: dcompute.d([[@LINE+1]]): Error: can only call functions from other `@compute` modules in `@compute` code
quux ~= 42;