Skip to content

Commit

Permalink
chore: replace IoId with CallId (#2150)
Browse files Browse the repository at this point in the history
Co-authored-by: Tushar Mathur <[email protected]>
  • Loading branch information
ssddOnTop and tusharmath authored Jun 9, 2024
1 parent 47dfcad commit 598b3f9
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 66 deletions.
46 changes: 46 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 @@ -159,6 +159,7 @@ tokio-test = "0.4.4"
base64 = "0.22.1"
tailcall-hasher = { path = "tailcall-hasher" }
serde_json_borrow = "0.5.0"
num = "0.4.3"

[dev-dependencies]
tailcall-prettier = { path = "tailcall-prettier" }
Expand Down
35 changes: 29 additions & 6 deletions src/core/counter.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
use std::cell::Cell;
use std::sync::Mutex;

pub trait Count {
type Item;
fn next(&self) -> Self::Item;
}

#[allow(unused)]
#[derive(Default)]
pub struct Counter(Cell<usize>);
impl Counter {
pub fn new(start: usize) -> Self {
pub struct Counter<A>(Cell<A>);
impl<A> Counter<A> {
pub fn new(start: A) -> Self {
Self(Cell::new(start))
}
pub fn next(&self) -> usize {
}

impl<A: Copy + num::Num> Count for Counter<A> {
type Item = A;

fn next(&self) -> A {
let curr = self.0.get();
self.0.set(curr + 1);
self.0.set(curr + A::one());
curr
}
}

#[derive(Default)]
pub struct AtomicCounter<A>(Mutex<A>);

impl<A: Copy + num::Num> Count for AtomicCounter<A> {
type Item = A;

fn next(&self) -> A {
let mut x = self.0.lock().unwrap();
*x = *x + A::one();
*x
}
}
4 changes: 2 additions & 2 deletions src/core/generator/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ pub use query_generator::QueryGenerator;
pub use schema_generator::SchemaGenerator;
pub use types_generator::TypesGenerator;

use crate::core::counter::Counter;
use crate::core::counter::{Count, Counter};

pub struct NameGenerator {
counter: Counter,
counter: Counter<usize>,
prefix: String,
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/ir/jit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use async_graphql_parser::types::{OperationType, SelectionSet};
use super::field_index::{FieldIndex, QueryField};
use super::model::*;
use crate::core::blueprint::Blueprint;
use crate::core::counter::Counter;
use crate::core::counter::{Count, Counter};
use crate::core::merge_right::MergeRight;

#[allow(unused)]
pub struct ExecutionPlanBuilder {
pub index: FieldIndex,
pub arg_id: Counter,
pub field_id: Counter,
pub arg_id: Counter<usize>,
pub field_id: Counter<usize>,
pub document: ExecutableDocument,
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/ir/jit/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use serde_json_borrow::OwnedValue;

use super::model::{ExecutionPlan, Field, FieldId, Parent};
use super::store::Store;
use crate::core::ir::{EvaluationError, IoId, IR};
use crate::core::ir::{CallId, EvaluationError, IR};

#[allow(unused)]
pub struct ExecutionContext {
plan: ExecutionPlan,
store: Mutex<Store<IoId, OwnedValue>>,
store: Mutex<Store<CallId, OwnedValue>>,
}

#[allow(unused)]
Expand Down Expand Up @@ -67,7 +67,7 @@ impl ExecutionContext {
.collect::<Vec<_>>()
}

pub async fn execute(self) -> Result<Store<IoId, OwnedValue>, EvaluationError> {
pub async fn execute(self) -> Result<Store<CallId, OwnedValue>, EvaluationError> {
future::join_all(
self.root()
.iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: src/core/ir/jit/builder.rs
expression: plan
---
ExecutionPlan {
fields: [
parent: [
Field {
id: 0,
name: "createPost",
Expand Down Expand Up @@ -48,7 +48,7 @@ ExecutionPlan {
),
},
],
field_children: [
children: [
Field {
id: 0,
name: "createPost",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: src/core/ir/jit/builder.rs
expression: plan
---
ExecutionPlan {
fields: [
parent: [
Field {
id: 0,
name: "name",
Expand Down Expand Up @@ -39,7 +39,7 @@ ExecutionPlan {
],
},
],
field_children: [
children: [
Field {
id: 0,
name: "name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: src/core/ir/jit/builder.rs
expression: plan
---
ExecutionPlan {
fields: [
parent: [
Field {
id: 0,
name: "posts",
Expand Down Expand Up @@ -36,7 +36,7 @@ ExecutionPlan {
),
},
],
field_children: [
children: [
Field {
id: 0,
name: "posts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: src/core/ir/jit/builder.rs
expression: plan
---
ExecutionPlan {
fields: [
parent: [
Field {
id: 0,
name: "user",
Expand Down Expand Up @@ -62,7 +62,7 @@ ExecutionPlan {
),
},
],
field_children: [
children: [
Field {
id: 0,
name: "user",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: src/core/ir/jit/builder.rs
expression: plan
---
ExecutionPlan {
fields: [
parent: [
Field {
id: 0,
name: "createUser",
Expand Down Expand Up @@ -103,7 +103,7 @@ ExecutionPlan {
),
},
],
field_children: [
children: [
Field {
id: 0,
name: "createUser",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: src/core/ir/jit/builder.rs
expression: plan
---
ExecutionPlan {
fields: [
parent: [
Field {
id: 0,
name: "posts",
Expand All @@ -28,7 +28,7 @@ ExecutionPlan {
),
},
],
field_children: [
children: [
Field {
id: 0,
name: "posts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: src/core/ir/jit/builder.rs
expression: plan
---
ExecutionPlan {
fields: [
parent: [
Field {
id: 0,
name: "getUserIdOrEmail",
Expand All @@ -24,7 +24,7 @@ ExecutionPlan {
],
},
],
field_children: [
children: [
Field {
id: 0,
name: "getUserIdOrEmail",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: src/core/ir/jit/builder.rs
expression: plan
---
ExecutionPlan {
fields: [
parent: [
Field {
id: 0,
name: "user",
Expand Down Expand Up @@ -42,7 +42,7 @@ ExecutionPlan {
),
},
],
field_children: [
children: [
Field {
id: 0,
name: "user",
Expand Down
Loading

0 comments on commit 598b3f9

Please sign in to comment.