Skip to content

Commit

Permalink
fix: Remove global state from ic-cdk-macros (#430)
Browse files Browse the repository at this point in the history
* Remove global state from ic-cdk-macros

* Update version and changelog
  • Loading branch information
adamspofford-dfinity authored Oct 2, 2023
1 parent 0ef0353 commit 847d689
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions src/ic-cdk-macros/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.8.1] - 2023-10-02

### Fixed

- Macros no longer use global state in the names of functions. JetBrains IDEs should no longer produce spurious errors. (#430)

## [0.8.0] - 2023-09-18

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/ic-cdk-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ic-cdk-macros"
version = "0.8.0" # no need to sync with ic-cdk
version = "0.8.1" # no need to sync with ic-cdk
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
8 changes: 4 additions & 4 deletions src/ic-cdk-macros/src/export.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use proc_macro2::{Ident, Span, TokenStream};
use quote::quote;
use quote::{format_ident, quote};
use serde::Deserialize;
use serde_tokenstream::from_tokenstream;
use std::fmt::Formatter;
Expand Down Expand Up @@ -57,7 +57,7 @@ impl std::fmt::Display for MethodType {
fn get_args(method: MethodType, signature: &Signature) -> Result<Vec<(Ident, Box<Type>)>, Error> {
// We only need the tuple of arguments, not their types. Magic of type inference.
let mut args = vec![];
for ref arg in &signature.inputs {
for (i, arg) in signature.inputs.iter().enumerate() {
let (ident, ty) = match arg {
FnArg::Receiver(r) => {
return Err(Error::new(
Expand All @@ -73,7 +73,7 @@ fn get_args(method: MethodType, signature: &Signature) -> Result<Vec<(Ident, Box
(ident.clone(), ty.clone())
} else {
(
syn::Ident::new(&format!("arg_{}", crate::id()), pat.span()),
format_ident!("__unnamed_arg_{i}", span = pat.span()),
ty.clone(),
)
}
Expand Down Expand Up @@ -133,7 +133,7 @@ fn dfn_macro(
get_args(method, signature)?.iter().cloned().unzip();
let name = &signature.ident;

let outer_function_ident = Ident::new(&format!("{}_{}_", name, crate::id()), Span::call_site());
let outer_function_ident = format_ident!("__canister_method_{name}");

let function_name = attrs.name.unwrap_or_else(|| name.to_string());
let export_name = if method.is_lifecycle() {
Expand Down
7 changes: 0 additions & 7 deletions src/ic-cdk-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,10 @@
)]

use proc_macro::TokenStream;
use std::sync::atomic::{AtomicU32, Ordering};
use syn::Error;

mod export;

// To generate unique identifiers for functions and arguments
static NEXT_ID: AtomicU32 = AtomicU32::new(0);
pub(crate) fn id() -> u32 {
NEXT_ID.fetch_add(1, Ordering::SeqCst)
}

fn handle_debug_and_errors<F>(
cb: F,
name: &str,
Expand Down

0 comments on commit 847d689

Please sign in to comment.