You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and `<package>.<receiver name>[<type args>]` are the same as above
294
-
except with comma separated type arguments in square brackets.
295
-
The type arguments are either the instance types, or type parameters
296
-
since the instance type could be a match for the type parameter on the
297
-
generic. For example `type Foo[T any] struct{}; type Bar[B any] { f Foo[B] }`
301
+
except with comma separated type parameters or type arguments in square brackets.
302
+
The type parameter names are not used, instead the constraint types are since
303
+
the names for type parameters may not match even if the constraints match.
304
+
For example `type Foo[T any] struct{}; type Bar[B any] { f Foo[B] }`
298
305
has `Foo[B]` used in `Bar` that is identical to `Foo[T]` even though
299
-
technically `Foo[B]` is an instance of `Foo[T]` with `B` as the type argument.
306
+
technically `Foo[B]` is an instance of `Foo[T]` with the `B` type parameter
307
+
as the type argument.
300
308
301
309
Command compiles, i.e. compiles with a `main` entry point, and test builds
302
-
should not have any instance types that aren't resolved to concrete types,
303
-
however to handle partial compiles of packages, instance types may still
310
+
should not have any type parameters that aren't resolved to concrete types,
311
+
however to handle partial compiles of packages, there may still
304
312
be a type parameter, including unions of approximate constraints,
305
313
i.e. `~int|~string`.
306
314
@@ -321,12 +329,12 @@ For the method name of unexposed methods,
321
329
The rest contains the signature, `(<parameter types>)(<result types>)`.
322
330
The signature is defined with only the types since
323
331
`(v, u int)(ok bool, err error)` should match `(x, y int)(bool, error)`.
324
-
To match both will have to be `(int, int)(bool, error)`.
332
+
To match both, both will have to be `(int, int)(bool, error)`.
325
333
Also the parameter types should include the veridic indicator,
326
-
e.g. `sum(...int)int`, since that affects how the signature is matched.
334
+
e.g. `sum(...int)int`, since that affects how the signature is matched.
327
335
If there are no results then the results part is left off. Otherwise,
328
336
the result types only need parenthesis if there are more than one result,
329
-
e.g. `(int, int)`, `(int, int)bool`, and `(int, int)(bool, error)`.
337
+
e.g. `(int, int)`, `(int, int)bool`, and `(int, int)(bool, error)`.
330
338
331
339
In either the object name or method name, if there is a recursive
332
340
type parameter, e.g. `func Foo[T Bar[T]]()` the second usage of the
@@ -336,7 +344,7 @@ is recursive, e.g. `Foo[Bar[Bar[...]]]`.
336
344
337
345
### Dependencies
338
346
339
-
The dependencies that are specified in an expression.
347
+
The dependencies are specified in an expression.
340
348
For example a function that invokes another function will be dependent on
341
349
that invoked function. When a dependency is added it will be added as one
342
350
or more names to the declaration that depends on it. It follows the
@@ -348,7 +356,7 @@ it would automatically add all unexported signatures as dependencies via
348
356
`<package path>.<method name>(<parameter type list>)(<result type list>)`.
349
357
However, we do not need to do that in GopherJS because we aren't using
350
358
the existence of realized methods in duck-typing. GopherJS stores full set
351
-
of method information when describing the type so that even when things like
359
+
of method information when describing the type so that, even when things like
352
360
unexported methods in interfaces are removed, duck-typing will still work
353
361
correctly. This reduces the size of the code by not keeping a potentially
354
362
long method body when the signature is all that is needed.
@@ -419,7 +427,7 @@ import "point"
419
427
funcmain() {
420
428
a:= point.Point{X: 10.2, Y: 45.3}
421
429
b:= point.Point{X: -23.0, Y: 7.7}
422
-
println(`Manhatten a to b:`, a.Manhattan(b))
430
+
println(`Manhattan a to b:`, a.Manhattan(b))
423
431
}
424
432
```
425
433
@@ -476,7 +484,7 @@ func main() {
476
484
### Side Effects
477
485
478
486
In this example unused variables are being initialized with expressions
479
-
that have side effects. The `max` value is 8 by the time `main` is called
487
+
that has side effects. The `max` value is 8 by the time `main` is called
480
488
because each initialization calls `count()` that increments `max`.
481
489
The expression doesn't have to have a function call and can be any combination
482
490
of operations.
@@ -512,17 +520,17 @@ func main() {
512
520
513
521
In this example the type `StringKeys[T any]` is a map that stores
514
522
any kind of value with string keys. There is an interface `IntProvider`
515
-
that `StringKeys` will duck-type to iff the instance type is `int`,
516
-
i.e. `StringKeys[int]`. This exemplifies how the instance types used
523
+
that `StringKeys` will duck-type to iff the type argument is `int`,
524
+
i.e. `StringKeys[int]`. This exemplifies how the type arguments used
517
525
in the type arguments affect the overall signature such that in some
518
526
cases a generic object may match an interface and in others it may not.
519
527
520
528
Also notice that the structure was typed with `T` as the parameter type's
521
529
name whereas the methods use `S`. This shows that the name of the type
522
530
doesn't matter in the instancing. Therefore, outputting a methods name
523
-
(assuming it is unexported) should use the instance type not the parameter
524
-
name, e.g. `value() []int` or `value() []any` instead of `value() []S` or
525
-
`value() []T`.
531
+
(assuming it is unexported) should use the type argument type,
532
+
not the type parameter name, e.g. `value() []int` or `value() []any`
533
+
instead of `value() []S` or `value() []T`.
526
534
527
535
```go
528
536
package main
@@ -606,9 +614,10 @@ the higher level constructs not being used.
606
614
Any variable internal to the body of a function or method that is unused or
607
615
only used for computing new values for itself, are left as is.
608
616
The Go compiler and linters have requirements that attempt to prevent this
609
-
kind of dead-code in a function body (so long as an underscore isn't used to quite
610
-
usage warnings) and prevent unreachable code. Therefore, we aren't going to
611
-
worry about trying to DCE inside of function bodies or in variable initializers.
617
+
kind of dead-code in a function body (unless an underscore is used to quite
618
+
usage warnings, e.g. `_ = unusedVar`) and prevent unreachable code.
619
+
Therefore, we aren't going to worry about trying to DCE inside of function
620
+
bodies or in variable initializers.
612
621
613
622
GopherJS does not implicitly perform JS Tree Shaking Algorithms, as discussed in
614
623
[How Modern Javascript eliminate dead code](https://blog.stackademic.com/how-modern-javascript-eliminates-dead-code-tree-shaking-algorithm-d7861e48df40)
0 commit comments