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
30 changes: 15 additions & 15 deletions layerstack_wasm/src/layer_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! Spec: AOUSD Core §7.3 (specs and their paths), §7.6 (spec fields),
//! §12.4 (list ops).

use alloc::{string::String, vec, vec::Vec};
use alloc::{vec, vec::Vec};

use layerstack::{
FieldEntry, FieldValue, InMemoryStore, Layer, LayerId, ListOp, Path, PathId, PrimSpec,
Expand Down Expand Up @@ -182,10 +182,10 @@ fn list_op_or_null<T>(op: Option<&ListOp<T>>, item: impl Fn(&T) -> Wire) -> Wire
}

/// Field names, sorted, each once.
fn sorted_names(mut names: Vec<String>) -> Wire {
names.sort_unstable();
fn sorted_names(mut names: Vec<&str>) -> Wire {
layerstack::sort::sort_unstable(&mut names);
names.dedup();
Wire::List(names.into_iter().map(Wire::Text).collect())
Wire::List(names.into_iter().map(Wire::text).collect())
}

/// The names of `tokens`, in order.
Expand Down Expand Up @@ -284,14 +284,14 @@ impl Stage {
fn pseudo_root_record(&self, shown: Wire, layer: &Layer, root: PathId) -> Wire {
let tokens = self.document().store().tokens();
let spec = layer.prim(root);
let mut fields: Vec<String> = layer
let mut fields: Vec<&str> = layer
.metadata_fields()
.iter()
.map(|entry| String::from(tokens.resolve(entry.name)))
.map(|entry| tokens.resolve(entry.name))
.collect();
let mut add = |authored: bool, name: &str| {
let mut add = |authored: bool, name: &'static str| {
if authored {
fields.push(String::from(name));
fields.push(name);
}
};
add(layer.default_prim().is_some(), "defaultPrim");
Expand Down Expand Up @@ -345,10 +345,10 @@ impl Stage {
FieldValue::TokenListOp(op) => Some(&**op),
_ => None,
});
let mut fields: Vec<String> = spec
let mut fields: Vec<&str> = spec
.fields()
.iter()
.map(|entry| String::from(tokens.resolve(entry.name)))
.map(|entry| tokens.resolve(entry.name))
.collect();
for (authored, name) in [
(specifier.is_some(), "specifier"),
Expand All @@ -371,7 +371,7 @@ impl Stage {
(spec.has_property_order(), "propertyOrder"),
] {
if authored {
fields.push(String::from(name));
fields.push(name);
}
}
let reference = |item: &Reference| self.reference_item(layer.id(), item);
Expand All @@ -382,7 +382,7 @@ impl Stage {
.iter()
.map(|(set, variant)| (tokens.resolve(set), tokens.resolve(variant)))
.collect();
pairs.sort_unstable();
layerstack::sort::sort_unstable(&mut pairs);
Wire::List(
pairs
.into_iter()
Expand Down Expand Up @@ -484,10 +484,10 @@ impl Stage {
/// The record of an attribute or relationship spec.
fn property_record(store: &InMemoryStore, shown: Wire, spec: &PropertySpec) -> Wire {
let tokens = store.tokens();
let mut fields: Vec<String> = spec
let mut fields: Vec<&str> = spec
.metadata
.iter()
.map(|entry| String::from(tokens.resolve(entry.name)))
.map(|entry| tokens.resolve(entry.name))
.collect();
let attribute = spec.kind == PropertyKind::Attribute;
for (authored, name) in [
Expand All @@ -511,7 +511,7 @@ fn property_record(store: &InMemoryStore, shown: Wire, spec: &PropertySpec) -> W
),
] {
if authored {
fields.push(String::from(name));
fields.push(name);
}
}
let targets = list_op_or_null(spec.targets.as_deref(), |target| {
Expand Down
2 changes: 1 addition & 1 deletion layerstack_wasm/src/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl Stage {
(path.display(store.paths(), store.tokens()), rule)
})
.collect();
rules.sort_unstable();
layerstack::sort::sort_unstable(&mut rules);
let mut key = String::from(query.expansion_rule().as_str());
for (path, rule) in &rules {
key.push_str(&alloc::format!("\n{path} {rule}"));
Expand Down
62 changes: 30 additions & 32 deletions layerstack_wasm/src/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,16 +993,14 @@ impl Stage {
pub(crate) fn load_rules(&self) -> Wire {
let store = self.document.store();
let rules = self.document.stage().stage().load_rules();
let mut ids: Vec<(PathId, PayloadRule)> = rules
.rules()
.map(|(path, rule)| (store.paths().intern(path.clone()), rule))
.collect();
ids.sort_by(|a, b| store.paths().cmp_paths(a.0, b.0, store.tokens()));
let mut rules: Vec<_> = rules.rules().collect();
layerstack::sort::sort_by(&mut rules, |a, b| a.0.cmp_with_tokens(b.0, store.tokens()));
Wire::List(
ids.into_iter()
.map(|(id, rule)| {
rules
.into_iter()
.map(|(path, rule)| {
Wire::List(vec![
Wire::text(store.paths().display(id, store.tokens())),
Wire::Text(path.display(store.tokens())),
Wire::text(rule_name(rule)),
])
})
Expand Down Expand Up @@ -1790,30 +1788,30 @@ impl Stage {
.collect(),
)
};
let mut rows: Vec<(String, Wire)> = registry
.schemas()
.map(|schema| {
let name = tokens.resolve(schema.name).to_string();
let kind = match schema.kind {
SchemaKind::ConcreteTyped => "concreteTyped",
SchemaKind::AbstractTyped => "abstractTyped",
SchemaKind::SingleApplyApi => "singleApplyApi",
SchemaKind::MultipleApplyApi => "multipleApplyApi",
};
// `ancestors` starts with the schema itself.
let bases = registry.ancestors(schema.name);
let row = Wire::List(vec![
Wire::text(&name),
Wire::text(kind),
names(bases.get(1..).unwrap_or(&[])),
names(&schema.can_only_apply_to),
names(&schema.allowed_instance_names),
]);
(name, row)
})
.collect();
rows.sort_by(|a, b| a.0.cmp(&b.0));
Wire::List(rows.into_iter().map(|(_, row)| row).collect())
let mut schemas: Vec<_> = registry.schemas().collect();
layerstack::sort::sort_unstable_by_key(&mut schemas, |schema| tokens.resolve(schema.name));
Wire::List(
schemas
.into_iter()
.map(|schema| {
let kind = match schema.kind {
SchemaKind::ConcreteTyped => "concreteTyped",
SchemaKind::AbstractTyped => "abstractTyped",
SchemaKind::SingleApplyApi => "singleApplyApi",
SchemaKind::MultipleApplyApi => "multipleApplyApi",
};
// `ancestors` starts with the schema itself.
let bases = registry.ancestors(schema.name);
Wire::List(vec![
Wire::text(tokens.resolve(schema.name)),
Wire::text(kind),
names(bases.get(1..).unwrap_or(&[])),
names(&schema.can_only_apply_to),
names(&schema.allowed_instance_names),
])
})
.collect(),
)
}

/// The relationship at the property path `path`: `[custom, targets]`,
Expand Down
Loading