From 2160f4001dd2e56f76318a267ba43fde611235e6 Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 13 Jun 2025 01:00:11 +0300 Subject: [PATCH] =?UTF-8?q?clear=20flags=20on=20=E2=80=A2bit.=5Fcast=20reu?= =?UTF-8?q?se?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/sysfn.c | 5 +++-- test/cases/system.bqn | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index bc6fe15e..071c2687 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -1512,13 +1512,14 @@ B bitcast_impl(B el0, B el1, B x) { if (rl>=USZ_MAX) thrM("•bit._cast: output too large"); B r = convert(xct, x); u8 rt = typeOfCast(rct); - if (rt==t_bitarr && (v(r)->refc!=1 || IS_SLICE(TY(r)))) { + if (rt==t_bitarr && (!reusable(r) || IS_SLICE(TY(r)))) { r = taga(copy(xct, r)); - } else if (v(r)->refc!=1) { + } else if (!reusable(r)) { B pr = r; Arr* r2 = TI(r,slice)(r, 0, IA(r)); r = taga(arr_shSetI(r2, xr, shObj(pr))); // safe to use pr because r has refcount>1 and slice only consumes one, leaving some behind } else { + REUSE(r); #if VERIFY_TAIL if (xct.s==1 && rct.s!=1) { FINISH_OVERALLOC(a(r), offsetof(TyArr,a)+IA(r)/8, offsetof(TyArr,a) + (BIT_N(IA(r))<<3)); diff --git a/test/cases/system.bqn b/test/cases/system.bqn index 02033418..377a1726 100644 --- a/test/cases/system.bqn +++ b/test/cases/system.bqn @@ -341,10 +341,14 @@ r←•MakeRand 1 ⋄ ! 1¨⊸≡ ∊{𝕊: 500 r.Deal 1000}¨ ↕4 !"•bit._cast: unsupported width 16 for type 'f'" % ⟨16‿'f',32⟩•bit._cast 128⥊0 !"•bit._cast: unsupported width 32 for type 'f'" % ⟨32,32‿'f'⟩•bit._cast 128⥊0 -!"•bit._cast: unsupported width 0 for type 'u'" % ⟨0‿'u',32⟩•bit._cast 128⥊0 -!"•bit._cast: unsupported width 8 for type 'u'" % ⟨8‿'u',32⟩•bit._cast 128⥊0 +!"•bit._cast: unsupported width 0 for type 'u'" % ⟨0‿'u',32⟩•bit._cast 128⥊0 +!"•bit._cast: unsupported width 8 for type 'u'" % ⟨8‿'u',32⟩•bit._cast 128⥊0 !"•bit._cast: unsupported width 32 for type 'u'" % ⟨8,32‿'u'⟩•bit._cast 128⥊0 -!"•bit._cast: unsupported width 1 for type 'i'" % ⟨8, 1‿'i'⟩•bit._cast 128⥊0 +!"•bit._cast: unsupported width 1 for type 'i'" % ⟨8, 1‿'i'⟩•bit._cast 128⥊0 + +%USE eqvar ⋄ {𝕊conv: {•internal.Keep 𝕩⍋1 ⋄ •internal.Validate conv •bit._cast 𝕩}_eqvar ↕64}¨ ≠´¨⊸/ ⥊ 8‿16‿32‿64 ⋈⌜ 1‿8‿16‿32‿64 +%USE eqvar ⋄ {𝕊conv: {•internal.Keep 𝕩⍒1 ⋄ •internal.Validate conv •bit._cast 𝕩}_eqvar ⌽↕64}¨ ≠´¨⊸/ ⥊ 8‿16‿32‿64 ⋈⌜ 1‿8‿16‿32‿64 +%USE eqvar ⋄ {𝕊conv: {•internal.Squeeze 𝕩 ⋄ •internal.Validate conv •bit._cast 𝕩}_eqvar 64↑2}¨ ≠´¨⊸/ ⥊ ⟨8⟩ ⋈⌜ 1‿8‿16‿32‿64 # •platform Str ← {!=𝕩 ⋄ !×≠𝕩 ⋄ ! ∧´2=•Type¨𝕩} ⋄ Str •platform.os ⋄ Str •platform.cpu.arch ⋄ Str •platform.bqn.impl_version ⋄ Str •platform.environment