add runtime calls to WARN_SLOW
This commit is contained in:
parent
78793ca700
commit
013897cc16
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
@ -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)); }
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
5
src/h.h
5
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);
|
||||
|
||||
10
src/load.c
10
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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user