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

Clouudy Swergers123 at gmail.com
Mon Oct 6 18:21:21 UTC 2025


On Monday, 6 October 2025 at 12:28:33 UTC, Dennis wrote:
> 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.

The idea I have is that you could iterate over every 
sub-expression within a constraint; for each sub-expression you'd 
determine whether it relies on just the first template parameter 
or if it needs other parameters as well. Then for each 
sub-expression that only needs the first template parameter you 
can verify whether that sub-expression evaluates to true or not. 
Any function with a definitively false constraint gets ruled out, 
while functions that are fully or partially/potentially true get 
offered as suggestions.

This would cover a lot of common constraints like whether 
something is a range or not, or whether it's an instance of a 
specific template type. I don't see any specific reason why it'd 
be impossible to do, at least hypothetically.

> 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.

Like I said I have the basic strategy for how to do this down, I 
just need to know how the frontend works to be able to implement 
it. I guess the specific questions I can ask are:
- How can I use the frontend to determine whether an expression 
can be evaluated or not?
- How can I actually evaluate that expression using the frontend?
- Would it be possible to partially match a template? As in, if 
DMD knows the name of the template and the first parameter, can 
it deduce what the actual template is, or a list of contenders?
- Is there a way to just push through any parsing/semantic 
analysis errors that appear and just mark or identify parts of 
the AST that couldn't be resolved as a result?
- Is there an easy way to get every possible type/variable that 
is visible from within a certain scope? How can I get a scope 
from just the line and character numbers within a file?


More information about the Dlang-internal mailing list