<feed xmlns='http://www.w3.org/2005/Atom'>
<title>slang.git/tests/diagnostics/gh-1374.slang, branch master</title>
<subtitle>Making it easier to work with shaders</subtitle>
<id>https://git.yummers.dev/slang.git/atom?h=master</id>
<link rel='self' href='https://git.yummers.dev/slang.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/'/>
<updated>2020-06-12T20:30:32+00:00</updated>
<entry>
<title>Diagnose circularly-defined constants (#1384)</title>
<updated>2020-06-12T20:30:32+00:00</updated>
<author>
<name>Tim Foley</name>
<email>tfoleyNV@users.noreply.github.com</email>
</author>
<published>2020-06-12T20:30:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=36a06f1289c9a68a261920ef5d34f075f2a43219'/>
<id>urn:sha1:36a06f1289c9a68a261920ef5d34f075f2a43219</id>
<content type='text'>
* Diagnose circularly-defined constants

Work on #1374

This change diagnoses cases like the following:

```hlsl
static const int kCircular = kCircular;

static const int kInfinite = kInfinite + 1;

static const int kHere = kThere;
static const int kThere = kHere;
```

By diagnosing these as errors in the front-end we protect against infinite recursion leading to stack overflow crashes.

The basic approach is to have front-end constant folding track variables that are in use when folding a sub-expression, and then diagnosing an error if the same variable is encountered again while it is in use. In order to make sure the error occurs whether or not the constant is referenced, we invoke constant folding on all `static const` integer variables.

Limitations:

* This only works for integers, since that is all front-end constant folding applies to. A future change can/should catch circularity in constants at the IR level (and handle more types).

* This only works for constants. Circular references in the definition of a global variable are harder to diagnose, but at least shouldn't result in compiler crashes.

* This doesn't work across modules, or through generic specialization: anything that requires global knowledge won't be checked

* fixup: missing files

* fixup: review feedback</content>
</entry>
</feed>
