Skip to content

Commit

Permalink
Specify Sync and Send
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer committed Dec 22, 2024
1 parent 0fd8419 commit d70ac4e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions xrcf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ clap = { version = "4.5", features = ["derive"] }
tracing = "0.1"
tracing-subscriber = "0.3"
parking_lot = { version = "0.12", features = ["deadlock_detection"] }
rayon = "1.10"

[dev-dependencies]
indoc = "2"
Expand Down
11 changes: 6 additions & 5 deletions xrcf/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::ir::Op;
use crate::shared::Shared;
use crate::shared::SharedExt;
use anyhow::Result;
use rayon::prelude::*;
use std::sync::Arc;
use tracing::debug;

Expand Down Expand Up @@ -61,7 +62,7 @@ impl RewriteResult {
}
}

pub trait Rewrite {
pub trait Rewrite: Send + Sync {
/// The name of the rewrite; is used for logging.
fn name(&self) -> &'static str;
/// Returns true if the rewrite can be applied to the given operation.
Expand All @@ -82,8 +83,8 @@ pub trait Rewrite {
fn rewrite(&self, op: Shared<dyn Op>) -> Result<RewriteResult>;
}

fn apply_rewrites_helper(
root: Shared<dyn Op>,
fn apply_rewrites_core(
root: Shared<dyn Op + Send + Sync>,
rewrites: &[&dyn Rewrite],
indent: i32,
) -> Result<RewriteResult> {
Expand All @@ -92,7 +93,7 @@ fn apply_rewrites_helper(
// Determine ops here because `rewrite` may delete an op.
for nested_op in ops.iter() {
let indent = indent + 1;
let result = apply_rewrites_helper(nested_op.clone(), rewrites, indent)?;
let result = apply_rewrites_core(nested_op.clone(), rewrites, indent)?;
if result.is_changed().is_some() {
let root_passthrough = ChangedOp::new(root.clone());
let root_passthrough = RewriteResult::Changed(root_passthrough);
Expand Down Expand Up @@ -124,7 +125,7 @@ pub fn apply_rewrites(root: Shared<dyn Op>, rewrites: &[&dyn Rewrite]) -> Result
let mut root = root;
let mut has_changed = false;
for _ in 0..max_iterations {
let result = apply_rewrites_helper(root.clone(), rewrites, 0)?;
let result = apply_rewrites_core(root.clone(), rewrites, 0)?;
match result {
RewriteResult::Changed(changed) => {
has_changed = true;
Expand Down
2 changes: 1 addition & 1 deletion xrcf/src/ir/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::sync::Arc;
/// Attributes are known-constant values of operations (a variable is not allowed).
/// Attributes belong to operations and can be used to, for example, specify
/// a SSA value.
pub trait Attribute {
pub trait Attribute: Send + Sync {
fn from_str(value: &str) -> Self
where
Self: Sized;
Expand Down
7 changes: 6 additions & 1 deletion xrcf/src/ir/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ use std::sync::Arc;
///
/// See [Operation] for more information about the relationship between
/// [Operation] and [Op].
pub trait Op {
///
/// ```
/// fn is_sharable<T: Send + Sync>() {}
///
/// ```
pub trait Op: Send + Sync {
fn operation_name() -> OperationName
where
Self: Sized;
Expand Down
2 changes: 1 addition & 1 deletion xrcf/src/ir/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use anyhow::Result;
use std::fmt::Display;
use std::fmt::Formatter;
use std::str::FromStr;
pub trait Type {
pub trait Type: Send + Sync {
/// Display the type.
///
/// This has to be implemented by each type so that calls to `Display::fmt`
Expand Down
1 change: 0 additions & 1 deletion xrcf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
//! So, the long-term goal of this project is to provide an easy-to-use set of tools that can be used to build your own compiler.
//! In other words, it should be easy to build a compiler that can transform your favorite language to this project's core IR, and then it should be easy to transform this to various platforms such as GPUs, CPUs, and TPUs.
#![allow(clippy::new_without_default)]
#![allow(clippy::arc_with_non_send_sync)]

mod canonicalize;
pub mod convert;
Expand Down

0 comments on commit d70ac4e

Please sign in to comment.