-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial conversion to const generics #1018
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,13 +81,21 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream { | |
let name = &f.sig.ident; | ||
// println!("{}", name); | ||
let mut arguments = Vec::new(); | ||
let mut const_arguments = Vec::new(); | ||
for input in f.sig.inputs.iter() { | ||
let ty = match *input { | ||
syn::FnArg::Typed(ref c) => &c.ty, | ||
_ => panic!("invalid argument on {}", name), | ||
}; | ||
arguments.push(to_type(ty)); | ||
} | ||
for generic in f.sig.generics.params.iter() { | ||
let ty = match *generic { | ||
syn::GenericParam::Const(ref c) => &c.ty, | ||
_ => panic!("invalid generic argument on {}", name), | ||
}; | ||
const_arguments.push(to_type(ty)); | ||
} | ||
let ret = match f.sig.output { | ||
syn::ReturnType::Default => quote! { None }, | ||
syn::ReturnType::Type(_, ref t) => { | ||
|
@@ -101,7 +109,23 @@ fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream { | |
} else { | ||
quote! { None } | ||
}; | ||
let required_const = find_required_const(&f.attrs); | ||
|
||
let required_const = find_required_const("rustc_args_required_const", &f.attrs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
let mut legacy_const_generics = | ||
find_required_const("rustc_legacy_const_generics", &f.attrs); | ||
if !required_const.is_empty() && !legacy_const_generics.is_empty() { | ||
panic!( | ||
"Can't have both #[rustc_args_required_const] and \ | ||
#[rustc_legacy_const_generics]" | ||
); | ||
} | ||
legacy_const_generics.sort(); | ||
for (idx, ty) in legacy_const_generics | ||
.into_iter() | ||
.zip(const_arguments.into_iter()) | ||
{ | ||
arguments.insert(idx, ty); | ||
} | ||
|
||
// strip leading underscore from fn name when building a test | ||
// _mm_foo -> mm_foo such that the test name is test_mm_foo. | ||
|
@@ -390,11 +414,11 @@ fn find_target_feature(attrs: &[syn::Attribute]) -> Option<syn::Lit> { | |
}) | ||
} | ||
|
||
fn find_required_const(attrs: &[syn::Attribute]) -> Vec<usize> { | ||
fn find_required_const(name: &str, attrs: &[syn::Attribute]) -> Vec<usize> { | ||
attrs | ||
.iter() | ||
.flat_map(|a| { | ||
if a.path.segments[0].ident == "rustc_args_required_const" { | ||
if a.path.segments[0].ident == name { | ||
syn::parse::<RustcArgsRequiredConst>(a.tokens.clone().into()) | ||
.unwrap() | ||
.args | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this is a breaking change compared to before, where you just discarded bits outside the lowest 8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but C compilers already reject out-of-range immediates at compile-time. I would argue that this is a bug fix since we model the vendor's API more closely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking the Intel Intrinsics Guide again, I see that it's supposed to be
unsigned int imm8
, so you're right.Why did we ever accept an
i32
to begin with? I guess this should have beenu32
the whole time, and arguablyu8
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#522
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oof, i'm actually already subscribed to this one and i'd forgotten about it. okay then.
Actually since
_MM_SHUFFLE
is still nightly, maybe we should change the shuffle to correctly takeu32
and then change_MM_SHUFFLE
(again) to make it also emitu32
values.But even then, if we're going to panic on values outside of
u8
, it's hard to justify not just taking au8
to begin with. I guess, are these conversions to const generics supposed to be otherwise completely non-breaking?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rust-lang/rust#82447 will rewrite an expression at the AST level to use const generics, but won't do anything to change the type of that expression. So I don't think we can change the type here, unless we decide to accept the breaking change anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well if the ship has sailed that's ultimately fine I guess.