[インデックス 15909] ファイルの概要
このコミットは、Go 1.1のリリースノートである doc/go1.1.html
ファイルに対する更新です。Go 1.1で導入された新機能や変更点に関するドキュメントを、より詳細かつ正確に記述することを目的としています。具体的には、メソッド値、go vet
コマンドの改善、go test
コマンドのプロファイリング機能(特にブロッキングプロファイル)、net
パッケージのListenUnixgram
関数の戻り値の修正、text/template
およびhtml/template
パッケージの機能強化など、多岐にわたる更新が含まれています。
コミット
commit bfeb79bae5e27977d1b82e8ffa4bf08c0a9d33fa
Author: Rob Pike <r@golang.org>
Date: Fri Mar 22 15:45:16 2013 -0700
doc/go1.1.html: blockprofile, method values, ListenUnixgram, etc.
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/7496051
GitHub上でのコミットページへのリンク
https://github.com/golang/go/commit/bfeb79bae5e27977d1b82e8ffa4bf08c0a9d33fa
元コミット内容
doc/go1.1.html: blockprofile, method values, ListenUnixgram, etc.
このコミットは、Go 1.1のドキュメントファイル doc/go1.1.html
を更新し、ブロッキングプロファイル、メソッド値、ListenUnixgram
関数の変更など、Go 1.1で導入された主要な機能や改善点について記述しています。
変更の背景
Go言語は継続的に進化しており、新しいバージョンがリリースされるたびに、その変更点をユーザーに伝えるための公式ドキュメントが更新されます。このコミットは、Go 1.1のリリースに向けて、その新機能や改善点を正確かつ包括的に説明するために doc/go1.1.html
を更新する一環として行われました。特に、Go 1.1では言語仕様の変更(メソッド値の導入)や、ツール(go vet
, go test
)の機能強化、標準ライブラリの修正や追加が行われており、これらの情報をユーザーに提供することが不可欠でした。
前提知識の解説
メソッド値 (Method values) とメソッド式 (Method expressions)
Go言語において、メソッドは特定の型に関連付けられた関数です。
- メソッド値: 特定のレシーバ値にバインドされた関数です。例えば、
bufio.Writer
型の変数w
がある場合、w.Write
はw
に常に書き込む関数となります。これは、w
をクロージャでキャプチャする関数リテラルと等価です。メソッド値は、レシーバが既に決定しているため、追加の引数を必要としません。 - メソッド式: 特定の型からメソッドを生成する関数です。例えば、
(*bufio.Writer).Write
は、(*bufio.Writer)
型のレシーバを最初の引数として取る関数と等価です。メソッド式は、レシーバがまだ決定していないため、呼び出し時にレシーバを引数として渡す必要があります。
Go 1.1でメソッド値が実装されたことで、より柔軟なプログラミングが可能になりましたが、既存のコードには影響を与えない後方互換性のある変更です。
go vet
コマンド
go vet
は、Goプログラムの潜在的なバグや疑わしい構造を検出するための静的解析ツールです。Go 1.1では、アセンブリで実装された関数が、対応するGoの関数プロトタイプと一致するかどうかをチェックする機能が追加されました。これにより、アセンブリコードとGoコード間の不整合によるバグを防ぐことができます。
go test
コマンドとプロファイリング
go test
は、Goパッケージのテストを実行するためのコマンドです。Go 1.1では、プロファイリング機能が強化されました。
- バイナリの削除抑制: プロファイリングを有効にして
go test
を実行した場合、テストバイナリ(例:mypackage.test
)が削除されなくなりました。これにより、プロファイル分析が容易になります。 - ブロッキングプロファイル (Blocking profile): ゴルーチンがイベント(チャネル通信など)を待機して停止する傾向がある場所を報告するプロファイリング情報です。
go test
コマンドの-blockprofile
オプションで有効にできます。これは、並行処理アプリケーションのパフォーマンスボトルネックを特定するのに非常に役立ちます。
net
パッケージの ListenUnixgram
関数
net
パッケージは、ネットワークI/Oのプリミティブを提供します。ListenUnixgram
関数は、Unixドメインデータグラム接続をリッスンするために使用されます。Go 1.1では、この関数の戻り値の型がnet/UDPConn
からnet/UnixConn
に変更されました。これはGo 1.0での間違いを修正するものであり、APIの変更ではありますが、バグ修正であるためGo 1互換性ルールによって許可されています。
text/template
および html/template
パッケージ
これらのパッケージは、Go言語でテンプレートを扱うための機能を提供します。
- パイプラインのグループ化: Go 1.1では、テンプレートのパイプライン要素を括弧でグループ化できるようになりました。これにより、複雑なパイプラインの構築が簡素化されます。
Node
インターフェースの変更: 新しいパーサーの一部として、Node
インターフェースにエラー報告を改善するための2つの新しいメソッドが追加されました。これはGo 1互換性ルールに違反しますが、このインターフェースはtext/template
およびhtml/template
パッケージによってのみ使用されることを意図しており、既存のコードに影響を与えないように保護されているため、問題ないとされています。
技術的詳細
このコミットは、doc/go1.1.html
ファイルに対して、主に以下のセクションにわたる変更を加えています。
-
Method values (メソッド値):
- Go 1.1でメソッド値が実装されたことを明記。
w.Write
のようなメソッド値が、w
をクロージャでキャプチャする関数リテラルと等価であることをコード例で説明。- メソッド値とメソッド式(例:
(*bufio.Writer).Write
)の違いを明確化し、メソッド式がレシーバを最初の引数として取る関数であることを説明。 - この変更が既存のコードに影響を与えない、後方互換性のある変更であることを強調。
-
Return requirements (戻り値の要件):
go vet
コマンドが、アセンブリで実装された関数がGoの関数プロトタイプと一致するかどうかをチェックするようになったことを追記。
-
Changes to the go test command (
go test
コマンドの変更):go test
コマンドがプロファイリングを有効にして実行された際に、バイナリを削除しなくなったことを説明。これにより、プロファイル分析が容易になる。- ブロッキングプロファイルの導入について詳細に記述。ゴルーチンがイベント(チャネル通信など)を待機して停止する場所を報告するプロファイリング情報であり、
-blockprofile
オプションで有効にできることを説明。
-
net package (
net
パッケージ):net
パッケージのListenUnixgram
関数が、net/UDPConn
ではなくnet/UnixConn
を返すように変更されたことを説明。これはGo 1.0での間違いを修正するものであり、バグ修正であるためGo 1互換性ルールによって許可されていることを明記。
-
text/template and html/template packages (
text/template
およびhtml/template
パッケージ):- テンプレートがパイプラインの要素をグループ化するために括弧を使用できるようになったことを説明。
- 新しいパーサーの一部として、
Node
インターフェースにエラー報告を改善するための2つの新しいメソッドが追加されたことを説明。 - この変更がGo 1互換性ルールに違反するものの、このインターフェースがこれらのパッケージによってのみ使用されることを意図しており、既存のコードに影響を与えないように保護されているため問題ないことを説明。
これらの変更は、Go 1.1の機能セットを正確に反映し、ユーザーが新しい機能や改善点を理解しやすくするための重要なドキュメント更新です。
コアとなるコードの変更箇所
このコミットは、doc/go1.1.html
ファイルのみを変更しています。主な変更箇所は以下の通りです。
--- a/doc/go1.1.html
+++ b/doc/go1.1.html
@@ -48,7 +48,39 @@ See the <a href="#unicode">Unicode</a> section for more information.
<h3 id="method_values">Method values</h3>
<p>
-TODO
+Go 1.1 now implements
+<a href="/ref/spec#Method_values">method values</a>,
+which are functions that have been bound to a specific receiver value.
+For instance, given a
+<a href="/pkg/bufio/#Writer"><code>Writer</code></a>
+value <code>w</code>,
+the expression
+<code>w.Write</code>,
+a method value, is a function that will always write to <code>w</code>; it is equivalent to
+a function literal closing over <code>w</code>:
+</p>
+
+<pre>
+func (p []byte) (n int, err error) {
+\treturn w.Write(n, err)
+}
+</pre>
+
+<p>
+Method values are distinct from method expressions, which generate functions
+from methods of a given type; the method expression <code>(*bufio.Writer).Write</code>
+is equivalent to a function with an extra first argument, a receiver of type
+<code>(*bufio.Writer)</code>:
+</p>
+
+<pre>
+func (w *bufio.Writer, p []byte) (n int, err error) {
+\treturn w.Write(n, err)
+}
+</pre>
+
+<p>
+<em>Updating</em>: No existing code is affected; the change is strictly backward-compatible.
</p>
<h3 id="return">Return requirements</h3>
@@ -88,10 +120,6 @@ Such code can be identified by <code>go vet</code>.
<h2 id="impl">Changes to the implementations and tools</h2>
-<p>
-TODO: more
-</p>
-
<h3 id="gc_flag">Command-line flag parsing</h3>
<p>
@@ -193,7 +221,7 @@ some editors add them as a kind of "magic number" identifying a UTF-8 encoded fi
<em>Updating</em>:
Most programs will be unaffected by the surrogate change.\n Programs that depend on the old behavior should be modified to avoid the issue.\n-The byte-order-mark change is strictly backwards-compatible.\n+The byte-order-mark change is strictly backward-compatible.\n </p>
<h3 id="gc_asm">The gc assemblers</h3>
@@ -206,7 +234,9 @@ to adjust frame pointer offsets.\n </p>\n \n <p>\n-TODO: Point to cmd/vet once it handles this.\n+<em>Updating</em>:\n+The <code>go vet</code> command now checks that functions implemented in assembly\n+match the Go function prototypes they implement.\n </p>\n \n <h3 id="gocmd">Changes to the go command</h3>
@@ -251,6 +281,8 @@ warning: GOPATH set to GOROOT (/home/User/go) has no effect\n package code.google.com/p/foo/quxx: cannot download, $GOPATH must not be set to $GOROOT. For more details see: go help gopath\n </pre>\n \n+<h3 id="gotest">Changes to the go test command</h3>\n+\n <p>\n The <code>go test</code> command no longer deletes the binary when run with profiling enabled,\n to make it easier to analyze the profile.\n@@ -265,7 +297,20 @@ $ go test -cpuprofile cpuprof.out mypackage\n the file <code>mypackage.test</code> will be left in the directory where <code>go test</code> was run.\n </p>\n \n-<h3 id="gofix">Changes to go fix</h3>\n+<p>\n+The <code>go test</code> command can now generate profiling information\n+that reports where goroutines are blocked, that is,\n+where they tend to stall waiting for an event such as a channel communication.\n+The information is presented as a\n+<em>blocking profile</em>\n+enabled with the\n+<code>-blockprofile</code>\n+option of\n+<code>go test</code>.\n+Run <code>go help test</code> for more information.\n+</p>\n+\n+<h3 id="gofix">Changes to the go fix command</h3>\n \n <p>\n The <a href="/cmd/fix/"><code>fix</code></a> command, usually run as\n@@ -408,14 +453,6 @@ only <code>T</code>.\n </p>\n \n \n-\n-<h3 id="runtime">runtime</h3>\n-\n-<p>\n-TODO:\n-<code>runtime</code>: BlockProfile\n-</p>\n-\n <h3 id="time">time</h3>\n <p>\n On FreeBSD, Linux, NetBSD, OS X and OpenBSD, previous versions of the\n@@ -643,6 +680,18 @@ has a new method for its\n to define the boundary separator used to package the output.\n </li>\n \n+<li>\n+The\n+<a href="/pkg/net/"><code>net</code></a> package\'s\n+<a href="/pkg/net/ListenUnixgram/"><code>net/ListenUnixgram</code></a>\n+function has changed return types: it now returns a\n+<a href="/pkg/net/UnixConn/"><code>net/UnixConn</code></a>\n+rather than a\n+<a href="/pkg/net/UDPConn/"><code>net/UDPConn</code></a>, which was\n+clearly a mistake in Go 1.0.\n+Since this API change fixes a bug, it is permitted by the Go 1 compatibility rules.\n+</li>\n+\n <li>\n The new <a href="/pkg/net/http/cookiejar/">net/http/cookiejar</a> package provides the basics for managing HTTP cookies.\n </li>\n@@ -748,6 +797,16 @@ and\n <a href="/pkg/html/template/"><code>html/template</code></a> packages,\n templates can now use parentheses to group the elements of pipelines, simplifying the construction of complex pipelines.\n TODO: Link to example.\n+Also, as part of the new parser, the\n+<a href="/pkg/text/template/parse/#Node"><code>Node</code></a> interface got two new methods to provide\n+better error reporting.\n+Although this violates the Go 1 compatibility rules,\n+no existing code should be affected because this interface is explicitly intended only to be used\n+by the\n+<a href="/pkg/text/template/"><code>text/template</code></a>\n+and\n+<a href="/pkg/html/template/"><code>html/template</code></a>\n+packages and there are safeguards to guarantee that.\n </li>\n \n <li>
コアとなるコードの解説
このコミットは、Go 1.1のリリースノートであるdoc/go1.1.html
ファイルに、以下の重要な情報を追加・修正しています。
-
メソッド値の導入 (
<h3 id="method_values">Method values</h3>
セクション):- 以前は
TODO
とだけ書かれていた箇所に、Go 1.1でメソッド値が実装されたこと、その定義、および具体的なコード例が追加されました。 w.Write
のようなメソッド値が、w
をキャプチャする関数リテラルと等価であることが示されています。- メソッド値とメソッド式(例:
(*bufio.Writer).Write
)の違いが明確に説明され、メソッド式がレシーバを最初の引数として取る関数であることが示されています。 - この変更が既存のコードに影響を与えない、後方互換性のある変更であることが明記されています。
- 以前は
-
go vet
の改善 (<h3 id="gc_asm">The gc assemblers</h3>
セクション):TODO: Point to cmd/vet once it handles this.
という記述が削除され、go vet
コマンドがアセンブリで実装された関数がGoの関数プロトタイプと一致するかどうかをチェックするようになったことが追記されました。
-
go test
コマンドの変更 (<h3 id="gotest">Changes to the go test command</h3>
セクション):go test
コマンドがプロファイリングを有効にして実行された際に、テストバイナリを削除しなくなったことが説明されています。- ブロッキングプロファイルの導入に関する詳細な説明が追加されました。これは、ゴルーチンがチャネル通信などのイベントを待機して停止する場所を報告するプロファイリング情報であり、
-blockprofile
オプションで有効にできることが示されています。
-
net
パッケージのListenUnixgram
関数の修正 (<li>
要素内):net
パッケージのListenUnixgram
関数が、Go 1.0での間違いを修正するために、net/UDPConn
ではなくnet/UnixConn
を返すように変更されたことが説明されています。このAPI変更がバグ修正であるため、Go 1互換性ルールによって許可されていることが明記されています。
-
text/template
およびhtml/template
パッケージの機能強化 (<li>
要素内):- テンプレートがパイプラインの要素をグループ化するために括弧を使用できるようになったことが説明されています。
- 新しいパーサーの一部として、
Node
インターフェースにエラー報告を改善するための2つの新しいメソッドが追加されたことが説明されています。この変更がGo 1互換性ルールに違反するものの、このインターフェースがこれらのパッケージによってのみ使用されることを意図しており、既存のコードに影響を与えないように保護されているため問題ないことが説明されています。
これらの変更は、Go 1.1の重要な新機能や改善点をユーザーに伝えるためのドキュメントの正確性と網羅性を高めるものです。
関連リンク
- Go CL 7496051: https://golang.org/cl/7496051
参考にした情報源リンク
- コミット情報から抽出したデータ
- Go言語の公式ドキュメント(Go 1.1リリースノートの文脈理解のため)
- Go言語の仕様(メソッド値、メソッド式などの概念理解のため)