Skip to content

Commit b26635f

Browse files
committed
Upgrade to const-type-layout v0.2.0 and MSRV to 1.75-nightly
1 parent 2876599 commit b26635f

File tree

27 files changed

+122
-125
lines changed

27 files changed

+122
-125
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ default-members = [
1010
[package]
1111
name = "rust-cuda"
1212
version = "0.1.0"
13-
authors = ["Juniper Tyree <juniper.langenstein@helsinki.fi>"]
13+
authors = ["Juniper Tyree <juniper.tyree@helsinki.fi>"]
1414
license = "MIT OR Apache-2.0"
1515
edition = "2021"
16+
rust-version = "1.75" # nightly
1617

1718
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1819

@@ -28,7 +29,7 @@ rustacuda_core = "0.1.2"
2829
rustacuda = { version = "0.1.3", optional = true }
2930
rustacuda_derive = { version = "0.1.2", optional = true }
3031

31-
const-type-layout = { git = "https://github.com/juntyr/const-type-layout", rev = "e163b36" }
32+
const-type-layout = { version = "0.2.0", features = ["derive"] }
3233

3334
final = "0.1.1"
3435
hashbrown = { version = "0.14", default-features = false, features = ["inline-more"], optional = true }

examples/derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ edition = "2021"
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
const-type-layout = { git = "https://github.com/juntyr/const-type-layout", rev = "e163b36" }
11+
const-type-layout = { version = "0.2.0" }
1212
rust-cuda = { path = "../../", features = ["derive", "host"] }

examples/derive/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#![deny(clippy::pedantic)]
2-
#![feature(cfg_version)]
3-
#![feature(const_trait_impl)]
42
#![feature(const_type_name)]
5-
#![cfg_attr(not(version("1.65.0")), feature(const_ptr_offset_from))]
6-
#![feature(const_refs_to_cell)]
7-
#![feature(const_mut_refs)]
3+
#![feature(offset_of)]
84

95
#[derive(rust_cuda::common::LendRustToCuda)]
106
struct Inner<T: Copy> {

examples/single-source/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2021"
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
const-type-layout = { git = "https://github.com/juntyr/const-type-layout", rev = "e163b36" }
11+
const-type-layout = { version = "0.2.0" }
1212

1313
[target.'cfg(target_os = "cuda")'.dependencies]
1414
rust-cuda = { path = "../../", features = ["derive"] }

examples/single-source/src/main.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@
55
#![cfg_attr(target_os = "cuda", feature(alloc_error_handler))]
66
#![cfg_attr(target_os = "cuda", feature(stdsimd))]
77
#![cfg_attr(target_os = "cuda", feature(asm_experimental_arch))]
8-
#![feature(cfg_version)]
98
#![feature(const_type_name)]
10-
#![cfg_attr(not(version("1.65.0")), feature(const_ptr_offset_from))]
11-
#![feature(const_refs_to_cell)]
12-
#![feature(const_trait_impl)]
13-
#![feature(const_mut_refs)]
14-
#![cfg_attr(not(version("1.61.0")), feature(const_fn_trait_bound))]
9+
#![feature(offset_of)]
1510

1611
extern crate alloc;
1712

rust-cuda-derive/src/kernel/link/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ pub fn emit_ptx_build_error() {
4242
)
4343
.byte_start(byte_start)
4444
.byte_end(byte_end)
45-
.line_start(call_site.start().line)
46-
.line_end(call_site.end().line)
47-
.column_start(call_site.start().column)
48-
.column_end(call_site.end().column)
45+
.line_start(call_site.start().line())
46+
.line_end(call_site.end().line())
47+
.column_start(call_site.start().column())
48+
.column_end(call_site.end().column())
4949
.is_primary(true)
5050
.text(vec![])
5151
.label(None)

rust-cuda-derive/src/kernel/link/mod.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn link_kernel(tokens: TokenStream) -> TokenStream {
8787
return (quote! {
8888
const PTX_STR: &'static str = "ERROR in this PTX compilation";
8989
})
90-
.into()
90+
.into();
9191
};
9292

9393
let kernel_layout_name = if specialisation.is_empty() {
@@ -113,7 +113,8 @@ pub fn link_kernel(tokens: TokenStream) -> TokenStream {
113113
let after_type_layout_start = type_layout_start + type_layout_start_pattern.len();
114114

115115
let Some(type_layout_middle) = kernel_ptx[after_type_layout_start..]
116-
.find(&format!(".visible .entry {kernel_layout_name}")).map(|i| after_type_layout_start + i)
116+
.find(&format!(".visible .entry {kernel_layout_name}"))
117+
.map(|i| after_type_layout_start + i)
117118
else {
118119
abort_call_site!(
119120
"Kernel compilation generated invalid PTX: incomplete type layout information"
@@ -148,12 +149,18 @@ pub fn link_kernel(tokens: TokenStream) -> TokenStream {
148149

149150
let Ok(len) = len.parse::<usize>() else {
150151
abort_call_site!(
151-
"Kernel compilation generated invalid PTX: invalid type layout length"
152+
"Kernel compilation generated invalid PTX: invalid type layout \
153+
length"
152154
)
153155
};
154-
let Ok(bytes) = bytes.split(", ").map(std::str::FromStr::from_str).collect::<Result<Vec<u8>, _>>() else {
156+
let Ok(bytes) = bytes
157+
.split(", ")
158+
.map(std::str::FromStr::from_str)
159+
.collect::<Result<Vec<u8>, _>>()
160+
else {
155161
abort_call_site!(
156-
"Kernel compilation generated invalid PTX: invalid type layout byte"
162+
"Kernel compilation generated invalid PTX: invalid type layout \
163+
byte"
157164
)
158165
};
159166

@@ -183,9 +190,10 @@ pub fn link_kernel(tokens: TokenStream) -> TokenStream {
183190
}
184191
}
185192

186-
let Some(type_layout_end) = kernel_ptx[type_layout_middle..].find('}').map(|i| {
187-
type_layout_middle + i + '}'.len_utf8()
188-
}) else {
193+
let Some(type_layout_end) = kernel_ptx[type_layout_middle..]
194+
.find('}')
195+
.map(|i| type_layout_middle + i + '}'.len_utf8())
196+
else {
189197
abort_call_site!("Kernel compilation generated invalid PTX")
190198
};
191199

rust-cuda-derive/src/kernel/wrapper/generate/cpu_linker_macro/kernel_func.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ fn generate_raw_func_input_wrap(
122122
)
123123
});
124124

125+
#[allow(invalid_reference_casting)]
125126
if !__check_is_sync(#pat) {
126127
// Safety:
127128
// * Since `#ty` is `!Sync`, it contains interior mutability

rust-cuda-derive/src/kernel/wrapper/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ enum InputCudaType {
229229

230230
struct InputPtxJit(bool);
231231

232+
#[allow(clippy::struct_field_names)]
232233
struct DeclGenerics<'f> {
233234
generic_start_token: &'f Option<syn::token::Lt>,
234235
generic_trait_params: &'f syn::punctuated::Punctuated<syn::GenericParam, syn::token::Comma>,
@@ -241,11 +242,13 @@ struct DeclGenerics<'f> {
241242
}
242243

243244
struct ImplGenerics<'f> {
245+
#[allow(clippy::struct_field_names)]
244246
impl_generics: syn::ImplGenerics<'f>,
245247
ty_generics: syn::TypeGenerics<'f>,
246248
where_clause: Option<&'f syn::WhereClause>,
247249
}
248250

251+
#[allow(clippy::struct_field_names)]
249252
struct FuncIdent<'f> {
250253
func_ident: &'f syn::Ident,
251254
func_ident_raw: syn::Ident,
@@ -275,8 +278,6 @@ fn ident_from_pat(pat: &syn::Pat) -> Option<syn::Ident> {
275278
syn::Pat::Struct(syn::PatStruct { fields, .. }) => {
276279
ident_from_pat_iter(fields.iter().map(|field| &*field.pat))
277280
},
278-
#[cfg_attr(test, deny(non_exhaustive_omitted_patterns))]
279-
#[cfg_attr(not(test), allow(non_exhaustive_omitted_patterns))]
280281
_ => Err(()).ok(),
281282
}
282283
}

rust-cuda-derive/src/rust_to_cuda/generics.rs

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,76 +43,83 @@ pub fn expand_cuda_struct_generics_where_requested_in_attrs(
4343
.push(bound),
4444
Err(err) => emit_error!(
4545
s.span(),
46-
"[rust-cuda]: Invalid #[cuda(bound = \
47-
\"<where-predicate>\")] struct attribute: {}.",
46+
"[rust-cuda]: Invalid #[cuda(bound = \"<where-predicate>\")] \
47+
struct attribute: {}.",
4848
err
4949
),
5050
},
5151
syn::NestedMeta::Meta(syn::Meta::NameValue(syn::MetaNameValue {
5252
path,
5353
lit: syn::Lit::Str(s),
5454
..
55-
})) if path.is_ident("free") => match syn::parse_str::<syn::Ident>(&s.value()) {
56-
Ok(param) => {
57-
if let Some(i) = type_params.iter().position(|ty| **ty == param)
58-
{
59-
type_params.swap_remove(i);
60-
} else {
61-
emit_error!(
62-
s.span(),
63-
"[rust-cuda]: Invalid #[cuda(free = \"{}\")] \
64-
attribute: \"{}\" is either not a type parameter or \
65-
has already been freed (duplicate attribute).",
66-
param,
67-
param,
68-
);
69-
}
70-
},
71-
Err(err) => emit_error!(
72-
s.span(),
73-
"[rust-cuda]: Invalid #[cuda(free = \"<type>\")] \
74-
attribute: {}.",
75-
err
76-
),
55+
})) if path.is_ident("free") => {
56+
match syn::parse_str::<syn::Ident>(&s.value()) {
57+
Ok(param) => {
58+
if let Some(i) = type_params.iter().position(|ty| **ty == param)
59+
{
60+
type_params.swap_remove(i);
61+
} else {
62+
emit_error!(
63+
s.span(),
64+
"[rust-cuda]: Invalid #[cuda(free = \"{}\")] \
65+
attribute: \"{}\" is either not a type parameter or \
66+
has already been freed (duplicate attribute).",
67+
param,
68+
param,
69+
);
70+
}
71+
},
72+
Err(err) => emit_error!(
73+
s.span(),
74+
"[rust-cuda]: Invalid #[cuda(free = \"<type>\")] attribute: \
75+
{}.",
76+
err
77+
),
78+
}
7779
},
7880
syn::NestedMeta::Meta(syn::Meta::NameValue(syn::MetaNameValue {
79-
path: syn::Path {
80-
leading_colon: None,
81-
segments,
82-
},
81+
path:
82+
syn::Path {
83+
leading_colon: None,
84+
segments,
85+
},
8386
lit: syn::Lit::Str(s),
8487
..
85-
})) if segments.len() == 2 && let syn::PathSegment {
86-
ident: layout_ident,
87-
arguments: syn::PathArguments::None,
88-
} = &segments[0] && let syn::PathSegment {
89-
ident: attr_ident,
90-
arguments: syn::PathArguments::None,
91-
} = &segments[1] && layout_ident == "layout" && !segments.trailing_punct() => {
88+
})) if segments.len() == 2
89+
&& let syn::PathSegment {
90+
ident: layout_ident,
91+
arguments: syn::PathArguments::None,
92+
} = &segments[0]
93+
&& let syn::PathSegment {
94+
ident: attr_ident,
95+
arguments: syn::PathArguments::None,
96+
} = &segments[1]
97+
&& layout_ident == "layout"
98+
&& !segments.trailing_punct() =>
99+
{
92100
struct_layout_attrs.push(syn::Attribute {
93101
pound_token: attr.pound_token,
94102
style: attr.style,
95103
bracket_token: attr.bracket_token,
96104
path: proc_macro2::Ident::new("layout", attr.path.span()).into(),
97105
tokens: quote_spanned!(s.span() => (#attr_ident = #s)),
98106
});
99-
}
107+
},
100108
_ => {
101109
emit_error!(
102110
meta.span(),
103-
"[rust-cuda]: Expected #[cuda(ignore)] / \
104-
#[cuda(bound = \"<where-predicate>\")] / \
105-
#[cuda(layout::ATTR = \"VALUE\")] struct attribute."
111+
"[rust-cuda]: Expected #[cuda(ignore)] / #[cuda(bound = \
112+
\"<where-predicate>\")] / #[cuda(layout::ATTR = \"VALUE\")] \
113+
struct attribute."
106114
);
107-
}
115+
},
108116
}
109117
}
110118
} else {
111119
emit_error!(
112120
attr.span(),
113-
"[rust-cuda]: Expected #[cuda(ignore)] / \
114-
#[cuda(bound = \"<where-predicate>\")] / \
115-
#[cuda(layout::ATTR = \"VALUE\")] struct attribute."
121+
"[rust-cuda]: Expected #[cuda(ignore)] / #[cuda(bound = \
122+
\"<where-predicate>\")] / #[cuda(layout::ATTR = \"VALUE\")] struct attribute."
116123
);
117124
}
118125

0 commit comments

Comments
 (0)