Skip to content

Commit

Permalink
Re-rename "directives" to "attributes" for modules, functions and oth…
Browse files Browse the repository at this point in the history
…er entities across the codebase and documentation.

PiperOrigin-RevId: 716766312
  • Loading branch information
dplassgit authored and copybara-github committed Jan 17, 2025
1 parent c63386f commit 8fbc488
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 99 deletions.
2 changes: 1 addition & 1 deletion docs_src/codegen_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Some names can be set at codegen via the following flags:
`--streaming_channel_valid_suffix=_vld` for a channel named `ABC` would
result in a valid port called `ABC_vld`.
- `--[no]emit_sv_types` sets whether the sv type names set for DSLX structures
by the `#[sv_type(NAME)]` directive are honored or not.
by the `#[sv_type(NAME)]` attribute are honored or not.

# Reset Signal Configuration

Expand Down
2 changes: 1 addition & 1 deletion docs_src/dslx_ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mapped to the return of the DSLX function:
fn foo(a: u32) -> u32 { a + u32:1 }
```

You can now add a directive `#[extern_verilog("...")]` to the DSLX function
You can now add an attribute `#[extern_verilog("...")]` to the DSLX function
that contains a textual template for the instantiation that should happen. There
are placeholders in `{...}`-braces that will be replaced with the actual values
at code-generation time:
Expand Down
18 changes: 9 additions & 9 deletions docs_src/dslx_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1064,9 +1064,9 @@ fn main(x: u3) -> u1 {
fn test_main() { assert_eq(u1:0b1, main(u3:0b001)) }
```

### Module directives
### Module attributes

A limited number of directives may be applied at module scope (currently just
A limited number of attributes may be applied at module scope (currently just
one), using the following syntax, which is conventionally placed at the top of
the module (`.x` file):

Expand Down Expand Up @@ -1900,15 +1900,15 @@ unary `-` `!` | n/a
## Testing and Debugging

DSLX allows specifying tests right in the implementation file via the `test` and
`quickcheck` directives.
`quickcheck` attributes.

Having test code in the implementation file serves two purposes. It helps to
ensure the code behaves as expected. Additionally, it serves as 'executable'
documentation, similar in spirit to Python docstrings.

### Unit Tests

As in Rust, unit tests are specified by the `test` directive, as seen below:
As in Rust, unit tests are specified by the `test` attribute, as seen below:

```dslx
#[test]
Expand All @@ -1920,7 +1920,7 @@ fn test_reverse() {
```

The DSLX interpreter will execute all functions that are proceeded by a `test`
directive. These functions should be non-parametric, take no arguments, and
attribute. These functions should be non-parametric, take no arguments, and
should return a unit-type.

Unless otherwise specified in the implementation's build configs, functions
Expand Down Expand Up @@ -1959,7 +1959,7 @@ QuickCheck is a [testing framework concept][hughes-paper] founded on
property-based testing. Instead of specifying expected and test values,
QuickCheck asks for properties of the implementation that should hold true
against any input of the specified type(s). In DSLX, we use the `quickcheck`
directive to designate functions to be run via the toolchain's QuickCheck
attribute to designate functions to be run via the toolchain's QuickCheck
framework. Here is an example that complements the unit testing of DSLX's `rev`
implementation from above:

Expand All @@ -1972,14 +1972,14 @@ fn prop_double_bitreverse(x: u32) -> bool {
```

The DSLX interpreter will execute all functions that are preceded by a
`quickcheck` directive. These functions should be non-parametric and return a
`quickcheck` attribute. These functions should be non-parametric and return a
`bool`. The framework will provide randomized input based on the types of the
arguments to the function (e.g., above, the framework will provided randomized
`u32`'s as `x`).

By default, the framework will run the function against 1000 sets of randomized
inputs. This default may be changed by specifying the `test_count` key in the
`quickcheck` directive before a particular test:
`quickcheck` attribute before a particular test:

```dslx-snippet
#[quickcheck(test_count=50000)]
Expand All @@ -1994,7 +1994,7 @@ For determinism, the DSLX interpreter should be run with the `seed` flag:

#### Exhaustive QuickCheck

For small domains the quickcheck directive can also be placed in exhaustive mode via the `exhaustive` directive:
For small domains the quickcheck attribute can also be placed in exhaustive mode via the `exhaustive` attribute:

```dslx
// `u8` space is small enough to check exhaustively.
Expand Down
4 changes: 2 additions & 2 deletions docs_src/tutorials/hello_xls.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Let's go over this, line-by-line:
list's closing parenthesis and before the function-opening curly brace, if
the function returned a value).
2. A comment line.
3. This second line invokes the built-in `trace!` directive, passing it the
3. This second line invokes the built-in `trace!` attribute, passing it the
function's input string, and throws away the result.

## 3. Say hello, XLS!
Expand Down Expand Up @@ -96,7 +96,7 @@ fn hello_test() {

Again, going line-by-line:

1. This directive tells the interpreter that the next function is a test
1. This attribute tells the interpreter that the next function is a test
function, meaning that it shouldn't be passed down the synthesis chain and
that it should be executed by the interpreter.
2. This line declares the [test] function `hello_test`, which takes no args and
Expand Down
2 changes: 1 addition & 1 deletion docs_src/tutorials/how_to_use_procs.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ of designs simply by adjusting a few parametric values.
The DSLX interpreter supports testing procs via the *test_proc* construct. A
test proc is very similar to a normal proc with the following changes:

* A test proc is preceded by the `#[test_proc]` directive. This directive, as
* A test proc is preceded by the `#[test_proc]` attribute. This attribute, as
one might expect, notifies the interpreter that the following proc is a test
proc.
* A test proc's `config` function must accept a single argument: a boolean
Expand Down
8 changes: 4 additions & 4 deletions xls/codegen/vast/dslx_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -719,13 +719,13 @@ absl::StatusOr<std::string> DslxBuilder::FormatModule() {
if (std::holds_alternative<dslx::ConstantDef*>(member)) {
// Allow non-standard constant names, because we do not canonicalize the
// original SV names to SCREAMING_SNAKE_CASE in the conversion process.
module_.AddDirective(
dslx::ModuleDirective::kAllowNonstandardConstantNaming);
module_.AddAttribute(
dslx::ModuleAttribute::kAllowNonstandardConstantNaming);

// Similar for members, they are not in SV going to be consistency named
// in `snake_case` convention.
module_.AddDirective(
dslx::ModuleDirective::kAllowNonstandardMemberNaming);
module_.AddAttribute(
dslx::ModuleAttribute::kAllowNonstandardMemberNaming);
break;
}
}
Expand Down
12 changes: 6 additions & 6 deletions xls/dslx/fmt/ast_fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2893,24 +2893,24 @@ static int NumHardLinesAfter(const AstNode* node, const ModuleMember& member,
absl::StatusOr<DocRef> Formatter::Format(const Module& n) {
std::vector<DocRef> pieces;

if (!n.directives().empty()) {
for (ModuleDirective annotation : n.directives()) {
if (!n.attributes().empty()) {
for (ModuleAttribute annotation : n.attributes()) {
switch (annotation) {
case ModuleDirective::kAllowNonstandardConstantNaming:
case ModuleAttribute::kAllowNonstandardConstantNaming:
pieces.push_back(
arena_.MakeText("#![allow(nonstandard_constant_naming)]"));
pieces.push_back(arena_.hard_line());
break;
case ModuleDirective::kAllowNonstandardMemberNaming:
case ModuleAttribute::kAllowNonstandardMemberNaming:
pieces.push_back(
arena_.MakeText("#![allow(nonstandard_member_naming)]"));
pieces.push_back(arena_.hard_line());
break;
case ModuleDirective::kTypeInferenceVersion2:
case ModuleAttribute::kTypeInferenceVersion2:
pieces.push_back(arena_.MakeText("#![feature(type_inference_v2)]"));
pieces.push_back(arena_.hard_line());
break;
case ModuleDirective::kAllowUseSyntax:
case ModuleAttribute::kAllowUseSyntax:
pieces.push_back(arena_.MakeText("#![feature(use_syntax)]"));
pieces.push_back(arena_.hard_line());
break;
Expand Down
2 changes: 0 additions & 2 deletions xls/dslx/fmt/format_disabler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ namespace xls::dslx {

// Implements formatter disabling via "dsl-fmt::off" and "dsl-fmt::on" comments.
//
// Used by the auto-formatter to implement the directives.
//
// NOTE: this class is stateful and should only be used once per module.
class FormatDisabler {
public:
Expand Down
4 changes: 2 additions & 2 deletions xls/dslx/frontend/ast_cloner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,8 @@ absl::StatusOr<std::unique_ptr<Module>> CloneModule(const Module& module,
CloneReplacer replacer) {
auto new_module = std::make_unique<Module>(module.name(), module.fs_path(),
*module.file_table());
for (const ModuleDirective& dir : module.directives()) {
new_module->AddDirective(dir);
for (const ModuleAttribute& dir : module.attributes()) {
new_module->AddAttribute(dir);
}
AstCloner cloner(new_module.get(), std::move(replacer));
XLS_RETURN_IF_ERROR(module.Accept(&cloner));
Expand Down
18 changes: 9 additions & 9 deletions xls/dslx/frontend/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,22 @@ std::string Module::ToString() const {
absl::StrAppend(out, ToAstNode(member)->ToString());
});

if (!directives().empty()) {
// Make an directive block above the module contents if there are
// directives.
if (!attributes().empty()) {
// Make an attribute block above the module contents if there are
// attributes.
std::string header = absl::StrJoin(
directives(), "\n", [](std::string* out, ModuleDirective directive) {
switch (directive) {
case ModuleDirective::kAllowNonstandardConstantNaming:
attributes(), "\n", [](std::string* out, ModuleAttribute attribute) {
switch (attribute) {
case ModuleAttribute::kAllowNonstandardConstantNaming:
absl::StrAppend(out, "#![allow(nonstandard_constant_naming)]");
break;
case ModuleDirective::kAllowNonstandardMemberNaming:
case ModuleAttribute::kAllowNonstandardMemberNaming:
absl::StrAppend(out, "#![allow(nonstandard_member_naming)]");
break;
case ModuleDirective::kTypeInferenceVersion2:
case ModuleAttribute::kTypeInferenceVersion2:
absl::StrAppend(out, "#![feature(type_inference_v2)]");
break;
case ModuleDirective::kAllowUseSyntax:
case ModuleAttribute::kAllowUseSyntax:
absl::StrAppend(out, "#![feature(use_syntax)]");
break;
}
Expand Down
16 changes: 8 additions & 8 deletions xls/dslx/frontend/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Pos GetPos(const ModuleMember& module_member);

std::string_view GetModuleMemberTypeName(const ModuleMember& module_member);

enum class ModuleDirective : uint8_t {
enum class ModuleAttribute : uint8_t {
// Suppresses the "constant naming" warning.
kAllowNonstandardConstantNaming,

Expand Down Expand Up @@ -262,14 +262,14 @@ class Module : public AstNode {
// Finds all the AST nodes that fall within the given span.
std::vector<const AstNode*> FindContained(const Span& target) const;

// Tags this module as having the given module-level directive "directive".
void AddDirective(ModuleDirective directive) {
directives_.insert(directive);
// Tags this module as having the given module-level attribute "attribute".
void AddAttribute(ModuleAttribute attribute) {
attributes_.insert(attribute);
}

// Returns all the module-level directive tags.
const absl::btree_set<ModuleDirective>& directives() const {
return directives_;
// Returns all the module-level attribute tags.
const absl::btree_set<ModuleAttribute>& attributes() const {
return attributes_;
}

FileTable* file_table() const { return file_table_; }
Expand Down Expand Up @@ -330,7 +330,7 @@ class Module : public AstNode {
// having many definition nodes of the same builtin thing floating around.
absl::flat_hash_map<std::string, BuiltinNameDef*> builtin_name_defs_;

absl::btree_set<ModuleDirective> directives_;
absl::btree_set<ModuleAttribute> attributes_;

// The span of the module is only known once parsing has completed.
//
Expand Down
Loading

0 comments on commit 8fbc488

Please sign in to comment.