Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sempass2: lift capture restriction #1427

Merged

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Aug 21, 2024

Summary

Procedures useable in both compile- and run-time contexts can now close
over compile-time-only locals even if nested in another procedure
usable in both contexts.

Fixes #1425.

Details

Given the nested procedures a: b: c:, where c closes over a local
of a, c effectively captures from b and b captures from a.

A procedure usable in both a compile- and run-time context may capture
from a compile-time-only procedure, so the aforementioned should work
when a is a compile-time-only procedure and the others are not, since
c can legally borrow from b and b from a, but it was disallowed
in practice.

The arbitrary restriction is now lifted, and the code implementing the
test restructured to be easier to understand.

Given the nested procedures `a: b: c:`, where `c` closes over a local
of `a`, `c` effectively captures from `b` and `b` captures from `a`. A
procedure usable in both a compile- and run-time context may capture
from a compile-time-only procedure, so the aforementioned should work
when `a` is a compile-time-only procedure and the others are not, but
it was forbidden in practice.

The restriction is now lifted, and the code implementing the test
restructured to be more intelligible.
@zerbina zerbina added compiler/sem Related to semantic-analysis system of the compiler language-design Language design syntax, semantics, types, statics and dynamics. labels Aug 21, 2024
@saem
Copy link
Collaborator

saem commented Aug 21, 2024

/merge

Copy link

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


Notes for Reviewers

  • the canCaptureFrom code was, in my opinion, unnecessarily hard to parse, so I restructured it a bit

@chore-runner chore-runner bot added this pull request to the merge queue Aug 21, 2024
Merged via the queue into nim-works:devel with commit 5178f0a Aug 21, 2024
35 checks passed
@zerbina zerbina deleted the lift-closure-capture-restriction branch August 21, 2024 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/sem Related to semantic-analysis system of the compiler language-design Language design syntax, semantics, types, statics and dynamics.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Variables in {.compileTime.} cannot be captured if the capturing closure is nested twice
2 participants