Skip to content

Commit

Permalink
fix(stageleft): properly handle crate:: imports
Browse files Browse the repository at this point in the history
Fixes #1092
  • Loading branch information
shadaj committed Nov 5, 2024
1 parent f4f77af commit d4a9edb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
1 change: 0 additions & 1 deletion hydroflow_plus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub mod deploy;
pub use deploy::{ClusterSpec, Deploy, ProcessSpec};

pub mod cycle;
pub use cycle::HfForwardRef;

pub mod builder;
pub use builder::FlowBuilder;
Expand Down
3 changes: 1 addition & 2 deletions hydroflow_plus/src/location/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ use serde::{Deserialize, Serialize};
use stageleft::runtime_support::FreeVariable;
use stageleft::{quote_type, Quoted};

// TODO(shadaj): have to use super due to stageleft limitations
use super::super::staging_util::get_this_crate;
use super::{Location, LocationId};
use crate::builder::FlowState;
use crate::staging_util::get_this_crate;

pub struct Cluster<'a, C> {
pub(crate) id: usize,
Expand Down
5 changes: 3 additions & 2 deletions hydroflow_plus/src/location/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ use stageleft::{q, Quoted};

use super::builder::FlowState;
use crate::cycle::{
CycleCollection, CycleCollectionWithInitial, DeferTick, ForwardRef, HfCycle, TickCycle,
CycleCollection, CycleCollectionWithInitial, DeferTick, ForwardRef, HfCycle, HfForwardRef,
TickCycle,
};
use crate::ir::{HfPlusNode, HfPlusSource};
use crate::{Bounded, HfForwardRef, Optional, Singleton, Stream, Unbounded};
use crate::{Bounded, Optional, Singleton, Stream, Unbounded};

pub mod external_process;
pub use external_process::ExternalProcess;
Expand Down
3 changes: 1 addition & 2 deletions hydroflow_plus/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use serde::Serialize;
use stageleft::{q, IntoQuotedMut, Quoted};
use syn::parse_quote;

// TODO(shadaj): have to uses super due to stageleft limitations
use super::staging_util::get_this_crate;
use crate::builder::FlowState;
use crate::cycle::{CycleCollection, CycleComplete, DeferTick, ForwardRef, TickCycle};
use crate::ir::{DebugInstantiate, HfPlusLeaf, HfPlusNode, TeeNode};
Expand All @@ -22,6 +20,7 @@ use crate::location::external_process::{ExternalBincodeStream, ExternalBytesPort
use crate::location::{
check_matching_location, CanSend, ExternalProcess, Location, LocationId, NoTick, Tick,
};
use crate::staging_util::get_this_crate;
use crate::{Cluster, ClusterId, Optional, Process, Singleton};

/// Marks the stream as being unbounded, which means that it is not
Expand Down
18 changes: 17 additions & 1 deletion stageleft_tool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::{env, fs};

use proc_macro2::Span;
use quote::ToTokens;
use syn::parse_quote;
use syn::visit::Visit;
use syn::visit_mut::VisitMut;
use syn::{parse_quote, UsePath};

struct GenMacroVistor {
exported_macros: BTreeSet<(String, String)>,
Expand Down Expand Up @@ -144,6 +144,22 @@ impl VisitMut for GenFinalPubVistor {
syn::visit_mut::visit_item_use_mut(self, i);
}

fn visit_use_path_mut(&mut self, i: &mut UsePath) {
if i.ident == "crate" {
*i = UsePath {
ident: syn::Ident::new("crate", Span::call_site()),
colon2_token: Default::default(),
tree: Box::new(syn::UseTree::Path(UsePath {
ident: parse_quote!(__staged),
colon2_token: Default::default(),
tree: i.tree.clone(),
})),
};
}

syn::visit_mut::visit_use_path_mut(self, i);
}

fn visit_item_mod_mut(&mut self, i: &mut syn::ItemMod) {
let is_runtime_or_test = i.attrs.iter().any(|a| {
a.path().to_token_stream().to_string() == "stageleft :: runtime"
Expand Down

0 comments on commit d4a9edb

Please sign in to comment.