From b81c2b551073c753674a8f3aa4bb12d0e3674a6c Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Thu, 15 Sep 2022 21:00:53 +0200 Subject: [PATCH] Adapt to new array-append frontend lowerings --- gen/arrays.cpp | 62 +-------------------------------------- gen/arrays.h | 2 -- gen/runtime.cpp | 8 ----- gen/toir.cpp | 8 ++--- tests/semantic/dcompute.d | 2 +- 5 files changed, 4 insertions(+), 78 deletions(-) diff --git a/gen/arrays.cpp b/gen/arrays.cpp index 487f680012..2d6c539689 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -37,15 +37,6 @@ LLValue *DtoSlice(LLValue *ptr, LLValue *length, LLType *elemType) { elemType = i1ToI8(voidToI8(elemType)); return DtoAggrPair(length, DtoBitCast(ptr, elemType->getPointerTo())); } - -LLValue *DtoSlice(Expression *e) { - DValue *dval = toElem(e); - if (dval->type->toBasetype()->ty == TY::Tsarray) { - // Convert static array to slice - return DtoSlice(DtoLVal(dval), DtoArrayLen(dval), DtoType(dval->type->nextOf())); - } - return DtoRVal(dval); -} } //////////////////////////////////////////////////////////////////////////////// @@ -787,57 +778,6 @@ DSliceValue *DtoResizeDynArray(const Loc &loc, Type *arrayType, DValue *array, //////////////////////////////////////////////////////////////////////////////// -void DtoCatAssignElement(const Loc &loc, DValue *array, Expression *exp) { - IF_LOG Logger::println("DtoCatAssignElement"); - LOG_SCOPE; - - assert(array); - - Type *arrayType = array->type->toBasetype(); - - // Evaluate the expression to be appended first; it may affect the array. - DValue *expVal = toElem(exp); - - // The druntime function extends the slice in-place (length += 1, ptr - // potentially moved to a new block). - LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendcTX"); - gIR->CreateCallOrInvoke( - fn, DtoTypeInfoOf(loc, arrayType), - DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(1)), - DtoConstSize_t(1), ".appendedArray"); - - // Assign to the new last element. - LLValue *newLength = DtoArrayLen(array); - LLValue *ptr = DtoArrayPtr(array); - LLType *ptrty = i1ToI8(DtoType(array->type->nextOf())); - LLValue *lastIndex = - gIR->ir->CreateSub(newLength, DtoConstSize_t(1), ".lastIndex"); - LLValue *lastElemPtr = DtoGEP1(ptrty, ptr, lastIndex, ".lastElem"); - DLValue lastElem(arrayType->nextOf(), lastElemPtr); - DtoAssign(loc, &lastElem, expVal, EXP::blit); - callPostblit(loc, exp, lastElemPtr); -} - -//////////////////////////////////////////////////////////////////////////////// - -DSliceValue *DtoCatAssignArray(const Loc &loc, DValue *arr, Expression *exp) { - IF_LOG Logger::println("DtoCatAssignArray"); - LOG_SCOPE; - Type *arrayType = arr->type; - - LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendT"); - // Call _d_arrayappendT(TypeInfo ti, byte[] *px, byte[] y) - LLValue *newArray = gIR->CreateCallOrInvoke( - fn, DtoTypeInfoOf(loc, arrayType), - DtoBitCast(DtoLVal(arr), fn->getFunctionType()->getParamType(1)), - DtoSlicePaint(DtoSlice(exp), fn->getFunctionType()->getParamType(2)), - ".appendedArray"); - - return getSlice(arrayType, newArray); -} - -//////////////////////////////////////////////////////////////////////////////// - static LLValue *DtoSlicePtr(DValue *dval) { Loc loc; Type *vt = dval->type->toBasetype(); @@ -868,7 +808,7 @@ static LLValue *DtoSlicePtr(Expression *e) { DSliceValue *DtoCatArrays(const Loc &loc, Type *arrayType, Expression *exp1, Expression *exp2) { - IF_LOG Logger::println("DtoCatAssignArray"); + IF_LOG Logger::println("DtoCatArrays"); LOG_SCOPE; llvm::SmallVector args; diff --git a/gen/arrays.h b/gen/arrays.h index 0d43ff917e..8ea6e5ccfb 100644 --- a/gen/arrays.h +++ b/gen/arrays.h @@ -67,8 +67,6 @@ DSliceValue *DtoNewMulDimDynArray(const Loc &loc, Type *arrayType, DSliceValue *DtoResizeDynArray(const Loc &loc, Type *arrayType, DValue *array, llvm::Value *newdim); -void DtoCatAssignElement(const Loc &loc, DValue *arr, Expression *exp); -DSliceValue *DtoCatAssignArray(const Loc &loc, DValue *arr, Expression *exp); DSliceValue *DtoCatArrays(const Loc &loc, Type *type, Expression *e1, Expression *e2); DSliceValue *DtoAppendDCharToString(const Loc &loc, DValue *arr, diff --git a/gen/runtime.cpp b/gen/runtime.cpp index ea1bdaef3b..699cbc5ef1 100644 --- a/gen/runtime.cpp +++ b/gen/runtime.cpp @@ -590,14 +590,6 @@ static void buildRuntimeModule() { {"_d_arraysetlengthT", "_d_arraysetlengthiT"}, {typeInfoTy, sizeTy, voidArrayPtrTy}, {STCconst, 0, 0}); - // byte[] _d_arrayappendcTX(const TypeInfo ti, ref byte[] px, size_t n) - createFwdDecl(LINK::c, voidArrayTy, {"_d_arrayappendcTX"}, - {typeInfoTy, voidArrayTy, sizeTy}, {STCconst, STCref, 0}); - - // void[] _d_arrayappendT(const TypeInfo ti, ref byte[] x, byte[] y) - createFwdDecl(LINK::c, voidArrayTy, {"_d_arrayappendT"}, - {typeInfoTy, voidArrayTy, voidArrayTy}, {STCconst, STCref, 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"}, diff --git a/gen/toir.cpp b/gen/toir.cpp index 61ddfbda56..7cdd3887d4 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -2174,13 +2174,9 @@ public: // append dchar to wchar[] DtoAppendDCharToUnicodeString(e->loc, result, e->e2); } - } else if (e1type->equals(e2type)) { - // append array - DSliceValue *slice = DtoCatAssignArray(e->loc, result, e->e2); - DtoStore(DtoRVal(slice), DtoLVal(result)); } else { - // append element - DtoCatAssignElement(e->loc, result, e->e2); + e->error("ICE: array append should have been lowered to `_d_arrayappend{T,cTX}`!"); + fatal(); } } diff --git a/tests/semantic/dcompute.d b/tests/semantic/dcompute.d index fb865d0054..44247e71f6 100644 --- a/tests/semantic/dcompute.d +++ b/tests/semantic/dcompute.d @@ -31,7 +31,7 @@ void func() int[] quux; //CHECK: dcompute.d([[@LINE+1]]): Error: can only call functions from other `@compute` modules in `@compute` code quux.length = 1; - //CHECK: dcompute.d([[@LINE+1]]): Error: cannot use operator `~=` in `@compute` code + //CHECK: dcompute.d([[@LINE+1]]): Error: can only call functions from other `@compute` modules in `@compute` code quux ~= 42; //CHECK: dcompute.d([[@LINE+1]]): Error: cannot use operator `~` in `@compute` code cast(void) (quux ~ 1);