[Dlang-internal] Frontend Issues w/ implementing UFCS Partial Template Evaluation (for language server use)

Dennis dkorpel at gmail.com
Mon Oct 6 12:28:33 UTC 2025


On Wednesday, 1 October 2025 at 23:26:53 UTC, Clouudy wrote:
> From the checking
> around I've done within the compiler, I haven't really found a
> function that can evaluate *only* that the first argument can
> be used with a specific template function, but not check any
> other arguments or unrelated constraints.

This looks like an intractable problem in the general case. 
Consider this function:

```D
void f(R, E)(R r, E e) if (Check!(R, E))
```

When the first argument is an `int` for example, how would you 
deduce whether Check!(int, E) is satisfiable for some E? 
Templates are not invertible like that.

> Without the ability to perform partial template evaluation, 
> completion from libraries such as `std.algorithm` would be 
> unwieldy and inaccurate, and the completion suggestions would 
> be about as bad as DCD's, or would be hardcoded only for 
> standard library functions.

Given the above, I think you still need to find a pragmatic 
simplification of the problem. Start with the most optimistic 
auto-completion possible, and collect a bunch of failure cases 
from real world usage where it does nonsense suggestions. Then 
inspect those cases and see if there's some property you can 
detect to prune most of the wrong candidates.

> I know that there was already talk about getting a DMD-based 
> language server off the ground before I started this project 
> myself; I would appreciate it if I could get some help on 
> solving this issue (either by suggesting methods for partial 
> evaluation or creating them if none are completely workable), 
> so that I can help accomplish this. Thank you.

I don't think I can offer concrete advice before trying to 
implement auto-completions myself first, but you're always 
welcome to ask more specific questions about the DMD code base.


More information about the Dlang-internal mailing list