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
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ libquickjs-ng-sys = "0.13.0"
serde = "1"
serde_json = "1"
sha2 = "0.11"
workshop-rs = "^1.13.0"
workshop-rs = "1.18.0"

[workspace.lints.rust]
unsafe_op_in_unsafe_fn = "deny"
Expand Down
6 changes: 3 additions & 3 deletions crates/opy-cli/src/bin/opy-compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ fn compile_and_parse(
&Locale::new("en-US"),
)
.map_err(|error| error.to_string())?;
let catalog = Catalog::builtin().map_err(|error| error.to_string())?;
let context = CompatibilityExpectedDomain { catalog: &catalog };
let catalog = Catalog::builtin_ref().map_err(|error| error.to_string())?;
let context = CompatibilityExpectedDomain { catalog };
let parse = |text: &str| {
workshop_rs::parser::parse_with_context(
&strip_workshop_comments(text),
&catalog,
catalog,
&Locale::new("en-US"),
&context,
)
Expand Down
12 changes: 6 additions & 6 deletions crates/opy-cli/src/bin/opy-compat/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ struct Reference {

pub(super) fn generate() -> Result<(), String> {
let manifest = Manifest::builtin().map_err(|error| error.to_string())?;
let catalog = Catalog::builtin().map_err(|error| error.to_string())?;
let catalog = Catalog::builtin_ref().map_err(|error| error.to_string())?;
let mut probes = Vec::new();
for function in manifest.functions() {
let calls = calls(&catalog, function);
let calls = calls(catalog, function);
if calls.is_empty() {
// Functions without a valid sample call would otherwise never
// reach the oracle; a name probe still verifies the declared
Expand Down Expand Up @@ -205,7 +205,7 @@ pub(super) fn generate() -> Result<(), String> {
// Every enum-member spelling the vocabulary lookup reports is an
// accepted OPY spelling by contract; probe each against the oracle so a
// catalog id or other upstream-rejected spelling cannot be advertised.
for (domain, spelling) in enum_spellings(manifest, &catalog) {
for (domain, spelling) in enum_spellings(manifest, catalog) {
probes.push(Probe {
id: format!("default:{domain}.{spelling}:spelling"),
source: source("", "eachPlayer", &format!("g = {domain}.{spelling}")),
Expand Down Expand Up @@ -462,13 +462,13 @@ pub(super) fn compare(probes: &Path, references: &Path) -> Result<(), String> {
let references: BTreeMap<String, Reference> = serde_json::from_str(&read(references)?)
.map_err(|error| format!("cannot parse references: {error}"))?;
let compiler = Compiler::new().map_err(|error| error.to_string())?;
let catalog = Catalog::builtin().map_err(|error| error.to_string())?;
let context = CompatibilityExpectedDomain { catalog: &catalog };
let catalog = Catalog::builtin_ref().map_err(|error| error.to_string())?;
let context = CompatibilityExpectedDomain { catalog };
let locale = Locale::new("en-US");
let parse = |text: &str| {
workshop_rs::parser::parse_with_context(
&strip_workshop_comments(text),
&catalog,
catalog,
&locale,
&context,
)
Expand Down
6 changes: 3 additions & 3 deletions crates/opy-rs/src/compiler/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct LinkReport {
}

pub(crate) struct CompilerContract {
pub(super) catalog: Catalog,
pub(super) catalog: &'static Catalog,
pub(super) manifest: &'static Manifest,
pub(super) links: LinkReport,
}
Expand Down Expand Up @@ -95,11 +95,11 @@ pub(crate) fn cross_check_manifest(
pub(crate) fn load_compiler_contract() -> Result<&'static CompilerContract, IntegrationError> {
COMPILER_CONTRACT
.get_or_init(|| {
let catalog = Catalog::builtin()
let catalog = Catalog::builtin_ref()
.map_err(|error| IntegrationError::new("catalog-load", error.to_string(), None))?;
let manifest = Manifest::builtin()
.map_err(|error| IntegrationError::new("manifest-load", error.to_string(), None))?;
let links = cross_check_manifest(manifest, &catalog)?;
let links = cross_check_manifest(manifest, catalog)?;
Ok(CompilerContract {
catalog,
manifest,
Expand Down
2 changes: 1 addition & 1 deletion crates/opy-rs/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl Compiler {
pub fn new() -> Result<Self, IntegrationError> {
let contract = load_compiler_contract()?;
Ok(Self {
catalog: &contract.catalog,
catalog: contract.catalog,
manifest: contract.manifest,
links: contract.links,
})
Expand Down
2 changes: 1 addition & 1 deletion crates/opy-rs/src/compiler/reconstruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn reconstruct(program: &Program) -> Result<String, ReconstructError> {
});
}
};
let catalog = match crate::enums::builtin_catalog() {
let catalog = match Catalog::builtin_ref() {
Ok(catalog) => catalog,
Err(error) => {
return Err(ReconstructError {
Expand Down
6 changes: 1 addition & 5 deletions crates/opy-rs/src/compiler/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,11 +1094,7 @@ fn workshop_hero_name(text: &str, locale: &Locale) -> Option<String> {
}

fn gameplay_catalog() -> &'static workshop_rs::gameplay::GameplayCatalog {
static CATALOG: std::sync::OnceLock<workshop_rs::gameplay::GameplayCatalog> =
std::sync::OnceLock::new();
CATALOG.get_or_init(|| {
workshop_rs::gameplay::data::builtin().expect("builtin gameplay catalog parses")
})
workshop_rs::gameplay::data::builtin_ref().expect("builtin gameplay catalog parses")
}

fn convert_settings_span(span: HirSpan) -> WorkshopSpan {
Expand Down
12 changes: 0 additions & 12 deletions crates/opy-rs/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ pub(crate) fn en_us() -> Locale {
Locale::new("en-US")
}

/// The bundled Workshop catalog, loaded once — `Catalog::builtin`
/// reparses the data on every call, which a per-id `resolveIds` request or
/// repeated `check`/`compile` runs cannot afford. The error is the load
/// failure's message.
pub(crate) fn builtin_catalog() -> Result<&'static Catalog, &'static str> {
static CATALOG: std::sync::OnceLock<Result<Catalog, String>> = std::sync::OnceLock::new();
CATALOG
.get_or_init(|| Catalog::builtin().map_err(|error| error.to_string()))
.as_ref()
.map_err(String::as_str)
}

/// The OPY source domain spellings that rename a canonical catalog domain
/// whose own name is not a reference source spelling: upstream's enum is
/// named `Clip`, so `Clipping.DO_NOT_CLIP` does not compile upstream even
Expand Down
6 changes: 3 additions & 3 deletions crates/opy-rs/src/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ pub fn lookup(query: &LookupQuery) -> LookupOutcome {
);
}
}
let Ok(catalog) = crate::enums::builtin_catalog() else {
let Ok(catalog) = Catalog::builtin_ref() else {
return unsupported("vocabulary data (manifest or catalog) is not bundled");
};
let Ok(manifest) = Manifest::builtin() else {
Expand Down Expand Up @@ -614,7 +614,7 @@ const SYNTAX_SPELLINGS: &[(&str, &str)] = &[
/// unknown.
pub fn call_spelling(canonical_id: &str) -> Option<&'static str> {
let manifest = Manifest::builtin().ok()?;
let catalog = crate::enums::builtin_catalog().ok()?;
let catalog = Catalog::builtin_ref().ok()?;
// A manifest entry's canonical identity is its `catalogId`, or — when
// it declares none — its own `id` when that id is a canonical call
// (`startRule`); a `catalogId`-free source name that is not a canonical
Expand Down Expand Up @@ -648,7 +648,7 @@ pub fn call_spelling(canonical_id: &str) -> Option<&'static str> {
/// and members the reference does not spell in source, and for OPY-only
/// members with no canonical id.
pub fn enum_member_spelling<'a>(domain: &'a str, member: &'a str) -> Option<&'a str> {
let catalog = crate::enums::builtin_catalog().ok()?;
let catalog = Catalog::builtin_ref().ok()?;
let enum_domain = catalog.enum_domain(domain)?;
if !enum_domain
.members
Expand Down
6 changes: 3 additions & 3 deletions crates/opy-rs/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub fn lower_with_preprocessing(
));
}
};
let catalog = crate::enums::builtin_catalog().map_err(|error| {
let catalog = Catalog::builtin_ref().map_err(|error| {
OpyError::new(
"catalog-error",
format!("cannot load the Workshop catalog: {error}"),
Expand Down Expand Up @@ -468,7 +468,7 @@ impl SettingsLowerer {
format!("cannot load the OPY semantic compatibility manifest: {error}"),
)
})?;
let catalog = crate::enums::builtin_catalog().map_err(|error| {
let catalog = Catalog::builtin_ref().map_err(|error| {
OpyError::new(
"catalog-error",
format!("cannot load the Workshop catalog: {error}"),
Expand Down Expand Up @@ -2308,7 +2308,7 @@ mod tests {
vec![],
&PreprocessingState::default(),
manifest,
crate::enums::builtin_catalog().expect("the builtin catalog loads"),
Catalog::builtin_ref().expect("the builtin catalog loads"),
)
}

Expand Down
Loading