diff --git a/Cargo.lock b/Cargo.lock index 9dc10bce0c..4f95de0ed8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1245,6 +1245,7 @@ dependencies = [ "infra_utils", "itertools 0.13.0", "markdown", + "rayon", "semver", "serde", "serde_json", diff --git a/crates/codegen/ebnf/src/builder.rs b/crates/codegen/ebnf/src/builder.rs index 9b90053be9..93e33e1b36 100644 --- a/crates/codegen/ebnf/src/builder.rs +++ b/crates/codegen/ebnf/src/builder.rs @@ -1,10 +1,10 @@ use std::collections::HashMap; use codegen_language_definition::model::{ - BuiltInLabel, EnumItem, EnumVariant, Field, FragmentItem, Identifier, Item, KeywordDefinition, - KeywordItem, KeywordValue, Language, OperatorModel, PrecedenceExpression, PrecedenceItem, - PrecedenceOperator, PrimaryExpression, RepeatedItem, Scanner, SeparatedItem, StructItem, - TokenDefinition, TokenItem, TriviaItem, VersionSpecifier, + EnumItem, EnumVariant, Field, FragmentItem, Identifier, Item, KeywordDefinition, KeywordItem, + KeywordValue, Language, OperatorModel, PrecedenceExpression, PrecedenceItem, + PrecedenceOperator, PredefinedLabel, PrimaryExpression, RepeatedItem, Scanner, SeparatedItem, + StructItem, TokenDefinition, TokenItem, TriviaItem, VersionSpecifier, }; use indexmap::IndexMap; use inflector::Inflector; @@ -128,7 +128,7 @@ impl Builder { let variants = variants.iter().map(|EnumVariant { reference, enabled }| { Value::new( - Self::build_ref(Some(BuiltInLabel::Variant.as_ref()), reference), + Self::build_ref(Some(PredefinedLabel::Variant.as_ref()), reference), Self::build_enabled_comment(enabled), ) }); @@ -151,7 +151,7 @@ impl Builder { self.add_entry(name, Terminal::No, Inlined::No); - let label = BuiltInLabel::Item.as_ref(); + let label = PredefinedLabel::Item.as_ref(); let expression = if allow_empty.unwrap_or_default() { Expression::new_zero_or_more(Self::build_ref(Some(label), reference).into()) } else { @@ -178,11 +178,11 @@ impl Builder { self.add_entry(name, Terminal::No, Inlined::No); let mut expression = Expression::new_sequence(vec![ - Self::build_ref(Some(BuiltInLabel::Item.as_ref()), reference), + Self::build_ref(Some(PredefinedLabel::Item.as_ref()), reference), Expression::new_zero_or_more( Expression::new_sequence(vec![ - Self::build_ref(Some(BuiltInLabel::Separator.as_ref()), separator), - Self::build_ref(Some(BuiltInLabel::Item.as_ref()), reference), + Self::build_ref(Some(PredefinedLabel::Separator.as_ref()), separator), + Self::build_ref(Some(PredefinedLabel::Item.as_ref()), reference), ]) .into(), ), @@ -216,7 +216,7 @@ impl Builder { let PrecedenceExpression { name, operators } = precedence_expression.as_ref(); values.push(Value::new( - Self::build_ref(Some(BuiltInLabel::Variant.as_ref()), name), + Self::build_ref(Some(PredefinedLabel::Variant.as_ref()), name), None, )); @@ -231,7 +231,7 @@ impl Builder { let PrimaryExpression { reference, enabled } = primary_expression; values.push(Value::new( - Self::build_ref(Some(BuiltInLabel::Variant.as_ref()), reference), + Self::build_ref(Some(PredefinedLabel::Variant.as_ref()), reference), Self::build_enabled_comment(enabled), )); } @@ -265,7 +265,7 @@ impl Builder { leading_comments.push("Prefix unary operator".to_string()); values.push(Value::new( - Self::build_ref(Some(BuiltInLabel::Operand.as_ref()), base_name), + Self::build_ref(Some(PredefinedLabel::Operand.as_ref()), base_name), None, )); } @@ -275,7 +275,7 @@ impl Builder { values.insert( 0, Value::new( - Self::build_ref(Some(BuiltInLabel::Operand.as_ref()), base_name), + Self::build_ref(Some(PredefinedLabel::Operand.as_ref()), base_name), None, ), ); @@ -286,12 +286,12 @@ impl Builder { values.insert( 0, Value::new( - Self::build_ref(Some(BuiltInLabel::LeftOperand.as_ref()), base_name), + Self::build_ref(Some(PredefinedLabel::LeftOperand.as_ref()), base_name), None, ), ); values.push(Value::new( - Self::build_ref(Some(BuiltInLabel::RightOperand.as_ref()), base_name), + Self::build_ref(Some(PredefinedLabel::RightOperand.as_ref()), base_name), None, )); } @@ -301,12 +301,12 @@ impl Builder { values.insert( 0, Value::new( - Self::build_ref(Some(BuiltInLabel::LeftOperand.as_ref()), base_name), + Self::build_ref(Some(PredefinedLabel::LeftOperand.as_ref()), base_name), None, ), ); values.push(Value::new( - Self::build_ref(Some(BuiltInLabel::RightOperand.as_ref()), base_name), + Self::build_ref(Some(PredefinedLabel::RightOperand.as_ref()), base_name), None, )); } diff --git a/crates/codegen/language/definition/src/model/manifest.rs b/crates/codegen/language/definition/src/model/manifest.rs index 116b73c568..cfe1ef7c82 100644 --- a/crates/codegen/language/definition/src/model/manifest.rs +++ b/crates/codegen/language/definition/src/model/manifest.rs @@ -177,7 +177,7 @@ pub struct Topic { Clone, Copy, Debug, strum_macros::AsRefStr, strum_macros::EnumIter, strum_macros::VariantNames, )] #[strum(serialize_all = "snake_case")] -pub enum BuiltInLabel { +pub enum PredefinedLabel { Item, Variant, Separator, diff --git a/crates/codegen/runtime/cargo/crate/src/runtime/cst/edge_label.rs.jinja2 b/crates/codegen/runtime/cargo/crate/src/runtime/cst/edge_label.rs.jinja2 index 44572d27d6..29b3009ece 100644 --- a/crates/codegen/runtime/cargo/crate/src/runtime/cst/edge_label.rs.jinja2 +++ b/crates/codegen/runtime/cargo/crate/src/runtime/cst/edge_label.rs.jinja2 @@ -17,7 +17,7 @@ #[derive(Clone, Copy)] pub enum EdgeLabel { // Built-in: - {% for label in model.kinds.built_in_labels -%} + {% for label in model.kinds.predefined_labels -%} {{ label | pascal_case }}, {%- endfor %} diff --git a/crates/codegen/runtime/cargo/wasm/src/runtime/interface/cst.wit.jinja2 b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/cst.wit.jinja2 index e656a9eee8..300e4b9479 100644 --- a/crates/codegen/runtime/cargo/wasm/src/runtime/interface/cst.wit.jinja2 +++ b/crates/codegen/runtime/cargo/wasm/src/runtime/interface/cst.wit.jinja2 @@ -50,7 +50,7 @@ interface cst { /// Represents the different types of relationships between nodes in the syntax tree. enum edge-label { - {%- for label in model.kinds.built_in_labels %} + {%- for label in model.kinds.predefined_labels %} {{ label | wit_case }}, {%- endfor %} diff --git a/crates/codegen/runtime/generator/src/ast/mod.rs b/crates/codegen/runtime/generator/src/ast/mod.rs index 89d271566a..892275f76e 100644 --- a/crates/codegen/runtime/generator/src/ast/mod.rs +++ b/crates/codegen/runtime/generator/src/ast/mod.rs @@ -1,4 +1,4 @@ -use codegen_language_definition::model::{self, BuiltInLabel}; +use codegen_language_definition::model::{self, PredefinedLabel}; use indexmap::{IndexMap, IndexSet}; use serde::Serialize; @@ -208,7 +208,7 @@ impl AstModel { base_name: &model::Identifier, expression: &model::PrecedenceExpression, ) { - let operand = |label: BuiltInLabel| Field { + let operand = |label: PredefinedLabel| Field { label: label.as_ref().into(), r#type: Some(base_name.clone()), is_optional: false, @@ -224,17 +224,17 @@ impl AstModel { match operator.model { model::OperatorModel::Prefix => { fields.extend(self.convert_fields(&operator.fields)); - fields.push(operand(BuiltInLabel::Operand)); + fields.push(operand(PredefinedLabel::Operand)); } model::OperatorModel::Postfix => { - fields.push(operand(BuiltInLabel::Operand)); + fields.push(operand(PredefinedLabel::Operand)); fields.extend(self.convert_fields(&operator.fields)); } model::OperatorModel::BinaryLeftAssociative | model::OperatorModel::BinaryRightAssociative => { - fields.push(operand(BuiltInLabel::LeftOperand)); + fields.push(operand(PredefinedLabel::LeftOperand)); fields.extend(self.convert_fields(&operator.fields)); - fields.push(operand(BuiltInLabel::RightOperand)); + fields.push(operand(PredefinedLabel::RightOperand)); } }; diff --git a/crates/codegen/runtime/generator/src/kinds/mod.rs b/crates/codegen/runtime/generator/src/kinds/mod.rs index 68cda75e9c..744c8a9e59 100644 --- a/crates/codegen/runtime/generator/src/kinds/mod.rs +++ b/crates/codegen/runtime/generator/src/kinds/mod.rs @@ -1,6 +1,6 @@ use std::collections::BTreeSet; -use codegen_language_definition::model::{self, BuiltInLabel, Identifier, Item}; +use codegen_language_definition::model::{self, Identifier, Item, PredefinedLabel}; use serde::Serialize; use strum::VariantNames; @@ -14,8 +14,8 @@ pub struct KindsModel { trivia_scanner_names: BTreeSet, /// Defines `EdgeLabel` enum variants. labels: BTreeSet, - /// Built-in labels for edges. - built_in_labels: &'static [&'static str], + /// Predefined labels for edges. + predefined_labels: &'static [&'static str], // Defines the `LexicalContext(Type)` enum and type-level variants. lexical_contexts: BTreeSet, /// Defines the root `NonterminalKind` for a source file of the language. @@ -29,7 +29,7 @@ impl Default for KindsModel { terminal_kinds: BTreeSet::default(), trivia_scanner_names: BTreeSet::default(), labels: BTreeSet::default(), - built_in_labels: BuiltInLabel::VARIANTS, + predefined_labels: PredefinedLabel::VARIANTS, lexical_contexts: BTreeSet::default(), root_kind: Identifier::from("Stub1"), } diff --git a/crates/codegen/runtime/generator/src/parser/grammar/resolver.rs b/crates/codegen/runtime/generator/src/parser/grammar/resolver.rs index 6d1062c42a..b1fffedfd5 100644 --- a/crates/codegen/runtime/generator/src/parser/grammar/resolver.rs +++ b/crates/codegen/runtime/generator/src/parser/grammar/resolver.rs @@ -6,7 +6,7 @@ use std::ops::Deref; use std::rc::Rc; use codegen_language_definition::model::{ - self, BuiltInLabel, FieldsErrorRecovery, Identifier, Item, Language, + self, FieldsErrorRecovery, Identifier, Item, Language, PredefinedLabel, }; use indexmap::IndexMap; use once_cell::sync::Lazy; @@ -336,7 +336,7 @@ fn resolve_trivia( match resolve_grammar_element(&reference, ctx) { GrammarElement::ScannerDefinition(parser) => { // Hack: This is a sequence of a single scanner in order to emit the names - ParserDefinitionNode::Sequence(vec![Labeled::with_builtin_label( + ParserDefinitionNode::Sequence(vec![Labeled::with_predefined_label( kind.label(), ParserDefinitionNode::ScannerDefinition(parser), )]) @@ -456,14 +456,17 @@ fn resolve_choice(item: model::EnumItem, ctx: &mut ResolveCtx) -> ParserDefiniti }) .collect(); - ParserDefinitionNode::Choice(Labeled::with_builtin_label(BuiltInLabel::Variant, variants)) - .versioned(item.enabled) + ParserDefinitionNode::Choice(Labeled::with_predefined_label( + PredefinedLabel::Variant, + variants, + )) + .versioned(item.enabled) } fn resolve_repeated(item: model::RepeatedItem, ctx: &mut ResolveCtx) -> ParserDefinitionNode { let reference = Box::new(resolve_grammar_element(&item.reference, ctx).into_parser_def_node()); - let repeated = Labeled::with_builtin_label(BuiltInLabel::Item, reference); + let repeated = Labeled::with_predefined_label(PredefinedLabel::Item, reference); if item.allow_empty.unwrap_or_default() { ParserDefinitionNode::ZeroOrMore(repeated).versioned(item.enabled) @@ -477,8 +480,8 @@ fn resolve_separated(item: model::SeparatedItem, ctx: &mut ResolveCtx) -> Parser let separator = resolve_grammar_element(&item.separator, ctx).into_parser_def_node(); let separated = ParserDefinitionNode::SeparatedBy( - Labeled::with_builtin_label(BuiltInLabel::Item, Box::new(reference)), - Labeled::with_builtin_label(BuiltInLabel::Separator, Box::new(separator)), + Labeled::with_predefined_label(PredefinedLabel::Item, Box::new(reference)), + Labeled::with_predefined_label(PredefinedLabel::Separator, Box::new(separator)), ); if item.allow_empty.unwrap_or_default() { @@ -507,8 +510,8 @@ fn resolve_precedence( "Precedence operator {item} has no primary expressions", item = item.name ), - _ => ParserDefinitionNode::Choice(Labeled::with_builtin_label( - BuiltInLabel::Variant, + _ => ParserDefinitionNode::Choice(Labeled::with_predefined_label( + PredefinedLabel::Variant, primaries, )), }); @@ -593,10 +596,10 @@ enum TriviaKind { } impl TriviaKind { - fn label(self) -> BuiltInLabel { + fn label(self) -> PredefinedLabel { match self { - TriviaKind::Leading => BuiltInLabel::LeadingTrivia, - TriviaKind::Trailing => BuiltInLabel::TrailingTrivia, + TriviaKind::Leading => PredefinedLabel::LeadingTrivia, + TriviaKind::Trailing => PredefinedLabel::TrailingTrivia, } } } @@ -645,7 +648,7 @@ impl VersionWrapped for ParserDefinitionNode { trait LabeledExt { fn anonymous(node: T) -> Self; fn with_ident_name(name: Identifier, node: T) -> Self; - fn with_builtin_label(name: BuiltInLabel, node: T) -> Self; + fn with_predefined_label(name: PredefinedLabel, node: T) -> Self; } impl LabeledExt for Labeled { @@ -663,7 +666,7 @@ impl LabeledExt for Labeled { } } - fn with_builtin_label(label: BuiltInLabel, value: T) -> Self { + fn with_predefined_label(label: PredefinedLabel, value: T) -> Self { Self { label: label.as_ref().to_owned(), value, diff --git a/crates/infra/cli/Cargo.toml b/crates/infra/cli/Cargo.toml index b3291e1dd9..8228a32ba0 100644 --- a/crates/infra/cli/Cargo.toml +++ b/crates/infra/cli/Cargo.toml @@ -14,6 +14,7 @@ clap_complete = { workspace = true } infra_utils = { workspace = true } itertools = { workspace = true } markdown = { workspace = true } +rayon = { workspace = true } semver = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } diff --git a/crates/infra/cli/src/commands/check/mod.rs b/crates/infra/cli/src/commands/check/mod.rs index 35ee967ceb..28bdc27550 100644 --- a/crates/infra/cli/src/commands/check/mod.rs +++ b/crates/infra/cli/src/commands/check/mod.rs @@ -3,6 +3,7 @@ use clap::{Parser, ValueEnum}; use infra_utils::cargo::CargoWorkspaceCommands; use infra_utils::commands::Command; use infra_utils::terminal::Terminal; +use rayon::iter::{ParallelBridge, ParallelIterator}; use strum::IntoEnumIterator; use crate::toolchains::mkdocs::Mkdocs; @@ -40,7 +41,7 @@ impl OrderedCommand for CheckCommand { match self { CheckCommand::Cargo => check_cargo(), CheckCommand::Rustdoc => check_rustdoc(), - CheckCommand::Npm => check_npm()?, + CheckCommand::Npm => check_npm(), CheckCommand::Mkdocs => check_mkdocs(), }; @@ -71,12 +72,10 @@ fn check_rustdoc() { .run(); } -fn check_npm() -> Result<()> { - for package in WasmPackage::iter() { - package.build()?; - } - - Ok(()) +fn check_npm() { + WasmPackage::iter() + .par_bridge() + .for_each(|package| package.build().unwrap()); } fn check_mkdocs() { diff --git a/crates/infra/cli/src/toolchains/wasm/mod.rs b/crates/infra/cli/src/toolchains/wasm/mod.rs index 160c5231ab..ae870af82c 100644 --- a/crates/infra/cli/src/toolchains/wasm/mod.rs +++ b/crates/infra/cli/src/toolchains/wasm/mod.rs @@ -7,7 +7,7 @@ use infra_utils::commands::Command; use infra_utils::paths::{FileWalker, PathExtensions}; use strum_macros::EnumIter; -pub const WASM_TARGET: &str = "wasm32-wasi"; +pub const WASM_TARGET: &str = "wasm32-wasip1"; #[derive(Clone, Copy, EnumIter)] pub enum WasmPackage {