Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Updates Benchmark macros to use linear! with range #13897

Closed
wants to merge 2 commits into from

Conversation

gupnik
Copy link
Contributor

@gupnik gupnik commented Apr 13, 2023

As discussed in #13845

@gupnik gupnik requested a review from sam0x17 April 13, 2023 05:42
Copy link
Contributor

@sam0x17 sam0x17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking great, like the linear! syntax as a solution to the ranges not being valid in type position issue, would love to hear @ggwpez's thoughts on this

I do think we still need some sort of static assertion to make sure start and end are Into

@@ -886,11 +875,6 @@ fn expand_benchmark(
// benchmark function definition
#fn_def

// compile-time assertions that each referenced param type implements ParamRange
#(
#home::assert_impl_all!(#param_types: #home::ParamRange);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so let's replace this with a compile-time assertion that start and end are both bounded by Into<u32>

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: test-linux-stable
Logs: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2677018

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: test-linux-stable
Logs: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2677016

fn transfer_increasing_users(u: Linear<0, 1_000>) {
fn transfer_increasing_users(u: linear![0..1_000]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep Linear<0..1_000>?
Since const generics cannot accept ranges or something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the advantage of having a type is that people can click on it in the language server and it explains what it does.

Copy link
Contributor

@sam0x17 sam0x17 Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason for the fake macro is rust isn't able to parse the enclosing module as an ItemMod if we do Linear<0..10> because the 0..10 can't appear in type position, so we would either have to do some kind of pre-pass where we remove these before parsing as an ItemMod (hard) or enclose the range in something that works in any position like a macro call

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So based on those trade-offs, I like this

Copy link
Contributor

@sam0x17 sam0x17 Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole root of this issue is if we are supporting things that are Into<u32> instead of just u32 literals, this is no longer really a type, it's an expression, because the info we need to collect from the programmer is an expression for the start of the range and an expression for the end of the range. Before we were abusing const u32 type params to do this, but we can't do that with things that are merely Into the same way

Copy link
Contributor

@sam0x17 sam0x17 Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something with a tuple though......? This was just the best idea that I had syntactically

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we can use Into<u32> but only with the Linear<start, end> syntax and not .
I dont see anything wrong with Linear<start, end> besides the fact that it is "less" rust.
On the other hand the start…end is also not quite right in the rust semantic, since we just skip specific values depending on the step size. So it is not actually a range in the rust sense.

Copy link
Contributor

@sam0x17 sam0x17 Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gupnik does ItemMod still parse if you do Linear<something, something_else> where something is (non-const) expr? I was under the impression it doesn't let you but I forget now

My whole complaint @ggwpez is that Linear<something.something(), 33> is no longer a type anyway so why not make it look like a range

Copy link
Member

@ggwpez ggwpez Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it is still a valid rust type; just needs brackets: Linear<{ something.something() }, 33>. Everything we do here must be compile time anyway, but that also applies to the V1 syntax.

This works just fine:

fn sort_vector(x: Linear<{MY_CONST * 2}, {my_fn() + MyConst::get()}>) {

It needs GenericArgument though, see diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! Thanks @ggwpez. Let me take this up.

@sam0x17
Copy link
Contributor

sam0x17 commented Apr 13, 2023 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants