KhronosGroup / KhronosGroup/GLSL

Supporting tail-recursion in GLSL

Open
#134 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
458
Forks
114
Avg merge
4m
Merged PRs (30d)
1

Description

GLSL currently does not support tail recursion, but this feature could be easily implemented using tail-call optimization. For example, this function is not yet compatible with GLSL:

```
int fib(int n)
{
if (n <= 1)
return n;
return fib(n - 1) + fib(n - 2);
}
```

But it's possible to eliminate recursion here, replacing the recursive call with a for-loop:

```
int fib(int n)
{
int a = 0, b = 1, c, i;
if (n == 0)
return a;
for (i = 2; i <= n; i++)
{
c = a + b;
a = b;
b = c;
}
return b;
}
```
Are there any plans to implement tail-recursion in a future version of GLSL?

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the GLSL specification and the existing recursion or function-call rules; the issue names no specific file or test. Determine whether tail recursion belongs in the language specification and define the required behavior and validation before implementation.

Written by the indexing model from the issue text.

Assessment

Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.