Skip to content

Commit 58ebd3a

Browse files
committed
Add stringify_list provisional feature -- SIMICS-22974
1 parent ea00bb8 commit 58ebd3a

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

RELEASENOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,6 @@
228228
as Coverity support is enabled by passing `--coverity` to DMLC.
229229
- `release 6 6356`
230230
- `release 7 7060`
231+
- `note 6` Added the `stringify_list` provisional feature, which extends
232+
`stringify` to support compile-time lists. This is primarily meant to provide
233+
a means of expressing lists within documentation strings.

py/dml/codegen.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import math
1313

1414
from . import objects, crep, ctree, ast, int_register, logging, serialize
15-
from . import dmlparse, output, compat
15+
from . import dmlparse, output, compat, provisional
1616
from .logging import *
1717
from .expr import *
1818
from .ctree import *
@@ -1138,6 +1138,13 @@ def expr_unop(tree, location, scope):
11381138
if not func.independent:
11391139
mark_method_statically_exported(func)
11401140
return ctree.AddressOfMethod(tree.site, func)
1141+
if (tree.site.provisional_enabled(provisional.stringify_list)
1142+
and op == 'stringify' and isinstance(rh, List)):
1143+
if not rh.constant:
1144+
raise ENCONST(rh, rh)
1145+
1146+
return mkStringConstant(tree.site, str(rh))
1147+
11411148
raise rh.exc()
11421149
if op == '!':
11431150
if compat.dml12_not in dml.globals.enabled_compat:

py/dml/provisional.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,29 @@ class explicit_param_decls(ProvisionalFeature):
7171
short = "Require := syntax for defining new params"
7272
stable = True
7373

74+
@feature
75+
class stringify_list(ProvisionalFeature):
76+
'''This feature extends upon `stringify`, making it able to stringify
77+
compile-time lists that feature stringifiable items. As with all other
78+
valid uses of `stringify`, the resulting string will be considered
79+
constant.
80+
81+
This is primarily meant as a stop-gap solution for expressing lists of
82+
items in documentation strings, which would not be possible otherwise as
83+
e.g. the `documentation` parameter requires the definition to be a constant
84+
string. `stringify_list` is provisional rather than built-in as it's a
85+
sub-par solution to the problem, while also making `stringify` more open to
86+
abuse.
87+
88+
Don't take advantage of this feature so that you may use `stringify` as a
89+
means of determining whether or not something is a compile-time list, as
90+
that is not considered a valid, supported use-case. You are only meant
91+
to use `stringify` to produce user-facing strings (e.g. for documentation
92+
or logging), or for anonymization (the `name` param).
93+
'''
94+
short = "Extend 'stringify' to support compile-time lists"
95+
stable = True
96+
7497
def parse_provisional(
7598
provs: list[("Site", str)]) -> dict[ProvisionalFeature, "Site"]:
7699
ret = {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
© 2025 Intel Corporation
3+
SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
dml 1.4;
7+
8+
provisional stringify_list;
9+
10+
device test;
11+
12+
/// COMPILE-ONLY
13+
14+
#if (stringify([["a",0],["b",1],["c",false]])
15+
!= "[[\"a\",0],[\"b\",1],[\"c\",false]]") { error; }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
© 2025 Intel Corporation
3+
SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
dml 1.4;
7+
8+
provisional stringify_list;
9+
10+
device test;
11+
12+
/// COMPILE-ONLY
13+
14+
/// ERROR ENCONST
15+
param p = stringify([["a",0],["b",1],["c",dev]]);

0 commit comments

Comments
 (0)