From b54629fe3fc48b42ae7f6c4f4594f85d5934c577 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 25 Apr 2018 11:58:06 -0700 Subject: 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). --- source/slang/ir.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source') 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(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(); -- cgit v1.2.3