Skip to content

CLS: advanced return type inlays#28886

Open
DanilaFe wants to merge 21 commits into
chapel-lang:mainfrom
DanilaFe:super-return-type-inlays
Open

CLS: advanced return type inlays#28886
DanilaFe wants to merge 21 commits into
chapel-lang:mainfrom
DanilaFe:super-return-type-inlays

Conversation

@DanilaFe

Copy link
Copy Markdown
Contributor

Builds on #28885.

I thought -- wouldn't it be super cool to show the return type of proc foo(x) do return x as x.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.type above) 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.

Screenshot 2026-05-26 at 3 44 13 PM

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 Resolver re-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 producing AnyTypes (normal) instead of PlaceholderTypes (unique to template signatures). To address this, add a 'isTemplateSignature' flag to the typed signature struct, and ensure the resolver creates PlaceholderTypes for template signatures.

Testing

  • CLS tests

Comment on lines +150 to 153
| | | |
| | Affects type, param, and return type | |
| | inlays. | |
+----------------+--------------------------------------------+---------------------------------------+

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment doesn't seem necessary

Comment thread tools/chpl-language-server/test/return_type_inlays.py
proc id(type x) type do return x;
proc weird(x: id(?hmm)) do return x;
"""
inlays = [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test for weird(x: id?hmm)): hmm?

Comment thread tools/chpl-language-server/src/chpl-language-server.py
@DanilaFe DanilaFe force-pushed the super-return-type-inlays branch from 33a207f to 3ee69c3 Compare June 2, 2026 21:23
Comment thread tools/chpl-language-server/src/chpl-language-server.py Outdated
Comment thread tools/chpl-language-server/src/chpl-language-server.py
Comment thread tools/chpl-language-server/src/chpl-language-server.py
Comment thread tools/chpl-language-server/src/chpl-language-server.py Outdated
Comment thread tools/chpl-language-server/test/return_type_inlays.py
Comment thread tools/chpl-language-server/src/chpl-language-server.py
DanilaFe added 19 commits June 4, 2026 20:39
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>
@DanilaFe DanilaFe force-pushed the super-return-type-inlays branch from 8309465 to f958ced Compare June 5, 2026 03:43
DanilaFe added 2 commits June 4, 2026 20:44
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
Signed-off-by: Danila Fedorin <daniel.fedorin@hpe.com>
@arifthpe arifthpe self-requested a review June 5, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants