Skip to content

Improve slice indexing assertion - #29984

Merged
bors merged 2 commits into
rust-lang:masterfrom
Manishearth:slice-assert
Nov 23, 2015
Merged

bors merged 2 commits into
rust-lang:masterfrom
Manishearth:slice-assert

Conversation

@Manishearth

Copy link
Copy Markdown
Member

I'd like to have the message print out the index and length values like it does elsewhere, but I'm not sure how to do that without affecting perf here. Will assert!(cond, "index out of bounds got {} but len is ", idx, len) make things slower? It calls panic_fmt which is marked as cold but also calls format_args!, and I don't know if that allocates or does any heavy lifting.

cc @alexcrichton @gankro

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@bluss

bluss commented Nov 22, 2015

Copy link
Copy Markdown
Contributor

str uses a separate function to put the formatting there

@alexcrichton

Copy link
Copy Markdown
Member

Yeah I think the str strategy would be appropriate here for some good messages. There's no concern really about performance here, LLVM typically does the correct thing, but it could accidentally be easy to inflate code sizes with lots of fancy asserts.

If, however, a concrete function in libcore were provided (e.g. not generic), then it could be as fancy as it wants!

@Manishearth

Copy link
Copy Markdown
Member Author

That should be marked cold, right?

@Gankra

Gankra commented Nov 23, 2015

Copy link
Copy Markdown
Contributor

@Manishearth might as well.

@Manishearth
Manishearth force-pushed the slice-assert branch 2 times, most recently from cae8692 to a1ff4b4 Compare November 23, 2015 04:08
@Manishearth

Copy link
Copy Markdown
Member Author

Updated. Error message could be improved.

@Manishearth Manishearth mentioned this pull request Nov 23, 2015
@alexcrichton

Copy link
Copy Markdown
Member

@bors: r+ 5c873be

@bors

bors commented Nov 23, 2015

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 5c873be with merge 4891c00...

bors added a commit that referenced this pull request Nov 23, 2015
I'd like to have the message print out the index and length values like it does elsewhere, but I'm not sure how to do that without affecting perf here. Will `assert!(cond, "index out of bounds got {} but len is ", idx, len)` make things slower? It calls `panic_fmt` which is marked as cold but also calls `format_args!`, and I don't know if that allocates or does any heavy lifting.

cc @alexcrichton @gankro
@bors
bors merged commit 5c873be into rust-lang:master Nov 23, 2015
@Manishearth
Manishearth deleted the slice-assert branch December 2, 2016 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants