Skip to content

Commit 9077bb8

Browse files
authored
Text tweaks (#4014)
* Text tweaks * No "of course"
1 parent 0abf707 commit 9077bb8

File tree

10 files changed

+45
-44
lines changed

10 files changed

+45
-44
lines changed

jane/doc/extensions/_01-stack-allocation/intro.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ and so they're safe to use in low-latency code that must currently be
1818
zero-alloc.
1919

2020
Because of these advantages, values are allocated on a stack whenever
21-
possible. Of course, not all values can be allocated on a stack: a value that is
21+
possible. Not all values can be allocated on a stack: a value that is
2222
used beyond the scope of its introduction must be on the heap. Accordingly,
2323
the compiler uses the _locality_ of a value to determine where it will be
2424
allocated: _local_ values go on the stack, while _global_ ones must go on the
@@ -76,7 +76,7 @@ let f (local_ x) = ...
7676
```
7777

7878
A local parameter is a promise by a function not to let a particular
79-
argument escape its region. In the body of f, you'll get a type error
79+
argument escape the region where it belongs. In the body of f, you'll get a type error
8080
if x escapes, but when calling f you can freely pass stack-allocated values as
8181
the argument. This promise is visible in the type of f:
8282

jane/doc/extensions/_01-stack-allocation/reference.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ The stack allocations language extension allows the compiler to
1313
stack-allocate some values, placing them on a stack rather than the
1414
garbage collected heap. Instead of waiting for the next GC, the memory
1515
used by stack-allocated values is reclaimed when their stack frame
16-
is reclaimed, and can be immediately reused. Whether the compiler
17-
stack-allocates certain values is controlled or inferred from new keywords
16+
is popped, and can be immediately reused. Whether the compiler
17+
stack-allocates certain values is inferred or controlled from new keywords
1818
`stack_` and `local_`, whose effects are explained below.
1919

2020
## Stack allocation
@@ -29,8 +29,8 @@ let abc = stack_ (42, 24) in
2929

3030
Here, the tuple cell will be stack-allocated. The `stack_` keyword works shallowly: it
3131
only forces the immediately following allocation to be on stack. In the following
32-
example, the outer tuple is guaranteed to be on stack, while the inner one is not (
33-
although likely to be due to optimization).
32+
example, the outer tuple is guaranteed to be on stack, while the inner one is not
33+
(although likely to be due to optimization).
3434
```ocaml
3535
let abc = stack_ (42, (24, 42)) in
3636
...
@@ -61,17 +61,17 @@ including:
6161

6262
At runtime, stack allocations do not take place on the function call stack, but on a
6363
separately-allocated stack that follows the same layout as the OCaml
64-
minor heap. In particular, this allows local-returning functions
65-
(see "Use `exclave_` to return a local value" below)
66-
without the need to copy returned values.
64+
minor heap. In particular, this enables local-returning functions
65+
without the need to copy returned values. See "Use `exclave_` to return a local value"
66+
below for more details.
6767

6868
The runtime records the stack pointer when entering a new stack frame,
6969
and leaving that stack frame resets the stack pointer to that value.
7070

7171
## Regions
7272

7373
Every stack allocation takes place inside a stack frame and is freed when the
74-
stack frame is freed. For this to be safe, stack-allocated values cannot be used
74+
stack frame is reclaimed. For this to be safe, stack-allocated values cannot be used
7575
after their stack frame is freed. This property is guaranteed at
7676
compile-time by the type checker as follows.
7777

@@ -103,7 +103,7 @@ let l = if n > 0 then stack_ (n :: x) else x in
103103
```
104104

105105
Here, if `n > 0`, then `l` will be a stack-allocated cons cell and thus local.
106-
However, if `n <= 0`, then `l` will be `x`, which is global. The latter is
106+
However, if `n <= 0`, then `l` will be `x`, which is global. In that second case, `x` is
107107
implicitly weakened to local (because both branches of an `if` must have the
108108
same locality), making the whole
109109
expression local.
@@ -168,7 +168,8 @@ including an entire file. This region never ends and is where global (heap-alloc
168168
values live.
169169

170170
One subtlety is that we wish to treat `local` variables from the current region
171-
differently than `local` variables from an enclosing region. The latter is called *outer-local*.
171+
differently than `local` variables from an enclosing region. Local from outside
172+
the current region is called *outer-local*.
172173

173174
For instance:
174175

@@ -183,16 +184,16 @@ let f () =
183184
```
184185

185186
At the point marked `??` inside `g`, both `outer` and `inner` are local values,
186-
but they live in different regions: `inner` lives in `g`'s region, while `outer`
187-
lives in the outer region and thus is outer-local.
187+
but they live in different regions: `inner` lives in the `g` region, while `outer`
188+
lives in the `f` region and thus is outer-local.
188189

189190
So, if we replace `??` with `inner`, we see an error:
190191

191192
Error: This local value escapes its region
192193

193194
However, if we replace `??` with `outer`, the compiler will accept it: the
194195
value `outer`, while being local, was definitely not local to the region of
195-
`g`, and there is therefore no problem allowing it to escape `g`'s region.
196+
`g`, and there is therefore no problem allowing it to escape the `g` region.
196197

197198
(This is quite subtle, and there is an additional wrinkle: how does the
198199
compiler know that it is safe to still refer to `outer` from within the closure
@@ -208,8 +209,8 @@ let f (local_ x) =
208209

209210
Both `x` and `y` are local and cannot, in general, escape a region. However, filling `??`
210211
in with `x` (but not `y`) is allowed. This is because we know that `x` lives outside of
211-
`f`'s region and therefore will continue to exist after `f` ends. In contrast, `y` is a cons cell
212-
in `f`'s region, which will be destroyed after `f` ends.
212+
the `f` region and therefore will continue to exist after `f` ends. In contrast, `y` is a cons cell
213+
in the `f` region, which will be destroyed after `f` ends.
213214

214215
## Inference
215216

@@ -317,8 +318,8 @@ which means it cannot be global. Therefore, it must be stack-allocated, and it
317318
local value `42 :: x` is not allowed to escape it.
318319

319320
It is possible to write functions like `f3` that return stack-allocated
320-
values, but this requires an explicit annotation, as it would otherwise be easy to
321-
do by mistake. See "Use `exclave_` to return a local value" below.
321+
values, but this requires an explicit annotation, as it could otherwise be done
322+
unintentionally. See "Use `exclave_` to return a local value" below.
322323

323324
Like local variables, inference can determine whether function arguments are
324325
local. However, note that for arguments of exported functions to be local, the
@@ -544,7 +545,7 @@ let make () = exclave_
544545
```
545546

546547
The keyword `exclave_` terminates the current region and executes the subsequent
547-
code in the outer region. Therefore, `ref 0` is executed in `f`'s region, which
548+
code in the outer region. Therefore, `ref 0` is executed in the `f` region, which
548549
allows its stack-allocation. The allocation will only be cleaned up when the
549550
region of `f` ends.
550551

@@ -577,7 +578,7 @@ In this example, the function `f` has a region where the allocation for the
577578
complex computation occurs. This region is terminated by `exclave_`, releasing
578579
all temporary allocations. Both `None` and `Some x` are allocated in the
579580
caller's stack frame and are allowed to be returned. In summary, the
580-
temporary allocations in the `f`'s region are promptly released, and the result
581+
temporary allocations in the `f` region are promptly released, and the result
581582
allocated in the caller's region is returned.
582583

583584
Here is another example in which the stack usage can be improved asymptotically
@@ -793,13 +794,13 @@ rejected:
793794
let local_ f : int -> int -> int = fun a b -> a + b + !counter in
794795
...
795796
796-
let f : int -> int -> int = stack_ fun a b -> a + b + !counter in
797+
let g : int -> int -> int = stack_ fun a b -> a + b + !counter in
797798
...
798799
```
799800

800801
Both define a closure which accepts two integers and returns an integer. The
801802
closure must be local, since it refers to the local value `counter`. In the
802-
former definition, the type of the function appears under the `local_` keyword,
803+
definition of `f`, the type of the function appears under the `local_` keyword,
803804
and as described above is interpreted as:
804805

805806
```ocaml
@@ -808,8 +809,8 @@ int -> local_ (int -> int)
808809

809810
This is the correct type for this function: if we partially apply it to
810811
a single argument, the resulting closure will still be local, as it refers to
811-
the original function which refers to `counter`. By contrast, in the latter
812-
definition the type of the function is outside the `stack_` keyword as is
812+
the original function which refers to `counter`. By contrast, in the
813+
definition of `g`, the type of the function is outside the `stack_` keyword as is
813814
interpreted as normal as:
814815

815816
```ocaml
@@ -822,7 +823,7 @@ case here. For this reason, this version is rejected. It would be accepted if
822823
written as follows:
823824

824825
```ocaml
825-
let f : int -> local_ (int -> int) = stack_ fun a b -> a + b + !counter in
826+
let g : int -> local_ (int -> int) = stack_ fun a b -> a + b + !counter in
826827
...
827828
```
828829

jane/doc/extensions/_02-unboxed-types/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ modules in the `janestreet_shims` library.)
175175

176176
* With a few specific exceptions (documented below), existing types all expect
177177
`value` arguments. Thus for basically any `t`, you cannot write `float# t` or
178-
`int64# t`. This includes obvious candidates like `float#
178+
`int64# t`. This includes natural candidates like `float#
179179
option`.
180180

181181
* Existing ppxs expect to work with `value` types. Accordingly, using `deriving` with

jane/doc/extensions/_04-modes/syntax.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Syntax
55
---
66

77
# Modes and modalities
8-
Currently a mode expression is simply a space-delimited list of modes.
8+
Currently a mode expression is a space-delimited list of modes.
99

1010
```
1111
mode := local | global | unique | shared | many | once | portable | nonportable
@@ -24,7 +24,7 @@ Modes are in a dedicated namespace separated from variable names or type names,
2424
which means you can continue to use `local` or `unique` as variable or type
2525
names.
2626

27-
Currently a modality expression is simply a space-delimited list of modalities.
27+
Currently a modality expression is a space-delimited list of modalities.
2828

2929
```
3030
modality := local | global | ..

jane/doc/extensions/_05-kinds/syntax.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ The abbreviations defined in the language are as follows:
120120
bound of `non_float` (because the value is not a pointer to a
121121
floating-point block).
122122

123-
Using `mod everything` is appropriate for simple data represented directly,
123+
Using `mod everything` is appropriate for data represented directly,
124124
like `int` or `float32#`.
125125

126126
* `any_non_null = any mod non_null`
@@ -227,7 +227,7 @@ still lower than both usages.
227227
The only question, then, is where to start the inference from? That is, what is
228228
default kind for a type parameter? It is tempting to say `any`, as that's the
229229
top. However, this would not be backward compatible, at least in module
230-
signatures, as we need the following very simple example to be accepted:
230+
signatures, as we need the following example to be accepted:
231231

232232
```ocaml
233233
module M : sig
@@ -376,7 +376,7 @@ val id : ('a : any). 'a -> 'a
376376
```
377377

378378
Here, we have annotated the binding site of `'a` to say that it should have kind
379-
`any`. (The type `('a : any). 'a -> 'a` is a perfectly good type, and a
379+
`any`. (The type `('a : any). 'a -> 'a` is valid, and a
380380
function of that type can be called on values of any type of any kind. However,
381381
you will be unable to define a function of that type, because the compiler will
382382
not know what register will hold the argument.) In contrast, writing
@@ -385,8 +385,8 @@ not know what register will hold the argument.) In contrast, writing
385385
val id : ('a : any) -> 'a
386386
```
387387

388-
does not do what you might think: it constrains a *usage site* of `'a`, stating
389-
that `'a` must have a subkind of `any` -- but of course `value` *is* a subkind
388+
constrains a *usage site* of `'a`, stating
389+
that `'a` must have a subkind of `any` -- but `value` *is* a subkind
390390
of `any`, so the default behavior of choosing `value` is unaffected. That is,
391391
the type `('a : any) -> 'a` is the same as just writing `'a -> 'a`.
392392

jane/doc/extensions/_05-kinds/types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ the component types>>` without constraining the kinds of any of the `ty_i`.
7575

7676
* An applied type constructor `(ty_1, ..., ty_n) t` (where n >= 0) has the kind
7777
assigned to `t` at its declaration, with type arguments substituted into any
78-
type variables mentioned in `t`'s with-bounds. Each of the `ty_i` is constrained
78+
type variables mentioned in the `t` with-bounds. Each of the `ty_i` is constrained
7979
to be a subkind of the kind on the corresponding type parameter to `t`.
8080

8181
* An object type `< f1 : ty_1; ...; fn : ty_n >` has kind `value mod

jane/doc/extensions/_06-uniqueness/reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ let bad r =
6969
The problem here is that the compiler can not determine whether `free r` might
7070
dereference `r.field1` again. As such, it would be unsafe to free `r.field1`.
7171
The uniqueness analysis carefully tracks which children of an allocation have
72-
already been consumed. This tracking also works with obvious aliases, such as
73-
simple renamings:
72+
already been consumed. This tracking also works with aliases, such as
73+
renamings:
7474

7575
```ocaml
7676
let okay r =

jane/doc/extensions/_07-comprehensions/01-intro.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ the conditions hold. The order of the result is given by evaluating the clauses
110110
(`for ... and ...` and `when` alike) in order from left to right; they may be
111111
thought of as nested loops/conditionals.
112112

113-
## A special-case optimization for simple (fixed-size) array comprehensions
113+
## A special-case optimization for fixed-size array comprehensions
114114

115115
One somewhat unusual design choice is the decision to allow multiple iterators
116116
in a single clause, via `for ITERATOR_1 and ITERATOR_2 and ... and ITERATOR_N`,
@@ -137,7 +137,7 @@ right could depend on the values generated by those on the left. Thus, the
137137
second example above (“Let’s describe some objects”) would preallocate an array
138138
of 6 strings and loop through it, whereas the fourth example (“Flatten a nested
139139
array”) would have to start with a smaller array and grow it as necessary.
140-
(Of course, this optimization does not apply to lists. The only thing we can do with a
140+
(This optimization does not apply to lists. The only thing we can do with a
141141
list is iterate over it, and the only way we can produce a list is by building it up piece
142142
by piece.)
143143

@@ -151,5 +151,5 @@ per surrounding iteration before any of them begin to iterate.
151151
## More details
152152

153153
This should be enough to use comprehensions on a day-to-day basis; if you have
154-
more questions, or are simply curious about how things work on the inside, see
154+
more questions, or are curious about how things work on the inside, see
155155
the [details page](../details).

jane/doc/extensions/_07-comprehensions/02-details.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ iterated over (the `seq` of a `for pat in seq` iterator, or the `start` and
107107
`end` of a `for x = start to/downto end` iterator); the function argument is
108108
then to be called once for each item. What goes in the function? It will be
109109
the next iterator, desugared in the same way. At any time, a `when` clause
110-
might intervene, which is simply desugared into a conditional that gates
110+
might intervene, which is desugared into a conditional that gates
111111
entering the next phase of the translation.
112112

113113
Eventually, we reach the body, which is placed into the body of the innermost
@@ -176,9 +176,9 @@ size.
176176
The second source of extra complexity is the fixed-size array case. In this
177177
case, we have to first compute the size of every iterator and multiply them
178178
together; for both of these operations, we have to check for overflow, in which
179-
case we simply fail. We also check to see if any of the iterators would be
179+
case we fail. We also check to see if any of the iterators would be
180180
empty (have size `0`), in which case we can shortcut this whole process and
181-
simply return an empty array. Once we do that, though, the loop body is simpler
181+
return an empty array. Once we do that, though, the loop body is lighter
182182
as there’s no need to double the array size, and we don’t need to cut the list
183183
down to size at the end.
184184

jane/doc/extensions/_08-miscellaneous-extensions/polymorphic-parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ all require defining a fresh type to contain `f`. These work-arounds
5353
require additional code at each call site to wrap `f` in the associated
5454
type.
5555

56-
With polymorphic parameters, you can simply annotate `f` as
56+
With polymorphic parameters, you can annotate `f` as
5757
polymorphic:
5858
```ocaml
5959
let create (f : 'a. 'a field -> 'a) =

0 commit comments

Comments
 (0)