From: Eugene Loh <eugene.loh@oracle.com>
To: Kris Van Hees <kris.van.hees@oracle.com>,
dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: Re: [DTrace-devel] [PATCH 3/3] cg: optimize ternary expressions for strings
Date: Wed, 16 Jul 2025 01:00:43 -0400 [thread overview]
Message-ID: <57838fc8-1e04-2f10-4d4c-e4416aea10bd@oracle.com> (raw)
In-Reply-To: <SJ0PR10MB5672AFCDA4B6377F37D0C949C257A@SJ0PR10MB5672.namprd10.prod.outlook.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
subject to a few comments below.
On 7/15/25 15:50, Kris Van Hees via DTrace-devel wrote:
> If either size of a ternary expression has a tstring value, it can be
s/size/side/
> re-used to store the value of the ternary expression, reducing the
> need for tstring allocation, especially in nested ternaries.
>
> diff --git a/libdtrace/dt_impl.h b/libdtrace/dt_impl.h
> @@ -222,7 +222,7 @@ typedef struct dt_kern_path {
> * - cleanpath() holds a prepended '/' char, a string, an appended '/' char,
> * and a terminating NUL char, or STRSZ + 3 chars altogether
> */
> -#define DT_TSTRING_SLOTS 4
> +#define DT_TSTRING_SLOTS 6
Same comment as I had for Alan's patch. The comment block before this
goes into excruciating detail about why the value should be 4. Whether
its logic is right or wrong, we cannot leave those old comments with a
new value. Why is the value now 6?
I assume 6 is not a "sufficient for all purposes" value. E.g., if I
kick up the complexity on tst.tstring_ternary_nested.d, I get:
$ git diff
diff --git a/test/unittest/codegen/tst.tstring_ternary_nested.d
b/test/unittest/codegen/tst.tstring_ternary_nested.d
@@ -16,6 +16,8 @@ BEGIN {
trace(x > 1 ? strjoin(strjoin("a", "bc"), strjoin("de", "f")) :
x > 2 ? strjoin(strjoin("A", "BC"), strjoin("DE", "F")) :
x > 3 ? strjoin(strjoin("u", "vw"), strjoin("xy", "z")) :
+ x > 4 ? strjoin(strjoin("u", "vw"), strjoin("xy", "z")) :
+ x > 5 ? strjoin(strjoin("u", "vw"), strjoin("xy", "z")) :
strjoin(strjoin("U", "VW"), strjoin("XY", "Z")));
exit(0);
$ sudo ./runtest.sh test/unittest/codegen/tst.tstring_ternary_nested.d
test/unittest/codegen/tst.tstring_ternary_nested.d: FAIL: core dumped.
1 cases (0 PASS, 1 FAIL, 0 XPASS, 0 XFAIL, 0 SKIP)
$ cat test/log/current/runtest.log
[...]
dtrace: libdtrace/dt_cg.c:1472: dt_cg_tstring_xalloc: Assertion `i <
DT_TSTRING_SLOTS' failed.
> diff --git a/test/unittest/codegen/tst.tstring_ternary_nested.d b/test/unittest/codegen/tst.tstring_ternary_nested.d
> @@ -0,0 +1,26 @@
> +BEGIN {
> + x = 42;
> + trace(x > 1 ? strjoin(strjoin("a", "bc"), strjoin("de", "f")) :
> + x > 2 ? strjoin(strjoin("A", "BC"), strjoin("DE", "F")) :
> + x > 3 ? strjoin(strjoin("u", "vw"), strjoin("xy", "z")) :
> + strjoin(strjoin("U", "VW"), strjoin("XY", "Z")));
> +
> + exit(0);
> +}
I guess that's fine for cg, but the skeptic in me notices that the three
tests all evaluate to true. I would think one could run through all
2x2x2=8 cases in a single test for a little bit more rigor.
next prev parent reply other threads:[~2025-07-16 5:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-15 19:50 [PATCH 3/3] cg: optimize ternary expressions for strings Kris Van Hees
2025-07-16 5:00 ` Eugene Loh [this message]
2025-07-16 5:32 ` [DTrace-devel] " Kris Van Hees
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=57838fc8-1e04-2f10-4d4c-e4416aea10bd@oracle.com \
--to=eugene.loh@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
--cc=kris.van.hees@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox