Skip to content

Misc. improvements to raw/debug SemIR output#6557

Merged
geoffromer merged 5 commits intocarbon-language:trunkfrom
geoffromer:debug-print
Jan 14, 2026
Merged

Misc. improvements to raw/debug SemIR output#6557
geoffromer merged 5 commits intocarbon-language:trunkfrom
geoffromer:debug-print

Conversation

@geoffromer
Copy link
Copy Markdown
Contributor

  • Distinguish attached vs. unattached constants.
  • Add some missing value stores to the top-level output.
  • Add missing fields to various Print methods.

- Distinguish attached vs. unattached constants.
- Add some missing value stores to the top-level output.
- Add missing fields to various Print methods.
@geoffromer geoffromer requested a review from a team as a code owner January 6, 2026 19:47
@geoffromer geoffromer requested review from zygoloid and removed request for a team January 6, 2026 19:47
Copy link
Copy Markdown
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

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

Some thoughts but none are blocking.

Comment thread toolchain/sem_ir/dump.cpp Outdated
Comment on lines 43 to 44
out << " (unattached)";
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd be inclined to leave out the (unattached) part since that's the "normal" case, and doesn't even make sense for non-symbolic constants, but I don't feel strongly -- if you think this is a useful reminder for users of the dump output, I don't mind it. If you want to keep it, how about using (attached) and (unattached) for symbolic constants, and (concrete) for concrete constants?

For the (attached) case, could we also include the attachment information like we do in formatted SemIR? (For the dump output, maybe it's better to list the generic ID and index instead of / in addition to the instruction in the eval block.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd be inclined to leave out the (unattached) part since that's the "normal" case, and doesn't even make sense for non-symbolic constants, but I don't feel strongly -- if you think this is a useful reminder for users of the dump output, I don't mind it.

Yeah, I think it's a useful reminder, so I'd prefer to keep it.

If you want to keep it, how about using (attached) and (unattached) for symbolic constants, and (concrete) for concrete constants?

Good idea. Done.

For the (attached) case, could we also include the attachment information like we do in formatted SemIR? (For the dump output, maybe it's better to list the generic ID and index instead of / in addition to the instruction in the eval block.)

Would that already be covered by the code above that prints the SymbolicConstant? If not, can you be more specific about what you mean by "attachment information"? I'm afraid my grasp on the whole concept of attachment remains extremely tenuous.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, I'd not looked at what we're doing there. Yeah:

auto Print(llvm::raw_ostream& out) const -> void {
out << "{inst: " << inst_id << ", generic: " << generic_id
<< ", index: " << index << ", kind: ";
switch (dependence) {
case ConstantDependence::None:
out << "<error: concrete>";
break;
case ConstantDependence::PeriodSelf:
out << "self";
break;
case ConstantDependence::Checked:
out << "checked";
break;
case ConstantDependence::Template:
out << "template";
break;
}

But this is also already printing out whether the symbolic constant is attached or not, although perhaps in a way that's not so obvious. Maybe we could put that information in the print for the SymbolicConstant instead? Eg:

   auto Print(llvm::raw_ostream& out) const -> void {
-    out << "{inst: " << inst_id << ", generic: " << generic_id
-        << ", index: " << index << ", kind: ";
+    out << "{inst: " << inst_id << ", attached: " << generic_id.has_value();
+    if (generic_id.has_value()) {
+      out << ", generic: " << generic_id << ", index: " << index;
+    }
+    out << ", kind: ";

That might cover a few more cases where we're dumping SymbolicConstants?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, yeah, that's a good idea. I've gone with a somewhat different format, though (see one_file.carbon for how it looks in practice). What do you think?

Comment thread toolchain/sem_ir/dump.cpp Outdated
Comment thread toolchain/sem_ir/dump.cpp
Comment thread toolchain/sem_ir/name.h Outdated
@geoffromer geoffromer requested a review from zygoloid January 7, 2026 00:59
Copy link
Copy Markdown
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

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

In case you didn't see, I responded to the remaining open comment thread. (Not sure if github would have notified you for that.)

On reflection I'm fine with this as-is if you prefer this approach (and approving on that basis), but I think including an attached field in the dump of a SymbolicConstant is at least worth considering as an alternative.

Copy link
Copy Markdown
Contributor Author

@geoffromer geoffromer left a comment

Choose a reason for hiding this comment

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

In case you didn't see, I responded to the remaining open comment thread. (Not sure if github would have notified you for that.)

Yeah, I got the notification, I just hadn't got back round to it yet.

Comment thread toolchain/sem_ir/dump.cpp Outdated
Comment on lines 43 to 44
out << " (unattached)";
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, yeah, that's a good idea. I've gone with a somewhat different format, though (see one_file.carbon for how it looks in practice). What do you think?

@geoffromer geoffromer requested a review from zygoloid January 13, 2026 23:06
Copy link
Copy Markdown
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

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

I'm OK with this, but as noted I'd prefer something that's more obviously valid YAML.

// CHECK:STDOUT: symbolic_constant60000114: {inst: inst6000014E, generic: generic60000000, index: generic_inst_in_def6, kind: checked}
// CHECK:STDOUT: symbolic_constant60000115: {inst: inst60000154, generic: generic<none>, index: generic_inst<none>, kind: checked}
// CHECK:STDOUT: symbolic_constant60000116: {inst: inst60000154, generic: generic60000000, index: generic_inst_in_def7, kind: checked}
// CHECK:STDOUT: symbolic_constant0: {inst: inst60000013, kind: self, <unattached>}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Our output here is supposed to be valid YAML. To my mild surprise, this is in fact valid despite the omitted :, and is equivalent to {inst: inst60000013, kind: self, <unattached>: null}. But perhaps something that's more obviously valid would be better? I'd be fine with attached: false or attached: null or unattached: true (or with omitting the attached: portion entirely) for unattached constants.

@geoffromer geoffromer enabled auto-merge January 14, 2026 18:56
@geoffromer geoffromer added this pull request to the merge queue Jan 14, 2026
Merged via the queue into carbon-language:trunk with commit e78af4d Jan 14, 2026
8 checks passed
@geoffromer geoffromer deleted the debug-print branch January 14, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants