summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-check-recursive-type.cpp
diff options
context:
space:
mode:
authorDarren Wihandi <65404740+fairywreath@users.noreply.github.com>2024-12-05 20:09:40 -0500
committerGitHub <noreply@github.com>2024-12-05 17:09:40 -0800
commitecc5a39feecbf73feedf352214406c8752af798a (patch)
treedcb65f45cbca2dae0ffe0cf7b68b4e4f5f410f46 /source/slang/slang-ir-check-recursive-type.cpp
parentd4136c93448bfdd8561af331ea6eebcec14719e3 (diff)
Do recursive function checks early during IR linking (#5777)
Diffstat (limited to 'source/slang/slang-ir-check-recursive-type.cpp')
-rw-r--r--source/slang/slang-ir-check-recursive-type.cpp65
1 files changed, 0 insertions, 65 deletions
diff --git a/source/slang/slang-ir-check-recursive-type.cpp b/source/slang/slang-ir-check-recursive-type.cpp
deleted file mode 100644
index ee4541735..000000000
--- a/source/slang/slang-ir-check-recursive-type.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "slang-ir-check-recursive-type.h"
-
-#include "slang-ir-util.h"
-
-namespace Slang
-{
-bool checkTypeRecursionImpl(
- HashSet<IRInst*>& checkedTypes,
- HashSet<IRInst*>& stack,
- IRInst* type,
- IRInst* field,
- DiagnosticSink* sink)
-{
- auto visitElementType = [&](IRInst* elementType, IRInst* field) -> bool
- {
- if (!stack.add(elementType))
- {
- sink->diagnose(field ? field : type, Diagnostics::recursiveType, type);
- return false;
- }
- if (checkedTypes.add(elementType))
- checkTypeRecursionImpl(checkedTypes, stack, elementType, field, sink);
- stack.remove(elementType);
- return true;
- };
- if (auto arrayType = as<IRArrayTypeBase>(type))
- {
- return visitElementType(arrayType->getElementType(), field);
- }
- else if (auto structType = as<IRStructType>(type))
- {
- for (auto sfield : structType->getFields())
- if (!visitElementType(sfield->getFieldType(), sfield))
- return false;
- }
- return true;
-}
-
-void checkTypeRecursion(HashSet<IRInst*>& checkedTypes, IRInst* type, DiagnosticSink* sink)
-{
- HashSet<IRInst*> stack;
- if (checkedTypes.add(type))
- {
- stack.add(type);
- checkTypeRecursionImpl(checkedTypes, stack, type, nullptr, sink);
- }
-}
-
-void checkForRecursiveTypes(IRModule* module, DiagnosticSink* sink)
-{
- HashSet<IRInst*> checkedTypes;
- for (auto globalInst : module->getGlobalInsts())
- {
- switch (globalInst->getOp())
- {
- case kIROp_StructType:
- {
- checkTypeRecursion(checkedTypes, globalInst, sink);
- }
- break;
- }
- }
-}
-
-} // namespace Slang