Skip to content

Commit 93f0e9b

Browse files
committed
Refine notes in kind.rs some more. Add a fixme to ty.rs.
Kinds are still pretty wobbly. See thread starting at https://mail.mozilla.org/pipermail/rust-dev/2011-September/000807.html
1 parent 798b353 commit 93f0e9b

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

src/comp/middle/kind.rs

+36-16
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,28 @@
3030
* you write fn<@T>(...). And if you need neither -- can work with any sort of
3131
* pinned data at all -- then you write fn<T>(...).
3232
*
33-
*
3433
* Most types are unique or shared. Other possible name combinations for these
3534
* two: (tree, graph; pruned, pooled; message, local; owned, common) are
3635
* plausible but nothing stands out as completely pithy-and-obvious.
3736
*
38-
* Resources cannot be copied or sent; they're pinned. They can't be copied
39-
* because it would interfere with destruction (multiple destruction?) They
40-
* cannot be sent because we don't want to oblige the communication system to
41-
* run destructors in some weird limbo context of messages-in-transit. It
42-
* should always be ok to just free messages it's dropping.
37+
* Pinned values arise in 2 contexts: resources and &-closures (blocks). The
38+
* latter absolutely must not be moved, since they could escape to the heap;
39+
* the former must not be copied, since they'd then be multiply-destructed.
40+
* We achieve the no-copy restriction by recycling the no-move restriction
41+
* in place on pinned kinds for &-closures; and as a benefit we can guarantee
42+
* that a resource passed by reference to C will never move during its life,
43+
* occasionally useful for FFI-code.
44+
*
45+
* Resources cannot be sent because we don't want to oblige the communication
46+
* system to run destructors in some weird limbo context of
47+
* messages-in-transit. It should always be ok to just free messages it's
48+
* dropping. Even if you wanted to send them, you'd need a new sigil for the
49+
* NOMOVE + SEND combination, and you couldn't use the move-mode library
50+
* interface to chan.send in that case (NOMOVE after all), so the whole thing
51+
* wouldn't really work as minimally as the encoding we have here.
4352
*
4453
* Note that obj~ and fn~ -- those that capture a unique environment -- can be
45-
* sent, so satisfy ~T. So can plain obj and fn.
46-
*
54+
* sent, so satisfy ~T. So can plain obj and fn. They can all also be copied.
4755
*
4856
* Further notes on copying and moving; sending is accomplished by calling a
4957
* move-in operator on something constrained to a unique type ~T.
@@ -53,20 +61,26 @@
5361
* --------
5462
*
5563
* A copy is made any time you pass-by-value or execute the = operator in a
56-
* non-init expression.
64+
* non-init expression. Copying requires discriminating on type constructor.
65+
*
66+
* @-boxes copy shallow, copying is always legal.
67+
*
68+
* ~-boxes copy deep, copying is only legal if pointee is unique-kind.
5769
*
58-
* @ copies shallow, is always legal
59-
* ~ copies deep, is only legal if pointee is unique.
60-
* pinned values (pinned resources, alias-closures) can't be copied
61-
* all other unique (eg. interior) values copy shallow
70+
* Pinned-kind values (resources, &-closures) can't be copied. All other
71+
* unique-kind (eg. interior) values can be copied, and copy shallow.
72+
*
73+
* Note: If you have no type constructor -- only an opaque typaram -- then
74+
* you can only copy if the typaram is constrained to ~T; this is because @T
75+
* might be a "~resource" box, and making a copy would cause a deep
76+
* resource-copy.
6277
*
63-
* Note this means that only type parameters constrained to ~T can be copied.
6478
*
6579
* MOVING:
6680
* -------
6781
*
68-
* A move is made any time you pass-by-move (that is, with 'move' mode) or
69-
* execute the <- operator.
82+
* A move is made any time you pass-by-move (that is, with move mode '-') or
83+
* execute the move ('<-') or swap ('<->') operators.
7084
*
7185
*/
7286

@@ -124,6 +138,12 @@ fn need_shared_lhs_rhs(tcx: ty::ctxt, a: @ast::expr, b: @ast::expr, op: str) {
124138

125139
fn check_expr(tcx: ty::ctxt, e: @ast::expr) {
126140
alt e.node {
141+
142+
// FIXME: These rules do not implement the copy type-constructor
143+
// discrimination described by the block comment at the top of
144+
// this file. This code is wrong; it lets you copy anything
145+
// shared-kind.
146+
127147
ast::expr_move(a, b) { need_shared_lhs_rhs(tcx, a, b, "<-"); }
128148
ast::expr_assign(a, b) { need_shared_lhs_rhs(tcx, a, b, "="); }
129149
ast::expr_assign_op(_, a, b) { need_shared_lhs_rhs(tcx, a, b, "op="); }

src/comp/middle/ty.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,11 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
10261026
result = kind::lower_kind(result, k);
10271027
}
10281028
// Unique containers pass through their pointee kind.
1029+
//
1030+
// FIXME: These rules do not implement the ~ rules given in
1031+
// the block comment describing the kind system in kind.rs.
1032+
// This code is wrong; it makes ~resource into ~-kind, not
1033+
// @-kind as it should be.
10291034
ty_vec(tm) | ty_uniq(tm) {
10301035
let k = type_kind(cx, tm.ty);
10311036
result = kind::lower_kind(result, k);

0 commit comments

Comments
 (0)