diff --git a/luisa_compute/src/lang/debug.rs b/luisa_compute/src/lang/debug.rs index abb305f..038023c 100644 --- a/luisa_compute/src/lang/debug.rs +++ b/luisa_compute/src/lang/debug.rs @@ -28,9 +28,15 @@ macro_rules! lc_assert { ($arg:expr) => { $crate::lang::debug::__assert($arg, stringify!($arg), file!(), line!(), column!()) }; + (crate=[$path:tt], $arg:expr) => { + $path::lang::debug::__assert($arg, stringify!($arg), file!(), line!(), column!()) + }; ($arg:expr, $msg:expr) => { $crate::lang::debug::__assert($arg, $msg, file!(), line!(), column!()) }; + (crate=[$path:tt], $arg:expr, $msg:expr) => { + $path::lang::debug::__assert($arg, $msg, file!(), line!(), column!()) + }; } pub fn __cpu_dbg(arg: Expr, file: &'static str, line: u32) { if !is_cpu_backend() { @@ -173,9 +179,21 @@ macro_rules! lc_comment_lineno { column!() )) }; + (crate=[$path:tt], $msg:literal) => { + $path::lang::debug::comment(&format!( + "`{}` at {}:{}:{}", + $msg, + file!(), + line!(), + column!() + )) + }; ($msg:literal, $e:expr) => { $crate::lang::debug::with_lineno($msg, file!(), line!(), column!(), || $e) }; + (crate=[$path:tt], $msg:literal, $e:expr) => { + $path::lang::debug::with_lineno($msg, file!(), line!(), column!(), || $e) + }; } pub fn with_lineno(msg: &str, file: &str, line: u32, col: u32, f: impl FnOnce() -> T) -> T { diff --git a/luisa_compute/src/lang/poly.rs b/luisa_compute/src/lang/poly.rs index 4da82be..a4417aa 100644 --- a/luisa_compute/src/lang/poly.rs +++ b/luisa_compute/src/lang/poly.rs @@ -41,16 +41,16 @@ pub trait PolymorphicImpl: Value { #[macro_export] macro_rules! impl_polymorphic { - ($trait_:ident, $ty:ty) => { - impl luisa_compute::lang::poly::PolymorphicImpl for $ty { + (crate=[$path:tt], $trait_:ident, $ty:ty) => { + impl $path::lang::poly::PolymorphicImpl for $ty { fn new_poly_array( - buffer: &luisa_compute::resource::BufferView, + buffer: &$path::resource::BufferView, tag: i32, key: K, owned: Box, - ) -> luisa_compute::lang::poly::PolyArray { + ) -> $path::lang::poly::PolyArray { let buffer = buffer.view(..); - luisa_compute::lang::poly::PolyArray::new( + $path::lang::poly::PolyArray::new( tag, key, Box::new(move |_, index| { @@ -61,6 +61,9 @@ macro_rules! impl_polymorphic { } } }; + ($trait_:ident, $ty:ty) => { + impl_polymorphic!(crate=[$crate], $trait_, $ty); + }; } struct PolyVec { device: Device, diff --git a/luisa_compute/src/lang/print.rs b/luisa_compute/src/lang/print.rs index e147331..88f1c52 100644 --- a/luisa_compute/src/lang/print.rs +++ b/luisa_compute/src/lang/print.rs @@ -47,10 +47,13 @@ impl DevicePrint for Var { #[macro_export] macro_rules! device_log { ($fmt:literal, $($arg:expr),*) => {{ - let mut fmt = $crate::lang::print::DevicePrintFormatter::new(); + device_log!(crate=[$crate], $fmt, $($arg),*) + }}; + (crate=[$path:tt], $fmt:literal, $($arg:expr),*) => {{ + let mut fmt = $path::lang::print::DevicePrintFormatter::new(); fmt.push_str($fmt); $( - $crate::lang::print::DevicePrint::fmt(&$arg, &mut fmt); + $path::lang::print::DevicePrint::fmt(&$arg, &mut fmt); )* fmt.print(); }}; diff --git a/luisa_compute_derive_impl/src/lib.rs b/luisa_compute_derive_impl/src/lib.rs index cf1cb02..0ea5699 100644 --- a/luisa_compute_derive_impl/src/lib.rs +++ b/luisa_compute_derive_impl/src/lib.rs @@ -237,6 +237,7 @@ impl Compiler { self.set_crate_path_from_attrs(&attrs); let span = struct_.span(); let lang_path = self.lang_path(); + let crate_path = &self.crate_path; let generics = &struct_.generics; let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); let name = &struct_.ident; @@ -259,7 +260,7 @@ impl Compiler { #[allow(unused_assignments)] fn from_soa_storage( - ___storage: ::luisa_compute::resource::ByteBufferVar, + ___storage: #crate_path::resource::ByteBufferVar, ___meta: Expr<#lang_path::soa::SoaMetadata>, ___global_offset: usize, ) -> Self { @@ -391,6 +392,7 @@ impl Compiler { }) .expect("Enum must have repr attribute."); let span = enum_.span(); + let crate_path = &self.crate_path; let lang_path = self.lang_path(); let name = &enum_.ident; let expr_proxy_name = syn::Ident::new(&format!("{}Expr", name), name.span()); @@ -419,9 +421,9 @@ impl Compiler { } } - ::luisa_compute::impl_simple_expr_proxy!(#expr_proxy_name for #name); - ::luisa_compute::impl_simple_var_proxy!(#var_proxy_name for #name); - ::luisa_compute::impl_simple_atomic_ref_proxy!(#atomic_ref_proxy_name for #name); + #crate_path::impl_simple_expr_proxy!(#expr_proxy_name for #name); + #crate_path::impl_simple_var_proxy!(#var_proxy_name for #name); + #crate_path::impl_simple_atomic_ref_proxy!(#atomic_ref_proxy_name for #name); impl #expr_proxy_name { pub fn #as_repr(&self) -> #lang_path::types::Expr<#repr> {