From a6dc3fa73a5fe5c16f55b8788df6da4e978450e6 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Sun, 16 Jul 2023 11:38:20 +0200 Subject: [PATCH] Adapt to new _d_arraysetlengthT template lowering --- gen/arrays.cpp | 28 ------------------- gen/arrays.h | 2 -- gen/runtime.cpp | 6 ---- gen/toir.cpp | 19 ++++++------- .../src/core/internal/array/capacity.d | 2 +- tests/semantic/dcompute.d | 2 +- 6 files changed, 10 insertions(+), 49 deletions(-) diff --git a/gen/arrays.cpp b/gen/arrays.cpp index 14b1b26614..f4e43eceea 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -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) { diff --git a/gen/arrays.h b/gen/arrays.h index 8ea6e5ccfb..3e893bbdc7 100644 --- a/gen/arrays.h +++ b/gen/arrays.h @@ -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); diff --git a/gen/runtime.cpp b/gen/runtime.cpp index 37cd6dc741..8f491df367 100644 --- a/gen/runtime.cpp +++ b/gen/runtime.cpp @@ -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"}, diff --git a/gen/toir.cpp b/gen/toir.cpp index 69f8b31faa..fd55bc8601 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -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 diff --git a/runtime/druntime/src/core/internal/array/capacity.d b/runtime/druntime/src/core/internal/array/capacity.d index 254e9501f6..10ce2c65c9 100644 --- a/runtime/druntime/src/core/internal/array/capacity.d +++ b/runtime/druntime/src/core/internal/array/capacity.d @@ -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); diff --git a/tests/semantic/dcompute.d b/tests/semantic/dcompute.d index 44247e71f6..1bde310b17 100644 --- a/tests/semantic/dcompute.d +++ b/tests/semantic/dcompute.d @@ -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;