Skip to content

Bare functions, typesafe spawn, function subtyping - #1051

Closed
brson wants to merge 21 commits into
rust-lang:masterfrom
brson:barefn-review
Closed

brson wants to merge 21 commits into
rust-lang:masterfrom
brson:barefn-review

Conversation

@brson

@brson brson commented Oct 20, 2011

Copy link
Copy Markdown
Contributor

This series does a lot of things to implement bare functions. It results in some things being more complicated and/or less pleasant to use, so I'd like to provide an opportunity to review it before I push.

At the end of the series, fn is a bare function, fn@ is a shared function and lambda is sugar for fn@.

385e595 introduces a spawn function that takes a bare function. This commit is still using a temporary fn# syntax for bare functions. Spawning now looks like

spawn(my_data, fn#(my_data: my_data_type) { /* work */ });

788be70 creates a subtyping relationship between function types, where fn# < fn@ < block. This is the only subtyping in the language besides mutable?, and the implementation is currently trivial as I've left the implementation of bare functions the same as closures.

7c81430 makes the big conversion from the existing fn to bare functions and shared closures. In the process many higher-order functions had to be changed to take fn@ and many generic functions had to be instantiated with bind (to convert them to a fn@).

TODO:

  • After snapshotting, the temorary syntax needs to be removed.
  • We need to make a decision about fn@/lambda and fn&/block, whether we want one or both forms.
  • Spawn is still ultimately implemented in terms of shared closures, but that implementation is unexported. Spawn should be rewritten.
  • We need to be able to instantiate generic bare functions, but that requires monomorphising.
  • Remove the environment parameter from bare functions and give them a single-word representation.

brson added 21 commits October 18, 2011 16:43
Currently they just wrap the unsafe versions. Will need to be rewritten
eventually.

Issue rust-lang#1022
This can't be done with bare functions.

Issue rust-lang#1022
Delete the rest of the old, unused spawn functions.

Issue rust-lang#1022
The meaning of various fn incantations is going to get temporarily confusing
fn is a proper subtype of block now
I don't know if this is the right thing to do, but it works
and it lets 'fn' always mean proto_bare
Now they are both just proto_shared and proto_shared takes an
argument indicating that it is sugared as 'lambda'
fn@ is intended to be caputring but isn't implemented.
Had to ignore some task failure tests due to the current implementation
of spawn which guarantees that there's always something in the spawned
task that needs to be unwound.

Fixed some win-specific build problems.
@marijnh

marijnh commented Oct 20, 2011

Copy link
Copy Markdown
Contributor

I still think lambda and block are better names than the sigil-abusing ones (especially since we're already overloading @ to the breaking point.

Apart from that, I think this works well.

@brson

brson commented Oct 21, 2011

Copy link
Copy Markdown
Contributor Author

I've put off the final decision on lambda a while longer. Thanks for the review marijnh.

@brson brson closed this Oct 21, 2011
U007D pushed a commit to U007D/rust-mos that referenced this pull request Aug 21, 2026
1051: Move ra_ide_api unit tests r=matklad a=detrumi

Closes rust-lang#1048

Co-authored-by: Wilco Kusee <wilcokusee@gmail.com>
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.

2 participants