Skip to content

ZJIT: Include local variable names in Get|SetLocal insn's print value#15423

Merged
st0012 merged 1 commit intoruby:masterfrom
Shopify:print-local-variable-names
Dec 5, 2025
Merged

ZJIT: Include local variable names in Get|SetLocal insn's print value#15423
st0012 merged 1 commit intoruby:masterfrom
Shopify:print-local-variable-names

Conversation

@st0012
Copy link
Member

@st0012 st0012 commented Dec 5, 2025

Closes Shopify#881

v2:BasicObject = GetLocal :a, l0, SP@4

# or if the local doesn't have a name

v2:BasicObject = GetLocal <empty>, l0, SP@4

@matzbot matzbot requested a review from a team December 5, 2025 18:47
zjit/src/hir.rs Outdated
/// Returns
/// - `:name, ` if iseq is available and name is a real identifier,
/// - `<anon>, ` for anonymous locals.
/// - empty string if iseq is not available.
Copy link
Member

Choose a reason for hiding this comment

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

Could you let the comment also explain when this happens? I'm not sure why we need to support this. Is it used only for Rust-level unit tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. It's used in HIR dump, graphviz output, and iongraph output.

Copy link
Member

Choose a reason for hiding this comment

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

🤔

My question was on this "empty string if iseq is not available" line, and I meant to ask "Is empty string used only for Rust-level unit tests?". Are you sure you print an empty string here on HIR dump?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I thought you meant the return value of this function in general.

Insn can also be printed in panic/debug messages too, like in disasm.rs we have:

    // For each instruction in this block
    for insn in insns.as_ref() {
        // ...
        writeln!(&mut out, "  {}", format!("{insn}").trim()).unwrap();
    }

In these cases, I think the fmt implementation for Display trait would be called, which can't access iseq:

impl std::fmt::Display for Insn {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        self.print(&PtrPrintMap::identity(), None).fmt(f)
    }
}

So the empty string is for those cases.

Copy link
Member

Choose a reason for hiding this comment

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

ok, that's probably useful to support then (as I asked above, please consider leaving the context in this line 🙏)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment 👍

@st0012 st0012 force-pushed the print-local-variable-names branch from 5fa8dcf to 9584213 Compare December 5, 2025 20:53
zjit/src/hir.rs Outdated
/// Returns
/// - `:name, ` if iseq is available and name is a real identifier,
/// - `<anon>, ` for anonymous locals.
/// - empty string if iseq is not available.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: does not return empty anymore if iseq is not available--returns none. pls fix comment

zjit/src/hir.rs Outdated
Comment on lines +1029 to +1030
/// - `<anon>, ` for anonymous locals.
/// - empty string if iseq is not available.
Copy link
Contributor

@tekknolagi tekknolagi Dec 5, 2025

Choose a reason for hiding this comment

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

Suggested change
/// - `<anon>, ` for anonymous locals.
/// - empty string if iseq is not available.
/// - `<empty>, ` for anonymous locals.
/// - None if iseq is not available.

@st0012 st0012 force-pushed the print-local-variable-names branch from 9584213 to 56df167 Compare December 5, 2025 21:14
@tekknolagi
Copy link
Contributor

Sweet, merge it

@st0012 st0012 merged commit c4c909b into ruby:master Dec 5, 2025
90 checks passed
@st0012 st0012 deleted the print-local-variable-names branch December 5, 2025 22:00
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.

ZJIT: Print local names for hir::Insn::GetLocal and SetLocal

3 participants