Skip to content

Add span! macro #21

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

Closed
wants to merge 1 commit into from
Closed

Add span! macro #21

wants to merge 1 commit into from

Conversation

benfrankel
Copy link
Contributor

The macro uses file!() and line!() to determine the file name and line number to pass to Span::new(...). It also uses a hack to determine the function name, which is the same hack used in stdext::function_name!, since the RFC to add a macro for this to the Rust stdlib is unresolved.

Alternatively, stdext could be added as a dependency, but that's probably overkill.

Also, it might be convenient to support omitting the callstack_depth with a default value of 62, which is the max according to Tracy documentation ("The maximum call stack depth that can be retrieved is 62 frames. This is a restriction at the level of operating system.").

@Ralith
Copy link
Contributor

Ralith commented Sep 6, 2021

This would be awesome to have!

Also, it might be convenient to support omitting the callstack_depth with a default value of 62

Sounds like a good plan to me.

Copy link
Owner

@nagisa nagisa left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me!

Sorry for taking a while to get to this.

fn f() {}
fn type_name_of<T>(_: T) -> &'static str {
std::any::type_name::<T>()
}
Copy link
Owner

Choose a reason for hiding this comment

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

From what I can tell this can be simplified to a

struct S; 
let func_name = std::any::type_name::<S>();
let function = &func_name[..func_name.len() - 3];

@nagisa
Copy link
Owner

nagisa commented Sep 18, 2021

Would be great if you could add a test that just calls the macro as well as bump the version of rustc in CI files to something like 1.52 or 1.53.

@nagisa
Copy link
Owner

nagisa commented Sep 18, 2021

Merged in f06d0fd

Thanks!

@nagisa nagisa closed this Sep 18, 2021
@Ralith
Copy link
Contributor

Ralith commented Sep 18, 2021

Awesome! Any chance of a patch release with this in it soon?

@nagisa
Copy link
Owner

nagisa commented Sep 18, 2021 via email

@nagisa
Copy link
Owner

nagisa commented Sep 19, 2021

Looks like we're seeing some SIGSEGVs on Windows in a doctest I added for the macro, which I'll need to investigate before I cut a release.

@nagisa
Copy link
Owner

nagisa commented Sep 19, 2021

Could not reproduce the issue locally and I bet its not a new failure mode anyway, so went ahead and published 0.12.5.

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.

3 participants