Skip to content

Commit 5d0dc90

Browse files
committed
Merge pull request #136 from zachpanz88/patch-2
2 parents 22e2557 + 27e452d commit 5d0dc90

File tree

1 file changed

+72
-72
lines changed

1 file changed

+72
-72
lines changed

docs/weak.rst

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -355,29 +355,29 @@ Finalization models built around calling a method on the
355355
finalized object (such as Objective-C's :code:`-dealloc`)
356356
suffer from a number of limitations and problems:
357357

358-
- Since the method receives a pointer to the object being
359-
deallocated, the implementation must guard against
360-
attempts to resurrect the object. This may complicate
361-
and/or slow down the system's basic reference-management
362-
logic, which tends to be quite important for performance.
363-
364-
- Since the method receives a pointer to the object being
365-
deallocated, the implementation must leave the object at
366-
least a minimally valid state until the user code is
367-
complete. For example, the instance variables of a
368-
subclass cannot be destroyed until a later phase of
369-
destruction, because a superclass finalizer might invoke
370-
subclass behavior. (This assumes that the dynamic type
371-
of the object does not change during destruction, which
372-
is an alternative that brings its own problems.)
373-
374-
- Finalization code must be inherent to the object; other
375-
objects cannot request that code be run when the object
376-
is deallocated. For example, an object that registers
377-
itself to observe a certain event source must explicitly
378-
deregister itself in a finalizer; the event source cannot
379-
simply automatically drop the object when it is
380-
deallocated.
358+
- Since the method receives a pointer to the object being
359+
deallocated, the implementation must guard against
360+
attempts to resurrect the object. This may complicate
361+
and/or slow down the system's basic reference-management
362+
logic, which tends to be quite important for performance.
363+
364+
- Since the method receives a pointer to the object being
365+
deallocated, the implementation must leave the object at
366+
least a minimally valid state until the user code is
367+
complete. For example, the instance variables of a
368+
subclass cannot be destroyed until a later phase of
369+
destruction, because a superclass finalizer might invoke
370+
subclass behavior. (This assumes that the dynamic type
371+
of the object does not change during destruction, which
372+
is an alternative that brings its own problems.)
373+
374+
- Finalization code must be inherent to the object; other
375+
objects cannot request that code be run when the object
376+
is deallocated. For example, an object that registers
377+
itself to observe a certain event source must explicitly
378+
deregister itself in a finalizer; the event source cannot
379+
simply automatically drop the object when it is
380+
deallocated.
381381

382382
Optimization
383383
------------
@@ -402,15 +402,15 @@ Proposal Overview
402402

403403
Looking at these use-cases, there are two main thrusts:
404404

405-
- There is a general need to set up back references to objects.
406-
These references must be designed for convenient use by non-expert
407-
users.
405+
- There is a general need to set up back references to objects.
406+
These references must be designed for convenient use by non-expert
407+
users.
408408

409-
- There are a number of more sophisticated use cases which require
410-
notification or interruption of deallocation; these can be used in
411-
the implementation of higher-level abstractions like weak caches.
412-
Here it is reasonable to expect more user expertise, such that
413-
power and flexibility should take priority over ease of use.
409+
- There are a number of more sophisticated use cases which require
410+
notification or interruption of deallocation; these can be used in
411+
the implementation of higher-level abstractions like weak caches.
412+
Here it is reasonable to expect more user expertise, such that
413+
power and flexibility should take priority over ease of use.
414414

415415
The second set of use cases should addressed by library types working
416416
on top of basic runtime support.
@@ -439,11 +439,11 @@ variable-like declaration of reference type :code:`T`. For
439439
type-system purposes, the variables behaves like a normal
440440
variable of type :code:`Optional<T>`, except:
441441

442-
- it does not maintain a +1 reference count invariant and
442+
- it does not maintain a +1 reference count invariant and
443443

444-
- loading from the variable after the current referent (if present)
445-
has started destruction will result in a :code:`Nothing` value,
446-
indistinguishable from the normal case.
444+
- loading from the variable after the current referent (if present)
445+
has started destruction will result in a :code:`Nothing` value,
446+
indistinguishable from the normal case.
447447

448448
The semantics are quite similar to weak references in other
449449
environments (particularly Objective-C) except that the change in
@@ -485,10 +485,10 @@ designed without first having a solid error-handling design.
485485
type-system purposes, the variable behaves exactly like a normal
486486
variable of type :code:`T`, except:
487487

488-
- it does not maintain a +1 reference count invariant and
488+
- it does not maintain a +1 reference count invariant and
489489

490-
- loading from the variable after the referent has started
491-
destruction causes an assertion failure.
490+
- loading from the variable after the referent has started
491+
destruction causes an assertion failure.
492492

493493
This is a refinement of :code:`weak` focused more narrowly on the case
494494
of a back reference with relatively tight validity invariants. This
@@ -498,32 +498,32 @@ references; see below.
498498
This name isn't really optimal. We've considered several different
499499
candidates:
500500

501-
- :code:`weak` is a poor choice because our semantics are very
502-
different from weak references in other environments where it's
503-
valid to access a cleared reference. Plus, we need to expose
504-
those semantics, so the name is claimed.
505-
506-
- :code:`backref` is strongly evocative of the major use case in the
507-
static reference graph; this would encourage users to use it for
508-
back references and to consider alternatives for other cases, both
509-
of which I like. The latter also makes the husk-leaking
510-
implementation (see below) more palatable. It also contrasts very
511-
well with :code:`weak`. However, its evocativeness makes it
512-
unwieldy to use for local reference-counting optimizations.
513-
514-
- :code:`dangling` is more general than :code:`backref`, but it has
515-
such strong negative associations that it wouldn't be unreasonable
516-
for users to assume that it's unsafe (with all the pursuant
517-
debugging difficulties) based on the name alone. I don't think
518-
we want to discourage a feature that can help users build tighter
519-
invariants on their classes.
520-
521-
- :code:`unowned` is somewhat cleaner-looking, and it isn't as tied
522-
to a specific use case, but it does not contrast with :code:`weak`
523-
*at all*; only someone with considerable exposure to weak
524-
references would understand why we named each one the way we did,
525-
and even they are likely to roll their eyes at us. But it's okay
526-
for a working proposal.
501+
- :code:`weak` is a poor choice because our semantics are very
502+
different from weak references in other environments where it's
503+
valid to access a cleared reference. Plus, we need to expose
504+
those semantics, so the name is claimed.
505+
506+
- :code:`backref` is strongly evocative of the major use case in the
507+
static reference graph; this would encourage users to use it for
508+
back references and to consider alternatives for other cases, both
509+
of which I like. The latter also makes the husk-leaking
510+
implementation (see below) more palatable. It also contrasts very
511+
well with :code:`weak`. However, its evocativeness makes it
512+
unwieldy to use for local reference-counting optimizations.
513+
514+
- :code:`dangling` is more general than :code:`backref`, but it has
515+
such strong negative associations that it wouldn't be unreasonable
516+
for users to assume that it's unsafe (with all the pursuant
517+
debugging difficulties) based on the name alone. I don't think
518+
we want to discourage a feature that can help users build tighter
519+
invariants on their classes.
520+
521+
- :code:`unowned` is somewhat cleaner-looking, and it isn't as tied
522+
to a specific use case, but it does not contrast with :code:`weak`
523+
*at all*; only someone with considerable exposure to weak
524+
references would understand why we named each one the way we did,
525+
and even they are likely to roll their eyes at us. But it's okay
526+
for a working proposal.
527527

528528
Asserting and Uncheckable
529529
.........................
@@ -857,19 +857,19 @@ become laborious and redundant, and a different mechanism is called for.
857857
In the following discussion, a *var-or-member expression* is an
858858
expression which is semantically constrained to be one of:
859859

860-
- A reference to a local variable-like declaration from an
861-
enclosing context.
860+
- A reference to a local variable-like declaration from an
861+
enclosing context.
862862

863-
- A member access thereof, possibly recursively.
863+
- A member access thereof, possibly recursively.
864864

865865
Such expressions have two useful traits:
866866

867-
- They always end in an identifier which on some level meaningfully
868-
identifies the object.
867+
- They always end in an identifier which on some level meaningfully
868+
identifies the object.
869869

870-
- Evaluating them is relatively likely (but not guaranteed) to not
871-
have interesting side effects, and so we feel less bad about
872-
apparently shifting their evaluation around.
870+
- Evaluating them is relatively likely (but not guaranteed) to not
871+
have interesting side effects, and so we feel less bad about
872+
apparently shifting their evaluation around.
873873

874874
Decorated Capture References
875875
----------------------------

0 commit comments

Comments
 (0)