Skip to content

Feature: #[trace(variables = [b])] #135

@taqtiqa-mark

Description

@taqtiqa-mark

Another use case to take into account while the model phase of #113 is taking shape.....

This is also related to the #134 use case, but not limited to:

  • aiding a new/infrequent user quickly get useful data to assist with debugging.
  • 'tracing' the LHS of the expression where the function is in a sealed trait or 3rd-party crate.

The following should be possible (initially sync only):

#[trace(variables=[p, n]]
fn factorial(mut n: u64) -> u64 {
    let mut p = 1;
    while n > 1 {
        p *= n;
        n -= 1;
    }
    p
}

The idea would be to have this become (better suggestions welcome):

fn factorial(mut n: u64) -> u64 {
    let _g = LocalSpan::enter_with_local_parent();
    let mut p;
    {
            let _mt = LocalSpan::enter_with_local_parent();
            p = 1;
    }
    while n > 1 {
        {
            let _mt = LocalSpan::enter_with_local_parent();
            p *= n;
        }
        {
            let _mt = LocalSpan::enter_with_local_parent();
            n -= 1;
        }
    }
    p
}

Producing SpanRecords for:

  • p = 1
  • p = 8
  • n = 7
  • p = 56
  • n = 6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions