summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-lower-generics.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-08-18 13:08:45 -0700
committerGitHub <noreply@github.com>2020-08-18 13:08:45 -0700
commitb820f34a1b6336af184458c5b1dfe2273c99f1ff (patch)
treeca9986891127cfe07eda18bfbdb5094eef5677cc /source/slang/slang-ir-lower-generics.cpp
parent9abcb6ea24dbc7184c3a2ad9f4458f63f8901928 (diff)
Support initializing an existential value from a generic value. (#1503)
* Support initializing an existential value from a generic value. * Remove trailing spaces and clean up debugging code.
Diffstat (limited to 'source/slang/slang-ir-lower-generics.cpp')
-rw-r--r--source/slang/slang-ir-lower-generics.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/source/slang/slang-ir-lower-generics.cpp b/source/slang/slang-ir-lower-generics.cpp
index b00e36ef1..63e1fdc49 100644
--- a/source/slang/slang-ir-lower-generics.cpp
+++ b/source/slang/slang-ir-lower-generics.cpp
@@ -2,6 +2,7 @@
#include "slang-ir-lower-generics.h"
#include "slang-ir-any-value-marshalling.h"
+#include "slang-ir-augment-make-existential.h"
#include "slang-ir-generics-lowering-context.h"
#include "slang-ir-lower-existential.h"
#include "slang-ir-lower-generic-function.h"
@@ -21,9 +22,15 @@ namespace Slang
sharedContext.module = module;
sharedContext.sink = sink;
- lowerExistentials(&sharedContext);
- if (sink->getErrorCount() != 0)
- return;
+ // Replace all `makeExistential` insts with `makeExistentialWithRTTI`
+ // before making any other changes. This is necessary because a parameter of
+ // generic type will be lowered into `AnyValueType`, and after that we can no longer
+ // access the original generic type parameter from the lowered parameter value.
+ // This steps ensures that the generic type parameter is available via an
+ // explicit operand in `makeExistentialWithRTTI`, so that type parameter
+ // can be translated into an RTTI object during `lower-generic-type`,
+ // and used to create a tuple representing the existential value.
+ augmentMakeExistentialInsts(module);
lowerGenericFunctions(&sharedContext);
if (sink->getErrorCount() != 0)
@@ -33,6 +40,10 @@ namespace Slang
if (sink->getErrorCount() != 0)
return;
+ lowerExistentials(&sharedContext);
+ if (sink->getErrorCount() != 0)
+ return;
+
lowerGenericCalls(&sharedContext);
if (sink->getErrorCount() != 0)
return;