summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-04-25 11:58:06 -0700
committerGitHub <noreply@github.com>2018-04-25 11:58:06 -0700
commitb54629fe3fc48b42ae7f6c4f4594f85d5934c577 (patch)
tree44781f1fbf7a513fbdde028f9f06f8d916c0d652 /source
parent9a7849d893ebb755a607befff6b3429830421112 (diff)
Fix for global generic parameter substitution (#512)
The problem here arises when multiple entry points are compiled in one pass. Each entry point has its own arguments for global generic parameters, and leads to us emitting a `bindGlobalGenericParameter(p, val)`. But once the first entry point's substitutions are applied, the second entry point's code gives `bindGlobalGenericParameter(val, val)` and the compiler crashes (in debug builds) because `val` is not a global generic parameter. This change just applies a quick fix. If we see `bindGlobalGenericParameter(x,y)` during specialization, and `x` is not a global generic parameter, then we skip it. The right long-term fix is to change the compiler's representation of global generic arguments so that they live on a `CompileRequest` instead of an `EntryPointRequest`. That is a more significant change (with impact on the public API), so I'm inclined to leave it as a cleanup for another day (given that no customers are using global generic parameters today).
Diffstat (limited to 'source')
-rw-r--r--source/slang/ir.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp
index 2b0e19a0c..a4a118250 100644
--- a/source/slang/ir.cpp
+++ b/source/slang/ir.cpp
@@ -6252,6 +6252,20 @@ namespace Slang
if(!bindInst)
continue;
+ // HACK: Our current front-end emit logic can end up emitting multiple
+ // `bindGlobalGeneric` instructions for the same parameter. This is
+ // a buggy behavior, but a real fix would require refactoring the way
+ // global generic arguments are specified today.
+ //
+ // For now we will do a sanity check to detect parameters that
+ // have already been specialized.
+ if( !as<IRGlobalGenericParam>(bindInst->getOperand(0)) )
+ {
+ // parameter operand is no longer a parameter, so it
+ // seems things must have been specialized already.
+ continue;
+ }
+
auto param = bindInst->getParam();
auto val = bindInst->getVal();