From 00490154ef0762839556b5884ba9b7523b265a1c Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 21 Dec 2017 16:16:23 -0800 Subject: Support generic `struct` types during IR-based emit Fixes #318 Most of the required support was actually in place, so this is just a bunch of fixes: - Detect when we are in "full IR" mode, so that we can always emit `struct` declarations with their mangled named (which will produce different names for different specializations, since we emit decl-refs) - Carefully exclude builtin types from this for now. We'll need a more complete solution for mapping HLSL/Slang builtin types to their GLSL equivalents soon. - Skip emitting types referenced by generic IR functions, since they might not be usable. - Also fix things up so that we emit types used in the initializer for any global variables. - Fix bug in generic specialization where we specialize the same function more than once, with different type arguments. We were crashing on a `Dictionary::Add` call where the key already exists from a previous specialization attempt. - Fix name-mangling logic so that when outputting a possibly-specialized generic it looks for the outer-most `GenericSubstitution` rather than just the first one in the list. This is to handle the way that we insert other substitutions willy-nilly in places where they realistically don't belong. :( All of these changes together allow us to pass a slightly modified (more advanced) version of the test case posted to #318. --- source/slang/ir.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'source/slang/ir.cpp') diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 38a0f0c03..cd36e8d47 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -3079,7 +3079,20 @@ namespace Slang { if(!originalValue) return; - context->getClonedValues().Add(originalValue, clonedValue); + + // Note: setting the entry direclty here rather than + // using `Add` or `AddIfNotExists` because we can conceivably + // clone the same value (e.g., a basic block inside a generic + // function) multiple times, and that is okay, and we really + // just need to keep track of the most recent value. + + // TODO: The same thing could potentially be handled more + // cleanly by having a notion of scoping for these cloned-value + // mappings, so that we register cloned values for things + // inside of a function to a temporary mapping that we + // throw away after the function is done. + + context->getClonedValues()[originalValue] = clonedValue; } // Information on values to use when registering a cloned value -- cgit v1.2.3