Skip to content
Merged
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
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ message-format-compiler = { path = "crates/message-format-compiler", version = "
message-format-resource-json = { path = "crates/message-format-resource-json", version = "0.1.0" }
message-format-resource-toml = { path = "crates/message-format-resource-toml", version = "0.1.0" }
message-format-runtime = { path = "crates/message-format-runtime", version = "0.1.0" }
profiling = { version = "1.0", default-features = false }

[workspace.lints]
# LINEBENDER LINT SET - Cargo.toml - v8
Expand Down
4 changes: 4 additions & 0 deletions crates/message-format-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ hashbrown = { default-features = false, features = [
], version = "0.17.0" }
icu_normalizer = { default-features = false, features = ["compiled_data"], version = "2.1.1" }
message-format-runtime = { workspace = true }
profiling = { optional = true, workspace = true }
serde = { features = ["derive"], version = "1.0" }
toml = "0.9"

[features]
profiling = ["dep:profiling", "message-format-runtime/profiling"]

[lints]
workspace = true
20 changes: 20 additions & 0 deletions crates/message-format-compiler/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ impl CatalogBuilder {

/// Parse one MF2 message body and add it under its explicit message id.
pub fn add_input(&mut self, input: CompileInput<'_>) -> Result<SourceId, BuildError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let source_id = self
.register_source(input.name, input.kind)
.map_err(|error| BuildError::error(None, error))?;
Expand Down Expand Up @@ -461,6 +463,8 @@ impl CatalogBuilder {

/// Parse one resource/container input made up of named MF2 message bodies.
pub fn add_resource_input(&mut self, input: ResourceInput) -> Result<SourceId, BuildError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let source_name = input.name.clone();
let source_kind = input.kind.clone();
let source_id = self
Expand Down Expand Up @@ -515,6 +519,8 @@ impl CatalogBuilder {

/// Compile into a binary catalog payload plus provenance sidecar data.
pub fn compile(self) -> CompileReport {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let Self {
options,
sources,
Expand Down Expand Up @@ -559,6 +565,8 @@ impl CatalogBuilder {
/// assert!(!bytes.is_empty());
/// ```
pub fn compile_str(source: &str) -> Result<Vec<u8>, CompileError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
compile(source, CompileOptions::default())
}

Expand All @@ -575,6 +583,8 @@ pub fn compile_str(source: &str) -> Result<Vec<u8>, CompileError> {
/// assert!(!bytes.is_empty());
/// ```
pub fn compile(source: &str, options: CompileOptions) -> Result<Vec<u8>, CompileError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let message = parse_single_message_with_source(source, options, Some(SourceId(0)))?;
compile_parsed_messages(vec![message], None, options)
}
Expand All @@ -588,6 +598,8 @@ pub fn compile_with_manifest(
options: CompileOptions,
manifest: &FunctionManifest,
) -> Result<Vec<u8>, CompileError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let message = parse_single_message_with_source(source, options, Some(SourceId(0)))?;
compile_parsed_messages(vec![message], Some(manifest), options)
}
Expand All @@ -597,6 +609,8 @@ pub fn compile_inputs<'a>(
inputs: impl IntoIterator<Item = CompileInput<'a>>,
options: CompileOptions,
) -> CompileReport {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let mut builder = CatalogBuilder::with_options(options);
let mut diagnostics = Vec::new();
for input in inputs {
Expand All @@ -612,6 +626,8 @@ pub fn compile_resources(
inputs: impl IntoIterator<Item = ResourceInput>,
options: CompileOptions,
) -> CompileReport {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let mut builder = CatalogBuilder::with_options(options);
let mut diagnostics = Vec::new();
for input in inputs {
Expand All @@ -626,6 +642,8 @@ pub fn compile_inputs_with_manifest<'a>(
options: CompileOptions,
manifest: &FunctionManifest,
) -> CompileReport {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let mut builder = CatalogBuilder::with_options(options);
builder.set_function_manifest(manifest.clone());
let mut diagnostics = Vec::new();
Expand All @@ -643,6 +661,8 @@ pub fn compile_resources_with_manifest(
options: CompileOptions,
manifest: &FunctionManifest,
) -> CompileReport {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let mut builder = CatalogBuilder::with_options(options);
builder.set_function_manifest(manifest.clone());
let mut diagnostics = Vec::new();
Expand Down
4 changes: 4 additions & 0 deletions crates/message-format-resource-json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ description = "JSON resource adapters for message-format compiler resource input
[dependencies]
json-spanned-value = "0.2.2"
message-format-compiler.workspace = true
profiling = { optional = true, workspace = true }

[features]
profiling = ["dep:profiling", "message-format-compiler/profiling"]

[lints]
workspace = true
6 changes: 6 additions & 0 deletions crates/message-format-resource-json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub fn parse_json_resource(
source: &str,
profile: JsonProfile,
) -> Result<ResourceInput, ResourceJsonError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let root: JsonValue = json_spanned_value::from_str(source)
.map_err(|err| ResourceJsonError::from_json(source, err))?;
match profile {
Expand All @@ -82,6 +84,8 @@ pub fn parse_flat_json_resource(
name: impl Into<String>,
source: &str,
) -> Result<ResourceInput, ResourceJsonError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
parse_json_resource(name, source, JsonProfile::Flat)
}

Expand All @@ -91,6 +95,8 @@ pub fn parse_chrome_json_resource(
name: impl Into<String>,
source: &str,
) -> Result<ResourceInput, ResourceJsonError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
parse_json_resource(name, source, JsonProfile::Chrome)
}

Expand Down
4 changes: 4 additions & 0 deletions crates/message-format-resource-toml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ description = "TOML resource adapter for message-format compiler resource inputs

[dependencies]
message-format-compiler.workspace = true
profiling = { optional = true, workspace = true }
toml = "1"

[features]
profiling = ["dep:profiling", "message-format-compiler/profiling"]

[lints]
workspace = true
2 changes: 2 additions & 0 deletions crates/message-format-resource-toml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub fn parse_resource_toml(
name: impl Into<String>,
source: &str,
) -> Result<ResourceInput, ResourceTomlError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let parsed = DeTable::parse(source).map_err(|err| ResourceTomlError::from_toml(source, err))?;
let root = parsed.into_inner();
let messages = root
Expand Down
2 changes: 2 additions & 0 deletions crates/message-format-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ icu_locale_core = { default-features = false, optional = true, version = "2.1.1"
icu_plurals = { default-features = false, features = [
"compiled_data",
], optional = true, version = "2.1.1" }
profiling = { optional = true, workspace = true }

[features]
default = []
Expand All @@ -39,6 +40,7 @@ icu4x = [
"dep:icu_calendar",
"dep:icu_datetime",
]
profiling = ["dep:profiling"]

[package.metadata.docs.rs]
all-features = true
Expand Down
2 changes: 2 additions & 0 deletions crates/message-format-runtime/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ impl BuiltinHost {
/// Returns:
/// - `FormatError::Trap(Trap::UnsupportedLocale)` when ICU plural rules are unavailable.
pub fn new(locale: &Locale) -> Result<Self, FormatError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let cardinal_rules = PluralRules::try_new_cardinal(locale.into())
.map_err(|_| FormatError::Trap(Trap::UnsupportedLocale))?;
let ordinal_rules = PluralRules::try_new_ordinal(locale.into())
Expand Down
2 changes: 2 additions & 0 deletions crates/message-format-runtime/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct Catalog {
impl Catalog {
/// Decode and verify a catalog payload.
pub fn from_bytes(bytes: &[u8]) -> Result<Self, CatalogError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
if bytes.len() < HEADER_LEN {
return Err(CatalogError::ChunkOutOfBounds);
}
Expand Down
12 changes: 12 additions & 0 deletions crates/message-format-runtime/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ impl<'a, H: Host> Formatter<'a, H> {
///
/// Calls [`Host::index`] to pre-compute catalog-specific data.
pub fn new(catalog: &'a Catalog, mut host: H) -> Result<Self, FormatError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let index = host.index(catalog)?;
Ok(Self {
catalog,
Expand All @@ -88,6 +90,8 @@ impl<'a, H: Host> Formatter<'a, H> {

/// Resolve a message id to a reusable handle.
pub fn resolve(&self, message_id: &str) -> Result<MessageHandle, FormatError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
MessageHandle::from_catalog(self.catalog, message_id)
}

Expand All @@ -105,6 +109,8 @@ impl<'a, H: Host> Formatter<'a, H> {
args: &dyn Args,
sink: &mut S,
) -> Result<Vec<FormatError>, FormatError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let mut diagnostics = VecDiagnostics::default();
run_bytecode(
self.catalog,
Expand Down Expand Up @@ -161,6 +167,8 @@ impl<'a, H: Host> MultiFormatter<'a, H> {
catalogs: impl IntoIterator<Item = &'a Catalog>,
mut host: H,
) -> Result<Self, FormatError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let catalogs: Box<[_]> = catalogs
.into_iter()
.map(|catalog| {
Expand Down Expand Up @@ -191,6 +199,8 @@ impl<'a, H: Host> MultiFormatter<'a, H> {
///
/// Returns a handle to the first catalog that contains the message.
pub fn resolve(&self, message_id: &str) -> Result<MultiMessageHandle, FormatError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
for (idx, (catalog, _)) in self.catalogs.iter().enumerate() {
if let Some(entry_pc) = catalog.message_pc(message_id) {
return Ok(MultiMessageHandle {
Expand Down Expand Up @@ -261,6 +271,8 @@ impl<'a, H: Host> MultiFormatter<'a, H> {
args: &dyn Args,
sink: &mut S,
) -> Result<Vec<FormatError>, FormatError> {
#[cfg(feature = "profiling")]
profiling::function_scope!();
let (catalog, index) = self
.catalogs
.get(message.catalog_idx as usize)
Expand Down
2 changes: 2 additions & 0 deletions crates/message-format/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ default = ["std"]
std = ["message-format-runtime/std"]
icu4x = ["message-format-runtime/icu4x"]
compile = ["dep:message-format-compiler"]
profiling = ["dep:profiling", "message-format-runtime/profiling", "message-format-compiler?/profiling"]

[dependencies]
icu_locale_core = { default-features = false, version = "2.1.1" }
message-format-compiler = { optional = true, workspace = true }
message-format-runtime = { workspace = true }
profiling = { optional = true, workspace = true }

[package.metadata.docs.rs]
all-features = true
Expand Down
Loading