Skip to content

Commit 78879d4

Browse files
committed
Add documentation for --deprecation
1 parent 0a35cba commit 78879d4

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ PYFILES := dml/__init__.py \
2121
dml/topsort.py \
2222
dml/traits.py \
2323
dml/types.py \
24-
dml/deprecations.py \
2524
dml/dmllex.py \
2625
dml/dmllex12.py \
2726
dml/dmllex14.py \
@@ -212,9 +211,11 @@ DOC_FILES_14 := $(wildcard $(DOC_SRC_DIR_14)/*.md) $(DOC_SRC_DIR_14)/toc.json
212211
DOC_DEST_14 := $(SIMICS_PROJECT)/$(HOST_TYPE)/doc/html/dml-1.4-reference-manual
213212
DOC_MARKER_14 := $(DOC_DEST_14)/filelist.json
214213

215-
GENERATED_MD_FILES_14 = $(addprefix generated-md-1.4/,grammar.md messages.md changes-auto.md dml-builtins.md utility.md)
214+
GENERATED_MD_FILES_14 = $(addprefix generated-md-1.4/,grammar.md messages.md changes-auto.md dml-builtins.md utility.md deprecations-auto.md)
216215
generated-md-1.4/changes-auto.md: $(SRC_BASE)/$(TARGET)/porting_to_md.py $(DMLC_BIN) | generated-md-1.4
217216
$(PYTHON) $< $(PYTHONPATH) $@
217+
generated-md-1.4/deprecations-auto.md: $(SRC_BASE)/$(TARGET)/deprecations_to_md.py $(SRC_BASE)/$(TARGET)/doc/1.4/deprecations-header.md $(DMLC_BIN) | generated-md-1.4
218+
$(PYTHON) $< $(PYTHONPATH) $(word 2,$^) $@
218219
generated-md-1.4/dml-builtins.md generated-md-1.4/utility.md: generated-md-1.4/%.md: $(DMLC_DIR)/lib/1.4/%.dml
219220
$(PYTHON) $(DMLC_DIR)/dmlcomments_to_md.py $< $@
220221
DOC_FILES_14 += $(GENERATED_MD_FILES_14)

deprecations_to_md.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# © 2023 Intel Corporation
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
import sys
5+
from pathlib import Path
6+
[path_to_dml, header, outfile] = sys.argv[1:]
7+
sys.path.append(path_to_dml)
8+
9+
from dml.deprecations import deprecations
10+
11+
with open(outfile, 'w') as f:
12+
f.write(Path(header).read_text())
13+
f.write("<dl>\n")
14+
for d in deprecations.values():
15+
assert d.__doc__
16+
f.write(f" <dt>{d.__class__.__name__}</dt>\n")
17+
doc = '\n'.join(line[4:] if line.startswith(' ') else line
18+
for line in d.__doc__.strip().splitlines())
19+
f.write(f" <dd>\n\n{doc}\n</dd>\n")
20+
f.write("</dl>\n")

doc/1.4/deprecations-header.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<!--
2+
© 2023 Intel Corporation
3+
SPDX-License-Identifier: MPL-2.0
4+
-->
5+
6+
# Managing deprecated language features
7+
8+
As the DML language evolves, we sometimes need to change the language in
9+
incompatible ways, which requires DML users to migrate their code. This
10+
appendix describes the mechanisms we provide to make this migration process
11+
smooth for users with large DML code bases.
12+
13+
In DML, deprecations can come in many forms. Deprecations in the form of
14+
removed or renamed symbols in libraries are rather easy to manage, since they
15+
give clear compile errors that often are straightforward to fix. A slightly
16+
harder type of deprecation is when some language construct or API function
17+
adjusts its semantics; this can make the model behave differently without
18+
signalling error messages. A third kind of deprecation is when DML changes how
19+
compiled models appear in Simics, typically to adjust changes in the Simics
20+
API. Such changes add another dimension because they typically affect the
21+
end-users of the DML models, rather than the authors of the models. Thus, as an
22+
author of a model you may need to synchronize your migration of such features
23+
with your end-users, to ease their transition to a new major version.
24+
25+
## Deprecation mechanisms
26+
27+
The simplest deprecation mechanism is Simics API versions: Each deprecated DML
28+
feature is associated with a Simics API version, and each Simics version
29+
supports a number of such API versions. Features reach end-of-life when moving
30+
to a new Simics major version, the features belonging to a previous Simics API
31+
version are dropped. Since Simics is currently the primary distribution channel
32+
for DML, this deprecation scheme is used for DML features as well.
33+
34+
This scheme allows users with a large code base to smoothly migrate from one
35+
Simics major version, N, to the next, N+1:
36+
* First, while still using version N, make sure all Simics modules are updated
37+
to use API version N. Modules can be migrated one by one.
38+
* Second, update the Simics version to N+1. This should normally have no
39+
effect on DML, but may come with other challenges.
40+
* Third, update modules to API N+1, one by one. Simics version N+1 will always
41+
offers full support for API N, so there is no rush to update, but changing
42+
the API version early makes sure deprecated features are not introduced in
43+
new code.
44+
45+
In addition to the API version, DML offers some compiler flags for selectively
46+
disabling deprecated features that are normally part of the used API. This has
47+
some uses, in particular:
48+
* During migration to a new API version, disabling one deprecated feature at a
49+
time can allow a smoother, more gradual, migration.
50+
* If a legacy feature is still fully supported in the latest API version, then
51+
it cannot be disabled by selecting an API version, so selectively disabling
52+
it is the only way to turn it off. There are reasons to do this, e.g.:
53+
* Disabling a feature before it is deprecated guarantees that it is not
54+
relied upon in new code, which eases later migration.
55+
* Avoiding a feature that has a newer replacement makes the code base
56+
cleaner and more consistent.
57+
* Some legacy features can also bloat models, by exposing features in a
58+
redundant manner. This can also have a negative impact on performance.
59+
60+
## Controlling deprecation on the DML command-line
61+
DMLC provides a command-line flag `--api-version` to specify the API version to
62+
be used for a model. When building with the standard Simics build system, this is controlled by the `SIMICS_API_VERSION` variable in `make`, or the `SIMICS_API`/`MODULE_SIMICS_API` variable in `CMake`.
63+
64+
DMLC also provides the <code>--deprecate=_tag_</code> flag, which disables the
65+
feature represented by _`tag`_. The available tags are listed in the next
66+
section. The tag also controls the name of a global boolean parameter that the
67+
DML program may use to check whether the feature is available. The parameter's
68+
name is the tag name preceded by `_deprecate_`.
69+
70+
## List of deprecated features

doc/1.4/toc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
{"file": "messages.md",
1717
"numbering": true,
1818
"appendix": true},
19+
{"file": "deprecations-auto.md",
20+
"numbering": true,
21+
"appendix": true},
1922
{"file": "changes.md",
2023
"numbering": true,
2124
"appendix": true,

0 commit comments

Comments
 (0)