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

Dennis dkorpel at gmail.com
Mon Oct 6 20:04:43 UTC 2025


On Monday, 6 October 2025 at 18:21:21 UTC, Clouudy wrote:
> - 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?

You can use `trySemantic` which returns `null` on failure, or the 
result of semantic analysis on the Expression on success. 
'evaluate' in the frontend usually refers to constant folding / 
CTFE, but I assume you don't need that here.

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

It's possible if you implement that logic yourself. You can maybe 
re-use bits like `deduceType` or `matchArg`, but dmd's 
`functionResolve` routine is made to resolve a complete argument 
list.

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

To prevent error messages from showing up, perhaps look at 
existing use of `global.startGagging`. DMD already creates error 
nodes (ErrorExp) for parts that fail to analyze, but it's only 
designed to reduce the chance of a blizzard of cascaded errors. 
It might not be good enough for your use case.

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

DMD's scopes are a stack made just for quick lookups while 
compiling. It doesn't retain a nice scope graph data structure or 
anything, and I remember Razvan (who has been working a lot on 
DMD as a library) stumbling on this before.


More information about the Dlang-internal mailing list