summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-05-30 21:15:55 -0700
committerGitHub <noreply@github.com>2023-05-30 21:15:55 -0700
commit5c28677ff8bb1ab498954795ae3907f3b6c3b03f (patch)
tree9056f65b0637a61700cd70c1af84d5b97b8c1b69 /source
parent5e1974e8cad3396a8c4bedfd63c1ad31b82ec8eb (diff)
Fix type checking & loop value hoisting (#2907)
* Fix type checking crash in language server. * Fix loop var hoisting logic. Fixes #2903. * fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check-constraint.cpp2
-rw-r--r--source/slang/slang-check-overload.cpp13
-rw-r--r--source/slang/slang-ir-autodiff-cfg-norm.cpp30
-rw-r--r--source/slang/slang-ir-validate.cpp9
-rw-r--r--source/slang/slang-stdlib.cpp2
5 files changed, 39 insertions, 17 deletions
diff --git a/source/slang/slang-check-constraint.cpp b/source/slang/slang-check-constraint.cpp
index cdffcf004..42d01a996 100644
--- a/source/slang/slang-check-constraint.cpp
+++ b/source/slang/slang-check-constraint.cpp
@@ -792,6 +792,8 @@ namespace Slang
Type* fst,
Type* snd)
{
+ if (!fst) return false;
+
if (fst->equals(snd)) return true;
// An error type can unify with anything, just so we avoid cascading errors.
diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp
index 4bd8506ed..0d10b05be 100644
--- a/source/slang/slang-check-overload.cpp
+++ b/source/slang/slang-check-overload.cpp
@@ -409,11 +409,12 @@ namespace Slang
auto& arg = context.getArg(ii);
auto argType = context.getArgType(ii);
auto paramType = paramTypes[ii];
-
+ if (!paramType)
+ return false;
+ if (!argType)
+ return false;
if (context.mode == OverloadResolveContext::Mode::JustTrying)
{
- SLANG_ASSERT(argType);
-
ConversionCost cost = kConversionCost_None;
if( context.disallowNestedConversions )
{
@@ -1656,7 +1657,11 @@ namespace Slang
for( UInt aa = 0; aa < argCount; ++aa )
{
if(aa != 0) argsListBuilder << ", ";
- context.getArgType(aa)->toText(argsListBuilder);
+ auto argType = context.getArgType(aa);
+ if (argType)
+ context.getArgType(aa)->toText(argsListBuilder);
+ else
+ argsListBuilder << "error";
}
argsListBuilder << ")";
return argsListBuilder.produceString();
diff --git a/source/slang/slang-ir-autodiff-cfg-norm.cpp b/source/slang/slang-ir-autodiff-cfg-norm.cpp
index 1727f7d8f..30c8a934e 100644
--- a/source/slang/slang-ir-autodiff-cfg-norm.cpp
+++ b/source/slang/slang-ir-autodiff-cfg-norm.cpp
@@ -709,24 +709,30 @@ void normalizeCFG(
IRBuilder builder(func);
for (auto b : workList)
{
- for (auto inst : b->getChildren())
+ for (auto inst : b->getModifiableChildren())
{
// If inst has uses outside the loop body, we need to hoist it.
IRVar* tempVar = nullptr;
- for (auto use = inst->firstUse; use; use = use->nextUse)
+ if (auto var = as<IRVar>(inst))
{
- auto userBlock = as<IRBlock>(use->getUser()->getParent());
- if (userBlock && !workListSet.contains(userBlock))
+ for (auto use = inst->firstUse; use; use = use->nextUse)
{
- // Hoist the inst.
- if (auto var = as<IRVar>(inst))
+ // If inst is an var, this is easy, we just move it to the
+ // loop header.
+ auto userBlock = as<IRBlock>(use->getUser()->getParent());
+ if (userBlock && !workListSet.contains(userBlock))
{
- // If inst is an var, this is easy, we just move it to the
- // loop header.
var->insertBefore(insertionPoint);
break;
}
- else
+ }
+ }
+ else
+ {
+ traverseUses(inst, [&](IRUse* use)
+ {
+ auto userBlock = as<IRBlock>(use->getUser()->getParent());
+ if (userBlock && !workListSet.contains(userBlock))
{
// For all other insts, we need to create a local var for it.
if (!tempVar)
@@ -741,8 +747,7 @@ void normalizeCFG(
auto load = builder.emitLoad(tempVar);
builder.replaceOperand(use, load);
}
- break;
- }
+ });
}
}
}
@@ -751,6 +756,9 @@ void normalizeCFG(
disableIRValidationAtInsert();
constructSSA(module, func);
enableIRValidationAtInsert();
+#if _DEBUG
+ validateIRInst(func);
+#endif
}
} // namespace Slang
diff --git a/source/slang/slang-ir-validate.cpp b/source/slang/slang-ir-validate.cpp
index 18229c9b6..bf1ce1956 100644
--- a/source/slang/slang-ir-validate.cpp
+++ b/source/slang/slang-ir-validate.cpp
@@ -144,7 +144,14 @@ namespace Slang
auto operandParent = operandValue->getParent();
- if (auto instParentBlock = as<IRBlock>(instParent))
+ auto instParentBlock = as<IRBlock>(instParent);
+ if (!instParentBlock && as<IRDecoration>(inst))
+ {
+ instParent = instParent->getParent();
+ instParentBlock = as<IRBlock>(instParent);
+ }
+
+ if (instParentBlock)
{
if (auto operandParentBlock = as<IRBlock>(operandParent))
{
diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp
index f80254ba6..1f8d0a97a 100644
--- a/source/slang/slang-stdlib.cpp
+++ b/source/slang/slang-stdlib.cpp
@@ -221,7 +221,7 @@ namespace Slang
static const IntrinsicOpInfo intrinsicUnaryOps[] = {
{ kIROp_Neg, "neg", "-", "__BuiltinArithmeticType", ARITHMETIC_MASK },
{ kIROp_Not, "logicalNot", "!", nullptr, BOOL_MASK | BOOL_RESULT },
- { kIROp_BitNot, "not", "~", "__BuiltinIntegerType", INT_MASK },
+ { kIROp_BitNot, "not", "~", "__BuiltinLogicalType", INT_MASK },
};
static const IntrinsicOpInfo intrinsicBinaryOps[] = {