Commit 3f5edd24 authored by Rob Pike's avatar Rob Pike

test/chan/select5.go: change "with" to "if" in templatea

I converted this program yesterday and the output is the
same as it used to be, ignoring space, but the result is
not the best expression of the algorithm.  The old {.section
Maybe} pieces are now {{with .Maybe}}, as a direct translation,
but I they should be {{if .Maybe}} as the output is just a
bool and there is no cascading.

I have verified that the output of the program is unaffected.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4889053
parent d2a45dbf
...@@ -146,26 +146,26 @@ func parse(name, s string) *template.Template { ...@@ -146,26 +146,26 @@ func parse(name, s string) *template.Template {
var recv = parse("recv", ` var recv = parse("recv", `
{{/* Send n, receive it one way or another into x, check that they match. */}} {{/* Send n, receive it one way or another into x, check that they match. */}}
c <- n c <- n
{{with .Maybe}} {{if .Maybe}}
x = <-c x = <-c
{{else}} {{else}}
select { select {
{{/* Blocking or non-blocking, before the receive. */}} {{/* Blocking or non-blocking, before the receive. */}}
{{/* The compiler implements two-case select where one is default with custom code, */}} {{/* The compiler implements two-case select where one is default with custom code, */}}
{{/* so test the default branch both before and after the send. */}} {{/* so test the default branch both before and after the send. */}}
{{with .MaybeDefault}} {{if .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
{{end}} {{end}}
{{/* Receive from c. Different cases are direct, indirect, :=, interface, and map assignment. */}} {{/* Receive from c. Different cases are direct, indirect, :=, interface, and map assignment. */}}
{{with .Maybe}} {{if .Maybe}}
case x = <-c: case x = <-c:
{{else}}{{with .Maybe}} {{else}}{{if .Maybe}}
case *f(&x) = <-c: case *f(&x) = <-c:
{{else}}{{with .Maybe}} {{else}}{{if .Maybe}}
case y := <-c: case y := <-c:
x = y x = y
{{else}}{{with .Maybe}} {{else}}{{if .Maybe}}
case i = <-c: case i = <-c:
x = i.(int) x = i.(int)
{{else}} {{else}}
...@@ -173,25 +173,25 @@ var recv = parse("recv", ` ...@@ -173,25 +173,25 @@ var recv = parse("recv", `
x = m[13] x = m[13]
{{end}}{{end}}{{end}}{{end}} {{end}}{{end}}{{end}}{{end}}
{{/* Blocking or non-blocking again, after the receive. */}} {{/* Blocking or non-blocking again, after the receive. */}}
{{with .MaybeDefault}} {{if .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
{{end}} {{end}}
{{/* Dummy send, receive to keep compiler from optimizing select. */}} {{/* Dummy send, receive to keep compiler from optimizing select. */}}
{{with .Maybe}} {{if .Maybe}}
case dummy <- 1: case dummy <- 1:
panic("dummy send") panic("dummy send")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case <-dummy: case <-dummy:
panic("dummy receive") panic("dummy receive")
{{end}} {{end}}
{{/* Nil channel send, receive to keep compiler from optimizing select. */}} {{/* Nil channel send, receive to keep compiler from optimizing select. */}}
{{with .Maybe}} {{if .Maybe}}
case nilch <- 1: case nilch <- 1:
panic("nilch send") panic("nilch send")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case <-nilch: case <-nilch:
panic("nilch recv") panic("nilch recv")
{{end}} {{end}}
...@@ -209,12 +209,12 @@ var recvOrder = parse("recvOrder", ` ...@@ -209,12 +209,12 @@ var recvOrder = parse("recvOrder", `
{{/* that the argument sequence is strictly increasing. */}} {{/* that the argument sequence is strictly increasing. */}}
order = 0 order = 0
c <- n c <- n
{{with .Maybe}} {{if .Maybe}}
{{/* Outside of select, left-to-right rule applies. */}} {{/* Outside of select, left-to-right rule applies. */}}
{{/* (Inside select, assignment waits until case is chosen, */}} {{/* (Inside select, assignment waits until case is chosen, */}}
{{/* so right hand side happens before anything on left hand side. */}} {{/* so right hand side happens before anything on left hand side. */}}
*fp(&x, 1) = <-fc(c, 2) *fp(&x, 1) = <-fc(c, 2)
{{else}}{{with .Maybe}} {{else}}{{if .Maybe}}
m[fn(13, 1)] = <-fc(c, 2) m[fn(13, 1)] = <-fc(c, 2)
x = m[13] x = m[13]
{{else}} {{else}}
...@@ -222,17 +222,17 @@ var recvOrder = parse("recvOrder", ` ...@@ -222,17 +222,17 @@ var recvOrder = parse("recvOrder", `
{{/* Blocking or non-blocking, before the receive. */}} {{/* Blocking or non-blocking, before the receive. */}}
{{/* The compiler implements two-case select where one is default with custom code, */}} {{/* The compiler implements two-case select where one is default with custom code, */}}
{{/* so test the default branch both before and after the send. */}} {{/* so test the default branch both before and after the send. */}}
{{with .MaybeDefault}} {{if .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
{{end}} {{end}}
{{/* Receive from c. Different cases are direct, indirect, :=, interface, and map assignment. */}} {{/* Receive from c. Different cases are direct, indirect, :=, interface, and map assignment. */}}
{{with .Maybe}} {{if .Maybe}}
case *fp(&x, 100) = <-fc(c, 1): case *fp(&x, 100) = <-fc(c, 1):
{{else}}{{with .Maybe}} {{else}}{{if .Maybe}}
case y := <-fc(c, 1): case y := <-fc(c, 1):
x = y x = y
{{else}}{{with .Maybe}} {{else}}{{if .Maybe}}
case i = <-fc(c, 1): case i = <-fc(c, 1):
x = i.(int) x = i.(int)
{{else}} {{else}}
...@@ -240,25 +240,25 @@ var recvOrder = parse("recvOrder", ` ...@@ -240,25 +240,25 @@ var recvOrder = parse("recvOrder", `
x = m[13] x = m[13]
{{end}}{{end}}{{end}} {{end}}{{end}}{{end}}
{{/* Blocking or non-blocking again, after the receive. */}} {{/* Blocking or non-blocking again, after the receive. */}}
{{with .MaybeDefault}} {{if .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
{{end}} {{end}}
{{/* Dummy send, receive to keep compiler from optimizing select. */}} {{/* Dummy send, receive to keep compiler from optimizing select. */}}
{{with .Maybe}} {{if .Maybe}}
case fc(dummy, 2) <- fn(1, 3): case fc(dummy, 2) <- fn(1, 3):
panic("dummy send") panic("dummy send")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case <-fc(dummy, 4): case <-fc(dummy, 4):
panic("dummy receive") panic("dummy receive")
{{end}} {{end}}
{{/* Nil channel send, receive to keep compiler from optimizing select. */}} {{/* Nil channel send, receive to keep compiler from optimizing select. */}}
{{with .Maybe}} {{if .Maybe}}
case fc(nilch, 5) <- fn(1, 6): case fc(nilch, 5) <- fn(1, 6):
panic("nilch send") panic("nilch send")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case <-fc(nilch, 7): case <-fc(nilch, 7):
panic("nilch recv") panic("nilch recv")
{{end}} {{end}}
...@@ -272,12 +272,12 @@ var recvOrder = parse("recvOrder", ` ...@@ -272,12 +272,12 @@ var recvOrder = parse("recvOrder", `
var send = parse("send", ` var send = parse("send", `
{{/* Send n one way or another, receive it into x, check that they match. */}} {{/* Send n one way or another, receive it into x, check that they match. */}}
{{with .Maybe}} {{if .Maybe}}
c <- n c <- n
{{else}} {{else}}
select { select {
{{/* Blocking or non-blocking, before the receive (same reason as in recv). */}} {{/* Blocking or non-blocking, before the receive (same reason as in recv). */}}
{{with .MaybeDefault}} {{if .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
{{end}} {{end}}
...@@ -285,25 +285,25 @@ var send = parse("send", ` ...@@ -285,25 +285,25 @@ var send = parse("send", `
{{/* from the send operation. */}} {{/* from the send operation. */}}
case c <- n: case c <- n:
{{/* Blocking or non-blocking. */}} {{/* Blocking or non-blocking. */}}
{{with .MaybeDefault}} {{if .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
{{end}} {{end}}
{{/* Dummy send, receive to keep compiler from optimizing select. */}} {{/* Dummy send, receive to keep compiler from optimizing select. */}}
{{with .Maybe}} {{if .Maybe}}
case dummy <- 1: case dummy <- 1:
panic("dummy send") panic("dummy send")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case <-dummy: case <-dummy:
panic("dummy receive") panic("dummy receive")
{{end}} {{end}}
{{/* Nil channel send, receive to keep compiler from optimizing select. */}} {{/* Nil channel send, receive to keep compiler from optimizing select. */}}
{{with .Maybe}} {{if .Maybe}}
case nilch <- 1: case nilch <- 1:
panic("nilch send") panic("nilch send")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case <-nilch: case <-nilch:
panic("nilch recv") panic("nilch recv")
{{end}} {{end}}
...@@ -321,12 +321,12 @@ var sendOrder = parse("sendOrder", ` ...@@ -321,12 +321,12 @@ var sendOrder = parse("sendOrder", `
{{/* Check order of operations along the way by calling functions that check */}} {{/* Check order of operations along the way by calling functions that check */}}
{{/* that the argument sequence is strictly increasing. */}} {{/* that the argument sequence is strictly increasing. */}}
order = 0 order = 0
{{with .Maybe}} {{if .Maybe}}
fc(c, 1) <- fn(n, 2) fc(c, 1) <- fn(n, 2)
{{else}} {{else}}
select { select {
{{/* Blocking or non-blocking, before the receive (same reason as in recv). */}} {{/* Blocking or non-blocking, before the receive (same reason as in recv). */}}
{{with .MaybeDefault}} {{if .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
{{end}} {{end}}
...@@ -334,25 +334,25 @@ var sendOrder = parse("sendOrder", ` ...@@ -334,25 +334,25 @@ var sendOrder = parse("sendOrder", `
{{/* from the send operation. */}} {{/* from the send operation. */}}
case fc(c, 1) <- fn(n, 2): case fc(c, 1) <- fn(n, 2):
{{/* Blocking or non-blocking. */}} {{/* Blocking or non-blocking. */}}
{{with .MaybeDefault}} {{if .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
{{end}} {{end}}
{{/* Dummy send, receive to keep compiler from optimizing select. */}} {{/* Dummy send, receive to keep compiler from optimizing select. */}}
{{with .Maybe}} {{if .Maybe}}
case fc(dummy, 3) <- fn(1, 4): case fc(dummy, 3) <- fn(1, 4):
panic("dummy send") panic("dummy send")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case <-fc(dummy, 5): case <-fc(dummy, 5):
panic("dummy receive") panic("dummy receive")
{{end}} {{end}}
{{/* Nil channel send, receive to keep compiler from optimizing select. */}} {{/* Nil channel send, receive to keep compiler from optimizing select. */}}
{{with .Maybe}} {{if .Maybe}}
case fc(nilch, 6) <- fn(1, 7): case fc(nilch, 6) <- fn(1, 7):
panic("nilch send") panic("nilch send")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case <-fc(nilch, 8): case <-fc(nilch, 8):
panic("nilch recv") panic("nilch recv")
{{end}} {{end}}
...@@ -370,42 +370,42 @@ var nonblock = parse("nonblock", ` ...@@ -370,42 +370,42 @@ var nonblock = parse("nonblock", `
{{/* Test various combinations of non-blocking operations. */}} {{/* Test various combinations of non-blocking operations. */}}
{{/* Receive assignments must not edit or even attempt to compute the address of the lhs. */}} {{/* Receive assignments must not edit or even attempt to compute the address of the lhs. */}}
select { select {
{{with .MaybeDefault}} {{if .MaybeDefault}}
default: default:
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case dummy <- 1: case dummy <- 1:
panic("dummy <- 1") panic("dummy <- 1")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case nilch <- 1: case nilch <- 1:
panic("nilch <- 1") panic("nilch <- 1")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case <-dummy: case <-dummy:
panic("<-dummy") panic("<-dummy")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case x = <-dummy: case x = <-dummy:
panic("<-dummy x") panic("<-dummy x")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case **(**int)(nil) = <-dummy: case **(**int)(nil) = <-dummy:
panic("<-dummy (and didn't crash saving result!)") panic("<-dummy (and didn't crash saving result!)")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case <-nilch: case <-nilch:
panic("<-nilch") panic("<-nilch")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case x = <-nilch: case x = <-nilch:
panic("<-nilch x") panic("<-nilch x")
{{end}} {{end}}
{{with .Maybe}} {{if .Maybe}}
case **(**int)(nil) = <-nilch: case **(**int)(nil) = <-nilch:
panic("<-nilch (and didn't crash saving result!)") panic("<-nilch (and didn't crash saving result!)")
{{end}} {{end}}
{{with .MustDefault}} {{if .MustDefault}}
default: default:
{{end}} {{end}}
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment