summaryrefslogtreecommitdiffstats
path: root/source/slang/check.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/check.cpp')
-rw-r--r--source/slang/check.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp
index 6a40f436a..d51785112 100644
--- a/source/slang/check.cpp
+++ b/source/slang/check.cpp
@@ -10763,6 +10763,41 @@ static bool doesParameterMatch(
Slang::_specializeExistentialTypeParams(getLinkage(), m_globalExistentialSlots, args, sink);
}
+ Type* Linkage::specializeType(
+ Type* unspecializedType,
+ Int argCount,
+ Type* const* args,
+ DiagnosticSink* sink)
+ {
+ // TODO: We should cache and re-use specialized types
+ // when the exact same arguments are provided again later.
+
+ SemanticsVisitor visitor(this, sink);
+
+
+ ExistentialTypeSlots slots;
+ _collectExistentialTypeParamsRec(slots, unspecializedType);
+
+ assert(slots.paramTypes.getCount() == argCount);
+
+ for( Int aa = 0; aa < argCount; ++aa )
+ {
+ auto argType = args[aa];
+
+ ExistentialTypeSlots::Arg arg;
+ arg.type = argType;
+ arg.witness = visitor.tryGetSubtypeWitness(argType, slots.paramTypes[aa]);
+ slots.args.add(arg);
+ }
+
+ RefPtr<ExistentialSpecializedType> specializedType = new ExistentialSpecializedType();
+ specializedType->baseType = unspecializedType;
+ specializedType->slots = slots;
+
+ m_specializedTypes.add(specializedType);
+
+ return specializedType;
+ }
/// Specialize a program to global generic arguments
RefPtr<Program> createSpecializedProgram(