Skip to content

Directly desugar lambdas#833

Closed
amomchilov wants to merge 12 commits intoAlex/extract-desugarMethodCallfrom
Alex/desugar-lambda
Closed

Directly desugar lambdas#833
amomchilov wants to merge 12 commits intoAlex/extract-desugarMethodCallfrom
Alex/desugar-lambda

Conversation

@amomchilov
Copy link

Motivation

Test plan

See included automated tests.

Copy link
Author

amomchilov commented Jan 9, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

amomchilov and others added 4 commits January 29, 2026 15:39
* Include parens in multi-target locs

* Delete now-unused loc helpers

* Fix location of `to_ary` call
* extract code to check for visible_to

* inline visibilityApplies

* delete this ENFORCE

* no-op: reorganize

* no-op: causesModularityError -> validToImport

* check visible_to at call sites and don't add imports that would violate visible_to

* test for gen-packages mode

* test for call sites

* use absl::c_any_of
* Skip loop if there's no splats at all

* Move `messageLoc` declaration

* Narrow scope of `blockPassLoc`

* Move `blockExpr` declaration up

* Move symbol proc desugaring up

* Simplify checks for `blockPassArg`

* Simplify checks for `blockExpr`

* Inline `blockPassArgIsSymbol`

* Invert `if`

* Narrow scope of block-related variables

* Narrow scope of `blockStatsStore` check

* Inline `methodName`

* Rename `name` → `methodName`

* Narrow scope of `prismBlock`

* FIXME: move this comment

* Extract `desugarLiteralBlock()`

Co-authored-by: Jesse Johnson <[email protected]>

* Extract `desugarBlockPassArgument()`

Co-authored-by: Jesse Johnson <[email protected]>

* Compare NameRefs instead of strings

* Move receiver handling up

* Lift out `argumentsNode` local

* Reuse `receiverNode` local

* Rename `messageLoc` → `methodNameLoc`

* Extract `desugarBlock()`

* Lift `block` desugaring up

* Migrate `computeMethodCallLoc()` block param

* Lift `block_given?` check up

* Lift `isPrivateOk` local

* Extract `desugarMethodCall()`

Co-authored-by: Alexander Momchilov <[email protected]>

---------

Co-authored-by: Jesse Johnson <[email protected]>
Co-authored-by: Thomas Marshall <[email protected]>
@amomchilov amomchilov force-pushed the Alex/desugar-lambda branch 5 times, most recently from 632e796 to 401023e Compare January 31, 2026 02:08
amomchilov and others added 7 commits February 2, 2026 10:45
* Move getQuickfixEdits to lsp_helpers

* prework: Expand concretizeIfAbstract

We currently don't use this ShowOption for an `overridable`
parent, so this change is a no-op. I thought about having a separate
option, so that callers could opt into the overridable or the abstract
behavior independently, but I don't think that there are any cases where
you really need that level of granularity, so I left it controlled by a
single boolean. I thought for a while about what a good name would be,
but couldn't come up with anything more compelling then the verbose
`concretizeIfAbstractOrOverridable`. Open to suggestions.

* Add a ClassDefResponse to LSP QueryResponse

One thing to note is that I opted not to implement the `retType` method
on `ClassDefResponse`, because this isn't an expression. (Technically it
is: it evaluates to the type of the last thing in the class body, but
Sorbet doesn't model that. Sorbet lies and says that the return type is
`NilClass`, but I figured it would be best to just raise).

I looked at all the places where we are calling `retType` to make sure
that this wouldn't cause problems, and ended up only needing to change
`hover.cc`

For my code action, I only had this match if your cursor is on the
`declLoc`, not if it's inside the `loc` that spans the entire class
body. I think that's something we could reconsider in the future, but I
didn't want to do something where having an extra query response in the
vector of query responses broke or changed the behavior of anything
currently out there—limiting this to only `declLoc` limits the blast
radius a bit.

It also means that, for example, if your cursor is inside the class body
on an empty line or a comment, you aren't presented with a lightbulb
icon. I wanted to avoid having it be the case that there's _always_ a
lightbulb icon following your cursor around.

* Main implementation and tests

* Add a quick screencast to the docs

* fastmod getQuickfixEdits autocorrect2DocumentEdits

* no-op: Remove core::

* Add test for Class.new

* Handle case of no responses

* clang-format

* Fix the <root> declLoc problem

* Fix CheckSize for ClassDefResponse
* Move getQuickfixEdits to lsp_helpers

* prework: Expand concretizeIfAbstract

We currently don't use this ShowOption for an `overridable`
parent, so this change is a no-op. I thought about having a separate
option, so that callers could opt into the overridable or the abstract
behavior independently, but I don't think that there are any cases where
you really need that level of granularity, so I left it controlled by a
single boolean. I thought for a while about what a good name would be,
but couldn't come up with anything more compelling then the verbose
`concretizeIfAbstractOrOverridable`. Open to suggestions.

* Add a ClassDefResponse to LSP QueryResponse

One thing to note is that I opted not to implement the `retType` method
on `ClassDefResponse`, because this isn't an expression. (Technically it
is: it evaluates to the type of the last thing in the class body, but
Sorbet doesn't model that. Sorbet lies and says that the return type is
`NilClass`, but I figured it would be best to just raise).

I looked at all the places where we are calling `retType` to make sure
that this wouldn't cause problems, and ended up only needing to change
`hover.cc`

For my code action, I only had this match if your cursor is on the
`declLoc`, not if it's inside the `loc` that spans the entire class
body. I think that's something we could reconsider in the future, but I
didn't want to do something where having an extra query response in the
vector of query responses broke or changed the behavior of anything
currently out there—limiting this to only `declLoc` limits the blast
radius a bit.

It also means that, for example, if your cursor is inside the class body
on an empty line or a comment, you aren't presented with a lightbulb
icon. I wanted to avoid having it be the case that there's _always_ a
lightbulb icon following your cursor around.

* Main implementation and tests

* Add a quick screencast to the docs

* fastmod getQuickfixEdits autocorrect2DocumentEdits

* no-op: Remove core::

* Add test for Class.new

* Handle case of no responses

* clang-format

* Fix the <root> declLoc problem

* Fix CheckSize for ClassDefResponse

* prework: Add declLoc to MethodDefResponse

Previously, `termLoc` was `declLoc`, so I've also changed all the old
usages of `termLoc` to `declLoc` to preserve the existing behavior.

* prework: Only store the FileRef once to save space

* prework: Add isAttrBestEffortUIOnly

* Add completion item to override a method

* Add a test

* Add docs to website

* Ban this test

The file fails to parse, and prism doesn't handle those yet.
* prework: Add declLoc to MethodDefResponse

Previously, `termLoc` was `declLoc`, so I've also changed all the old
usages of `termLoc` to `declLoc` to preserve the existing behavior.

* prework: Only store the FileRef once to save space

* prework: Add isAttrBestEffortUIOnly

* Add completion item to override a method

* Add a test

* Add docs to website

* Ban this test

The file fails to parse, and prism doesn't handle those yet.
@amomchilov
Copy link
Author

Upstreamed in sorbet#9825

@amomchilov amomchilov closed this Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants