From 8fbc4889430e251c3838e8481bdc55f9cf7fe1dd Mon Sep 17 00:00:00 2001 From: David Plass Date: Fri, 17 Jan 2025 12:45:39 -0800 Subject: [PATCH] Re-rename "directives" to "attributes" for modules, functions and other entities across the codebase and documentation. PiperOrigin-RevId: 716766312 --- docs_src/codegen_options.md | 2 +- docs_src/dslx_ffi.md | 2 +- docs_src/dslx_reference.md | 18 +++--- docs_src/tutorials/hello_xls.md | 4 +- docs_src/tutorials/how_to_use_procs.md | 2 +- xls/codegen/vast/dslx_builder.cc | 8 +-- xls/dslx/fmt/ast_fmt.cc | 12 ++-- xls/dslx/fmt/format_disabler.h | 2 - xls/dslx/frontend/ast_cloner.cc | 4 +- xls/dslx/frontend/module.cc | 18 +++--- xls/dslx/frontend/module.h | 16 ++--- xls/dslx/frontend/parser.cc | 64 +++++++++---------- xls/dslx/frontend/parser.h | 14 ++-- xls/dslx/frontend/parser_test.cc | 20 +++--- xls/dslx/parse_and_typecheck.cc | 2 +- xls/dslx/type_system/deduce.cc | 4 +- .../deduce_struct_def_base_utils.cc | 4 +- 17 files changed, 97 insertions(+), 99 deletions(-) diff --git a/docs_src/codegen_options.md b/docs_src/codegen_options.md index 46480dbf28..a5ba91b817 100644 --- a/docs_src/codegen_options.md +++ b/docs_src/codegen_options.md @@ -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 diff --git a/docs_src/dslx_ffi.md b/docs_src/dslx_ffi.md index ed37083c71..ae885efbbb 100644 --- a/docs_src/dslx_ffi.md +++ b/docs_src/dslx_ffi.md @@ -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: diff --git a/docs_src/dslx_reference.md b/docs_src/dslx_reference.md index b38a84daf7..b0cf07958c 100644 --- a/docs_src/dslx_reference.md +++ b/docs_src/dslx_reference.md @@ -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): @@ -1900,7 +1900,7 @@ 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' @@ -1908,7 +1908,7 @@ 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] @@ -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 @@ -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: @@ -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)] @@ -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. diff --git a/docs_src/tutorials/hello_xls.md b/docs_src/tutorials/hello_xls.md index 31790492fd..fa501a6f24 100644 --- a/docs_src/tutorials/hello_xls.md +++ b/docs_src/tutorials/hello_xls.md @@ -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! @@ -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 diff --git a/docs_src/tutorials/how_to_use_procs.md b/docs_src/tutorials/how_to_use_procs.md index c227a5fa55..c5af0d57b8 100644 --- a/docs_src/tutorials/how_to_use_procs.md +++ b/docs_src/tutorials/how_to_use_procs.md @@ -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 diff --git a/xls/codegen/vast/dslx_builder.cc b/xls/codegen/vast/dslx_builder.cc index 3ec011853b..c5ae97374e 100644 --- a/xls/codegen/vast/dslx_builder.cc +++ b/xls/codegen/vast/dslx_builder.cc @@ -719,13 +719,13 @@ absl::StatusOr DslxBuilder::FormatModule() { if (std::holds_alternative(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; } } diff --git a/xls/dslx/fmt/ast_fmt.cc b/xls/dslx/fmt/ast_fmt.cc index 2453abd2be..4f3c03a5ce 100644 --- a/xls/dslx/fmt/ast_fmt.cc +++ b/xls/dslx/fmt/ast_fmt.cc @@ -2893,24 +2893,24 @@ static int NumHardLinesAfter(const AstNode* node, const ModuleMember& member, absl::StatusOr Formatter::Format(const Module& n) { std::vector 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; diff --git a/xls/dslx/fmt/format_disabler.h b/xls/dslx/fmt/format_disabler.h index a1f90a7bf1..a39edf54bf 100644 --- a/xls/dslx/fmt/format_disabler.h +++ b/xls/dslx/fmt/format_disabler.h @@ -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: diff --git a/xls/dslx/frontend/ast_cloner.cc b/xls/dslx/frontend/ast_cloner.cc index 8333bbd82b..44a485ee4c 100644 --- a/xls/dslx/frontend/ast_cloner.cc +++ b/xls/dslx/frontend/ast_cloner.cc @@ -1148,8 +1148,8 @@ absl::StatusOr> CloneModule(const Module& module, CloneReplacer replacer) { auto new_module = std::make_unique(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)); diff --git a/xls/dslx/frontend/module.cc b/xls/dslx/frontend/module.cc index 22e5755c2b..51c9775f03 100644 --- a/xls/dslx/frontend/module.cc +++ b/xls/dslx/frontend/module.cc @@ -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; } diff --git a/xls/dslx/frontend/module.h b/xls/dslx/frontend/module.h index e5f0e6bb6c..48955988dd 100644 --- a/xls/dslx/frontend/module.h +++ b/xls/dslx/frontend/module.h @@ -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, @@ -262,14 +262,14 @@ class Module : public AstNode { // Finds all the AST nodes that fall within the given span. std::vector 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& directives() const { - return directives_; + // Returns all the module-level attribute tags. + const absl::btree_set& attributes() const { + return attributes_; } FileTable* file_table() const { return file_table_; } @@ -330,7 +330,7 @@ class Module : public AstNode { // having many definition nodes of the same builtin thing floating around. absl::flat_hash_map builtin_name_defs_; - absl::btree_set directives_; + absl::btree_set attributes_; // The span of the module is only known once parsing has completed. // diff --git a/xls/dslx/frontend/parser.cc b/xls/dslx/frontend/parser.cc index f049fdc0cd..b3e3acd1cb 100644 --- a/xls/dslx/frontend/parser.cc +++ b/xls/dslx/frontend/parser.cc @@ -237,39 +237,39 @@ absl::StatusOr Parser::ParseFunction( return f; } -absl::Status Parser::ParseModuleDirective() { +absl::Status Parser::ParseModuleAttribute() { XLS_RETURN_IF_ERROR(DropTokenOrError(TokenKind::kOBrack)); - Span directive_span; - XLS_ASSIGN_OR_RETURN(std::string directive, - PopIdentifierOrError(&directive_span)); - if (directive == "feature") { + Span attribute_span; + XLS_ASSIGN_OR_RETURN(std::string attribute, + PopIdentifierOrError(&attribute_span)); + if (attribute == "feature") { XLS_RETURN_IF_ERROR(DropTokenOrError(TokenKind::kOParen)); XLS_ASSIGN_OR_RETURN(std::string feature, PopIdentifierOrError()); XLS_RETURN_IF_ERROR(DropTokenOrError(TokenKind::kCParen)); XLS_RETURN_IF_ERROR(DropTokenOrError(TokenKind::kCBrack)); if (feature == "use_syntax") { - module_->AddDirective(ModuleDirective::kAllowUseSyntax); + module_->AddAttribute(ModuleAttribute::kAllowUseSyntax); } else if (feature == "type_inference_v2") { - module_->AddDirective(ModuleDirective::kTypeInferenceVersion2); + module_->AddAttribute(ModuleAttribute::kTypeInferenceVersion2); } else { return ParseErrorStatus( - directive_span, + attribute_span, absl::StrFormat("Unsupported feature: `%s`", feature)); } return absl::OkStatus(); } - if (directive != "allow") { - return ParseErrorStatus(directive_span, + if (attribute != "allow") { + return ParseErrorStatus(attribute_span, "Only 'allow' and 'type_inference_version' are " - "supported as module-level directives"); + "supported as module-level attributes"); } XLS_RETURN_IF_ERROR(DropTokenOrError(TokenKind::kOParen)); XLS_ASSIGN_OR_RETURN(std::string to_allow, PopIdentifierOrError()); if (to_allow == "nonstandard_constant_naming") { - module_->AddDirective(ModuleDirective::kAllowNonstandardConstantNaming); + module_->AddAttribute(ModuleAttribute::kAllowNonstandardConstantNaming); } if (to_allow == "nonstandard_member_naming") { - module_->AddDirective(ModuleDirective::kAllowNonstandardMemberNaming); + module_->AddAttribute(ModuleAttribute::kAllowNonstandardMemberNaming); } XLS_RETURN_IF_ERROR(DropTokenOrError(TokenKind::kCParen)); XLS_RETURN_IF_ERROR(DropTokenOrError(TokenKind::kCBrack)); @@ -382,13 +382,13 @@ absl::StatusOr> Parser::ParseModule( if (hash.has_value()) { XLS_ASSIGN_OR_RETURN(bool dropped_bang, TryDropToken(TokenKind::kBang)); if (dropped_bang) { - XLS_RETURN_IF_ERROR(ParseModuleDirective()); + XLS_RETURN_IF_ERROR(ParseModuleAttribute()); continue; } XLS_ASSIGN_OR_RETURN( auto attribute, - ParseDirective(&name_to_fn, *bindings, hash->span().start())); + ParseAttribute(&name_to_fn, *bindings, hash->span().start())); XLS_RETURN_IF_ERROR(absl::visit( Visitor{ [&](auto* t) { return module_->AddTop(t, make_collision_error); }, @@ -449,7 +449,7 @@ absl::StatusOr> Parser::ParseModule( break; } case Keyword::kImport: { - if (module_->directives().contains(ModuleDirective::kAllowUseSyntax)) { + if (module_->attributes().contains(ModuleAttribute::kAllowUseSyntax)) { return ParseErrorStatus( peek->span(), "`import` syntax is disabled for this module via " @@ -460,7 +460,7 @@ absl::StatusOr> Parser::ParseModule( break; } case Keyword::kUse: { - if (!module_->directives().contains(ModuleDirective::kAllowUseSyntax)) { + if (!module_->attributes().contains(ModuleAttribute::kAllowUseSyntax)) { return ParseErrorStatus( peek->span(), "`use` syntax is not enabled for this module; enable with " @@ -527,18 +527,18 @@ absl::StatusOr> Parser::ParseModule( absl::StatusOr> -Parser::ParseDirective(absl::flat_hash_map* name_to_fn, +Parser::ParseAttribute(absl::flat_hash_map* name_to_fn, Bindings& bindings, const Pos& hash_pos) { // Ignore the Rust "bang" in Attribute declarations, i.e. we don't yet have // a use for inner vs. outer attributes, but that day will likely come. XLS_RETURN_IF_ERROR(DropTokenOrError(TokenKind::kOBrack)); XLS_ASSIGN_OR_RETURN( - Token directive_tok, + Token attribute_tok, PopTokenOrError(TokenKind::kIdentifier, /*start=*/nullptr, "Expected attribute identifier")); - const std::string& directive_name = directive_tok.GetStringValue(); + const std::string& attribute_name = attribute_tok.GetStringValue(); - if (directive_name == "test") { + if (attribute_name == "test") { XLS_ASSIGN_OR_RETURN(Token cbrack, PopTokenOrError(TokenKind::kCBrack)); XLS_ASSIGN_OR_RETURN(const Token* peek, PeekToken()); if (peek->IsKeyword(Keyword::kFn)) { @@ -548,7 +548,7 @@ Parser::ParseDirective(absl::flat_hash_map* name_to_fn, return ParseErrorStatus( peek->span(), absl::StrCat("Invalid test type: ", peek->ToString())); } - if (directive_name == "extern_verilog") { + if (attribute_name == "extern_verilog") { XLS_RETURN_IF_ERROR(DropTokenOrError(TokenKind::kOParen)); Pos template_start = GetPos(); Pos template_limit; @@ -577,19 +577,19 @@ Parser::ParseDirective(absl::flat_hash_map* name_to_fn, f->set_extern_verilog_module(*parsed_ffi_annotation); return f; } - if (directive_name == "test_proc") { + if (attribute_name == "test_proc") { XLS_RETURN_IF_ERROR(DropTokenOrError(TokenKind::kCBrack)); return ParseTestProc(bindings); } - if (directive_name == "quickcheck") { + if (attribute_name == "quickcheck") { return ParseQuickCheck(name_to_fn, bindings, hash_pos); } - if (directive_name == "sv_type") { + if (attribute_name == "sv_type") { XLS_RETURN_IF_ERROR(DropTokenOrError(TokenKind::kOParen)); Pos ident_limit; XLS_ASSIGN_OR_RETURN( Token sv_type_id, - PopTokenOrError(TokenKind::kString, /*start=*/&directive_tok, + PopTokenOrError(TokenKind::kString, /*start=*/&attribute_tok, "sv_type identifier", &ident_limit)); XLS_RETURN_IF_ERROR(DropTokenOrError(TokenKind::kCParen)); XLS_RETURN_IF_ERROR(DropTokenOrError(TokenKind::kCBrack)); @@ -619,13 +619,13 @@ Parser::ParseDirective(absl::flat_hash_map* name_to_fn, enum_def->set_extern_type_name(sv_type_id.GetStringValue()); return enum_def; } - return ParseErrorStatus(directive_tok.span(), + return ParseErrorStatus(attribute_tok.span(), "#[sv_type(\"name\")] is only valid on type-alias, " "struct or enum definitions"); } return ParseErrorStatus( - directive_tok.span(), - absl::StrFormat("Unknown directive: '%s'", directive_name)); + attribute_tok.span(), + absl::StrFormat("Unknown attribute: '%s'", attribute_name)); } absl::StatusOr Parser::ParseExpression(Bindings& bindings, @@ -1715,7 +1715,7 @@ absl::StatusOr Parser::ParseQuickCheckConfig() { } return ParseErrorStatus(tok.span(), "Expected 'exhaustive' or 'test_count' in " - "quickcheck directive"); + "quickcheck attribute"); } absl::StatusOr Parser::ParseQuickCheck( @@ -3618,7 +3618,7 @@ absl::StatusOr> Parser::ParseParametrics( } absl::StatusOr Parser::ParseTestFunction( - Bindings& bindings, const Span& directive_span) { + Bindings& bindings, const Span& attribute_span) { XLS_ASSIGN_OR_RETURN( Function * f, ParseFunctionInternal(GetPos(), /*is_public=*/false, bindings)); @@ -3632,7 +3632,7 @@ absl::StatusOr Parser::ParseTestFunction( f->identifier(), ToAstNode(**member)->GetSpan()->ToString(file_table()))); } - Span tf_span(directive_span.start(), f->span().limit()); + Span tf_span(attribute_span.start(), f->span().limit()); TestFunction* tf = module_->Make(tf_span, *f); tf->SetParentage(); // Ensure the function has its parent marked. return tf; diff --git a/xls/dslx/frontend/parser.h b/xls/dslx/frontend/parser.h index 3ed7257849..d418af8bd8 100644 --- a/xls/dslx/frontend/parser.h +++ b/xls/dslx/frontend/parser.h @@ -597,7 +597,7 @@ class Parser : public TokenParser { // Returns TestFunction AST node by parsing new-style unit test construct. absl::StatusOr ParseTestFunction(Bindings& bindings, - const Span& directive_span); + const Span& attribute_span); absl::StatusOr ParseTestProc(Bindings& bindings); @@ -611,15 +611,15 @@ class Parser : public TokenParser { absl::flat_hash_map* name_to_fn, Bindings& bindings, const Pos& hash_pos); - // Parses the test count configuration for a quickcheck directive. + // Parses the test count configuration for a quickcheck attribute. absl::StatusOr ParseQuickCheckConfig(); - // Parses a module-level directive -- cursor should be over the open bracket. + // Parses a module-level attribute -- cursor should be over the open bracket. // - // Side-effect: module_ is tagged with the parsed directive on success. - absl::Status ParseModuleDirective(); + // Side-effect: module_ is tagged with the parsed attribute on success. + absl::Status ParseModuleAttribute(); - // Parses DSLX directives, analogous to Rust's attributes. + // Parses DSLX attributes, analogous to Rust's attributes. // // This accepts the following: // #[test] Expects a 'fn', returns TestFunction* @@ -629,7 +629,7 @@ class Parser : public TokenParser { // #[sv_type(...)] Expects a TypeDefinition, returns TypeDefinition absl::StatusOr> - ParseDirective(absl::flat_hash_map* name_to_fn, + ParseAttribute(absl::flat_hash_map* name_to_fn, Bindings& bindings, const Pos& hash_pos); // Parses a "spawn" statement, which creates & initializes a proc. diff --git a/xls/dslx/frontend/parser_test.cc b/xls/dslx/frontend/parser_test.cc index 21abb07227..a3270cfd48 100644 --- a/xls/dslx/frontend/parser_test.cc +++ b/xls/dslx/frontend/parser_test.cc @@ -2406,14 +2406,14 @@ TEST_F(ParserTest, EllipsisNotInTrailingLeading) { "Ellipsis may only be in trailing position."))); } -TEST_F(ParserTest, QuickCheckDirective) { +TEST_F(ParserTest, QuickCheckAttribute) { RoundTrip(R"(#[quickcheck] fn foo(x: u5) -> bool { true })"); } -TEST_F(ParserTest, QuickCheckDirectiveWithTestCount) { +TEST_F(ParserTest, QuickCheckAttributeWithTestCount) { RoundTrip(R"(#[quickcheck(test_count=1024)] fn foo(x: u5) -> bool { true @@ -2971,23 +2971,23 @@ TEST_F(ParserTest, ParseAllowNonstandardConstantNamingAnnotation) { XLS_ASSERT_OK_AND_ASSIGN(std::unique_ptr module, parser.ParseModule()); EXPECT_THAT( - module->directives(), - testing::ElementsAre(ModuleDirective::kAllowNonstandardConstantNaming)); + module->attributes(), + testing::ElementsAre(ModuleAttribute::kAllowNonstandardConstantNaming)); } TEST_F(ParserTest, NoAttributeForTypeInferenceVersion) { XLS_ASSERT_OK_AND_ASSIGN(std::unique_ptr module, Parse(R"( fn f() { () } )")); - EXPECT_THAT(module->directives(), testing::IsEmpty()); + EXPECT_THAT(module->attributes(), testing::IsEmpty()); } TEST_F(ParserTest, ParseTypeInferenceVersionAttributeWithValue2) { XLS_ASSERT_OK_AND_ASSIGN(std::unique_ptr module, Parse(R"( #![feature(type_inference_v2)] )")); - EXPECT_THAT(module->directives(), - testing::ElementsAre(ModuleDirective::kTypeInferenceVersion2)); + EXPECT_THAT(module->attributes(), + testing::ElementsAre(ModuleAttribute::kTypeInferenceVersion2)); } // Verifies that we can walk backwards through a tree. In this case, from the @@ -3255,7 +3255,7 @@ TEST(ParserErrorTest, BadTestTarget) { IsPosError("ParseError", HasSubstr("Invalid test type: let"))); } -TEST(ParserErrorTest, BadDirectiveTokenType) { +TEST(ParserErrorTest, BadAttributeTokenType) { constexpr std::string_view kProgram = R"(#[3])"; FileTable file_table; Scanner s{file_table, Fileno(0), std::string(kProgram)}; @@ -3266,14 +3266,14 @@ TEST(ParserErrorTest, BadDirectiveTokenType) { IsPosError("ParseError", HasSubstr("Expected attribute identifier"))); } -TEST(ParserErrorTest, BadDirective) { +TEST(ParserErrorTest, BadAttribute) { constexpr std::string_view kProgram = R"(#[foo])"; FileTable file_table; Scanner s{file_table, Fileno(0), std::string(kProgram)}; Parser parser{"test", &s}; absl::StatusOr> module = parser.ParseModule(); EXPECT_THAT(module.status(), - IsPosError("ParseError", HasSubstr("Unknown directive: 'foo'"))); + IsPosError("ParseError", HasSubstr("Unknown attribute: 'foo'"))); } TEST(ParserErrorTest, FailLabelVerilogIdentifierConstraintReported) { diff --git a/xls/dslx/parse_and_typecheck.cc b/xls/dslx/parse_and_typecheck.cc index 584b4ed37f..57a84575b1 100644 --- a/xls/dslx/parse_and_typecheck.cc +++ b/xls/dslx/parse_and_typecheck.cc @@ -97,7 +97,7 @@ absl::StatusOr TypecheckModule( WarningCollector warnings(import_data->enabled_warnings()); XLS_ASSIGN_OR_RETURN( TypeInfo * type_info, - module->directives().contains(ModuleDirective::kTypeInferenceVersion2) + module->attributes().contains(ModuleAttribute::kTypeInferenceVersion2) ? TypecheckModuleV2(module.get(), import_data, &warnings) : TypecheckModule(module.get(), import_data, &warnings)); TypecheckedModule result{module.get(), type_info, std::move(warnings)}; diff --git a/xls/dslx/type_system/deduce.cc b/xls/dslx/type_system/deduce.cc index 82b03bfa9a..2e2a9ec9d0 100644 --- a/xls/dslx/type_system/deduce.cc +++ b/xls/dslx/type_system/deduce.cc @@ -234,8 +234,8 @@ static void WarnOnInappropriateConstantName(std::string_view identifier, const Module& module, DeduceCtx* ctx) { if (!IsScreamingSnakeCase(identifier) && - !module.directives().contains( - ModuleDirective::kAllowNonstandardConstantNaming)) { + !module.attributes().contains( + ModuleAttribute::kAllowNonstandardConstantNaming)) { ctx->warnings()->Add( span, WarningKind::kConstantNaming, absl::StrFormat("Standard style is SCREAMING_SNAKE_CASE for constant " diff --git a/xls/dslx/type_system/deduce_struct_def_base_utils.cc b/xls/dslx/type_system/deduce_struct_def_base_utils.cc index ea532f08d0..f407274f18 100644 --- a/xls/dslx/type_system/deduce_struct_def_base_utils.cc +++ b/xls/dslx/type_system/deduce_struct_def_base_utils.cc @@ -57,8 +57,8 @@ void WarnOnInappropriateMemberName(std::string_view member_name, const Span& span, const Module& module, DeduceCtx* ctx) { if (!IsAcceptablySnakeCase(member_name) && - !module.directives().contains( - ModuleDirective::kAllowNonstandardMemberNaming)) { + !module.attributes().contains( + ModuleAttribute::kAllowNonstandardMemberNaming)) { ctx->warnings()->Add( span, WarningKind::kMemberNaming, absl::StrFormat("Standard style is snake_case for struct member names; "