summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-peephole.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-06-04 13:05:58 -0700
committerGitHub <noreply@github.com>2025-06-04 13:05:58 -0700
commit812e478989e27983b8dea7ab11964de751654ba2 (patch)
treee6db6def9c7896ee48c5fe42926856644e81c0e6 /source/slang/slang-ir-peephole.cpp
parentb9dc21d362f65f22bc707bede733a9537b80460a (diff)
Make interface types non c-style in Slang2026. (#7260)
* Make interface types non c-style. * Make Optional<T> work with autodiff and existential types. * Fix. * patch behind slang 2026. * Fix warnings. * cleanup. * Fix tests. * Fix. * Fix com interface lowering. * Add comment to test. * regenerate command line reference * Add test for passing `none` to autodiff function. * Fix recording of `getDynamicObjectRTTIBytes`. * Fix nested Optional types. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-ir-peephole.cpp')
-rw-r--r--source/slang/slang-ir-peephole.cpp34
1 files changed, 27 insertions, 7 deletions
diff --git a/source/slang/slang-ir-peephole.cpp b/source/slang/slang-ir-peephole.cpp
index 28e98fdb6..7f3ff1d68 100644
--- a/source/slang/slang-ir-peephole.cpp
+++ b/source/slang/slang-ir-peephole.cpp
@@ -802,13 +802,33 @@ struct PeepholeContext : InstPassBase
{
if (inst->getOperand(0)->getOp() == kIROp_MakeOptionalValue)
{
- IRBuilder builder(module);
- IRBuilderSourceLocRAII srcLocRAII(&builder, inst->sourceLoc);
- builder.setInsertBefore(inst);
- auto trueVal = builder.getBoolValue(true);
- inst->replaceUsesWith(trueVal);
- maybeRemoveOldInst(inst);
- changed = true;
+ auto getHasValue = as<IROptionalHasValue>(inst);
+ auto optionalType =
+ as<IROptionalType>(getHasValue->getOptionalOperand()->getDataType());
+ if (!optionalType)
+ break;
+ if (as<IROptionalType>(optionalType->getValueType()))
+ {
+ // HasValue(o : Optional<Optional<T>>) ==> HasValue(o.value).
+ IRBuilder builder(module);
+ IRBuilderSourceLocRAII srcLocRAII(&builder, inst->sourceLoc);
+ builder.setInsertBefore(inst);
+ auto newVal = builder.emitOptionalHasValue(
+ builder.emitGetOptionalValue(getHasValue->getOptionalOperand()));
+ inst->replaceUsesWith(newVal);
+ maybeRemoveOldInst(inst);
+ changed = true;
+ }
+ else
+ {
+ IRBuilder builder(module);
+ IRBuilderSourceLocRAII srcLocRAII(&builder, inst->sourceLoc);
+ builder.setInsertBefore(inst);
+ auto trueVal = builder.getBoolValue(true);
+ inst->replaceUsesWith(trueVal);
+ maybeRemoveOldInst(inst);
+ changed = true;
+ }
}
else if (inst->getOperand(0)->getOp() == kIROp_MakeOptionalNone)
{