Skip to content

Commit

Permalink
switch cfg_attrs to use maybe_send macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Pistonight committed Oct 10, 2023
1 parent 3e6872f commit 21101d4
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 39 deletions.
18 changes: 13 additions & 5 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 @@ -2,6 +2,7 @@
resolver = "2"
members = [
"compiler-core/",
"compiler-macros/",
"compiler-types/",
"compiler-wasm/",
"web-server/",
Expand Down
3 changes: 3 additions & 0 deletions compiler-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
async-recursion = "1.0.4"
async-trait = "0.1.73"
cached = { version = "0.45.1", features = ["async"]}
compiler-macros = { path = "../compiler-macros" }
compiler-types = { path = "../compiler-types" }
derivative = "2.2.0"
futures = "0.3.28"
Expand Down Expand Up @@ -41,7 +42,9 @@ wasm = [
"js-sys",
"web-sys/Window",
"instant/wasm-bindgen",
"no-async-send",
]
no-async-send=[]

[lib]
name = "celerc"
Expand Down
4 changes: 2 additions & 2 deletions compiler-core/src/comp/comp_preset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use serde_json::Value;

use crate::json::{Cast, Coerce};
use crate::lang::PresetInst;
use crate::macros::{async_recursion, maybe_send};
use crate::prop;

use super::{validate_not_array_or_object, Compiler, CompilerError};
Expand All @@ -12,8 +13,7 @@ impl Compiler {
/// Apply the preset to the output.
///
/// Presets are applied recursively, including presets in the movements
#[cfg_attr(not(feature = "wasm"), async_recursion::async_recursion)]
#[cfg_attr(feature = "wasm", async_recursion::async_recursion(?Send))]
#[maybe_send(async_recursion)]
pub async fn apply_preset(
&self,
depth: usize,
Expand Down
4 changes: 2 additions & 2 deletions compiler-core/src/lang/preset/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::BTreeMap;
use serde_json::Value;

use crate::lang::TempStr;
use crate::macros::{maybe_send, async_recursion};

use super::{Preset, PresetBlob};

Expand Down Expand Up @@ -37,8 +38,7 @@ impl PresetBlob {
/// If the blob has any template strings in it, returns a Some variant with
/// the template strings compiled and the input value taken out.
/// Otherwise returns a None variant.
#[cfg_attr(not(feature = "wasm"), async_recursion::async_recursion)]
#[cfg_attr(feature = "wasm", async_recursion::async_recursion(?Send))]
#[maybe_send(async_recursion)]
async fn compile_internal(value: &mut Value) -> Option<Self> {
match value {
Value::String(s) => {
Expand Down
5 changes: 3 additions & 2 deletions compiler-core/src/lang/preset/hydrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::collections::BTreeMap;

use serde_json::{json, Value};

use crate::macros::{maybe_send, async_recursion};

use super::{Preset, PresetBlob};

impl Preset {
Expand All @@ -22,8 +24,7 @@ impl Preset {

impl PresetBlob {
/// Hydrate a preset blob with the given arguments
#[cfg_attr(not(feature = "wasm"), async_recursion::async_recursion)]
#[cfg_attr(feature = "wasm", async_recursion::async_recursion(?Send))]
#[maybe_send(async_recursion)]
pub async fn hydrate<S>(&self, args: &[S]) -> Value
where
S: AsRef<str> + Sync,
Expand Down
7 changes: 7 additions & 0 deletions compiler-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ pub mod plug;
pub mod metrics;
pub mod prop;
pub mod util;

/// Re-exports of macros
pub mod macros {
pub use celercmacros::maybe_send;
pub use async_recursion::async_recursion;
pub use async_trait::async_trait;
}
4 changes: 2 additions & 2 deletions compiler-core/src/pack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub use resource::*;

use crate::json::Cast;
use crate::lang::parse_poor;
use crate::macros::{async_recursion, maybe_send};

#[derive(Debug, Clone, PartialEq, thiserror::Error, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", tag = "type", content = "data")]
Expand Down Expand Up @@ -230,8 +231,7 @@ impl PackerValue {
}
}

#[cfg_attr(not(feature = "wasm"), async_recursion::async_recursion)]
#[cfg_attr(feature = "wasm", async_recursion::async_recursion(?Send))]
#[maybe_send(async_recursion)]
async fn flatten_internal(self, output_errors: &mut Vec<PackerError>) -> Option<Value> {
match self {
Self::Ok(x) => Some(x),
Expand Down
4 changes: 2 additions & 2 deletions compiler-core/src/pack/pack_preset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde_json::Value;

use crate::json::Cast;
use crate::lang::Preset;
use crate::macros::{async_recursion, maybe_send};
use crate::prop;
use crate::util::async_for;

Expand All @@ -20,8 +21,7 @@ pub async fn pack_presets(
Ok(output)
}

#[cfg_attr(not(feature = "wasm"), async_recursion::async_recursion)]
#[cfg_attr(feature = "wasm", async_recursion::async_recursion(?Send))]
#[maybe_send(async_recursion)]
async fn pack_presets_internal(
preset_name: &str,
value: Value,
Expand Down
4 changes: 2 additions & 2 deletions compiler-core/src/pack/pack_route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::collections::BTreeMap;
use serde_json::Value;

use crate::json::Cast;
use crate::macros::{async_recursion, maybe_send};
use crate::util::async_for;

use super::{PackerError, PackerValue, Resource, Use, ValidUse};
Expand All @@ -29,8 +30,7 @@ pub async fn pack_route(
}

/// Pack a portion of the route
#[cfg_attr(not(feature = "wasm"), async_recursion::async_recursion)]
#[cfg_attr(feature = "wasm", async_recursion::async_recursion(?Send))]
#[maybe_send(async_recursion)]
async fn pack_route_internal(
// The resource that contains the route
resource: &Resource,
Expand Down
4 changes: 2 additions & 2 deletions compiler-core/src/pack/resource/loader.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use serde_json::Value;

use crate::macros::{async_trait, maybe_send};
use crate::pack::{PackerError, PackerResult};

/// Loader that loads resources from external place
#[cfg_attr(not(feature = "wasm"), async_trait::async_trait)]
#[cfg_attr(feature = "wasm", async_trait::async_trait(?Send))]
#[maybe_send(async_trait)]
pub trait ResourceLoader {
/// Load a resource as raw bytes
async fn load_raw(&self, path: &str) -> PackerResult<Vec<u8>>;
Expand Down
5 changes: 3 additions & 2 deletions compiler-core/src/pack/resource/loader_cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// currently unused. implementation kept for reference
use cached::proc_macro::cached;
use serde_json::Value;

use crate::macros::{async_recursion, maybe_send};
use crate::pack::PackerResult;

use super::{ArcLoader, ResourceLoader};
Expand All @@ -16,8 +18,7 @@ impl<L> GlobalCacheLoader<L> {
}
}

#[cfg_attr(not(feature = "wasm"), async_trait::async_trait)]
#[cfg_attr(feature = "wasm", async_trait::async_trait(?Send))]
#[maybe_send(async_trait)]
impl<L> ResourceLoader for GlobalCacheLoader<L> where L: ResourceLoader {
async fn load_raw(&self, r: &str) -> PackerResult<Vec<u8>> {
load_raw_internal(&self.delegate, r).await
Expand Down
4 changes: 2 additions & 2 deletions compiler-core/src/pack/resource/loader_empty.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::macros::{async_trait, maybe_send};
use crate::pack::{PackerError, PackerResult};

use super::ResourceLoader;
Expand All @@ -13,8 +14,7 @@ impl EmptyLoader {
}
}

#[cfg_attr(not(feature = "wasm"), async_trait::async_trait)]
#[cfg_attr(feature = "wasm", async_trait::async_trait(?Send))]
#[maybe_send(async_trait)]
impl ResourceLoader for EmptyLoader {
async fn load_raw(&self, _: &str) -> PackerResult<Vec<u8>> {
Err(Self::throw())
Expand Down
6 changes: 3 additions & 3 deletions compiler-core/src/pack/resource/resource_github.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! GitHub resource resolver and loader impl
use std::sync::Arc;

use crate::macros::{maybe_send, async_trait};
use crate::util::Path;
use crate::pack::{PackerError, PackerResult, ValidUse};

use super::{ArcLoader, EmptyLoader, Resource, ResourcePath, ResourceResolver};
use crate::pack::{PackerError, PackerResult, ValidUse};

pub struct GitHubResourceResolver {
owner: String,
Expand All @@ -24,8 +25,7 @@ impl GitHubResourceResolver {
}
}

#[cfg_attr(not(feature = "wasm"), async_trait::async_trait)]
#[cfg_attr(feature = "wasm", async_trait::async_trait(?Send))]
#[maybe_send(async_trait)]
impl ResourceResolver for GitHubResourceResolver {
async fn resolve(&self, source: &Resource, target: &ValidUse) -> PackerResult<Resource> {
match target {
Expand Down
12 changes: 6 additions & 6 deletions compiler-core/src/pack/resource/resource_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ use std::sync::Arc;
use serde_json::Value;

use crate::pack::{PackerResult, ValidUse};
use crate::macros::{maybe_send, async_trait};
use crate::util::Path;

use super::ResourceLoader;

#[cfg(not(feature = "wasm"))]
#[cfg(not(feature = "no-async-send"))]
pub type ArcLoader = Arc<dyn ResourceLoader + Send + Sync>;
#[cfg(not(feature = "wasm"))]
#[cfg(not(feature = "no-async-send"))]
pub type ArcResolver = Arc<dyn ResourceResolver + Send + Sync>;
#[cfg(feature = "wasm")]
#[cfg(feature = "no-async-send")]
pub type ArcLoader = Arc<dyn ResourceLoader>;
#[cfg(feature = "wasm")]
#[cfg(feature = "no-async-send")]
pub type ArcResolver = Arc<dyn ResourceResolver>;

macro_rules! loader_delegate {
Expand Down Expand Up @@ -81,8 +82,7 @@ impl Resource {
}
}

#[cfg_attr(not(feature = "wasm"), async_trait::async_trait)]
#[cfg_attr(feature = "wasm", async_trait::async_trait(?Send))]
#[maybe_send(async_trait)]
pub trait ResourceResolver {
/// Resolve a resource from the given `Use` and loader
async fn resolve(&self, source: &Resource, target: &ValidUse) -> PackerResult<Resource>;
Expand Down
4 changes: 2 additions & 2 deletions compiler-core/src/pack/resource/resource_local.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::sync::Arc;

use crate::macros::{maybe_send, async_trait};
use crate::pack::{PackerError, PackerResult, ValidUse};
use crate::util::Path;

use super::{create_github_resource_from, Resource, ResourcePath, ResourceResolver};

pub struct LocalResourceResolver(pub Path);

#[cfg_attr(not(feature = "wasm"), async_trait::async_trait)]
#[cfg_attr(feature = "wasm", async_trait::async_trait(?Send))]
#[maybe_send(async_trait)]
impl ResourceResolver for LocalResourceResolver {
async fn resolve(&self, source: &Resource, target: &ValidUse) -> PackerResult<Resource> {
match target {
Expand Down
1 change: 0 additions & 1 deletion compiler-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ serde-wasm-bindgen = "0.5.0"
wasm-bindgen = "0.2.87"
wasm-bindgen-futures = "0.4.37"
js-sys = "0.3.64"
async-trait = "0.1.73"
log = { version = "0.4.20", features = ["std"] }
web-sys = { version = "0.3.64", features = ["console", "Location", "Window"] }
base64 = "0.21.4"
Expand Down
4 changes: 2 additions & 2 deletions compiler-wasm/src/loader_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use cached::proc_macro::cached;
use serde_json::Value;

use celerc::macros::async_trait;
use celerc::pack::{ ResourceLoader, PackerResult};


/// A loader that caches loaded JSON object in memory to skip parsing. The cache is global.
pub struct CachedLoader<L> {
delegate: L,
Expand All @@ -21,7 +21,7 @@ impl<L> CachedLoader<L> {
}
}

#[async_trait::async_trait(?Send)]
#[async_trait(?Send)]
impl<L> ResourceLoader for CachedLoader<L> where L: ResourceLoader {
async fn load_raw(&self, r: &str) -> PackerResult<Vec<u8>> {
self.delegate.load_raw(r).await
Expand Down
3 changes: 2 additions & 1 deletion compiler-wasm/src/loader_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use base64::Engine;
use std::cell::RefCell;

use celerc::pack::{ImageFormat, PackerError, PackerResult, ResourceLoader};
use celerc::macros::async_trait;
use celerc::yield_now;
use js_sys::{Function, Uint8Array};
use wasm_bindgen::{JsCast, JsValue};
Expand All @@ -30,7 +31,7 @@ impl FileLoader {
}
}

#[async_trait::async_trait(?Send)]
#[async_trait(?Send)]
impl ResourceLoader for FileLoader {
async fn load_raw(&self, path: &str) -> PackerResult<Vec<u8>> {
let _ = yield_now!();
Expand Down
3 changes: 2 additions & 1 deletion compiler-wasm/src/loader_url.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::cell::RefCell;

use celerc::pack::{PackerError, PackerResult, ResourceLoader};
use celerc::macros::async_trait;
use celerc::yield_now;
use js_sys::{Function, Uint8Array};
use wasm_bindgen::{JsCast, JsValue};
Expand All @@ -27,7 +28,7 @@ impl UrlLoader {
}
}

#[async_trait::async_trait(?Send)]
#[async_trait(?Send)]
impl ResourceLoader for UrlLoader {
async fn load_raw(&self, url: &str) -> PackerResult<Vec<u8>> {
let _ = yield_now!();
Expand Down

0 comments on commit 21101d4

Please sign in to comment.