[sil] Add a new instruction ignored_use.

This is used for synthetic uses like _ = x that do not act as a true use but
instead only suppress unused variable warnings. This patch just adds the
instruction.

Eventually, we can use it to move the unused variable warning from Sema to SIL
slimmming the type checker down a little bit... but for now I am using it so
that other diagnostic passes can have a SIL instruction (with SIL location) so
that we can emit diagnostics on code like _ = x. Today we just do not emit
anything at all for that case so a diagnostic SIL pass would not see any
instruction that it could emit a diagnostic upon. In the next patch of this
series, I am going to add SILGen support to do that.
This commit is contained in:
Michael Gottesman
2024-12-17 18:15:49 -08:00
parent bdfb6099b2
commit 7ae56aab2e
20 changed files with 114 additions and 3 deletions

View File

@@ -1692,6 +1692,17 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
break;
}
case SILInstructionKind::IgnoredUseInst: {
// Use SILOneOperandLayout to specify our operand.
auto *iui = cast<IgnoredUseInst>(&SI);
unsigned abbrCode = SILAbbrCodes[SILOneOperandLayout::Code];
SILOneOperandLayout::emitRecord(
Out, ScratchRecord, abbrCode, (unsigned)iui->getKind(), 0,
S.addTypeRef(iui->getOperand()->getType().getRawASTType()),
(unsigned)iui->getOperand()->getType().getCategory(),
addValueRef(iui->getOperand()));
break;
}
case SILInstructionKind::DynamicFunctionRefInst: {
// Use SILOneOperandLayout to specify the function type and the function
// name (IdentifierID).