Skip to content

Add stringify_list provisional feature -- SIMICS-22974 #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,6 @@
non-constant expressions (fixes SIMICS-13113).
- `release 6 6363`
- `release 7 7064`
- `note 6` Added the `stringify_list` provisional feature, which extends
`stringify` to support compile-time lists. This is primarily meant to provide
a means of expressing lists within documentation strings.
9 changes: 8 additions & 1 deletion py/dml/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import math

from . import objects, crep, ctree, ast, int_register, logging, serialize
from . import dmlparse, output, compat
from . import dmlparse, output, compat, provisional
from .logging import *
from .expr import *
from .ctree import *
Expand Down Expand Up @@ -1138,6 +1138,13 @@ def expr_unop(tree, location, scope):
if not func.independent:
mark_method_statically_exported(func)
return ctree.AddressOfMethod(tree.site, func)
if (tree.site.provisional_enabled(provisional.stringify_list)
and op == 'stringify' and isinstance(rh, List)):
if not rh.constant:
raise ENCONST(rh, rh)

return mkStringConstant(tree.site, str(rh))

raise rh.exc()
if op == '!':
if compat.dml12_not in dml.globals.enabled_compat:
Expand Down
23 changes: 23 additions & 0 deletions py/dml/provisional.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ class explicit_param_decls(ProvisionalFeature):
short = "Require := syntax for defining new params"
stable = True

@feature
class stringify_list(ProvisionalFeature):
'''This feature extends upon `stringify`, making it able to stringify
compile-time lists that feature stringifiable items. As with all other
valid uses of `stringify`, the resulting string will be considered
constant.

This is primarily meant as a stop-gap solution for expressing lists of
items in documentation strings, which would not be possible otherwise as
e.g. the `documentation` parameter requires the definition to be a constant
string. `stringify_list` is provisional rather than built-in as it's a
sub-par solution to the problem, while also making `stringify` more open to
abuse.

Don't take advantage of this feature so that you may use `stringify` as a
means of determining whether or not something is a compile-time list, as
that is not considered a valid, supported use-case. You are only meant
to use `stringify` to produce user-facing strings (e.g. for documentation
or logging), or for anonymization (the `name` param).
'''
short = "Extend 'stringify' to support compile-time lists"
stable = True

def parse_provisional(
provs: list[("Site", str)]) -> dict[ProvisionalFeature, "Site"]:
ret = {}
Expand Down
15 changes: 15 additions & 0 deletions test/1.4/provisional/T_stringify_list.dml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
© 2025 Intel Corporation
SPDX-License-Identifier: MPL-2.0
*/

dml 1.4;

provisional stringify_list;

device test;

/// COMPILE-ONLY

#if (stringify([["a",0],["b",1],["c",false]])
!= "[[\"a\",0],[\"b\",1],[\"c\",false]]") { error; }
15 changes: 15 additions & 0 deletions test/1.4/provisional/T_stringify_list_ENCONST.dml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
© 2025 Intel Corporation
SPDX-License-Identifier: MPL-2.0
*/

dml 1.4;

provisional stringify_list;

device test;

/// COMPILE-ONLY

/// ERROR ENCONST
param p = stringify([["a",0],["b",1],["c",dev]]);