diff --git a/src/builtins/fns.c b/src/builtins/fns.c index ca405931..2a21531d 100644 --- a/src/builtins/fns.c +++ b/src/builtins/fns.c @@ -202,7 +202,7 @@ B fne_c2(B t, B w, B x) { extern B rt_find; B find_c2(B t, B w, B x) { - return c2(rt_find, w, x); + return c2rt(find, w, x); } static H_b2i* prevImports; diff --git a/src/builtins/group.c b/src/builtins/group.c index c0b486d1..674bb9e0 100644 --- a/src/builtins/group.c +++ b/src/builtins/group.c @@ -320,7 +320,7 @@ B group_c2(B t, B w, B x) { } } base: - return c2(rt_group, w, x); + return c2rt(group, w, x); } B group_c1(B t, B x) { if (isArr(x) && RNK(x)==1 && TI(x,arrD1)) { @@ -328,5 +328,5 @@ B group_c1(B t, B x) { B range = C1(ud, m_f64(ia)); return C2(group, x, range); } - return c1(rt_group, x); + return c1rt(group, x); } diff --git a/src/builtins/inverse.c b/src/builtins/inverse.c index 68fec757..1f131a05 100644 --- a/src/builtins/inverse.c +++ b/src/builtins/inverse.c @@ -13,6 +13,7 @@ B fn_invSwap_c2(B t, B w, B x) { B f = nfn_objU(t); return TI(f, fn_iw)(f, w, x) extern B rt_undo; B undo_c1(Md1D* d, B x) { B f = d->f; if (isFun(f)) return TI(f, fn_im)(f, x); + SLOW1("!runtime undo", x); B fi = m1_d(incG(rt_undo), inc(f)); B r = c1(fi, x); decG(fi); @@ -20,6 +21,7 @@ B undo_c1(Md1D* d, B x) { B f = d->f; } B undo_c2(Md1D* d, B w, B x) { B f = d->f; if (isFun(f)) return TI(f, fn_ix)(f, w, x); + SLOW2("!runtime undo", w, x); B fi = m1_d(incG(rt_undo), inc(f)); B r = c2(fi, w, x); decG(fi); @@ -30,11 +32,11 @@ B setInvReg_c1 (B t, B x) { rt_invFnReg = x; rt_invFnRegFn = c(Fun,x)->c1; ret B setInvSwap_c1(B t, B x) { rt_invFnSwap = x; rt_invFnSwapFn = c(Fun,x)->c1; return incG(bi_nativeInvSwap); } B nativeInvReg_c1(B t, B x) { if (isFun(x)) return m_nfn(fn_invRegDesc, x); - return c1(rt_invFnReg, x); + return c1rt(invFnReg, x); } B nativeInvSwap_c1(B t, B x) { if (isFun(x)) return m_nfn(fn_invSwapDesc, x); - return c1(rt_invFnSwap, x); + return c1rt(invFnSwap, x); } void inverse_init() { diff --git a/src/builtins/md1.c b/src/builtins/md1.c index 4d17459b..79fc1065 100644 --- a/src/builtins/md1.c +++ b/src/builtins/md1.c @@ -260,7 +260,7 @@ extern B rt_insert; B insert_c1(Md1D* d, B x) { B f = d->f; if (isAtm(x) || RNK(x)==0) thrM("˝: 𝕩 must have rank at least 1"); usz xia = IA(x); - if (xia==0) return m1c1(rt_insert, f, x); + if (xia==0) { SLOW2("!π•ŽΛπ•©", f, x); return m1c1(rt_insert, f, x); } if (RNK(x)==1 && isFun(f) && isPervasiveDy(f)) { return m_atomUnit(fold_c1(d, x)); } diff --git a/src/builtins/md2.c b/src/builtins/md2.c index b84f8bdc..b5a21160 100644 --- a/src/builtins/md2.c +++ b/src/builtins/md2.c @@ -157,7 +157,6 @@ B cond_c2(Md2D* d, B w, B x) { B g=d->g; } } -extern B rt_under, bi_before; B under_c1(Md2D* d, B x) { B f=d->f; B g=d->g; return (LIKELY(isVal(g))? TI(g,fn_uc1) : def_fn_uc1)(g, f, x); } @@ -472,8 +471,8 @@ B rank_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g; extern B rt_depth; -B depth_c1(Md2D* d, B x) { return m2c1(rt_depth, d->f, d->g, x); } -B depth_c2(Md2D* d, B w, B x) { return m2c2(rt_depth, d->f, d->g, w, x); } +B depth_c1(Md2D* d, B x) { SLOW3("!Fβš‡π•¨ 𝕩", d->g, x, d->f); return m2c1(rt_depth, d->f, d->g, x); } +B depth_c2(Md2D* d, B w, B x) { SLOW3("!𝕨 π”½βš‡f 𝕩", w, x, d->g); return m2c2(rt_depth, d->f, d->g, w, x); } static void print_md2BI(FILE* f, B x) { fprintf(f, "%s", pm2_repr(c(Md1,x)->extra)); } diff --git a/src/builtins/search.c b/src/builtins/search.c index 3b97d37a..42d3f49f 100644 --- a/src/builtins/search.c +++ b/src/builtins/search.c @@ -213,7 +213,7 @@ B memberOf_c2(B t, B w, B x) { extern B rt_count; B count_c2(B t, B w, B x) { if (!isArr(w) || RNK(w)==0) thrM("βŠ’: 𝕨 must have rank at least 1"); - if (RNK(w)!=1) return c2(rt_count, w, x); + if (RNK(w)!=1) return c2rt(count, w, x); if (!isArr(x) || IA(x)<=1) return indexOf_c2(m_f64(0), w, x); u8 we = TI(w,elType); usz wia = IA(w); u8 xe = TI(x,elType); usz xia = IA(x); diff --git a/src/builtins/select.c b/src/builtins/select.c index f5639be3..c403e403 100644 --- a/src/builtins/select.c +++ b/src/builtins/select.c @@ -227,7 +227,7 @@ B select_c2(B t, B w, B x) { } base:; dec(xf); - return c2(rt_select, w, x); + return c2rt(select, w, x); dec_ret:; decG(w); decG(x); return r; diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 49d9fa97..67586d6c 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -463,7 +463,7 @@ static NOINLINE B takedrop_highrank(bool take, B w, B x) { r = take? C2(take, w0, x) : C2(drop, w0, x); goto decW_ret; } else { - // return take? c2(rt_take, w, x) : c2(rt_drop, w, x); + // return take? c2rt(take, w, x) : c2rt(drop, w, x); ur xr = RNK(x); ur rr = xr>wia? xr : wia; @@ -1127,7 +1127,7 @@ B reverse_c1(B t, B x) { return withFill(mut_fcd(r, x), xf); } B reverse_c2(B t, B w, B x) { - if (isArr(w)) return c2(rt_reverse, w, x); + if (isArr(w)) return c2rt(reverse, w, x); if (isAtm(x) || RNK(x)==0) thrM("⌽: 𝕩 must have rank at least 1 for atom 𝕨"); usz xia = IA(x); if (xia==0) return x; @@ -1230,7 +1230,7 @@ B transp_c1(B t, B x) { } decG(x); return taga(r); } -B transp_c2(B t, B w, B x) { return c2(rt_transp, w, x); } +B transp_c2(B t, B w, B x) { return c2rt(transp, w, x); } B transp_im(B t, B x) { if (isAtm(x)) thrM("⍉⁼: 𝕩 must not be an atom"); diff --git a/src/builtins/slash.c b/src/builtins/slash.c index 32de1f0a..10dad7d5 100644 --- a/src/builtins/slash.c +++ b/src/builtins/slash.c @@ -900,7 +900,7 @@ B slash_c2(B t, B w, B x) { goto decX_ret; } base: - return c2(rt_slash, w, x); + return c2rt(slash, w, x); } diff --git a/src/core/stuff.c b/src/core/stuff.c index b2433588..05145d05 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -55,12 +55,14 @@ NOINLINE B arr_c2(B t, B w, B x) { return inc(t); } extern B rt_under, bi_before; static B rtUnder_c1(B f, B g, B x) { // consumes x + SLOW3("!runtime π•ŽβŒΎF 𝕩", f, x, g); B fn = m2_d(incG(rt_under), inc(f), inc(g)); B r = c1(fn, x); decG(fn); return r; } static B rtUnder_cw(B f, B g, B w, B x) { // consumes w,x + SLOW3("!runtime π”½βŒΎ(π•¨βŠΈF) 𝕩", w, x, g); B fn = m2_d(incG(rt_under), inc(f), m2_d(incG(bi_before), w, inc(g))); B r = c1(fn, x); decG(fn); @@ -840,7 +842,12 @@ void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); } err(""); } #endif -#if WARN_SLOW==1 +#if WARN_SLOW + #if WARN_SLOW==2 + #define ONLY_ALWAYS if (!always) return + #else + #define ONLY_ALWAYS + #endif static void warn_ln(B x) { if (isArr(x)) fprint_fmt(stderr, "%s items, %S, shape=%H\n", IA(x), eltype_repr(TI(x,elType)), x); else { @@ -850,18 +857,27 @@ void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); } } } void warn_slow1(char* s, B x) { - if (isArr(x) && IA(x)<100) return; + bool always = '!'==*s; + if (always) s++; + else if (isArr(x) && IA(x)<100) return; + ONLY_ALWAYS; fprintf(stderr, "slow %s: ", s); warn_ln(x); fflush(stderr); } void warn_slow2(char* s, B w, B x) { - if ((isArr(w)||isArr(x)) && (!isArr(w) || IA(w)<50) && (!isArr(x) || IA(x)<50)) return; + bool always = '!'==*s; + if (always) s++; + else if ((isArr(w)||isArr(x)) && (!isArr(w) || IA(w)<50) && (!isArr(x) || IA(x)<50)) return; + ONLY_ALWAYS; fprintf(stderr, "slow %s:\n 𝕨: ", s); warn_ln(w); fprintf(stderr, " 𝕩: "); warn_ln(x); fflush(stderr); } void warn_slow3(char* s, B w, B x, B y) { - if ((isArr(w)||isArr(x)) && (!isArr(w) || IA(w)<50) && (!isArr(x) || IA(x)<50)) return; + bool always = '!'==*s; + if (always) s++; + else if ((isArr(w)||isArr(x)) && (!isArr(w) || IA(w)<50) && (!isArr(x) || IA(x)<50)) return; + ONLY_ALWAYS; fprintf(stderr, "slow %s:\n 𝕨: ", s); warn_ln(w); fprintf(stderr, " 𝕩: "); warn_ln(x); fprintf(stderr, " f: "); warn_ln(y); diff --git a/src/h.h b/src/h.h index d61e6f46..2d21ffa8 100644 --- a/src/h.h +++ b/src/h.h @@ -315,7 +315,7 @@ typedef struct Arr { #define VALIDATEP(X) (X) #define UD __builtin_unreachable(); #endif -#if WARN_SLOW==1 +#if WARN_SLOW void warn_slow1(char* s, B x); void warn_slow2(char* s, B w, B x); void warn_slow3(char* s, B w, B x, B y); @@ -644,6 +644,9 @@ typedef struct Fun { B c1F(B f, B x); B c2F(B f, B w, B x); + +#define c1rt(N, X) ({ B x_=(X); SLOW1("!rt_" #N, x_); c1(rt_##N, x_); }) +#define c2rt(N, W, X) ({ B w_=(W); B x_=(X); SLOW2("!rt_" #N,w_,x_); c2(rt_##N, w_, x_); }) static B c1(B f, B x) { // BQN-call f monadically; consumes x if (isFun(f)) return VALIDATE(VRES(c(Fun,f)->c1(f, VRES(x)))); return c1F(f, x); diff --git a/src/load.c b/src/load.c index 7ea19773..5de5467b 100644 --- a/src/load.c +++ b/src/load.c @@ -572,10 +572,10 @@ static Arr* def_slice(B x, usz s, usz ia) { thrM("cannot slice non-array!"); } B rt_invFnReg, rt_invFnSwap; BB2B rt_invFnRegFn; BB2B rt_invFnSwapFn; -B def_fn_im(B t, B x) { B fn = rt_invFnRegFn(rt_invFnReg, inc(t)); B r = c1(fn, x); dec(fn); return r; } -B def_fn_is(B t, B x) { B fn = rt_invFnSwapFn(rt_invFnSwap, inc(t)); B r = c1(fn, x); dec(fn); return r; } -B def_fn_iw(B t, B w, B x) { B fn = rt_invFnSwapFn(rt_invFnSwap, inc(t)); B r = c2(fn, w, x); dec(fn); return r; } -B def_fn_ix(B t, B w, B x) { B fn = rt_invFnRegFn(rt_invFnReg, inc(t)); B r = c2(fn, w, x); dec(fn); return r; } +B def_fn_im(B t, B x) { B fn = rt_invFnRegFn(rt_invFnReg, inc(t)); SLOW2("!runtime π•ŽβΌπ•©", t, x); B r = c1(fn, x); dec(fn); return r; } +B def_fn_is(B t, B x) { B fn = rt_invFnSwapFn(rt_invFnSwap, inc(t)); SLOW2("!runtime π•ŽβΌπ•©", t, x); B r = c1(fn, x); dec(fn); return r; } +B def_fn_iw(B t, B w, B x) { B fn = rt_invFnSwapFn(rt_invFnSwap, inc(t)); SLOW3("!runtime 𝕨F⁼𝕩", w, x, t); B r = c2(fn, w, x); dec(fn); return r; } +B def_fn_ix(B t, B w, B x) { B fn = rt_invFnRegFn(rt_invFnReg, inc(t)); SLOW3("!runtime 𝕨F⁼𝕩", w, x, t); B r = c2(fn, w, x); dec(fn); return r; } B def_m1_im(Md1D* t, B x) { return def_fn_im(tag(t,FUN_TAG), x); } B def_m1_iw(Md1D* t, B w, B x) { return def_fn_iw(tag(t,FUN_TAG), w, x); } B def_m1_ix(Md1D* t, B w, B x) { return def_fn_ix(tag(t,FUN_TAG), w, x); } @@ -607,7 +607,7 @@ static B funBI_imRt(B t, B x) { return c1(c(BFn, t)->rtInvReg, x); } static B funBI_imInit(B t, B x) { - B f = c(BFn, t)->rtInvReg = c1(rt_invFnReg, inc(t)); + B f = c(BFn, t)->rtInvReg = c1rt(invFnReg, inc(t)); c(BFn, t)->im = funBI_imRt; return c1(f, x); }