CLS: advanced return type inlays#28886
Open
DanilaFe wants to merge 21 commits into
Open
Conversation
jabraham17
reviewed
May 26, 2026
Comment on lines
+150
to
153
| | | | | | ||
| | | Affects type, param, and return type | | | ||
| | | inlays. | | | ||
| +----------------+--------------------------------------------+---------------------------------------+ |
Member
There was a problem hiding this comment.
nit, this should technically go on the previous PR. But no strong need to change the git history imo
| formalsErroredBitmap, | ||
| std::move(visitor.outerVariables)); | ||
| std::move(visitor.outerVariables), | ||
| /* usePlaceholders */ usePlaceholders); |
Member
There was a problem hiding this comment.
this comment doesn't seem necessary
| proc id(type x) type do return x; | ||
| proc weird(x: id(?hmm)) do return x; | ||
| """ | ||
| inlays = [ |
Member
There was a problem hiding this comment.
A test for weird(x: id?hmm)): hmm?
33a207f to
3ee69c3
Compare
arifthpe
requested changes
Jun 4, 2026
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
8309465 to
f958ced
Compare
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
arifthpe
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #28885.
I thought -- wouldn't it be super cool to show the return type of
proc foo(x) do return xasx.type? Turns out, it's possible!This PR enables CLS to infer types for generic functions without needing their instantiations. This works best with parametrically polymorphic functions. I've added support for referring to formals (
x.typeabove) and to type queries, including some fairly convoluted cases. I haven't found this to be particularly unstable, but it does lean on some pretty tricky machinery (see below), so I disabled this feature by default.This works by leveraging the machinery I built up for interface resolution in #26396. Specifically, it leans on Dyno's 'template signature' functionality, which creates a signature for a generic function where generic formals are give unique, concrete "placeholder types". The idea is to resolve a function with this signature and compute its return type. If the return type contains a reference to the placeholder type, and we know that placeholder type was (e.g.) created for a formal, we can replace the placeholder type with
formal.type.Placeholder types are only used in interface resolution in Dyno (making them niche), and resolving placeholder functions has never been done before. This is what makes this approach "tricky", and this is why I disabled it by default.
Honestly, that's mostly it. There was an issue caused by the
Resolverre-resolving function formals while resolving a function (even though we've already resolved them while computing the original typed signature). This is a long-standing concern, but seems relatively hard to fix in a principled manner. For this PR, the core issue was that the re-resolution was producingAnyTypes (normal) instead ofPlaceholderTypes (unique to template signatures). To address this, add a 'isTemplateSignature' flag to the typed signature struct, and ensure the resolver createsPlaceholderTypes for template signatures.Testing