diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/README.md b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d6f2c549605d2aae2eae1d3ba5ee3d5fce30da7e --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/README.md @@ -0,0 +1,42 @@ +This directory contains test files (*.txt) for the comment parser. + +The files are in [txtar format](https://pkg.go.dev/golang.org/x/tools/txtar). +Consider this example: + + -- input -- + Hello. + -- gofmt -- + Hello. + -- html -- +

Hello. + -- markdown -- + Hello. + -- text -- + Hello. + +Each `-- name --` line introduces a new file with the given name. +The file named “input” must be first and contains the input to +[comment.Parser](https://pkg.go.dev/go/doc/comment/#Parser). + +The remaining files contain the expected output for the named format generated by +[comment.Printer](https://pkg.go.dev/go/doc/comment/#Printer): +“gofmt” for Printer.Comment (Go comment format, as used by gofmt), +“html” for Printer.HTML, “markdown” for Printer.Markdown, and “text” for Printer.Text. +The format can also be “dump” for a textual dump of the raw data structures. + +The text before the `-- input --` line, if present, is JSON to be unmarshalled +to initialize a comment.Printer. For example, this test case sets the Printer's +TextWidth field to 20: + + {"TextWidth": 20} + -- input -- + Package gob manages streams of gobs - binary values exchanged between an + Encoder (transmitter) and a Decoder (receiver). + -- text -- + Package gob + manages streams + of gobs - binary + values exchanged + between an Encoder + (transmitter) and a + Decoder (receiver). diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/blank.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/blank.txt new file mode 100644 index 0000000000000000000000000000000000000000..9049fde76ed387b0520220b79f881eb1d7221454 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/blank.txt @@ -0,0 +1,12 @@ +-- input -- + $ + Blank line at start and end. + $ +-- gofmt -- +Blank line at start and end. +-- text -- +Blank line at start and end. +-- markdown -- +Blank line at start and end. +-- html -- +

Blank line at start and end. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code.txt new file mode 100644 index 0000000000000000000000000000000000000000..06b1519574c75c3b8fe2ebcbeace7a5f3b0555ac --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code.txt @@ -0,0 +1,94 @@ +-- input -- +Text. + A tab-indented + (no, not eight-space indented) + code block and haiku. +More text. + One space + is + enough + to + start + a + block. +More text. + + Blocks + can + + have + blank + lines. +-- gofmt -- +Text. + + A tab-indented + (no, not eight-space indented) + code block and haiku. + +More text. + + One space + is + enough + to + start + a + block. + +More text. + + Blocks + can + + have + blank + lines. +-- markdown -- +Text. + + A tab-indented + (no, not eight-space indented) + code block and haiku. + +More text. + + One space + is + enough + to + start + a + block. + +More text. + + Blocks + can + + have + blank + lines. +-- html -- +

Text. +

A tab-indented
+(no, not eight-space indented)
+code block and haiku.
+
+

More text. +

One space
+ is
+  enough
+   to
+    start
+     a
+      block.
+
+

More text. +

    Blocks
+  can
+
+have
+  blank
+    lines.
+
diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code2.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code2.txt new file mode 100644 index 0000000000000000000000000000000000000000..0810bed41c2079682b95f791ac1dae1f0e0894a4 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code2.txt @@ -0,0 +1,31 @@ +-- input -- +Text. + + A tab-indented + (no, not eight-space indented) + code block and haiku. + +More text. +-- gofmt -- +Text. + + A tab-indented + (no, not eight-space indented) + code block and haiku. + +More text. +-- markdown -- +Text. + + A tab-indented + (no, not eight-space indented) + code block and haiku. + +More text. +-- html -- +

Text. +

A tab-indented
+(no, not eight-space indented)
+code block and haiku.
+
+

More text. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code3.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code3.txt new file mode 100644 index 0000000000000000000000000000000000000000..4a96a0e9ab9e83f9601a1bec6ef018690a376163 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code3.txt @@ -0,0 +1,33 @@ +-- input -- +Text. + + $ + A tab-indented + (surrounded by more blank lines) + code block and haiku. + $ + +More text. +-- gofmt -- +Text. + + A tab-indented + (surrounded by more blank lines) + code block and haiku. + +More text. +-- markdown -- +Text. + + A tab-indented + (surrounded by more blank lines) + code block and haiku. + +More text. +-- html -- +

Text. +

A tab-indented
+(surrounded by more blank lines)
+code block and haiku.
+
+

More text. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code4.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code4.txt new file mode 100644 index 0000000000000000000000000000000000000000..f128c9aeff72d371b257a59c6c54200f824addec --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code4.txt @@ -0,0 +1,38 @@ +-- input -- +To test, run this command: + go test -more + +Or, to test specific things, run this command: + +go test -more \ + -pkg first/package \ + -pkg second/package \ + -pkg third/package + +Happy testing! +-- gofmt -- +To test, run this command: + + go test -more + +Or, to test specific things, run this command: + + go test -more \ + -pkg first/package \ + -pkg second/package \ + -pkg third/package + +Happy testing! +-- markdown -- +To test, run this command: + + go test -more + +Or, to test specific things, run this command: + + go test -more \ + -pkg first/package \ + -pkg second/package \ + -pkg third/package + +Happy testing! diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code5.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code5.txt new file mode 100644 index 0000000000000000000000000000000000000000..0e340dd129838231be264bcf6eb89e267f3ca299 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code5.txt @@ -0,0 +1,21 @@ +-- input -- +L1 +L2 +L3 +L4 +L5 +- L6 { + L7 +} +L8 +-- gofmt -- +L1 +L2 +L3 +L4 +L5 + - L6 { + L7 + } + +L8 diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code6.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code6.txt new file mode 100644 index 0000000000000000000000000000000000000000..d2915d10680158fa9b8002fd79d799e2057f0358 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/code6.txt @@ -0,0 +1,24 @@ +-- input -- +Run this program: + +func main() { + fmt.Println("hello, world") +} + +Or this: + +go func() { + fmt.Println("hello, world") +}() +-- gofmt -- +Run this program: + + func main() { + fmt.Println("hello, world") + } + +Or this: + + go func() { + fmt.Println("hello, world") + }() diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/crash1.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/crash1.txt new file mode 100644 index 0000000000000000000000000000000000000000..6bb2f6fdda1f4dc7063e72d6bd0145dcddbb5f03 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/crash1.txt @@ -0,0 +1,16 @@ +-- input -- +[] + +[]: http:// +-- gofmt -- +[] + +[]: http:// +-- html -- +

+-- markdown -- +[](http://) +-- text -- + + +[]: http:// diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink.txt new file mode 100644 index 0000000000000000000000000000000000000000..a9323471fd450a2aa3a522c447978e29a46691ca --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink.txt @@ -0,0 +1,21 @@ +-- input -- +In this package, see [Doc] and [Parser.Parse]. +There is no [Undef] or [Undef.Method]. +See also the [comment] package, +especially [comment.Doc] and [comment.Parser.Parse]. +-- gofmt -- +In this package, see [Doc] and [Parser.Parse]. +There is no [Undef] or [Undef.Method]. +See also the [comment] package, +especially [comment.Doc] and [comment.Parser.Parse]. +-- text -- +In this package, see Doc and Parser.Parse. There is no [Undef] or +[Undef.Method]. See also the comment package, especially comment.Doc and +comment.Parser.Parse. +-- markdown -- +In this package, see [Doc](#Doc) and [Parser.Parse](#Parser.Parse). There is no \[Undef] or \[Undef.Method]. See also the [comment](/go/doc/comment) package, especially [comment.Doc](/go/doc/comment#Doc) and [comment.Parser.Parse](/go/doc/comment#Parser.Parse). +-- html -- +

In this package, see Doc and Parser.Parse. +There is no [Undef] or [Undef.Method]. +See also the comment package, +especially comment.Doc and comment.Parser.Parse. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink2.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink2.txt new file mode 100644 index 0000000000000000000000000000000000000000..ecd8e4e0bce4fab044d0ad912af6613ff80cc3be --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink2.txt @@ -0,0 +1,8 @@ +-- input -- +We use [io.Reader] a lot, and also a few map[io.Reader]string. + +Never [io.Reader]int or Slice[io.Reader] though. +-- markdown -- +We use [io.Reader](/io#Reader) a lot, and also a few map\[io.Reader]string. + +Never \[io.Reader]int or Slice\[io.Reader] though. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink3.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink3.txt new file mode 100644 index 0000000000000000000000000000000000000000..0ccfb3df70826fcae93076f71fd486afc116bd10 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink3.txt @@ -0,0 +1,8 @@ +-- input -- +[encoding/json.Marshal] is a doc link. + +[rot13.Marshal] is not. +-- markdown -- +[encoding/json.Marshal](/encoding/json#Marshal) is a doc link. + +\[rot13.Marshal] is not. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink4.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink4.txt new file mode 100644 index 0000000000000000000000000000000000000000..c7095276bfea309f5e0d5f99d65df5999d6e7d17 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink4.txt @@ -0,0 +1,7 @@ +-- input -- +[io] at start of comment. +[io] at start of line. +At end of line: [io] +At end of comment: [io] +-- markdown -- +[io](/io) at start of comment. [io](/io) at start of line. At end of line: [io](/io) At end of comment: [io](/io) diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink5.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink5.txt new file mode 100644 index 0000000000000000000000000000000000000000..ac7b3ae100d80dd3f3adbca724ea1e0dac8fbffc --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink5.txt @@ -0,0 +1,5 @@ +{"DocLinkBaseURL": "https://pkg.go.dev"} +-- input -- +[encoding/json.Marshal] is a doc link. +-- markdown -- +[encoding/json.Marshal](https://pkg.go.dev/encoding/json#Marshal) is a doc link. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink6.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink6.txt new file mode 100644 index 0000000000000000000000000000000000000000..1acd03b61639b676b64665eea86e6621c89d9826 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink6.txt @@ -0,0 +1,5 @@ +{"DocLinkBaseURL": "https://go.dev/pkg/"} +-- input -- +[encoding/json.Marshal] is a doc link, and so is [rsc.io/quote.NonExist]. +-- markdown -- +[encoding/json.Marshal](https://go.dev/pkg/encoding/json/#Marshal) is a doc link, and so is [rsc.io/quote.NonExist](https://go.dev/pkg/rsc.io/quote/#NonExist). diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink7.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink7.txt new file mode 100644 index 0000000000000000000000000000000000000000..d34979a3854572c08fd7422f5063d0aa7301d15e --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/doclink7.txt @@ -0,0 +1,4 @@ +-- input -- +You see more [*bytes.Buffer] than [bytes.Buffer]. +-- markdown -- +You see more [\*bytes.Buffer](/bytes#Buffer) than [bytes.Buffer](/bytes#Buffer). diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/escape.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/escape.txt new file mode 100644 index 0000000000000000000000000000000000000000..f54663f5c3ea58bedb356244ef6e8d361f554ed8 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/escape.txt @@ -0,0 +1,55 @@ +-- input -- +What the ~!@#$%^&*()_+-=`{}|[]\:";',./<>? + ++ Line + +- Line + +* Line + +999. Line + +## Line +-- gofmt -- +What the ~!@#$%^&*()_+-=`{}|[]\:";',./<>? + ++ Line + +- Line + +* Line + +999. Line + +## Line +-- text -- +What the ~!@#$%^&*()_+-=`{}|[]\:";',./<>? + ++ Line + +- Line + +* Line + +999. Line + +## Line +-- markdown -- +What the ~!@#$%^&\*()\_+-=\`{}|\[]\\:";',./\<>? + +\+ Line + +\- Line + +\* Line + +999\. Line + +\## Line +-- html -- +

What the ~!@#$%^&*()_+-=`{}|[]\:";',./<>? +

+ Line +

- Line +

* Line +

999. Line +

## Line diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/head.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/head.txt new file mode 100644 index 0000000000000000000000000000000000000000..b99a8c59f3fe7192a4d01cada9dbbe506a937226 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/head.txt @@ -0,0 +1,92 @@ +-- input -- +Some text. + +An Old Heading + +Not An Old Heading. + +And some text. + +# A New Heading. + +And some more text. + +# Not a heading, +because text follows it. + +Because text precedes it, +# not a heading. + +## Not a heading either. + +-- gofmt -- +Some text. + +# An Old Heading + +Not An Old Heading. + +And some text. + +# A New Heading. + +And some more text. + +# Not a heading, +because text follows it. + +Because text precedes it, +# not a heading. + +## Not a heading either. + +-- text -- +Some text. + +# An Old Heading + +Not An Old Heading. + +And some text. + +# A New Heading. + +And some more text. + +# Not a heading, because text follows it. + +Because text precedes it, # not a heading. + +## Not a heading either. + +-- markdown -- +Some text. + +### An Old Heading {#hdr-An_Old_Heading} + +Not An Old Heading. + +And some text. + +### A New Heading. {#hdr-A_New_Heading_} + +And some more text. + +\# Not a heading, because text follows it. + +Because text precedes it, # not a heading. + +\## Not a heading either. + +-- html -- +

Some text. +

An Old Heading

+

Not An Old Heading. +

And some text. +

A New Heading.

+

And some more text. +

# Not a heading, +because text follows it. +

Because text precedes it, +# not a heading. +

## Not a heading either. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/head2.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/head2.txt new file mode 100644 index 0000000000000000000000000000000000000000..d3576325e04998274c8caf6cc8fe94370382d43f --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/head2.txt @@ -0,0 +1,36 @@ +-- input -- +✦ + +Almost a+heading + +✦ + +Don't be a heading + +✦ + +A.b is a heading + +✦ + +A. b is not a heading + +✦ +-- gofmt -- +✦ + +Almost a+heading + +✦ + +Don't be a heading + +✦ + +# A.b is a heading + +✦ + +A. b is not a heading + +✦ diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/head3.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/head3.txt new file mode 100644 index 0000000000000000000000000000000000000000..dbb7cb3ffb8d2d089e551ecc264fdb54270510e0 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/head3.txt @@ -0,0 +1,7 @@ +{"HeadingLevel": 5} +-- input -- +# Heading +-- markdown -- +##### Heading {#hdr-Heading} +-- html -- +

Heading
diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/hello.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/hello.txt new file mode 100644 index 0000000000000000000000000000000000000000..fb07f1eb7575df12261acc19c09c29e272e09815 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/hello.txt @@ -0,0 +1,35 @@ +-- input -- + Hello, + world + + This is + a test. +-- dump -- +Doc + Paragraph + Plain + "Hello,\n" + "world" + Paragraph + Plain + "This is\n" + "a test." +-- gofmt -- +Hello, +world + +This is +a test. +-- html -- +

Hello, +world +

This is +a test. +-- markdown -- +Hello, world + +This is a test. +-- text -- +Hello, world + +This is a test. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link.txt new file mode 100644 index 0000000000000000000000000000000000000000..551e3065ce79add68ec539de1e981334ae423dbb --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link.txt @@ -0,0 +1,17 @@ +-- input -- +The Go home page is https://go.dev/. +It used to be https://golang.org. + +-- gofmt -- +The Go home page is https://go.dev/. +It used to be https://golang.org. + +-- text -- +The Go home page is https://go.dev/. It used to be https://golang.org. + +-- markdown -- +The Go home page is [https://go.dev/](https://go.dev/). It used to be [https://golang.org](https://golang.org). + +-- html -- +

The Go home page is https://go.dev/. +It used to be https://golang.org. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link2.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link2.txt new file mode 100644 index 0000000000000000000000000000000000000000..8637a32f01ab752baf2f764b41608bfcb8f68f54 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link2.txt @@ -0,0 +1,31 @@ +-- input -- +The Go home page is https://go.dev/. +It used to be https://golang.org. +https:// is not a link. +Nor is https:// +https://☺ is not a link. +https://:80 is not a link. + +-- gofmt -- +The Go home page is https://go.dev/. +It used to be https://golang.org. +https:// is not a link. +Nor is https:// +https://☺ is not a link. +https://:80 is not a link. + +-- text -- +The Go home page is https://go.dev/. It used to be https://golang.org. https:// +is not a link. Nor is https:// https://☺ is not a link. https://:80 is not a +link. + +-- markdown -- +The Go home page is [https://go.dev/](https://go.dev/). It used to be [https://golang.org](https://golang.org). https:// is not a link. Nor is https:// https://☺ is not a link. https://:80 is not a link. + +-- html -- +

The Go home page is https://go.dev/. +It used to be https://golang.org. +https:// is not a link. +Nor is https:// +https://☺ is not a link. +https://:80 is not a link. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link3.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link3.txt new file mode 100644 index 0000000000000000000000000000000000000000..5a115b5cb7199b79cce4877a02c4e4aa748ba705 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link3.txt @@ -0,0 +1,14 @@ +-- input -- +Doc text. + +[Go home page]: https://go.dev +-- gofmt -- +Doc text. + +[Go home page]: https://go.dev +-- text -- +Doc text. +-- markdown -- +Doc text. +-- html -- +

Doc text. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link4.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link4.txt new file mode 100644 index 0000000000000000000000000000000000000000..75f194c845c2ecc879ef44165d1025adea10f559 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link4.txt @@ -0,0 +1,77 @@ +-- input -- +These are not links. + +[x + +[x]: + +[x]:https://go.dev + +[x]https://go.dev + +[x]: surprise://go.dev + +[x]: surprise! + +But this is, with a tab (although it's unused). + +[z]: https://go.dev +-- gofmt -- +These are not links. + +[x + +[x]: + +[x]:https://go.dev + +[x]https://go.dev + +[x]: surprise://go.dev + +[x]: surprise! + +But this is, with a tab (although it's unused). + +[z]: https://go.dev +-- text -- +These are not links. + +[x + +[x]: + +[x]:https://go.dev + +[x]https://go.dev + +[x]: surprise://go.dev + +[x]: surprise! + +But this is, with a tab (although it's unused). +-- markdown -- +These are not links. + +\[x + +\[x]: + +\[x]:[https://go.dev](https://go.dev) + +\[x][https://go.dev](https://go.dev) + +\[x]: surprise://go.dev + +\[x]: surprise! + +But this is, with a tab (although it's unused). +-- html -- +

These are not links. +

[x +

[x]: +

[x]:https://go.dev +

[x]https://go.dev +

[x]: surprise://go.dev +

[x]: surprise! +

But this is, with a tab (although it's unused). diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link5.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link5.txt new file mode 100644 index 0000000000000000000000000000000000000000..b4fb5889f47dca450da55ccf5b76850ad4a56640 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link5.txt @@ -0,0 +1,36 @@ +-- input -- +See the [Go home page] and the [pkg +site]. + +[Go home page]: https://go.dev/ +[pkg site]: https://pkg.go.dev +[Go home page]: https://duplicate.ignored + +They're really great! + +-- gofmt -- +See the [Go home page] and the [pkg +site]. + +They're really great! + +[Go home page]: https://go.dev/ +[pkg site]: https://pkg.go.dev + +[Go home page]: https://duplicate.ignored + +-- text -- +See the Go home page and the pkg site. + +They're really great! + +[Go home page]: https://go.dev/ +[pkg site]: https://pkg.go.dev +-- markdown -- +See the [Go home page](https://go.dev/) and the [pkg site](https://pkg.go.dev). + +They're really great! +-- html -- +

See the Go home page and the pkg +site. +

They're really great! diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link6.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link6.txt new file mode 100644 index 0000000000000000000000000000000000000000..ff629b4573653da1d801d1050756878745d9bc17 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link6.txt @@ -0,0 +1,50 @@ +-- input -- +URLs with punctuation are hard. +We don't want to consume the end-of-sentence punctuation. + +For example, https://en.wikipedia.org/wiki/John_Adams_(miniseries). +And https://example.com/[foo]/bar{. +And https://example.com/(foo)/bar! +And https://example.com/{foo}/bar{. +And https://example.com/)baz{foo}. + +[And https://example.com/]. + +-- gofmt -- +URLs with punctuation are hard. +We don't want to consume the end-of-sentence punctuation. + +For example, https://en.wikipedia.org/wiki/John_Adams_(miniseries). +And https://example.com/[foo]/bar{. +And https://example.com/(foo)/bar! +And https://example.com/{foo}/bar{. +And https://example.com/)baz{foo}. + +[And https://example.com/]. + +-- text -- +URLs with punctuation are hard. We don't want to consume the end-of-sentence +punctuation. + +For example, https://en.wikipedia.org/wiki/John_Adams_(miniseries). +And https://example.com/[foo]/bar{. And https://example.com/(foo)/bar! And +https://example.com/{foo}/bar{. And https://example.com/)baz{foo}. + +[And https://example.com/]. + +-- markdown -- +URLs with punctuation are hard. We don't want to consume the end-of-sentence punctuation. + +For example, [https://en.wikipedia.org/wiki/John\_Adams\_(miniseries)](https://en.wikipedia.org/wiki/John_Adams_(miniseries)). And [https://example.com/\[foo]/bar](https://example.com/[foo]/bar){. And [https://example.com/(foo)/bar](https://example.com/(foo)/bar)! And [https://example.com/{foo}/bar](https://example.com/{foo}/bar){. And [https://example.com/](https://example.com/))baz{foo}. + +\[And [https://example.com/](https://example.com/)]. + +-- html -- +

URLs with punctuation are hard. +We don't want to consume the end-of-sentence punctuation. +

For example, https://en.wikipedia.org/wiki/John_Adams_(miniseries). +And https://example.com/[foo]/bar{. +And https://example.com/(foo)/bar! +And https://example.com/{foo}/bar{. +And https://example.com/)baz{foo}. +

[And https://example.com/]. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link7.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link7.txt new file mode 100644 index 0000000000000000000000000000000000000000..89a8b3170e0116b92d2dfd260d9b1c56eee0632f --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/link7.txt @@ -0,0 +1,25 @@ +-- input -- +[math] is a package but this is not a doc link. + +[io] is a doc link. + +[math]: https://example.com +-- gofmt -- +[math] is a package but this is not a doc link. + +[io] is a doc link. + +[math]: https://example.com +-- text -- +math is a package but this is not a doc link. + +io is a doc link. + +[math]: https://example.com +-- markdown -- +[math](https://example.com) is a package but this is not a doc link. + +[io](/io) is a doc link. +-- html -- +

math is a package but this is not a doc link. +

io is a doc link. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/linklist.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/linklist.txt new file mode 100644 index 0000000000000000000000000000000000000000..baf40624b345d26b9ce49ffe1c8fbff32bc2750c --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/linklist.txt @@ -0,0 +1,18 @@ +{"DocLinkBaseURL": "https://pkg.go.dev"} +-- input -- +Did you know? + + - [encoding/json.Marshal] is a doc link. So is [encoding/json.Unmarshal]. +-- text -- +Did you know? + + - encoding/json.Marshal is a doc link. So is encoding/json.Unmarshal. +-- markdown -- +Did you know? + + - [encoding/json.Marshal](https://pkg.go.dev/encoding/json#Marshal) is a doc link. So is [encoding/json.Unmarshal](https://pkg.go.dev/encoding/json#Unmarshal). +-- html -- +

Did you know? +

diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/linklist2.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/linklist2.txt new file mode 100644 index 0000000000000000000000000000000000000000..81b306100f3205e218d70af0290676cf7c9cf0cd --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/linklist2.txt @@ -0,0 +1,39 @@ +{"DocLinkBaseURL": "https://pkg.go.dev"} +-- input -- +Did you know? + + - [testing.T] is one doc link. + - So is [testing.M]. + - So is [testing.B]. + This is the same list paragraph. + + There is [testing.PB] in this list item, too! +-- text -- +Did you know? + + - testing.T is one doc link. + + - So is testing.M. + + - So is testing.B. This is the same list paragraph. + + There is testing.PB in this list item, too! +-- markdown -- +Did you know? + + - [testing.T](https://pkg.go.dev/testing#T) is one doc link. + + - So is [testing.M](https://pkg.go.dev/testing#M). + + - So is [testing.B](https://pkg.go.dev/testing#B). This is the same list paragraph. + + There is [testing.PB](https://pkg.go.dev/testing#PB) in this list item, too! +-- html -- +

Did you know? +

diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/linklist3.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/linklist3.txt new file mode 100644 index 0000000000000000000000000000000000000000..701a54ecff4f68bdf2d2bf44fafe00f41b717e96 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/linklist3.txt @@ -0,0 +1,31 @@ +{"DocLinkBaseURL": "https://pkg.go.dev"} +-- input -- +Cool things: + + - Foo + - [Go] + - Bar + +[Go]: https://go.dev/ +-- text -- +Cool things: + + - Foo + - Go + - Bar + +[Go]: https://go.dev/ +-- markdown -- +Cool things: + + - Foo + - [Go](https://go.dev/) + - Bar + +-- html -- +

Cool things: +

diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/linklist4.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/linklist4.txt new file mode 100644 index 0000000000000000000000000000000000000000..db39ec4ee1063ef7425d3ec41fe9eb89130774ba --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/linklist4.txt @@ -0,0 +1,36 @@ +{"DocLinkBaseURL": "https://pkg.go.dev"} +-- input -- +Cool things: + + - Foo + - [Go] is great + + [Go]: https://go.dev/ + - Bar + +-- text -- +Cool things: + + - Foo + + - Go is great + + - Bar + +[Go]: https://go.dev/ +-- markdown -- +Cool things: + + - Foo + + - [Go](https://go.dev/) is great + + - Bar + +-- html -- +

Cool things: +

diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list.txt new file mode 100644 index 0000000000000000000000000000000000000000..455782f864ffeb8822e2cab7a48471a4482cd2f3 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list.txt @@ -0,0 +1,48 @@ +-- input -- +Text. +- Not a list. + - Here is the list. + • Using multiple bullets. + * Indentation does not matter. + + Lots of bullets. +More text. + +-- gofmt -- +Text. +- Not a list. + - Here is the list. + - Using multiple bullets. + - Indentation does not matter. + - Lots of bullets. + +More text. + +-- text -- +Text. - Not a list. + - Here is the list. + - Using multiple bullets. + - Indentation does not matter. + - Lots of bullets. + +More text. + +-- markdown -- +Text. - Not a list. + + - Here is the list. + - Using multiple bullets. + - Indentation does not matter. + - Lots of bullets. + +More text. + +-- html -- +

Text. +- Not a list. +

+

More text. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list10.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list10.txt new file mode 100644 index 0000000000000000000000000000000000000000..9c490834560c40fdbba606c33ac88cdf8e5d9e7a --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list10.txt @@ -0,0 +1,13 @@ +-- input -- + + 1. This list + 2. Starts the comment + 3. And also has a blank line before it. + +All of which is a little weird. +-- gofmt -- + 1. This list + 2. Starts the comment + 3. And also has a blank line before it. + +All of which is a little weird. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list2.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list2.txt new file mode 100644 index 0000000000000000000000000000000000000000..c390b3d59a5bb3b2e1f5f28736f82acb51b04fd8 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list2.txt @@ -0,0 +1,57 @@ +-- input -- +Text. + 1. Uno + 2) Dos + 3. Tres + 5. Cinco + 7. Siete + 11. Once + 12. Doce + 13. Trece. + +-- gofmt -- +Text. + 1. Uno + 2. Dos + 3. Tres + 5. Cinco + 7. Siete + 11. Once + 12. Doce + 13. Trece. + +-- text -- +Text. + 1. Uno + 2. Dos + 3. Tres + 5. Cinco + 7. Siete + 11. Once + 12. Doce + 13. Trece. + +-- markdown -- +Text. + + 1. Uno + 2. Dos + 3. Tres + 5. Cinco + 7. Siete + 11. Once + 12. Doce + 13. Trece. + +-- html -- +

Text. +

    +
  1. Uno +
  2. Dos +
  3. Tres +
  4. Cinco +
  5. Siete +
  6. Once +
  7. Doce +
  8. Trece. +
diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list3.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list3.txt new file mode 100644 index 0000000000000000000000000000000000000000..d7d345d2d3ca34e1c2f23db1cd3497ee59131743 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list3.txt @@ -0,0 +1,32 @@ +-- input -- +Text. + + 1. Uno + 1. Dos + 1. Tres + 1. Quatro + +-- gofmt -- +Text. + + 1. Uno + 1. Dos + 1. Tres + 1. Quatro + +-- markdown -- +Text. + + 1. Uno + 1. Dos + 1. Tres + 1. Quatro + +-- html -- +

Text. +

    +
  1. Uno +
  2. Dos +
  3. Tres +
  4. Quatro +
diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list4.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list4.txt new file mode 100644 index 0000000000000000000000000000000000000000..9c28d65b6c3e2c01651e8784a9eca6e45a410fe4 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list4.txt @@ -0,0 +1,38 @@ +-- input -- +Text. + 1. List +2. Not indented, not a list. + 3. Another list. + +-- gofmt -- +Text. + 1. List + +2. Not indented, not a list. + 3. Another list. + +-- text -- +Text. + 1. List + +2. Not indented, not a list. + 3. Another list. + +-- markdown -- +Text. + + 1. List + +2\. Not indented, not a list. + + 3. Another list. + +-- html -- +

Text. +

    +
  1. List +
+

2. Not indented, not a list. +

    +
  1. Another list. +
diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list5.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list5.txt new file mode 100644 index 0000000000000000000000000000000000000000..a5128e5b7c06527c4f4bcc00d497e3faa9e468e7 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list5.txt @@ -0,0 +1,40 @@ +-- input -- +Text. + + 1. One + 999999999999999999999. Big + 1000000000000000000000. Bigger + 1000000000000000000001. Biggest + +-- gofmt -- +Text. + + 1. One + 999999999999999999999. Big + 1000000000000000000000. Bigger + 1000000000000000000001. Biggest + +-- text -- +Text. + + 1. One + 999999999999999999999. Big + 1000000000000000000000. Bigger + 1000000000000000000001. Biggest + +-- markdown -- +Text. + + 1. One + 999999999999999999999. Big + 1000000000000000000000. Bigger + 1000000000000000000001. Biggest + +-- html -- +

Text. +

    +
  1. One +
  2. Big +
  3. Bigger +
  4. Biggest +
diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list6.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list6.txt new file mode 100644 index 0000000000000000000000000000000000000000..ffc0122f52ad532d3af330e21b648ee37ffa116a --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list6.txt @@ -0,0 +1,129 @@ +-- input -- +Text. + - List immediately after. + - Another. + +More text. + + - List after blank line. + - Another. + +Even more text. + - List immediately after. + + - Blank line between items. + +Yet more text. + + - Another list after blank line. + + - Blank line between items. + +Still more text. + - One list item. + + Multiple paragraphs. +-- dump -- +Doc + Paragraph + Plain "Text." + List ForceBlankBefore=false ForceBlankBetween=false + Item Number="" + Paragraph + Plain "List immediately after." + Item Number="" + Paragraph + Plain "Another." + Paragraph + Plain "More text." + List ForceBlankBefore=true ForceBlankBetween=false + Item Number="" + Paragraph + Plain "List after blank line." + Item Number="" + Paragraph + Plain "Another." + Paragraph + Plain "Even more text." + List ForceBlankBefore=false ForceBlankBetween=true + Item Number="" + Paragraph + Plain "List immediately after." + Item Number="" + Paragraph + Plain "Blank line between items." + Paragraph + Plain "Yet more text." + List ForceBlankBefore=true ForceBlankBetween=true + Item Number="" + Paragraph + Plain "Another list after blank line." + Item Number="" + Paragraph + Plain "Blank line between items." + Paragraph + Plain "Still more text." + List ForceBlankBefore=false ForceBlankBetween=true + Item Number="" + Paragraph + Plain "One list item." + Paragraph + Plain "Multiple paragraphs." + +-- gofmt -- +Text. + - List immediately after. + - Another. + +More text. + + - List after blank line. + - Another. + +Even more text. + + - List immediately after. + + - Blank line between items. + +Yet more text. + + - Another list after blank line. + + - Blank line between items. + +Still more text. + + - One list item. + + Multiple paragraphs. + +-- markdown -- +Text. + + - List immediately after. + - Another. + +More text. + + - List after blank line. + - Another. + +Even more text. + + - List immediately after. + + - Blank line between items. + +Yet more text. + + - Another list after blank line. + + - Blank line between items. + +Still more text. + + - One list item. + + Multiple paragraphs. + diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list7.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list7.txt new file mode 100644 index 0000000000000000000000000000000000000000..446605061f6d0e9c71d0a8f9b6f9bcdb1ae8d5a2 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list7.txt @@ -0,0 +1,98 @@ +-- input -- +Almost list markers (but not quite): + + - + +❦ + + - $ + +❦ + + - $ + +❦ + + $ + $ + +❦ + + 1! List. + +❦ +-- gofmt -- +Almost list markers (but not quite): + + - + +❦ + + - $ + +❦ + + - $ + +❦ + +❦ + + 1! List. + +❦ +-- text -- +Almost list markers (but not quite): + + - + +❦ + + - + +❦ + + - + +❦ + +❦ + + 1! List. + +❦ +-- markdown -- +Almost list markers (but not quite): + + - + +❦ + + - $ + +❦ + + - $ + +❦ + +❦ + + 1! List. + +❦ +-- html -- +

Almost list markers (but not quite): +

-
+
+

❦ +

- $
+
+

❦ +

- $
+
+

❦ +

❦ +

1! List.
+
+

❦ diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list8.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list8.txt new file mode 100644 index 0000000000000000000000000000000000000000..fc46b0d83515531721601563ca259c90b666ed04 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list8.txt @@ -0,0 +1,56 @@ +-- input -- +Loose lists. + - A + + B + - C + D + - E + - F +-- gofmt -- +Loose lists. + + - A + + B + + - C + D + + - E + + - F +-- text -- +Loose lists. + + - A + + B + + - C D + + - E + + - F +-- markdown -- +Loose lists. + + - A + + B + + - C D + + - E + + - F +-- html -- +

Loose lists. +

diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list9.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list9.txt new file mode 100644 index 0000000000000000000000000000000000000000..48e4673d543cc974bd6b7c325b7cda79e3dfdc4d --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/list9.txt @@ -0,0 +1,30 @@ +-- input -- +Text. + +1. Not a list +2. because it is +3. unindented. + +4. This one + is a list + because of the indented text. +5. More wrapped + items. +6. And unwrapped. + +7. The blank line stops the heuristic. +-- gofmt -- +Text. + +1. Not a list +2. because it is +3. unindented. + + 4. This one + is a list + because of the indented text. + 5. More wrapped + items. + 6. And unwrapped. + +7. The blank line stops the heuristic. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/para.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/para.txt new file mode 100644 index 0000000000000000000000000000000000000000..2355fa8172a959c19ff79b96c7bb81d46b30affb --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/para.txt @@ -0,0 +1,17 @@ +-- input -- +Hello, world. +This is a paragraph. + +-- gofmt -- +Hello, world. +This is a paragraph. + +-- text -- +Hello, world. This is a paragraph. + +-- markdown -- +Hello, world. This is a paragraph. + +-- html -- +

Hello, world. +This is a paragraph. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/quote.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/quote.txt new file mode 100644 index 0000000000000000000000000000000000000000..b64adae0b36680f05943188eaeb4c63ff2d9a062 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/quote.txt @@ -0,0 +1,15 @@ +-- input -- +Doubled single quotes like `` and '' turn into Unicode double quotes, +but single quotes ` and ' do not. +Misplaced markdown fences ``` do not either. +-- gofmt -- +Doubled single quotes like “ and ” turn into Unicode double quotes, +but single quotes ` and ' do not. +Misplaced markdown fences ``` do not either. +-- text -- +Doubled single quotes like “ and ” turn into Unicode double quotes, but single +quotes ` and ' do not. Misplaced markdown fences ``` do not either. +-- html -- +

Doubled single quotes like “ and ” turn into Unicode double quotes, +but single quotes ` and ' do not. +Misplaced markdown fences ``` do not either. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text.txt new file mode 100644 index 0000000000000000000000000000000000000000..c4de6e20d22d26d8368ab1919374ef754cd16914 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text.txt @@ -0,0 +1,62 @@ +{"TextPrefix":"|", "TextCodePrefix": "@"} +-- input -- +Hello, world + Code block here. +More text. +Tight list + - one + - two + - three +Loose list + - one + + - two + + - three + +# Heading + +More text. +-- gofmt -- +Hello, world + + Code block here. + +More text. +Tight list + - one + - two + - three + +Loose list + + - one + + - two + + - three + +# Heading + +More text. +-- text -- +|Hello, world +| +@Code block here. +| +|More text. Tight list +| - one +| - two +| - three +| +|Loose list +| +| - one +| +| - two +| +| - three +| +|# Heading +| +|More text. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text2.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text2.txt new file mode 100644 index 0000000000000000000000000000000000000000..a099d0b8c686093bee219464583dd00dbfeba302 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text2.txt @@ -0,0 +1,14 @@ +{"TextWidth": -1} +-- input -- +Package gob manages streams of gobs - binary values exchanged between an +Encoder (transmitter) and a Decoder (receiver). A typical use is +transporting arguments and results of remote procedure calls (RPCs) such as +those provided by package "net/rpc". + +The implementation compiles a custom codec for each data type in the stream +and is most efficient when a single Encoder is used to transmit a stream of +values, amortizing the cost of compilation. +-- text -- +Package gob manages streams of gobs - binary values exchanged between an Encoder (transmitter) and a Decoder (receiver). A typical use is transporting arguments and results of remote procedure calls (RPCs) such as those provided by package "net/rpc". + +The implementation compiles a custom codec for each data type in the stream and is most efficient when a single Encoder is used to transmit a stream of values, amortizing the cost of compilation. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text3.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text3.txt new file mode 100644 index 0000000000000000000000000000000000000000..75d2c3765ccce2a3d08e8d73573ac1958f6c8776 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text3.txt @@ -0,0 +1,28 @@ +{"TextWidth": 30} +-- input -- +Package gob manages streams of gobs - binary values exchanged between an +Encoder (transmitter) and a Decoder (receiver). A typical use is +transporting arguments and results of remote procedure calls (RPCs) such as +those provided by package "net/rpc". + +The implementation compiles a custom codec for each data type in the stream +and is most efficient when a single Encoder is used to transmit a stream of +values, amortizing the cost of compilation. +-- text -- +Package gob manages streams +of gobs - binary values +exchanged between an Encoder +(transmitter) and a Decoder +(receiver). A typical use is +transporting arguments and +results of remote procedure +calls (RPCs) such as those +provided by package "net/rpc". + +The implementation compiles +a custom codec for each data +type in the stream and is +most efficient when a single +Encoder is used to transmit a +stream of values, amortizing +the cost of compilation. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text4.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text4.txt new file mode 100644 index 0000000000000000000000000000000000000000..e429985077e24e2ff8b3bc49109d9a4a5fa248ab --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text4.txt @@ -0,0 +1,29 @@ +{"TextWidth": 29} +-- input -- +Package gob manages streams of gobs - binary values exchanged between an +Encoder (transmitter) and a Decoder (receiver). A typical use is +transporting arguments and results of remote procedure calls (RPCs) such as +those provided by package "net/rpc". + +The implementation compiles a custom codec for each data type in the stream +and is most efficient when a single Encoder is used to transmit a stream of +values, amortizing the cost of compilation. +-- text -- +Package gob manages streams +of gobs - binary values +exchanged between an Encoder +(transmitter) and a Decoder +(receiver). A typical use +is transporting arguments +and results of remote +procedure calls (RPCs) such +as those provided by package +"net/rpc". + +The implementation compiles +a custom codec for each data +type in the stream and is +most efficient when a single +Encoder is used to transmit a +stream of values, amortizing +the cost of compilation. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text5.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text5.txt new file mode 100644 index 0000000000000000000000000000000000000000..2408fc559d3b36692cca340f05ccd2b3fb2ba9f7 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text5.txt @@ -0,0 +1,38 @@ +{"TextWidth": 20} +-- input -- +Package gob manages streams of gobs - binary values exchanged between an +Encoder (transmitter) and a Decoder (receiver). A typical use is +transporting arguments and results of remote procedure calls (RPCs) such as +those provided by package "net/rpc". + +The implementation compiles a custom codec for each data type in the stream +and is most efficient when a single Encoder is used to transmit a stream of +values, amortizing the cost of compilation. +-- text -- +Package gob +manages streams +of gobs - binary +values exchanged +between an Encoder +(transmitter) and a +Decoder (receiver). +A typical use +is transporting +arguments and +results of remote +procedure calls +(RPCs) such as those +provided by package +"net/rpc". + +The implementation +compiles a custom +codec for each +data type in the +stream and is most +efficient when a +single Encoder is +used to transmit a +stream of values, +amortizing the cost +of compilation. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text6.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text6.txt new file mode 100644 index 0000000000000000000000000000000000000000..d6deff52cf830985d44d9eca26c6b0fbce03c6b7 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text6.txt @@ -0,0 +1,18 @@ +-- input -- +Package gob manages streams of gobs - binary values exchanged between an +Encoder (transmitter) and a Decoder (receiver). A typical use is +transporting arguments and results of remote procedure calls (RPCs) such as +those provided by package "net/rpc". + +The implementation compiles a custom codec for each data type in the stream +and is most efficient when a single Encoder is used to transmit a stream of +values, amortizing the cost of compilation. +-- text -- +Package gob manages streams of gobs - binary values exchanged between an Encoder +(transmitter) and a Decoder (receiver). A typical use is transporting arguments +and results of remote procedure calls (RPCs) such as those provided by package +"net/rpc". + +The implementation compiles a custom codec for each data type in the stream and +is most efficient when a single Encoder is used to transmit a stream of values, +amortizing the cost of compilation. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text7.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text7.txt new file mode 100644 index 0000000000000000000000000000000000000000..c9fb6d37547d1f8cae075ade0d1c2b6539fb6a72 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text7.txt @@ -0,0 +1,21 @@ +{"TextPrefix": " "} +-- input -- +Package gob manages streams of gobs - binary values exchanged between an +Encoder (transmitter) and a Decoder (receiver). A typical use is +transporting arguments and results of remote procedure calls (RPCs) such as +those provided by package "net/rpc". + +The implementation compiles a custom codec for each data type in the stream +and is most efficient when a single Encoder is used to transmit a stream of +values, amortizing the cost of compilation. +-- text -- + Package gob manages streams of gobs - binary values + exchanged between an Encoder (transmitter) and a Decoder + (receiver). A typical use is transporting arguments and + results of remote procedure calls (RPCs) such as those + provided by package "net/rpc". + + The implementation compiles a custom codec for each data + type in the stream and is most efficient when a single + Encoder is used to transmit a stream of values, amortizing + the cost of compilation. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text8.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text8.txt new file mode 100644 index 0000000000000000000000000000000000000000..560ac951c1774359784c694be14470d2bb31e405 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text8.txt @@ -0,0 +1,94 @@ +{"TextWidth": 40} +-- input -- +If the arguments have version suffixes (like @latest or @v1.0.0), "go install" +builds packages in module-aware mode, ignoring the go.mod file in the current +directory or any parent directory, if there is one. This is useful for +installing executables without affecting the dependencies of the main module. +To eliminate ambiguity about which module versions are used in the build, the +arguments must satisfy the following constraints: + + - Arguments must be package paths or package patterns (with "..." wildcards). + They must not be standard packages (like fmt), meta-patterns (std, cmd, + all), or relative or absolute file paths. + + - All arguments must have the same version suffix. Different queries are not + allowed, even if they refer to the same version. + + - All arguments must refer to packages in the same module at the same version. + + - Package path arguments must refer to main packages. Pattern arguments + will only match main packages. + + - No module is considered the "main" module. If the module containing + packages named on the command line has a go.mod file, it must not contain + directives (replace and exclude) that would cause it to be interpreted + differently than if it were the main module. The module must not require + a higher version of itself. + + - Vendor directories are not used in any module. (Vendor directories are not + included in the module zip files downloaded by 'go install'.) + +If the arguments don't have version suffixes, "go install" may run in +module-aware mode or GOPATH mode, depending on the GO111MODULE environment +variable and the presence of a go.mod file. See 'go help modules' for details. +If module-aware mode is enabled, "go install" runs in the context of the main +module. +-- text -- +If the arguments have version suffixes +(like @latest or @v1.0.0), "go install" +builds packages in module-aware mode, +ignoring the go.mod file in the current +directory or any parent directory, +if there is one. This is useful for +installing executables without affecting +the dependencies of the main module. +To eliminate ambiguity about which +module versions are used in the build, +the arguments must satisfy the following +constraints: + + - Arguments must be package paths + or package patterns (with "..." + wildcards). They must not be + standard packages (like fmt), + meta-patterns (std, cmd, all), + or relative or absolute file paths. + + - All arguments must have the same + version suffix. Different queries + are not allowed, even if they refer + to the same version. + + - All arguments must refer to packages + in the same module at the same + version. + + - Package path arguments must refer + to main packages. Pattern arguments + will only match main packages. + + - No module is considered the "main" + module. If the module containing + packages named on the command line + has a go.mod file, it must not + contain directives (replace and + exclude) that would cause it to be + interpreted differently than if it + were the main module. The module + must not require a higher version of + itself. + + - Vendor directories are not used in + any module. (Vendor directories are + not included in the module zip files + downloaded by 'go install'.) + +If the arguments don't have version +suffixes, "go install" may run in +module-aware mode or GOPATH mode, +depending on the GO111MODULE environment +variable and the presence of a go.mod +file. See 'go help modules' for details. +If module-aware mode is enabled, +"go install" runs in the context of the +main module. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text9.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text9.txt new file mode 100644 index 0000000000000000000000000000000000000000..07a64aa2276a96b24a9ca5794020d30201f4700b --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/text9.txt @@ -0,0 +1,12 @@ +{"TextPrefix":"|", "TextCodePrefix": "@"} +-- input -- +Hello, world + Code block here. +-- gofmt -- +Hello, world + + Code block here. +-- text -- +|Hello, world +| +@Code block here. diff --git a/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/words.txt b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/words.txt new file mode 100644 index 0000000000000000000000000000000000000000..63c7e1a1b2b44a32e5c4ecf0f9fcd9cbe0e1733f --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/comment/testdata/words.txt @@ -0,0 +1,10 @@ +-- input -- +This is an italicword and a linkedword and Unicöde. +-- gofmt -- +This is an italicword and a linkedword and Unicöde. +-- text -- +This is an italicword and a linkedword and Unicöde. +-- markdown -- +This is an *italicword* and a [*linkedword*](https://example.com/linkedword) and Unicöde. +-- html -- +

This is an italicword and a linkedword and Unicöde. diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/README.md b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a1c18e88ecce05cfc8a3e96008718bbb481004ad --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/README.md @@ -0,0 +1,12 @@ +These files are processed by example_test.go:TestExamples. + +A .golden file is a txtar file with two sections for each example that should be +created by doc.Examples from the corresponding .go file. + +One section, named EXAMPLE_NAME.Output, contains the example's output, +the value of the field Example.Output. + +The other, named EXAMPLE_NAME.Play, contains the formatted code for a playable +version of the example, the value of the field Example.Play. + +If a section is missing, it is treated as being empty. diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/empty.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/empty.go new file mode 100644 index 0000000000000000000000000000000000000000..0b10420f4245a61738befad29fbb70a56538508f --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/empty.go @@ -0,0 +1,8 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func Example() {} +func Example_a() diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/empty.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/empty.golden new file mode 100644 index 0000000000000000000000000000000000000000..2aafd204352805cd9c94d921fd97fbfd550dfa6c --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/empty.golden @@ -0,0 +1,6 @@ +-- .Play -- +package main + +func main() {} +func main() + diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/generic_constraints.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/generic_constraints.go new file mode 100644 index 0000000000000000000000000000000000000000..ea5d2b37f4aee20811a2abcd0c35abf573f3553a --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/generic_constraints.go @@ -0,0 +1,38 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p_test + +import ( + "fmt" + "time" +) + +type C1 interface { + string | int +} + +type C2 interface { + M(time.Time) +} + +type G[T C1] int + +func g[T C2](x T) {} + +type Tm int + +func (Tm) M(time.Time) {} + +type Foo int + +func Example() { + fmt.Println("hello") +} + +func ExampleGeneric() { + var x G[string] + g(Tm(3)) + fmt.Println(x) +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/generic_constraints.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/generic_constraints.golden new file mode 100644 index 0000000000000000000000000000000000000000..6c7b0eda9f90dc1477125b5235aa421b67791c96 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/generic_constraints.golden @@ -0,0 +1,39 @@ +-- .Play -- +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("hello") +} +-- Generic.Play -- +package main + +import ( + "fmt" + "time" +) + +type C1 interface { + string | int +} + +type C2 interface { + M(time.Time) +} + +type G[T C1] int + +func g[T C2](x T) {} + +type Tm int + +func (Tm) M(time.Time) {} + +func main() { + var x G[string] + g(Tm(3)) + fmt.Println(x) +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/import_groups.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/import_groups.go new file mode 100644 index 0000000000000000000000000000000000000000..05f21caaaa7c32cffcc6553dd82c93b047df5867 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/import_groups.go @@ -0,0 +1,23 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package foo_test + +import ( + "fmt" + "time" + + "golang.org/x/time/rate" +) + +func Example() { + fmt.Println("Hello, world!") + // Output: Hello, world! +} + +func ExampleLimiter() { + // Uses fmt, time and rate. + l := rate.NewLimiter(rate.Every(time.Second), 1) + fmt.Println(l) +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/import_groups.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/import_groups.golden new file mode 100644 index 0000000000000000000000000000000000000000..efe2cc1df5965bd8deb66dd4b746bebf1266af75 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/import_groups.golden @@ -0,0 +1,27 @@ +-- .Play -- +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Hello, world!") +} +-- .Output -- +Hello, world! +-- Limiter.Play -- +package main + +import ( + "fmt" + "time" + + "golang.org/x/time/rate" +) + +func main() { + // Uses fmt, time and rate. + l := rate.NewLimiter(rate.Every(time.Second), 1) + fmt.Println(l) +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/import_groups_named.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/import_groups_named.go new file mode 100644 index 0000000000000000000000000000000000000000..377022b22aa996c8c2299c297fd5855cebc18f05 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/import_groups_named.go @@ -0,0 +1,23 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package foo_test + +import ( + "fmt" + tm "time" + + r "golang.org/x/time/rate" +) + +func Example() { + fmt.Println("Hello, world!") + // Output: Hello, world! +} + +func ExampleLimiter() { + // Uses fmt, time and rate. + l := r.NewLimiter(r.Every(tm.Second), 1) + fmt.Println(l) +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/import_groups_named.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/import_groups_named.golden new file mode 100644 index 0000000000000000000000000000000000000000..9baf373cd8a5042fe774619e9c246f1740f90d53 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/import_groups_named.golden @@ -0,0 +1,27 @@ +-- .Play -- +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Hello, world!") +} +-- .Output -- +Hello, world! +-- Limiter.Play -- +package main + +import ( + "fmt" + tm "time" + + r "golang.org/x/time/rate" +) + +func main() { + // Uses fmt, time and rate. + l := r.NewLimiter(r.Every(tm.Second), 1) + fmt.Println(l) +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/inspect_signature.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/inspect_signature.go new file mode 100644 index 0000000000000000000000000000000000000000..c4a36e758d23ebf991d46c4f2a2ec8fe77eae301 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/inspect_signature.go @@ -0,0 +1,23 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package foo_test + +import ( + "bytes" + "io" +) + +func getReader() io.Reader { return nil } + +func do(b bytes.Reader) {} + +func Example() { + getReader() + do() + // Output: +} + +func ExampleIgnored() { +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/inspect_signature.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/inspect_signature.golden new file mode 100644 index 0000000000000000000000000000000000000000..c0d9b2ecc87eaf043597e95ccf8c4050760f5989 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/inspect_signature.golden @@ -0,0 +1,24 @@ +-- .Play -- +package main + +import ( + "bytes" + "io" +) + +func getReader() io.Reader { return nil } + +func do(b bytes.Reader) {} + +func main() { + getReader() + do() +} +-- Ignored.Play -- +package main + +import () + +func main() { +} + diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/iota.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/iota.go new file mode 100644 index 0000000000000000000000000000000000000000..c878b7708ea64a6a22b8590afe5218caf57b28a9 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/iota.go @@ -0,0 +1,34 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package foo_test + +const ( + a = iota + b +) + +const ( + c = 3 + d = 4 +) + +const ( + e = iota + f +) + +// The example refers to only one of the constants in the iota group, but we +// must keep all of them because of the iota. The second group of constants can +// be trimmed. The third has an iota, but is unused, so it can be eliminated. + +func Example() { + _ = b + _ = d +} + +// Need two examples to hit the playExample function. + +func Example2() { +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/iota.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/iota.golden new file mode 100644 index 0000000000000000000000000000000000000000..748770260bb275bdd71991f0e6420cfb1da15e8f --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/iota.golden @@ -0,0 +1,23 @@ +-- .Play -- +package main + +import () + +const ( + a = iota + b +) + +const d = 4 + +func main() { + _ = b + _ = d +} +-- 2.Play -- +package main + +import () + +func main() { +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/issue43658.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/issue43658.go new file mode 100644 index 0000000000000000000000000000000000000000..385223acf312bfa783fb6a4d30be5777d7d48c83 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/issue43658.go @@ -0,0 +1,223 @@ +// Copyright ©2016 The Gonum Authors. All rights reserved. +// Copyright 2021 The Go Authors. All rights reserved. +// (above line required for our license-header checker) +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package community_test + +import ( + "fmt" + "log" + "sort" + + "golang.org/x/exp/rand" + + "gonum.org/v1/gonum/graph/community" + "gonum.org/v1/gonum/graph/internal/ordered" + "gonum.org/v1/gonum/graph/simple" +) + +func ExampleProfile_simple() { + // Profile calls Modularize which implements the Louvain modularization algorithm. + // Since this is a randomized algorithm we use a defined random source to ensure + // consistency between test runs. In practice, results will not differ greatly + // between runs with different PRNG seeds. + src := rand.NewSource(1) + + // Create dumbell graph: + // + // 0 4 + // |\ /| + // | 2 - 3 | + // |/ \| + // 1 5 + // + g := simple.NewUndirectedGraph() + for u, e := range smallDumbell { + for v := range e { + g.SetEdge(simple.Edge{F: simple.Node(u), T: simple.Node(v)}) + } + } + + // Get the profile of internal node weight for resolutions + // between 0.1 and 10 using logarithmic bisection. + p, err := community.Profile( + community.ModularScore(g, community.Weight, 10, src), + true, 1e-3, 0.1, 10, + ) + if err != nil { + log.Fatal(err) + } + + // Print out each step with communities ordered. + for _, d := range p { + comm := d.Communities() + for _, c := range comm { + sort.Sort(ordered.ByID(c)) + } + sort.Sort(ordered.BySliceIDs(comm)) + fmt.Printf("Low:%.2v High:%.2v Score:%v Communities:%v Q=%.3v\n", + d.Low, d.High, d.Score, comm, community.Q(g, comm, d.Low)) + } + + // Output: + // Low:0.1 High:0.29 Score:14 Communities:[[0 1 2 3 4 5]] Q=0.9 + // Low:0.29 High:2.3 Score:12 Communities:[[0 1 2] [3 4 5]] Q=0.714 + // Low:2.3 High:3.5 Score:4 Communities:[[0 1] [2] [3] [4 5]] Q=-0.31 + // Low:3.5 High:10 Score:0 Communities:[[0] [1] [2] [3] [4] [5]] Q=-0.607 +} + +// intset is an integer set. +type intset map[int]struct{} + +func linksTo(i ...int) intset { + if len(i) == 0 { + return nil + } + s := make(intset) + for _, v := range i { + s[v] = struct{}{} + } + return s +} + +var ( + smallDumbell = []intset{ + 0: linksTo(1, 2), + 1: linksTo(2), + 2: linksTo(3), + 3: linksTo(4, 5), + 4: linksTo(5), + 5: nil, + } + + // http://www.slate.com/blogs/the_world_/2014/07/17/the_middle_east_friendship_chart.html + middleEast = struct{ friends, complicated, enemies []intset }{ + // green cells + friends: []intset{ + 0: nil, + 1: linksTo(5, 7, 9, 12), + 2: linksTo(11), + 3: linksTo(4, 5, 10), + 4: linksTo(3, 5, 10), + 5: linksTo(1, 3, 4, 8, 10, 12), + 6: nil, + 7: linksTo(1, 12), + 8: linksTo(5, 9, 11), + 9: linksTo(1, 8, 12), + 10: linksTo(3, 4, 5), + 11: linksTo(2, 8), + 12: linksTo(1, 5, 7, 9), + }, + + // yellow cells + complicated: []intset{ + 0: linksTo(2, 4), + 1: linksTo(4, 8), + 2: linksTo(0, 3, 4, 5, 8, 9), + 3: linksTo(2, 8, 11), + 4: linksTo(0, 1, 2, 8), + 5: linksTo(2), + 6: nil, + 7: linksTo(9, 11), + 8: linksTo(1, 2, 3, 4, 10, 12), + 9: linksTo(2, 7, 11), + 10: linksTo(8), + 11: linksTo(3, 7, 9, 12), + 12: linksTo(8, 11), + }, + + // red cells + enemies: []intset{ + 0: linksTo(1, 3, 5, 6, 7, 8, 9, 10, 11, 12), + 1: linksTo(0, 2, 3, 6, 10, 11), + 2: linksTo(1, 6, 7, 10, 12), + 3: linksTo(0, 1, 6, 7, 9, 12), + 4: linksTo(6, 7, 9, 11, 12), + 5: linksTo(0, 6, 7, 9, 11), + 6: linksTo(0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12), + 7: linksTo(0, 2, 3, 4, 5, 6, 8, 10), + 8: linksTo(0, 6, 7), + 9: linksTo(0, 3, 4, 5, 6, 10), + 10: linksTo(0, 1, 2, 6, 7, 9, 11, 12), + 11: linksTo(0, 1, 4, 5, 6, 10), + 12: linksTo(0, 2, 3, 4, 6, 10), + }, + } +) + +var friends, enemies *simple.WeightedUndirectedGraph + +func init() { + friends = simple.NewWeightedUndirectedGraph(0, 0) + for u, e := range middleEast.friends { + // Ensure unconnected nodes are included. + if friends.Node(int64(u)) == nil { + friends.AddNode(simple.Node(u)) + } + for v := range e { + friends.SetWeightedEdge(simple.WeightedEdge{F: simple.Node(u), T: simple.Node(v), W: 1}) + } + } + enemies = simple.NewWeightedUndirectedGraph(0, 0) + for u, e := range middleEast.enemies { + // Ensure unconnected nodes are included. + if enemies.Node(int64(u)) == nil { + enemies.AddNode(simple.Node(u)) + } + for v := range e { + enemies.SetWeightedEdge(simple.WeightedEdge{F: simple.Node(u), T: simple.Node(v), W: -1}) + } + } +} + +func ExampleProfile_multiplex() { + // Profile calls ModularizeMultiplex which implements the Louvain modularization + // algorithm. Since this is a randomized algorithm we use a defined random source + // to ensure consistency between test runs. In practice, results will not differ + // greatly between runs with different PRNG seeds. + src := rand.NewSource(1) + + // The undirected graphs, friends and enemies, are the political relationships + // in the Middle East as described in the Slate article: + // http://www.slate.com/blogs/the_world_/2014/07/17/the_middle_east_friendship_chart.html + g, err := community.NewUndirectedLayers(friends, enemies) + if err != nil { + log.Fatal(err) + } + weights := []float64{1, -1} + + // Get the profile of internal node weight for resolutions + // between 0.1 and 10 using logarithmic bisection. + p, err := community.Profile( + community.ModularMultiplexScore(g, weights, true, community.WeightMultiplex, 10, src), + true, 1e-3, 0.1, 10, + ) + if err != nil { + log.Fatal(err) + } + + // Print out each step with communities ordered. + for _, d := range p { + comm := d.Communities() + for _, c := range comm { + sort.Sort(ordered.ByID(c)) + } + sort.Sort(ordered.BySliceIDs(comm)) + fmt.Printf("Low:%.2v High:%.2v Score:%v Communities:%v Q=%.3v\n", + d.Low, d.High, d.Score, comm, community.QMultiplex(g, comm, weights, []float64{d.Low})) + } + + // Output: + // Low:0.1 High:0.72 Score:26 Communities:[[0] [1 7 9 12] [2 8 11] [3 4 5 10] [6]] Q=[24.7 1.97] + // Low:0.72 High:1.1 Score:24 Communities:[[0 6] [1 7 9 12] [2 8 11] [3 4 5 10]] Q=[16.9 14.1] + // Low:1.1 High:1.2 Score:18 Communities:[[0 2 6 11] [1 7 9 12] [3 4 5 8 10]] Q=[9.16 25.1] + // Low:1.2 High:1.6 Score:10 Communities:[[0 3 4 5 6 10] [1 7 9 12] [2 8 11]] Q=[10.5 26.7] + // Low:1.6 High:1.6 Score:8 Communities:[[0 1 6 7 9 12] [2 8 11] [3 4 5 10]] Q=[5.56 39.8] + // Low:1.6 High:1.8 Score:2 Communities:[[0 2 3 4 5 6 10] [1 7 8 9 11 12]] Q=[-1.82 48.6] + // Low:1.8 High:2.3 Score:-6 Communities:[[0 2 3 4 5 6 8 10 11] [1 7 9 12]] Q=[-5 57.5] + // Low:2.3 High:2.4 Score:-10 Communities:[[0 1 2 6 7 8 9 11 12] [3 4 5 10]] Q=[-11.2 79] + // Low:2.4 High:4.3 Score:-52 Communities:[[0 1 2 3 4 5 6 7 8 9 10 11 12]] Q=[-46.1 117] + // Low:4.3 High:10 Score:-54 Communities:[[0 1 2 3 4 6 7 8 9 10 11 12] [5]] Q=[-82 254] +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/issue43658.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/issue43658.golden new file mode 100644 index 0000000000000000000000000000000000000000..5200d14584f92c696236d41eab73b83261a25076 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/issue43658.golden @@ -0,0 +1,156 @@ +-- Profile_simple.Play -- +package main + +import ( + "fmt" + "log" + "sort" + + "golang.org/x/exp/rand" + + "gonum.org/v1/gonum/graph/community" + "gonum.org/v1/gonum/graph/internal/ordered" + "gonum.org/v1/gonum/graph/simple" +) + +func main() { + // Profile calls Modularize which implements the Louvain modularization algorithm. + // Since this is a randomized algorithm we use a defined random source to ensure + // consistency between test runs. In practice, results will not differ greatly + // between runs with different PRNG seeds. + src := rand.NewSource(1) + + // Create dumbell graph: + // + // 0 4 + // |\ /| + // | 2 - 3 | + // |/ \| + // 1 5 + // + g := simple.NewUndirectedGraph() + for u, e := range smallDumbell { + for v := range e { + g.SetEdge(simple.Edge{F: simple.Node(u), T: simple.Node(v)}) + } + } + + // Get the profile of internal node weight for resolutions + // between 0.1 and 10 using logarithmic bisection. + p, err := community.Profile( + community.ModularScore(g, community.Weight, 10, src), + true, 1e-3, 0.1, 10, + ) + if err != nil { + log.Fatal(err) + } + + // Print out each step with communities ordered. + for _, d := range p { + comm := d.Communities() + for _, c := range comm { + sort.Sort(ordered.ByID(c)) + } + sort.Sort(ordered.BySliceIDs(comm)) + fmt.Printf("Low:%.2v High:%.2v Score:%v Communities:%v Q=%.3v\n", + d.Low, d.High, d.Score, comm, community.Q(g, comm, d.Low)) + } + +} + +// intset is an integer set. +type intset map[int]struct{} + +func linksTo(i ...int) intset { + if len(i) == 0 { + return nil + } + s := make(intset) + for _, v := range i { + s[v] = struct{}{} + } + return s +} + +var smallDumbell = []intset{ + 0: linksTo(1, 2), + 1: linksTo(2), + 2: linksTo(3), + 3: linksTo(4, 5), + 4: linksTo(5), + 5: nil, +} + +-- Profile_simple.Output -- +Low:0.1 High:0.29 Score:14 Communities:[[0 1 2 3 4 5]] Q=0.9 +Low:0.29 High:2.3 Score:12 Communities:[[0 1 2] [3 4 5]] Q=0.714 +Low:2.3 High:3.5 Score:4 Communities:[[0 1] [2] [3] [4 5]] Q=-0.31 +Low:3.5 High:10 Score:0 Communities:[[0] [1] [2] [3] [4] [5]] Q=-0.607 + +-- Profile_multiplex.Play -- + +package main + +import ( + "fmt" + "log" + "sort" + + "golang.org/x/exp/rand" + + "gonum.org/v1/gonum/graph/community" + "gonum.org/v1/gonum/graph/internal/ordered" + "gonum.org/v1/gonum/graph/simple" +) + +var friends, enemies *simple.WeightedUndirectedGraph + +func main() { + // Profile calls ModularizeMultiplex which implements the Louvain modularization + // algorithm. Since this is a randomized algorithm we use a defined random source + // to ensure consistency between test runs. In practice, results will not differ + // greatly between runs with different PRNG seeds. + src := rand.NewSource(1) + + // The undirected graphs, friends and enemies, are the political relationships + // in the Middle East as described in the Slate article: + // http://www.slate.com/blogs/the_world_/2014/07/17/the_middle_east_friendship_chart.html + g, err := community.NewUndirectedLayers(friends, enemies) + if err != nil { + log.Fatal(err) + } + weights := []float64{1, -1} + + // Get the profile of internal node weight for resolutions + // between 0.1 and 10 using logarithmic bisection. + p, err := community.Profile( + community.ModularMultiplexScore(g, weights, true, community.WeightMultiplex, 10, src), + true, 1e-3, 0.1, 10, + ) + if err != nil { + log.Fatal(err) + } + + // Print out each step with communities ordered. + for _, d := range p { + comm := d.Communities() + for _, c := range comm { + sort.Sort(ordered.ByID(c)) + } + sort.Sort(ordered.BySliceIDs(comm)) + fmt.Printf("Low:%.2v High:%.2v Score:%v Communities:%v Q=%.3v\n", + d.Low, d.High, d.Score, comm, community.QMultiplex(g, comm, weights, []float64{d.Low})) + } + +} +-- Profile_multiplex.Output -- +Low:0.1 High:0.72 Score:26 Communities:[[0] [1 7 9 12] [2 8 11] [3 4 5 10] [6]] Q=[24.7 1.97] +Low:0.72 High:1.1 Score:24 Communities:[[0 6] [1 7 9 12] [2 8 11] [3 4 5 10]] Q=[16.9 14.1] +Low:1.1 High:1.2 Score:18 Communities:[[0 2 6 11] [1 7 9 12] [3 4 5 8 10]] Q=[9.16 25.1] +Low:1.2 High:1.6 Score:10 Communities:[[0 3 4 5 6 10] [1 7 9 12] [2 8 11]] Q=[10.5 26.7] +Low:1.6 High:1.6 Score:8 Communities:[[0 1 6 7 9 12] [2 8 11] [3 4 5 10]] Q=[5.56 39.8] +Low:1.6 High:1.8 Score:2 Communities:[[0 2 3 4 5 6 10] [1 7 8 9 11 12]] Q=[-1.82 48.6] +Low:1.8 High:2.3 Score:-6 Communities:[[0 2 3 4 5 6 8 10 11] [1 7 9 12]] Q=[-5 57.5] +Low:2.3 High:2.4 Score:-10 Communities:[[0 1 2 6 7 8 9 11 12] [3 4 5 10]] Q=[-11.2 79] +Low:2.4 High:4.3 Score:-52 Communities:[[0 1 2 3 4 5 6 7 8 9 10 11 12]] Q=[-46.1 117] +Low:4.3 High:10 Score:-54 Communities:[[0 1 2 3 4 6 7 8 9 10 11 12] [5]] Q=[-82 254] diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/multiple.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/multiple.go new file mode 100644 index 0000000000000000000000000000000000000000..27282644d8fd478b7838b1139592c33d082b8b4f --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/multiple.go @@ -0,0 +1,98 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package foo_test + +import ( + "flag" + "fmt" + "log" + "os/exec" + "sort" +) + +func ExampleHello() { + fmt.Println("Hello, world!") + // Output: Hello, world! +} + +func ExampleImport() { + out, err := exec.Command("date").Output() + if err != nil { + log.Fatal(err) + } + fmt.Printf("The date is %s\n", out) +} + +func ExampleKeyValue() { + v := struct { + a string + b int + }{ + a: "A", + b: 1, + } + fmt.Print(v) + // Output: a: "A", b: 1 +} + +func ExampleKeyValueImport() { + f := flag.Flag{ + Name: "play", + } + fmt.Print(f) + // Output: Name: "play" +} + +var keyValueTopDecl = struct { + a string + b int +}{ + a: "B", + b: 2, +} + +func ExampleKeyValueTopDecl() { + fmt.Print(keyValueTopDecl) + // Output: a: "B", b: 2 +} + +// Person represents a person by name and age. +type Person struct { + Name string + Age int +} + +// String returns a string representation of the Person. +func (p Person) String() string { + return fmt.Sprintf("%s: %d", p.Name, p.Age) +} + +// ByAge implements sort.Interface for []Person based on +// the Age field. +type ByAge []Person + +// Len returns the number of elements in ByAge. +func (a ByAge) Len() int { return len(a) } + +// Swap swaps the elements in ByAge. +func (a ByAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a ByAge) Less(i, j int) bool { return a[i].Age < a[j].Age } + +// people is the array of Person +var people = []Person{ + {"Bob", 31}, + {"John", 42}, + {"Michael", 17}, + {"Jenny", 26}, +} + +func ExampleSort() { + fmt.Println(people) + sort.Sort(ByAge(people)) + fmt.Println(people) + // Output: + // [Bob: 31 John: 42 Michael: 17 Jenny: 26] + // [Michael: 17 Jenny: 26 Bob: 31 John: 42] +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/multiple.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/multiple.golden new file mode 100644 index 0000000000000000000000000000000000000000..d2d791effabf7e8ebaff66de5d399027aea6440d --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/multiple.golden @@ -0,0 +1,129 @@ +-- Hello.Play -- +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Hello, world!") +} +-- Hello.Output -- +Hello, world! +-- Import.Play -- +package main + +import ( + "fmt" + "log" + "os/exec" +) + +func main() { + out, err := exec.Command("date").Output() + if err != nil { + log.Fatal(err) + } + fmt.Printf("The date is %s\n", out) +} +-- KeyValue.Play -- +package main + +import ( + "fmt" +) + +func main() { + v := struct { + a string + b int + }{ + a: "A", + b: 1, + } + fmt.Print(v) +} +-- KeyValue.Output -- +a: "A", b: 1 +-- KeyValueImport.Play -- +package main + +import ( + "flag" + "fmt" +) + +func main() { + f := flag.Flag{ + Name: "play", + } + fmt.Print(f) +} +-- KeyValueImport.Output -- +Name: "play" +-- KeyValueTopDecl.Play -- +package main + +import ( + "fmt" +) + +var keyValueTopDecl = struct { + a string + b int +}{ + a: "B", + b: 2, +} + +func main() { + fmt.Print(keyValueTopDecl) +} +-- KeyValueTopDecl.Output -- +a: "B", b: 2 +-- Sort.Play -- +package main + +import ( + "fmt" + "sort" +) + +// Person represents a person by name and age. +type Person struct { + Name string + Age int +} + +// String returns a string representation of the Person. +func (p Person) String() string { + return fmt.Sprintf("%s: %d", p.Name, p.Age) +} + +// ByAge implements sort.Interface for []Person based on +// the Age field. +type ByAge []Person + +// Len returns the number of elements in ByAge. +func (a ByAge) Len() int { return len(a) } + +// Swap swaps the elements in ByAge. +func (a ByAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a ByAge) Less(i, j int) bool { return a[i].Age < a[j].Age } + +// people is the array of Person +var people = []Person{ + {"Bob", 31}, + {"John", 42}, + {"Michael", 17}, + {"Jenny", 26}, +} + +func main() { + fmt.Println(people) + sort.Sort(ByAge(people)) + fmt.Println(people) +} +-- Sort.Output -- +[Bob: 31 John: 42 Michael: 17 Jenny: 26] +[Michael: 17 Jenny: 26 Bob: 31 John: 42] diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/values.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/values.go new file mode 100644 index 0000000000000000000000000000000000000000..64b0de476d19de840c5f4f95b1708df479decb46 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/values.go @@ -0,0 +1,22 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package foo_test + +// Variable declaration with fewer values than names. + +func f() (int, int) { + return 1, 2 +} + +var a, b = f() + +// Need two examples to hit playExample. + +func ExampleA() { + _ = a +} + +func ExampleB() { +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/values.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/values.golden new file mode 100644 index 0000000000000000000000000000000000000000..00c19917af100ed9c294f43fba0df44bbd9a06ae --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/values.golden @@ -0,0 +1,21 @@ +-- A.Play -- +package main + +import () + +func f() (int, int) { + return 1, 2 +} + +var a, b = f() + +func main() { + _ = a +} +-- B.Play -- +package main + +import () + +func main() { +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_file.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_file.go new file mode 100644 index 0000000000000000000000000000000000000000..61954ceceaafb0e7347544a4518e4ea0db4a4b18 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_file.go @@ -0,0 +1,23 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package foo_test + +import "fmt" + +type X int + +func (X) Foo() { +} + +func (X) TestBlah() { +} + +func (X) BenchmarkFoo() { +} + +func Example() { + fmt.Println("Hello, world!") + // Output: Hello, world! +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_file.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_file.golden new file mode 100644 index 0000000000000000000000000000000000000000..74a2291f5140a5635942d8d9c42b62afc55bd75e --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_file.golden @@ -0,0 +1,21 @@ +-- .Play -- +package main + +import "fmt" + +type X int + +func (X) Foo() { +} + +func (X) TestBlah() { +} + +func (X) BenchmarkFoo() { +} + +func main() { + fmt.Println("Hello, world!") +} +-- .Output -- +Hello, world! diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_function.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_function.go new file mode 100644 index 0000000000000000000000000000000000000000..1754ee341281115d200ab8fd5799d76aa7109628 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_function.go @@ -0,0 +1,13 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package foo_test + +func Foo(x int) { +} + +func Example() { + fmt.Println("Hello, world!") + // Output: Hello, world! +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_function.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_function.golden new file mode 100644 index 0000000000000000000000000000000000000000..7d5b5cbd7f9a2f54e37480bf60021f2ef22bdc5c --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_function.golden @@ -0,0 +1,11 @@ +-- .Play -- +package main + +func Foo(x int) { +} + +func main() { + fmt.Println("Hello, world!") +} +-- .Output -- +Hello, world! diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_function_external.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_function_external.go new file mode 100644 index 0000000000000000000000000000000000000000..0e0e2f58560530f04e2ee3ec74bd1ec8d1dae5e2 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_function_external.go @@ -0,0 +1,12 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package foo_test + +func foo(int) + +func Example() { + foo(42) + // Output: +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_function_external.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_function_external.golden new file mode 100644 index 0000000000000000000000000000000000000000..ec8f114abe255381466f285675743afa88065312 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/examples/whole_function_external.golden @@ -0,0 +1,8 @@ +-- .Play -- +package main + +func foo(int) + +func main() { + foo(42) +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/issue16153.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue16153.go new file mode 100644 index 0000000000000000000000000000000000000000..528be4235608fc9ad636e5acb78889633e7cfcfb --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue16153.go @@ -0,0 +1,27 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue16153 + +// original test case +const ( + x1 uint8 = 255 + Y1 = 256 +) + +// variations +const ( + x2 uint8 = 255 + Y2 +) + +const ( + X3 int64 = iota + Y3 = 1 +) + +const ( + X4 int64 = iota + Y4 +) diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/issue17788.0.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue17788.0.golden new file mode 100644 index 0000000000000000000000000000000000000000..42c00da50414f697aea681ac2de663e896eba32c --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue17788.0.golden @@ -0,0 +1,8 @@ +// +PACKAGE issue17788 + +IMPORTPATH + testdata/issue17788 + +FILENAMES + testdata/issue17788.go diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/issue17788.1.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue17788.1.golden new file mode 100644 index 0000000000000000000000000000000000000000..42c00da50414f697aea681ac2de663e896eba32c --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue17788.1.golden @@ -0,0 +1,8 @@ +// +PACKAGE issue17788 + +IMPORTPATH + testdata/issue17788 + +FILENAMES + testdata/issue17788.go diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/issue17788.2.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue17788.2.golden new file mode 100644 index 0000000000000000000000000000000000000000..42c00da50414f697aea681ac2de663e896eba32c --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue17788.2.golden @@ -0,0 +1,8 @@ +// +PACKAGE issue17788 + +IMPORTPATH + testdata/issue17788 + +FILENAMES + testdata/issue17788.go diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/issue17788.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue17788.go new file mode 100644 index 0000000000000000000000000000000000000000..883ad5f76954d7eba81fffdfa00642cb7a7ee47d --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue17788.go @@ -0,0 +1,8 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue17788 + +func ( /* receiver type */ ) f0() { +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/issue22856.0.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue22856.0.golden new file mode 100644 index 0000000000000000000000000000000000000000..a88f43f4bd7e219bdaf3b6ca670ac57d0b351324 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue22856.0.golden @@ -0,0 +1,45 @@ +// +PACKAGE issue22856 + +IMPORTPATH + testdata/issue22856 + +FILENAMES + testdata/issue22856.go + +FUNCTIONS + // NewPointerSliceOfSlice is not a factory function because slices ... + func NewPointerSliceOfSlice() [][]*T + + // NewSlice3 is not a factory function because 3 nested slices of ... + func NewSlice3() [][][]T + + // NewSliceOfSlice is not a factory function because slices of a ... + func NewSliceOfSlice() [][]T + + +TYPES + // + type T struct{} + + // + func New() T + + // + func NewArray() [1]T + + // + func NewPointer() *T + + // + func NewPointerArray() [1]*T + + // + func NewPointerOfPointer() **T + + // + func NewPointerSlice() []*T + + // + func NewSlice() []T + diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/issue22856.1.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue22856.1.golden new file mode 100644 index 0000000000000000000000000000000000000000..a88f43f4bd7e219bdaf3b6ca670ac57d0b351324 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue22856.1.golden @@ -0,0 +1,45 @@ +// +PACKAGE issue22856 + +IMPORTPATH + testdata/issue22856 + +FILENAMES + testdata/issue22856.go + +FUNCTIONS + // NewPointerSliceOfSlice is not a factory function because slices ... + func NewPointerSliceOfSlice() [][]*T + + // NewSlice3 is not a factory function because 3 nested slices of ... + func NewSlice3() [][][]T + + // NewSliceOfSlice is not a factory function because slices of a ... + func NewSliceOfSlice() [][]T + + +TYPES + // + type T struct{} + + // + func New() T + + // + func NewArray() [1]T + + // + func NewPointer() *T + + // + func NewPointerArray() [1]*T + + // + func NewPointerOfPointer() **T + + // + func NewPointerSlice() []*T + + // + func NewSlice() []T + diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/issue22856.2.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue22856.2.golden new file mode 100644 index 0000000000000000000000000000000000000000..a88f43f4bd7e219bdaf3b6ca670ac57d0b351324 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue22856.2.golden @@ -0,0 +1,45 @@ +// +PACKAGE issue22856 + +IMPORTPATH + testdata/issue22856 + +FILENAMES + testdata/issue22856.go + +FUNCTIONS + // NewPointerSliceOfSlice is not a factory function because slices ... + func NewPointerSliceOfSlice() [][]*T + + // NewSlice3 is not a factory function because 3 nested slices of ... + func NewSlice3() [][][]T + + // NewSliceOfSlice is not a factory function because slices of a ... + func NewSliceOfSlice() [][]T + + +TYPES + // + type T struct{} + + // + func New() T + + // + func NewArray() [1]T + + // + func NewPointer() *T + + // + func NewPointerArray() [1]*T + + // + func NewPointerOfPointer() **T + + // + func NewPointerSlice() []*T + + // + func NewSlice() []T + diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/issue22856.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue22856.go new file mode 100644 index 0000000000000000000000000000000000000000..f4569981aaac659ae081aa3233ce159e0f18ca78 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/issue22856.go @@ -0,0 +1,27 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue22856 + +type T struct{} + +func New() T { return T{} } +func NewPointer() *T { return &T{} } +func NewPointerSlice() []*T { return []*T{&T{}} } +func NewSlice() []T { return []T{T{}} } +func NewPointerOfPointer() **T { x := &T{}; return &x } +func NewArray() [1]T { return [1]T{T{}} } +func NewPointerArray() [1]*T { return [1]*T{&T{}} } + +// NewSliceOfSlice is not a factory function because slices of a slice of +// type *T are not factory functions of type T. +func NewSliceOfSlice() [][]T { return []T{[]T{}} } + +// NewPointerSliceOfSlice is not a factory function because slices of a +// slice of type *T are not factory functions of type T. +func NewPointerSliceOfSlice() [][]*T { return []*T{[]*T{}} } + +// NewSlice3 is not a factory function because 3 nested slices of type T +// are not factory functions of type T. +func NewSlice3() [][][]T { return []T{[]T{[]T{}}} } diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/pkgdoc/doc.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/pkgdoc/doc.go new file mode 100644 index 0000000000000000000000000000000000000000..3f822c75546c637bf5c03bbe0acc8d16c4a878bd --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/pkgdoc/doc.go @@ -0,0 +1,24 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pkgdoc + +import ( + crand "crypto/rand" + "math/rand" +) + +type T int + +type U int + +func (T) M() {} + +var _ = rand.Int +var _ = crand.Reader + +type G[T any] struct{ x T } + +func (g G[T]) M1() {} +func (g *G[T]) M2() {} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/predeclared.0.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/predeclared.0.golden new file mode 100644 index 0000000000000000000000000000000000000000..9f37b069f072a552cc7eabfd02617bbe30e49f0d --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/predeclared.0.golden @@ -0,0 +1,8 @@ +// Package predeclared is a go/doc test for handling of exported ... +PACKAGE predeclared + +IMPORTPATH + testdata/predeclared + +FILENAMES + testdata/predeclared.go diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/predeclared.1.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/predeclared.1.golden new file mode 100644 index 0000000000000000000000000000000000000000..2ff8ee666bd9467b32a6a6df66ef386f44805efb --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/predeclared.1.golden @@ -0,0 +1,22 @@ +// Package predeclared is a go/doc test for handling of exported ... +PACKAGE predeclared + +IMPORTPATH + testdata/predeclared + +FILENAMES + testdata/predeclared.go + +TYPES + // + type bool int + + // Must not be visible. + func (b bool) String() string + + // + type error struct{} + + // Must not be visible. + func (e error) Error() string + diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/predeclared.2.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/predeclared.2.golden new file mode 100644 index 0000000000000000000000000000000000000000..9f37b069f072a552cc7eabfd02617bbe30e49f0d --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/predeclared.2.golden @@ -0,0 +1,8 @@ +// Package predeclared is a go/doc test for handling of exported ... +PACKAGE predeclared + +IMPORTPATH + testdata/predeclared + +FILENAMES + testdata/predeclared.go diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/predeclared.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/predeclared.go new file mode 100644 index 0000000000000000000000000000000000000000..c6dd806cba0c2704fcc40912680ad95c4b2745b9 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/predeclared.go @@ -0,0 +1,22 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package predeclared is a go/doc test for handling of +// exported methods on locally-defined predeclared types. +// See issue 9860. +package predeclared + +type error struct{} + +// Must not be visible. +func (e error) Error() string { + return "" +} + +type bool int + +// Must not be visible. +func (b bool) String() string { + return "" +} diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/template.txt b/platform/dbops/binaries/go/go/src/go/doc/testdata/template.txt new file mode 100644 index 0000000000000000000000000000000000000000..1b07382611660bd28daf1fd32d2ae73e4b9f12bd --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/template.txt @@ -0,0 +1,68 @@ +{{synopsis .Doc}} +PACKAGE {{.Name}} + +IMPORTPATH + {{.ImportPath}} + +{{with .Imports}}IMPORTS +{{range .}} {{.}} +{{end}} +{{end}}{{/* + +*/}}FILENAMES +{{range .Filenames}} {{.}} +{{end}}{{/* + +*/}}{{with .Consts}} +CONSTANTS +{{range .}} {{synopsis .Doc}} + {{node .Decl $.FSet}} + +{{end}}{{end}}{{/* + +*/}}{{with .Vars}} +VARIABLES +{{range .}} {{synopsis .Doc}} + {{node .Decl $.FSet}} + +{{end}}{{end}}{{/* + +*/}}{{with .Funcs}} +FUNCTIONS +{{range .}} {{synopsis .Doc}} + {{node .Decl $.FSet}} + +{{end}}{{end}}{{/* + +*/}}{{with .Types}} +TYPES +{{range .}} {{synopsis .Doc}} + {{node .Decl $.FSet}} + +{{range .Consts}} {{synopsis .Doc}} + {{node .Decl $.FSet}} + +{{end}}{{/* + +*/}}{{range .Vars}} {{synopsis .Doc}} + {{node .Decl $.FSet}} + +{{end}}{{/* + +*/}}{{range .Funcs}} {{synopsis .Doc}} + {{node .Decl $.FSet}} + +{{end}}{{/* + +*/}}{{range .Methods}} {{synopsis .Doc}} + {{node .Decl $.FSet}} + +{{end}}{{end}}{{end}}{{/* + +*/}}{{with .Bugs}} +BUGS .Bugs is now deprecated, please use .Notes instead +{{range .}}{{indent "\t" .}} +{{end}}{{end}}{{with .Notes}}{{range $marker, $content := .}} +{{$marker}}S +{{range $content}}{{$marker}}({{.UID}}){{indent "\t" .Body}} +{{end}}{{end}}{{end}} \ No newline at end of file diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/testing.0.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/testing.0.golden new file mode 100644 index 0000000000000000000000000000000000000000..61dac8bb66ca5937e374e1cb14ae8083e66f1561 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/testing.0.golden @@ -0,0 +1,156 @@ +// Package testing provides support for automated testing of Go ... +PACKAGE testing + +IMPORTPATH + testdata/testing + +IMPORTS + bytes + flag + fmt + io + os + runtime + runtime/pprof + strconv + strings + time + +FILENAMES + testdata/benchmark.go + testdata/example.go + testdata/testing.go + +FUNCTIONS + // An internal function but exported because it is cross-package; ... + func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) + + // An internal function but exported because it is cross-package; ... + func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) + + // + func RunExamples(examples []InternalExample) (ok bool) + + // + func RunTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ok bool) + + // Short reports whether the -test.short flag is set. + func Short() bool + + +TYPES + // B is a type passed to Benchmark functions to manage benchmark ... + type B struct { + N int + // contains filtered or unexported fields + } + + // Error is equivalent to Log() followed by Fail(). + func (c *B) Error(args ...any) + + // Errorf is equivalent to Logf() followed by Fail(). + func (c *B) Errorf(format string, args ...any) + + // Fail marks the function as having failed but continues ... + func (c *B) Fail() + + // FailNow marks the function as having failed and stops its ... + func (c *B) FailNow() + + // Failed reports whether the function has failed. + func (c *B) Failed() bool + + // Fatal is equivalent to Log() followed by FailNow(). + func (c *B) Fatal(args ...any) + + // Fatalf is equivalent to Logf() followed by FailNow(). + func (c *B) Fatalf(format string, args ...any) + + // Log formats its arguments using default formatting, analogous ... + func (c *B) Log(args ...any) + + // Logf formats its arguments according to the format, analogous ... + func (c *B) Logf(format string, args ...any) + + // ResetTimer sets the elapsed benchmark time to zero. It does not ... + func (b *B) ResetTimer() + + // SetBytes records the number of bytes processed in a single ... + func (b *B) SetBytes(n int64) + + // StartTimer starts timing a test. This function is called ... + func (b *B) StartTimer() + + // StopTimer stops timing a test. This can be used to pause the ... + func (b *B) StopTimer() + + // The results of a benchmark run. + type BenchmarkResult struct { + N int // The number of iterations. + T time.Duration // The total time taken. + Bytes int64 // Bytes processed in one iteration. + } + + // Benchmark benchmarks a single function. Useful for creating ... + func Benchmark(f func(b *B)) BenchmarkResult + + // + func (r BenchmarkResult) NsPerOp() int64 + + // + func (r BenchmarkResult) String() string + + // An internal type but exported because it is cross-package; part ... + type InternalBenchmark struct { + Name string + F func(b *B) + } + + // + type InternalExample struct { + Name string + F func() + Output string + } + + // An internal type but exported because it is cross-package; part ... + type InternalTest struct { + Name string + F func(*T) + } + + // T is a type passed to Test functions to manage test state and ... + type T struct { + // contains filtered or unexported fields + } + + // Error is equivalent to Log() followed by Fail(). + func (c *T) Error(args ...any) + + // Errorf is equivalent to Logf() followed by Fail(). + func (c *T) Errorf(format string, args ...any) + + // Fail marks the function as having failed but continues ... + func (c *T) Fail() + + // FailNow marks the function as having failed and stops its ... + func (c *T) FailNow() + + // Failed reports whether the function has failed. + func (c *T) Failed() bool + + // Fatal is equivalent to Log() followed by FailNow(). + func (c *T) Fatal(args ...any) + + // Fatalf is equivalent to Logf() followed by FailNow(). + func (c *T) Fatalf(format string, args ...any) + + // Log formats its arguments using default formatting, analogous ... + func (c *T) Log(args ...any) + + // Logf formats its arguments according to the format, analogous ... + func (c *T) Logf(format string, args ...any) + + // Parallel signals that this test is to be run in parallel with ... + func (t *T) Parallel() + diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/testing.1.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/testing.1.golden new file mode 100644 index 0000000000000000000000000000000000000000..1655af11a8cddb7487058e753148908ae9f867c2 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/testing.1.golden @@ -0,0 +1,298 @@ +// Package testing provides support for automated testing of Go ... +PACKAGE testing + +IMPORTPATH + testdata/testing + +IMPORTS + bytes + flag + fmt + io + os + runtime + runtime/pprof + strconv + strings + time + +FILENAMES + testdata/benchmark.go + testdata/example.go + testdata/testing.go + +VARIABLES + // + var ( + // The short flag requests that tests run more quickly, but its functionality + // is provided by test writers themselves. The testing package is just its + // home. The all.bash installation script sets it to make installation more + // efficient, but by default the flag is off so a plain "go test" will do a + // full test of the package. + short = flag.Bool("test.short", false, "run smaller test suite to save time") + + // Report as tests are run; default is silent for success. + chatty = flag.Bool("test.v", false, "verbose: print additional output") + match = flag.String("test.run", "", "regular expression to select tests to run") + memProfile = flag.String("test.memprofile", "", "write a memory profile to the named file after execution") + memProfileRate = flag.Int("test.memprofilerate", 0, "if >=0, sets runtime.MemProfileRate") + cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profile to the named file during execution") + timeout = flag.Duration("test.timeout", 0, "if positive, sets an aggregate time limit for all tests") + cpuListStr = flag.String("test.cpu", "", "comma-separated list of number of CPUs to use for each test") + parallel = flag.Int("test.parallel", runtime.GOMAXPROCS(0), "maximum test parallelism") + + cpuList []int + ) + + // + var benchTime = flag.Duration("test.benchtime", 1*time.Second, "approximate run time for each benchmark") + + // + var matchBenchmarks = flag.String("test.bench", "", "regular expression to select benchmarks to run") + + // + var timer *time.Timer + + +FUNCTIONS + // An internal function but exported because it is cross-package; ... + func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) + + // An internal function but exported because it is cross-package; ... + func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) + + // + func RunExamples(examples []InternalExample) (ok bool) + + // + func RunTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ok bool) + + // Short reports whether the -test.short flag is set. + func Short() bool + + // after runs after all testing. + func after() + + // alarm is called if the timeout expires. + func alarm() + + // before runs before all testing. + func before() + + // decorate inserts the final newline if needed and indentation ... + func decorate(s string, addFileLine bool) string + + // + func max(x, y int) int + + // + func min(x, y int) int + + // + func parseCpuList() + + // roundDown10 rounds a number down to the nearest power of 10. + func roundDown10(n int) int + + // roundUp rounds x up to a number of the form [1eX, 2eX, 5eX]. + func roundUp(n int) int + + // startAlarm starts an alarm if requested. + func startAlarm() + + // stopAlarm turns off the alarm. + func stopAlarm() + + // + func tRunner(t *T, test *InternalTest) + + +TYPES + // B is a type passed to Benchmark functions to manage benchmark ... + type B struct { + common + N int + benchmark InternalBenchmark + bytes int64 + timerOn bool + result BenchmarkResult + } + + // Error is equivalent to Log() followed by Fail(). + func (c *B) Error(args ...any) + + // Errorf is equivalent to Logf() followed by Fail(). + func (c *B) Errorf(format string, args ...any) + + // Fail marks the function as having failed but continues ... + func (c *B) Fail() + + // FailNow marks the function as having failed and stops its ... + func (c *B) FailNow() + + // Failed reports whether the function has failed. + func (c *B) Failed() bool + + // Fatal is equivalent to Log() followed by FailNow(). + func (c *B) Fatal(args ...any) + + // Fatalf is equivalent to Logf() followed by FailNow(). + func (c *B) Fatalf(format string, args ...any) + + // Log formats its arguments using default formatting, analogous ... + func (c *B) Log(args ...any) + + // Logf formats its arguments according to the format, analogous ... + func (c *B) Logf(format string, args ...any) + + // ResetTimer sets the elapsed benchmark time to zero. It does not ... + func (b *B) ResetTimer() + + // SetBytes records the number of bytes processed in a single ... + func (b *B) SetBytes(n int64) + + // StartTimer starts timing a test. This function is called ... + func (b *B) StartTimer() + + // StopTimer stops timing a test. This can be used to pause the ... + func (b *B) StopTimer() + + // launch launches the benchmark function. It gradually increases ... + func (b *B) launch() + + // log generates the output. It's always at the same stack depth. + func (c *B) log(s string) + + // + func (b *B) nsPerOp() int64 + + // run times the benchmark function in a separate goroutine. + func (b *B) run() BenchmarkResult + + // runN runs a single benchmark for the specified number of ... + func (b *B) runN(n int) + + // trimOutput shortens the output from a benchmark, which can be ... + func (b *B) trimOutput() + + // The results of a benchmark run. + type BenchmarkResult struct { + N int // The number of iterations. + T time.Duration // The total time taken. + Bytes int64 // Bytes processed in one iteration. + } + + // Benchmark benchmarks a single function. Useful for creating ... + func Benchmark(f func(b *B)) BenchmarkResult + + // + func (r BenchmarkResult) NsPerOp() int64 + + // + func (r BenchmarkResult) String() string + + // + func (r BenchmarkResult) mbPerSec() float64 + + // An internal type but exported because it is cross-package; part ... + type InternalBenchmark struct { + Name string + F func(b *B) + } + + // + type InternalExample struct { + Name string + F func() + Output string + } + + // An internal type but exported because it is cross-package; part ... + type InternalTest struct { + Name string + F func(*T) + } + + // T is a type passed to Test functions to manage test state and ... + type T struct { + common + name string // Name of test. + startParallel chan bool // Parallel tests will wait on this. + } + + // Error is equivalent to Log() followed by Fail(). + func (c *T) Error(args ...any) + + // Errorf is equivalent to Logf() followed by Fail(). + func (c *T) Errorf(format string, args ...any) + + // Fail marks the function as having failed but continues ... + func (c *T) Fail() + + // FailNow marks the function as having failed and stops its ... + func (c *T) FailNow() + + // Failed reports whether the function has failed. + func (c *T) Failed() bool + + // Fatal is equivalent to Log() followed by FailNow(). + func (c *T) Fatal(args ...any) + + // Fatalf is equivalent to Logf() followed by FailNow(). + func (c *T) Fatalf(format string, args ...any) + + // Log formats its arguments using default formatting, analogous ... + func (c *T) Log(args ...any) + + // Logf formats its arguments according to the format, analogous ... + func (c *T) Logf(format string, args ...any) + + // Parallel signals that this test is to be run in parallel with ... + func (t *T) Parallel() + + // log generates the output. It's always at the same stack depth. + func (c *T) log(s string) + + // + func (t *T) report() + + // common holds the elements common between T and B and captures ... + type common struct { + output []byte // Output generated by test or benchmark. + failed bool // Test or benchmark has failed. + start time.Time // Time test or benchmark started + duration time.Duration + self any // To be sent on signal channel when done. + signal chan any // Output for serial tests. + } + + // Error is equivalent to Log() followed by Fail(). + func (c *common) Error(args ...any) + + // Errorf is equivalent to Logf() followed by Fail(). + func (c *common) Errorf(format string, args ...any) + + // Fail marks the function as having failed but continues ... + func (c *common) Fail() + + // FailNow marks the function as having failed and stops its ... + func (c *common) FailNow() + + // Failed reports whether the function has failed. + func (c *common) Failed() bool + + // Fatal is equivalent to Log() followed by FailNow(). + func (c *common) Fatal(args ...any) + + // Fatalf is equivalent to Logf() followed by FailNow(). + func (c *common) Fatalf(format string, args ...any) + + // Log formats its arguments using default formatting, analogous ... + func (c *common) Log(args ...any) + + // Logf formats its arguments according to the format, analogous ... + func (c *common) Logf(format string, args ...any) + + // log generates the output. It's always at the same stack depth. + func (c *common) log(s string) + diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/testing.2.golden b/platform/dbops/binaries/go/go/src/go/doc/testdata/testing.2.golden new file mode 100644 index 0000000000000000000000000000000000000000..61dac8bb66ca5937e374e1cb14ae8083e66f1561 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/testing.2.golden @@ -0,0 +1,156 @@ +// Package testing provides support for automated testing of Go ... +PACKAGE testing + +IMPORTPATH + testdata/testing + +IMPORTS + bytes + flag + fmt + io + os + runtime + runtime/pprof + strconv + strings + time + +FILENAMES + testdata/benchmark.go + testdata/example.go + testdata/testing.go + +FUNCTIONS + // An internal function but exported because it is cross-package; ... + func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) + + // An internal function but exported because it is cross-package; ... + func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark) + + // + func RunExamples(examples []InternalExample) (ok bool) + + // + func RunTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ok bool) + + // Short reports whether the -test.short flag is set. + func Short() bool + + +TYPES + // B is a type passed to Benchmark functions to manage benchmark ... + type B struct { + N int + // contains filtered or unexported fields + } + + // Error is equivalent to Log() followed by Fail(). + func (c *B) Error(args ...any) + + // Errorf is equivalent to Logf() followed by Fail(). + func (c *B) Errorf(format string, args ...any) + + // Fail marks the function as having failed but continues ... + func (c *B) Fail() + + // FailNow marks the function as having failed and stops its ... + func (c *B) FailNow() + + // Failed reports whether the function has failed. + func (c *B) Failed() bool + + // Fatal is equivalent to Log() followed by FailNow(). + func (c *B) Fatal(args ...any) + + // Fatalf is equivalent to Logf() followed by FailNow(). + func (c *B) Fatalf(format string, args ...any) + + // Log formats its arguments using default formatting, analogous ... + func (c *B) Log(args ...any) + + // Logf formats its arguments according to the format, analogous ... + func (c *B) Logf(format string, args ...any) + + // ResetTimer sets the elapsed benchmark time to zero. It does not ... + func (b *B) ResetTimer() + + // SetBytes records the number of bytes processed in a single ... + func (b *B) SetBytes(n int64) + + // StartTimer starts timing a test. This function is called ... + func (b *B) StartTimer() + + // StopTimer stops timing a test. This can be used to pause the ... + func (b *B) StopTimer() + + // The results of a benchmark run. + type BenchmarkResult struct { + N int // The number of iterations. + T time.Duration // The total time taken. + Bytes int64 // Bytes processed in one iteration. + } + + // Benchmark benchmarks a single function. Useful for creating ... + func Benchmark(f func(b *B)) BenchmarkResult + + // + func (r BenchmarkResult) NsPerOp() int64 + + // + func (r BenchmarkResult) String() string + + // An internal type but exported because it is cross-package; part ... + type InternalBenchmark struct { + Name string + F func(b *B) + } + + // + type InternalExample struct { + Name string + F func() + Output string + } + + // An internal type but exported because it is cross-package; part ... + type InternalTest struct { + Name string + F func(*T) + } + + // T is a type passed to Test functions to manage test state and ... + type T struct { + // contains filtered or unexported fields + } + + // Error is equivalent to Log() followed by Fail(). + func (c *T) Error(args ...any) + + // Errorf is equivalent to Logf() followed by Fail(). + func (c *T) Errorf(format string, args ...any) + + // Fail marks the function as having failed but continues ... + func (c *T) Fail() + + // FailNow marks the function as having failed and stops its ... + func (c *T) FailNow() + + // Failed reports whether the function has failed. + func (c *T) Failed() bool + + // Fatal is equivalent to Log() followed by FailNow(). + func (c *T) Fatal(args ...any) + + // Fatalf is equivalent to Logf() followed by FailNow(). + func (c *T) Fatalf(format string, args ...any) + + // Log formats its arguments using default formatting, analogous ... + func (c *T) Log(args ...any) + + // Logf formats its arguments according to the format, analogous ... + func (c *T) Logf(format string, args ...any) + + // Parallel signals that this test is to be run in parallel with ... + func (t *T) Parallel() + diff --git a/platform/dbops/binaries/go/go/src/go/doc/testdata/testing.go b/platform/dbops/binaries/go/go/src/go/doc/testdata/testing.go new file mode 100644 index 0000000000000000000000000000000000000000..d3076c95b502736b2ae9d7bf3d3efec20258b121 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/doc/testdata/testing.go @@ -0,0 +1,404 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package testing provides support for automated testing of Go packages. +// It is intended to be used in concert with the “go test” utility, which automates +// execution of any function of the form +// func TestXxx(*testing.T) +// where Xxx can be any alphanumeric string (but the first letter must not be in +// [a-z]) and serves to identify the test routine. +// These TestXxx routines should be declared within the package they are testing. +// +// Functions of the form +// func BenchmarkXxx(*testing.B) +// are considered benchmarks, and are executed by go test when the -test.bench +// flag is provided. +// +// A sample benchmark function looks like this: +// func BenchmarkHello(b *testing.B) { +// for i := 0; i < b.N; i++ { +// fmt.Sprintf("hello") +// } +// } +// The benchmark package will vary b.N until the benchmark function lasts +// long enough to be timed reliably. The output +// testing.BenchmarkHello 10000000 282 ns/op +// means that the loop ran 10000000 times at a speed of 282 ns per loop. +// +// If a benchmark needs some expensive setup before running, the timer +// may be stopped: +// func BenchmarkBigLen(b *testing.B) { +// b.StopTimer() +// big := NewBig() +// b.StartTimer() +// for i := 0; i < b.N; i++ { +// big.Len() +// } +// } +package testing + +import ( + "flag" + "fmt" + "os" + "runtime" + "runtime/pprof" + "strconv" + "strings" + "time" +) + +var ( + // The short flag requests that tests run more quickly, but its functionality + // is provided by test writers themselves. The testing package is just its + // home. The all.bash installation script sets it to make installation more + // efficient, but by default the flag is off so a plain "go test" will do a + // full test of the package. + short = flag.Bool("test.short", false, "run smaller test suite to save time") + + // Report as tests are run; default is silent for success. + chatty = flag.Bool("test.v", false, "verbose: print additional output") + match = flag.String("test.run", "", "regular expression to select tests to run") + memProfile = flag.String("test.memprofile", "", "write a memory profile to the named file after execution") + memProfileRate = flag.Int("test.memprofilerate", 0, "if >=0, sets runtime.MemProfileRate") + cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profile to the named file during execution") + timeout = flag.Duration("test.timeout", 0, "if positive, sets an aggregate time limit for all tests") + cpuListStr = flag.String("test.cpu", "", "comma-separated list of number of CPUs to use for each test") + parallel = flag.Int("test.parallel", runtime.GOMAXPROCS(0), "maximum test parallelism") + + cpuList []int +) + +// common holds the elements common between T and B and +// captures common methods such as Errorf. +type common struct { + output []byte // Output generated by test or benchmark. + failed bool // Test or benchmark has failed. + start time.Time // Time test or benchmark started + duration time.Duration + self any // To be sent on signal channel when done. + signal chan any // Output for serial tests. +} + +// Short reports whether the -test.short flag is set. +func Short() bool { + return *short +} + +// decorate inserts the final newline if needed and indentation tabs for formatting. +// If addFileLine is true, it also prefixes the string with the file and line of the call site. +func decorate(s string, addFileLine bool) string { + if addFileLine { + _, file, line, ok := runtime.Caller(3) // decorate + log + public function. + if ok { + // Truncate file name at last file name separator. + if index := strings.LastIndex(file, "/"); index >= 0 { + file = file[index+1:] + } else if index = strings.LastIndex(file, "\\"); index >= 0 { + file = file[index+1:] + } + } else { + file = "???" + line = 1 + } + s = fmt.Sprintf("%s:%d: %s", file, line, s) + } + s = "\t" + s // Every line is indented at least one tab. + n := len(s) + if n > 0 && s[n-1] != '\n' { + s += "\n" + n++ + } + for i := 0; i < n-1; i++ { // -1 to avoid final newline + if s[i] == '\n' { + // Second and subsequent lines are indented an extra tab. + return s[0:i+1] + "\t" + decorate(s[i+1:n], false) + } + } + return s +} + +// T is a type passed to Test functions to manage test state and support formatted test logs. +// Logs are accumulated during execution and dumped to standard error when done. +type T struct { + common + name string // Name of test. + startParallel chan bool // Parallel tests will wait on this. +} + +// Fail marks the function as having failed but continues execution. +func (c *common) Fail() { c.failed = true } + +// Failed reports whether the function has failed. +func (c *common) Failed() bool { return c.failed } + +// FailNow marks the function as having failed and stops its execution. +// Execution will continue at the next Test. +func (c *common) FailNow() { + c.Fail() + + // Calling runtime.Goexit will exit the goroutine, which + // will run the deferred functions in this goroutine, + // which will eventually run the deferred lines in tRunner, + // which will signal to the test loop that this test is done. + // + // A previous version of this code said: + // + // c.duration = ... + // c.signal <- c.self + // runtime.Goexit() + // + // This previous version duplicated code (those lines are in + // tRunner no matter what), but worse the goroutine teardown + // implicit in runtime.Goexit was not guaranteed to complete + // before the test exited. If a test deferred an important cleanup + // function (like removing temporary files), there was no guarantee + // it would run on a test failure. Because we send on c.signal during + // a top-of-stack deferred function now, we know that the send + // only happens after any other stacked defers have completed. + runtime.Goexit() +} + +// log generates the output. It's always at the same stack depth. +func (c *common) log(s string) { + c.output = append(c.output, decorate(s, true)...) +} + +// Log formats its arguments using default formatting, analogous to Println(), +// and records the text in the error log. +func (c *common) Log(args ...any) { c.log(fmt.Sprintln(args...)) } + +// Logf formats its arguments according to the format, analogous to Printf(), +// and records the text in the error log. +func (c *common) Logf(format string, args ...any) { c.log(fmt.Sprintf(format, args...)) } + +// Error is equivalent to Log() followed by Fail(). +func (c *common) Error(args ...any) { + c.log(fmt.Sprintln(args...)) + c.Fail() +} + +// Errorf is equivalent to Logf() followed by Fail(). +func (c *common) Errorf(format string, args ...any) { + c.log(fmt.Sprintf(format, args...)) + c.Fail() +} + +// Fatal is equivalent to Log() followed by FailNow(). +func (c *common) Fatal(args ...any) { + c.log(fmt.Sprintln(args...)) + c.FailNow() +} + +// Fatalf is equivalent to Logf() followed by FailNow(). +func (c *common) Fatalf(format string, args ...any) { + c.log(fmt.Sprintf(format, args...)) + c.FailNow() +} + +// Parallel signals that this test is to be run in parallel with (and only with) +// other parallel tests in this CPU group. +func (t *T) Parallel() { + t.signal <- (*T)(nil) // Release main testing loop + <-t.startParallel // Wait for serial tests to finish +} + +// An internal type but exported because it is cross-package; part of the implementation +// of go test. +type InternalTest struct { + Name string + F func(*T) +} + +func tRunner(t *T, test *InternalTest) { + t.start = time.Now() + + // When this goroutine is done, either because test.F(t) + // returned normally or because a test failure triggered + // a call to runtime.Goexit, record the duration and send + // a signal saying that the test is done. + defer func() { + t.duration = time.Since(t.start) + t.signal <- t + }() + + test.F(t) +} + +// An internal function but exported because it is cross-package; part of the implementation +// of go test. +func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) { + flag.Parse() + parseCpuList() + + before() + startAlarm() + testOk := RunTests(matchString, tests) + exampleOk := RunExamples(examples) + if !testOk || !exampleOk { + fmt.Println("FAIL") + os.Exit(1) + } + fmt.Println("PASS") + stopAlarm() + RunBenchmarks(matchString, benchmarks) + after() +} + +func (t *T) report() { + tstr := fmt.Sprintf("(%.2f seconds)", t.duration.Seconds()) + format := "--- %s: %s %s\n%s" + if t.failed { + fmt.Printf(format, "FAIL", t.name, tstr, t.output) + } else if *chatty { + fmt.Printf(format, "PASS", t.name, tstr, t.output) + } +} + +func RunTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ok bool) { + ok = true + if len(tests) == 0 { + fmt.Fprintln(os.Stderr, "testing: warning: no tests to run") + return + } + for _, procs := range cpuList { + runtime.GOMAXPROCS(procs) + // We build a new channel tree for each run of the loop. + // collector merges in one channel all the upstream signals from parallel tests. + // If all tests pump to the same channel, a bug can occur where a test + // kicks off a goroutine that Fails, yet the test still delivers a completion signal, + // which skews the counting. + var collector = make(chan any) + + numParallel := 0 + startParallel := make(chan bool) + + for i := 0; i < len(tests); i++ { + matched, err := matchString(*match, tests[i].Name) + if err != nil { + fmt.Fprintf(os.Stderr, "testing: invalid regexp for -test.run: %s\n", err) + os.Exit(1) + } + if !matched { + continue + } + testName := tests[i].Name + if procs != 1 { + testName = fmt.Sprintf("%s-%d", tests[i].Name, procs) + } + t := &T{ + common: common{ + signal: make(chan any), + }, + name: testName, + startParallel: startParallel, + } + t.self = t + if *chatty { + fmt.Printf("=== RUN %s\n", t.name) + } + go tRunner(t, &tests[i]) + out := (<-t.signal).(*T) + if out == nil { // Parallel run. + go func() { + collector <- <-t.signal + }() + numParallel++ + continue + } + t.report() + ok = ok && !out.failed + } + + running := 0 + for numParallel+running > 0 { + if running < *parallel && numParallel > 0 { + startParallel <- true + running++ + numParallel-- + continue + } + t := (<-collector).(*T) + t.report() + ok = ok && !t.failed + running-- + } + } + return +} + +// before runs before all testing. +func before() { + if *memProfileRate > 0 { + runtime.MemProfileRate = *memProfileRate + } + if *cpuProfile != "" { + f, err := os.Create(*cpuProfile) + if err != nil { + fmt.Fprintf(os.Stderr, "testing: %s", err) + return + } + if err := pprof.StartCPUProfile(f); err != nil { + fmt.Fprintf(os.Stderr, "testing: can't start cpu profile: %s", err) + f.Close() + return + } + // Could save f so after can call f.Close; not worth the effort. + } + +} + +// after runs after all testing. +func after() { + if *cpuProfile != "" { + pprof.StopCPUProfile() // flushes profile to disk + } + if *memProfile != "" { + f, err := os.Create(*memProfile) + if err != nil { + fmt.Fprintf(os.Stderr, "testing: %s", err) + return + } + if err = pprof.WriteHeapProfile(f); err != nil { + fmt.Fprintf(os.Stderr, "testing: can't write %s: %s", *memProfile, err) + } + f.Close() + } +} + +var timer *time.Timer + +// startAlarm starts an alarm if requested. +func startAlarm() { + if *timeout > 0 { + timer = time.AfterFunc(*timeout, alarm) + } +} + +// stopAlarm turns off the alarm. +func stopAlarm() { + if *timeout > 0 { + timer.Stop() + } +} + +// alarm is called if the timeout expires. +func alarm() { + panic("test timed out") +} + +func parseCpuList() { + if len(*cpuListStr) == 0 { + cpuList = append(cpuList, runtime.GOMAXPROCS(-1)) + } else { + for _, val := range strings.Split(*cpuListStr, ",") { + cpu, err := strconv.Atoi(val) + if err != nil || cpu <= 0 { + fmt.Fprintf(os.Stderr, "testing: invalid value %q for -test.cpu", val) + os.Exit(1) + } + cpuList = append(cpuList, cpu) + } + } +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/ar.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/ar.go new file mode 100644 index 0000000000000000000000000000000000000000..9df7934212611b34d21d49b035dc5b7794547a48 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/ar.go @@ -0,0 +1,171 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package gccgoimporter + +import ( + "bytes" + "debug/elf" + "errors" + "fmt" + "internal/xcoff" + "io" + "strconv" + "strings" +) + +// Magic strings for different archive file formats. +const ( + armag = "!\n" + armagt = "!\n" + armagb = "\n" +) + +// Offsets and sizes for fields in a standard archive header. +const ( + arNameOff = 0 + arNameSize = 16 + arDateOff = arNameOff + arNameSize + arDateSize = 12 + arUIDOff = arDateOff + arDateSize + arUIDSize = 6 + arGIDOff = arUIDOff + arUIDSize + arGIDSize = 6 + arModeOff = arGIDOff + arGIDSize + arModeSize = 8 + arSizeOff = arModeOff + arModeSize + arSizeSize = 10 + arFmagOff = arSizeOff + arSizeSize + arFmagSize = 2 + + arHdrSize = arFmagOff + arFmagSize +) + +// The contents of the fmag field of a standard archive header. +const arfmag = "`\n" + +// arExportData takes an archive file and returns a ReadSeeker for the +// export data in that file. This assumes that there is only one +// object in the archive containing export data, which is not quite +// what gccgo does; gccgo concatenates together all the export data +// for all the objects in the file. In practice that case does not arise. +func arExportData(archive io.ReadSeeker) (io.ReadSeeker, error) { + if _, err := archive.Seek(0, io.SeekStart); err != nil { + return nil, err + } + + var buf [len(armag)]byte + if _, err := archive.Read(buf[:]); err != nil { + return nil, err + } + + switch string(buf[:]) { + case armag: + return standardArExportData(archive) + case armagt: + return nil, errors.New("unsupported thin archive") + case armagb: + return aixBigArExportData(archive) + default: + return nil, fmt.Errorf("unrecognized archive file format %q", buf[:]) + } +} + +// standardArExportData returns export data from a standard archive. +func standardArExportData(archive io.ReadSeeker) (io.ReadSeeker, error) { + off := int64(len(armag)) + for { + var hdrBuf [arHdrSize]byte + if _, err := archive.Read(hdrBuf[:]); err != nil { + return nil, err + } + off += arHdrSize + + if !bytes.Equal(hdrBuf[arFmagOff:arFmagOff+arFmagSize], []byte(arfmag)) { + return nil, fmt.Errorf("archive header format header (%q)", hdrBuf[:]) + } + + size, err := strconv.ParseInt(strings.TrimSpace(string(hdrBuf[arSizeOff:arSizeOff+arSizeSize])), 10, 64) + if err != nil { + return nil, fmt.Errorf("error parsing size in archive header (%q): %v", hdrBuf[:], err) + } + + fn := hdrBuf[arNameOff : arNameOff+arNameSize] + if fn[0] == '/' && (fn[1] == ' ' || fn[1] == '/' || string(fn[:8]) == "/SYM64/ ") { + // Archive symbol table or extended name table, + // which we don't care about. + } else { + archiveAt := readerAtFromSeeker(archive) + ret, err := elfFromAr(io.NewSectionReader(archiveAt, off, size)) + if ret != nil || err != nil { + return ret, err + } + } + + if size&1 != 0 { + size++ + } + off += size + if _, err := archive.Seek(off, io.SeekStart); err != nil { + return nil, err + } + } +} + +// elfFromAr tries to get export data from an archive member as an ELF file. +// If there is no export data, this returns nil, nil. +func elfFromAr(member *io.SectionReader) (io.ReadSeeker, error) { + ef, err := elf.NewFile(member) + if err != nil { + return nil, err + } + sec := ef.Section(".go_export") + if sec == nil { + return nil, nil + } + return sec.Open(), nil +} + +// aixBigArExportData returns export data from an AIX big archive. +func aixBigArExportData(archive io.ReadSeeker) (io.ReadSeeker, error) { + archiveAt := readerAtFromSeeker(archive) + arch, err := xcoff.NewArchive(archiveAt) + if err != nil { + return nil, err + } + + for _, mem := range arch.Members { + f, err := arch.GetFile(mem.Name) + if err != nil { + return nil, err + } + sdat := f.CSect(".go_export") + if sdat != nil { + return bytes.NewReader(sdat), nil + } + } + + return nil, fmt.Errorf(".go_export not found in this archive") +} + +// readerAtFromSeeker turns an io.ReadSeeker into an io.ReaderAt. +// This is only safe because there won't be any concurrent seeks +// while this code is executing. +func readerAtFromSeeker(rs io.ReadSeeker) io.ReaderAt { + if ret, ok := rs.(io.ReaderAt); ok { + return ret + } + return seekerReadAt{rs} +} + +type seekerReadAt struct { + seeker io.ReadSeeker +} + +func (sra seekerReadAt) ReadAt(p []byte, off int64) (int, error) { + if _, err := sra.seeker.Seek(off, io.SeekStart); err != nil { + return 0, err + } + return sra.seeker.Read(p) +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/gccgoinstallation.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/gccgoinstallation.go new file mode 100644 index 0000000000000000000000000000000000000000..8fc7ce3232190c93bb74f445bf55be1929e4c786 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/gccgoinstallation.go @@ -0,0 +1,97 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package gccgoimporter + +import ( + "bufio" + "go/types" + "os" + "os/exec" + "path/filepath" + "strings" +) + +// Information about a specific installation of gccgo. +type GccgoInstallation struct { + // Version of gcc (e.g. 4.8.0). + GccVersion string + + // Target triple (e.g. x86_64-unknown-linux-gnu). + TargetTriple string + + // Built-in library paths used by this installation. + LibPaths []string +} + +// Ask the driver at the given path for information for this GccgoInstallation. +// The given arguments are passed directly to the call of the driver. +func (inst *GccgoInstallation) InitFromDriver(gccgoPath string, args ...string) (err error) { + argv := append([]string{"-###", "-S", "-x", "go", "-"}, args...) + cmd := exec.Command(gccgoPath, argv...) + stderr, err := cmd.StderrPipe() + if err != nil { + return + } + + err = cmd.Start() + if err != nil { + return + } + + scanner := bufio.NewScanner(stderr) + for scanner.Scan() { + line := scanner.Text() + switch { + case strings.HasPrefix(line, "Target: "): + inst.TargetTriple = line[8:] + + case line[0] == ' ': + args := strings.Fields(line) + for _, arg := range args[1:] { + if strings.HasPrefix(arg, "-L") { + inst.LibPaths = append(inst.LibPaths, arg[2:]) + } + } + } + } + + argv = append([]string{"-dumpversion"}, args...) + stdout, err := exec.Command(gccgoPath, argv...).Output() + if err != nil { + return + } + inst.GccVersion = strings.TrimSpace(string(stdout)) + + return +} + +// Return the list of export search paths for this GccgoInstallation. +func (inst *GccgoInstallation) SearchPaths() (paths []string) { + for _, lpath := range inst.LibPaths { + spath := filepath.Join(lpath, "go", inst.GccVersion) + fi, err := os.Stat(spath) + if err != nil || !fi.IsDir() { + continue + } + paths = append(paths, spath) + + spath = filepath.Join(spath, inst.TargetTriple) + fi, err = os.Stat(spath) + if err != nil || !fi.IsDir() { + continue + } + paths = append(paths, spath) + } + + paths = append(paths, inst.LibPaths...) + + return +} + +// Return an importer that searches incpaths followed by the gcc installation's +// built-in search paths and the current directory. +func (inst *GccgoInstallation) GetImporter(incpaths []string, initmap map[*types.Package]InitData) Importer { + return GetImporter(append(append(incpaths, inst.SearchPaths()...), "."), initmap) +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/gccgoinstallation_test.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/gccgoinstallation_test.go new file mode 100644 index 0000000000000000000000000000000000000000..df0188ace7f70e82bc76c0a4730baa4ed698b9f0 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/gccgoinstallation_test.go @@ -0,0 +1,192 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package gccgoimporter + +import ( + "go/types" + "testing" +) + +// importablePackages is a list of packages that we verify that we can +// import. This should be all standard library packages in all relevant +// versions of gccgo. Note that since gccgo follows a different release +// cycle, and since different systems have different versions installed, +// we can't use the last-two-versions rule of the gc toolchain. +var importablePackages = [...]string{ + "archive/tar", + "archive/zip", + "bufio", + "bytes", + "compress/bzip2", + "compress/flate", + "compress/gzip", + "compress/lzw", + "compress/zlib", + "container/heap", + "container/list", + "container/ring", + "crypto/aes", + "crypto/cipher", + "crypto/des", + "crypto/dsa", + "crypto/ecdsa", + "crypto/elliptic", + "crypto", + "crypto/hmac", + "crypto/md5", + "crypto/rand", + "crypto/rc4", + "crypto/rsa", + "crypto/sha1", + "crypto/sha256", + "crypto/sha512", + "crypto/subtle", + "crypto/tls", + "crypto/x509", + "crypto/x509/pkix", + "database/sql/driver", + "database/sql", + "debug/dwarf", + "debug/elf", + "debug/gosym", + "debug/macho", + "debug/pe", + "encoding/ascii85", + "encoding/asn1", + "encoding/base32", + "encoding/base64", + "encoding/binary", + "encoding/csv", + "encoding/gob", + // "encoding", // Added in GCC 4.9. + "encoding/hex", + "encoding/json", + "encoding/pem", + "encoding/xml", + "errors", + "expvar", + "flag", + "fmt", + "go/ast", + "go/build", + "go/doc", + // "go/format", // Added in GCC 4.8. + "go/parser", + "go/printer", + "go/scanner", + "go/token", + "hash/adler32", + "hash/crc32", + "hash/crc64", + "hash/fnv", + "hash", + "html", + "html/template", + "image/color", + // "image/color/palette", // Added in GCC 4.9. + "image/draw", + "image/gif", + "image", + "image/jpeg", + "image/png", + "index/suffixarray", + "io", + "io/ioutil", + "log", + "log/syslog", + "math/big", + "math/cmplx", + "math", + "math/rand", + "mime", + "mime/multipart", + "net", + "net/http/cgi", + // "net/http/cookiejar", // Added in GCC 4.8. + "net/http/fcgi", + "net/http", + "net/http/httptest", + "net/http/httputil", + "net/http/pprof", + "net/mail", + "net/rpc", + "net/rpc/jsonrpc", + "net/smtp", + "net/textproto", + "net/url", + "os/exec", + "os", + "os/signal", + "os/user", + "path/filepath", + "path", + "reflect", + "regexp", + "regexp/syntax", + "runtime/debug", + "runtime", + "runtime/pprof", + "sort", + "strconv", + "strings", + "sync/atomic", + "sync", + "syscall", + "testing", + "testing/iotest", + "testing/quick", + "text/scanner", + "text/tabwriter", + "text/template", + "text/template/parse", + "time", + "unicode", + "unicode/utf16", + "unicode/utf8", +} + +func TestInstallationImporter(t *testing.T) { + // This test relies on gccgo being around. + gpath := gccgoPath() + if gpath == "" { + t.Skip("This test needs gccgo") + } + + var inst GccgoInstallation + err := inst.InitFromDriver(gpath) + if err != nil { + t.Fatal(err) + } + imp := inst.GetImporter(nil, nil) + + // Ensure we don't regress the number of packages we can parse. First import + // all packages into the same map and then each individually. + pkgMap := make(map[string]*types.Package) + for _, pkg := range importablePackages { + _, err = imp(pkgMap, pkg, ".", nil) + if err != nil { + t.Error(err) + } + } + + for _, pkg := range importablePackages { + _, err = imp(make(map[string]*types.Package), pkg, ".", nil) + if err != nil { + t.Error(err) + } + } + + // Test for certain specific entities in the imported data. + for _, test := range [...]importerTest{ + {pkgpath: "io", name: "Reader", want: "type Reader interface{Read(p []byte) (n int, err error)}"}, + {pkgpath: "io", name: "ReadWriter", want: "type ReadWriter interface{Reader; Writer}"}, + {pkgpath: "math", name: "Pi", want: "const Pi untyped float"}, + {pkgpath: "math", name: "Sin", want: "func Sin(x float64) float64"}, + {pkgpath: "sort", name: "Search", want: "func Search(n int, f func(int) bool) int"}, + {pkgpath: "unsafe", name: "Pointer", want: "type Pointer"}, + } { + runImporterTest(t, imp, nil, &test) + } +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/importer.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/importer.go new file mode 100644 index 0000000000000000000000000000000000000000..94f2defd8d3af91c19ae10f43bafec6adc6a2b31 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/importer.go @@ -0,0 +1,261 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package gccgoimporter implements Import for gccgo-generated object files. +package gccgoimporter // import "go/internal/gccgoimporter" + +import ( + "bytes" + "debug/elf" + "fmt" + "go/types" + "internal/xcoff" + "io" + "os" + "path/filepath" + "strings" +) + +// A PackageInit describes an imported package that needs initialization. +type PackageInit struct { + Name string // short package name + InitFunc string // name of init function + Priority int // priority of init function, see InitData.Priority +} + +// The gccgo-specific init data for a package. +type InitData struct { + // Initialization priority of this package relative to other packages. + // This is based on the maximum depth of the package's dependency graph; + // it is guaranteed to be greater than that of its dependencies. + Priority int + + // The list of packages which this package depends on to be initialized, + // including itself if needed. This is the subset of the transitive closure of + // the package's dependencies that need initialization. + Inits []PackageInit +} + +// Locate the file from which to read export data. +// This is intended to replicate the logic in gofrontend. +func findExportFile(searchpaths []string, pkgpath string) (string, error) { + for _, spath := range searchpaths { + pkgfullpath := filepath.Join(spath, pkgpath) + pkgdir, name := filepath.Split(pkgfullpath) + + for _, filepath := range [...]string{ + pkgfullpath, + pkgfullpath + ".gox", + pkgdir + "lib" + name + ".so", + pkgdir + "lib" + name + ".a", + pkgfullpath + ".o", + } { + fi, err := os.Stat(filepath) + if err == nil && !fi.IsDir() { + return filepath, nil + } + } + } + + return "", fmt.Errorf("%s: could not find export data (tried %s)", pkgpath, strings.Join(searchpaths, ":")) +} + +const ( + gccgov1Magic = "v1;\n" + gccgov2Magic = "v2;\n" + gccgov3Magic = "v3;\n" + goimporterMagic = "\n$$ " + archiveMagic = "!" + // Take name from Name method (like on os.File) if present. + if n, ok := rc.(interface{ Name() string }); ok { + fpath = n.Name() + } + } else { + fpath, err = findExportFile(searchpaths, pkgpath) + if err != nil { + return nil, err + } + + r, closer, err := openExportFile(fpath) + if err != nil { + return nil, err + } + if closer != nil { + defer closer.Close() + } + reader = r + } + + var magics string + magics, err = readMagic(reader) + if err != nil { + return + } + + if magics == archiveMagic || magics == aixbigafMagic { + reader, err = arExportData(reader) + if err != nil { + return + } + magics, err = readMagic(reader) + if err != nil { + return + } + } + + switch magics { + case gccgov1Magic, gccgov2Magic, gccgov3Magic: + var p parser + p.init(fpath, reader, imports) + pkg = p.parsePackage() + if initmap != nil { + initmap[pkg] = p.initdata + } + + // Excluded for now: Standard gccgo doesn't support this import format currently. + // case goimporterMagic: + // var data []byte + // data, err = io.ReadAll(reader) + // if err != nil { + // return + // } + // var n int + // n, pkg, err = importer.ImportData(imports, data) + // if err != nil { + // return + // } + + // if initmap != nil { + // suffixreader := bytes.NewReader(data[n:]) + // var p parser + // p.init(fpath, suffixreader, nil) + // p.parseInitData() + // initmap[pkg] = p.initdata + // } + + default: + err = fmt.Errorf("unrecognized magic string: %q", magics) + } + + return + } +} + +// readMagic reads the four bytes at the start of a ReadSeeker and +// returns them as a string. +func readMagic(reader io.ReadSeeker) (string, error) { + var magic [4]byte + if _, err := reader.Read(magic[:]); err != nil { + return "", err + } + if _, err := reader.Seek(0, io.SeekStart); err != nil { + return "", err + } + return string(magic[:]), nil +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/importer_test.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/importer_test.go new file mode 100644 index 0000000000000000000000000000000000000000..76b4500f3b53ffce2ef6f5968655a56a538573d1 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/importer_test.go @@ -0,0 +1,199 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package gccgoimporter + +import ( + "go/types" + "internal/testenv" + "os" + "os/exec" + "path/filepath" + "regexp" + "strconv" + "testing" +) + +type importerTest struct { + pkgpath, name, want, wantval string + wantinits []string + gccgoVersion int // minimum gccgo version (0 => any) +} + +func runImporterTest(t *testing.T, imp Importer, initmap map[*types.Package]InitData, test *importerTest) { + pkg, err := imp(make(map[string]*types.Package), test.pkgpath, ".", nil) + if err != nil { + t.Error(err) + return + } + + if test.name != "" { + obj := pkg.Scope().Lookup(test.name) + if obj == nil { + t.Errorf("%s: object not found", test.name) + return + } + + got := types.ObjectString(obj, types.RelativeTo(pkg)) + if got != test.want { + t.Errorf("%s: got %q; want %q", test.name, got, test.want) + } + + if test.wantval != "" { + gotval := obj.(*types.Const).Val().String() + if gotval != test.wantval { + t.Errorf("%s: got val %q; want val %q", test.name, gotval, test.wantval) + } + } + } + + if len(test.wantinits) > 0 { + initdata := initmap[pkg] + found := false + // Check that the package's own init function has the package's priority + for _, pkginit := range initdata.Inits { + if pkginit.InitFunc == test.wantinits[0] { + found = true + break + } + } + + if !found { + t.Errorf("%s: could not find expected function %q", test.pkgpath, test.wantinits[0]) + } + + // FIXME: the original version of this test was written against + // the v1 export data scheme for capturing init functions, so it + // verified the priority values. We moved away from the priority + // scheme some time ago; it is not clear how much work it would be + // to validate the new init export data. + } +} + +// When adding tests to this list, be sure to set the 'gccgoVersion' +// field if the testcases uses a "recent" Go addition (ex: aliases). +var importerTests = [...]importerTest{ + {pkgpath: "pointer", name: "Int8Ptr", want: "type Int8Ptr *int8"}, + {pkgpath: "complexnums", name: "NN", want: "const NN untyped complex", wantval: "(-1 + -1i)"}, + {pkgpath: "complexnums", name: "NP", want: "const NP untyped complex", wantval: "(-1 + 1i)"}, + {pkgpath: "complexnums", name: "PN", want: "const PN untyped complex", wantval: "(1 + -1i)"}, + {pkgpath: "complexnums", name: "PP", want: "const PP untyped complex", wantval: "(1 + 1i)"}, + {pkgpath: "conversions", name: "Bits", want: "const Bits Units", wantval: `"bits"`}, + {pkgpath: "time", name: "Duration", want: "type Duration int64"}, + {pkgpath: "time", name: "Nanosecond", want: "const Nanosecond Duration", wantval: "1"}, + {pkgpath: "unicode", name: "IsUpper", want: "func IsUpper(r rune) bool"}, + {pkgpath: "unicode", name: "MaxRune", want: "const MaxRune untyped rune", wantval: "1114111"}, + {pkgpath: "imports", wantinits: []string{"imports..import", "fmt..import"}}, + {pkgpath: "importsar", name: "Hello", want: "var Hello string"}, + {pkgpath: "aliases", name: "A14", gccgoVersion: 7, want: "type A14 = func(int, T0) chan T2"}, + {pkgpath: "aliases", name: "C0", gccgoVersion: 7, want: "type C0 struct{f1 C1; f2 C1}"}, + {pkgpath: "escapeinfo", name: "NewT", want: "func NewT(data []byte) *T"}, + {pkgpath: "issue27856", name: "M", gccgoVersion: 7, want: "type M struct{E F}"}, + {pkgpath: "v1reflect", name: "Type", want: "type Type interface{Align() int; AssignableTo(u Type) bool; Bits() int; ChanDir() ChanDir; Elem() Type; Field(i int) StructField; FieldAlign() int; FieldByIndex(index []int) StructField; FieldByName(name string) (StructField, bool); FieldByNameFunc(match func(string) bool) (StructField, bool); Implements(u Type) bool; In(i int) Type; IsVariadic() bool; Key() Type; Kind() Kind; Len() int; Method(int) Method; MethodByName(string) (Method, bool); Name() string; NumField() int; NumIn() int; NumMethod() int; NumOut() int; Out(i int) Type; PkgPath() string; Size() uintptr; String() string; common() *commonType; rawString() string; runtimeType() *runtimeType; uncommon() *uncommonType}"}, + {pkgpath: "nointerface", name: "I", want: "type I int"}, + {pkgpath: "issue29198", name: "FooServer", gccgoVersion: 7, want: "type FooServer struct{FooServer *FooServer; user string; ctx context.Context}"}, + {pkgpath: "issue30628", name: "Apple", want: "type Apple struct{hey sync.RWMutex; x int; RQ [517]struct{Count uintptr; NumBytes uintptr; Last uintptr}}"}, + {pkgpath: "issue31540", name: "S", gccgoVersion: 7, want: "type S struct{b int; map[Y]Z}"}, // should want "type S struct{b int; A2}" (issue #44410) + {pkgpath: "issue34182", name: "T1", want: "type T1 struct{f *T2}"}, + {pkgpath: "notinheap", name: "S", want: "type S struct{}"}, +} + +func TestGoxImporter(t *testing.T) { + testenv.MustHaveExec(t) + initmap := make(map[*types.Package]InitData) + imp := GetImporter([]string{"testdata"}, initmap) + + for _, test := range importerTests { + runImporterTest(t, imp, initmap, &test) + } +} + +// gccgoPath returns a path to gccgo if it is present (either in +// path or specified via GCCGO environment variable), or an +// empty string if no gccgo is available. +func gccgoPath() string { + gccgoname := os.Getenv("GCCGO") + if gccgoname == "" { + gccgoname = "gccgo" + } + if gpath, gerr := exec.LookPath(gccgoname); gerr == nil { + return gpath + } + return "" +} + +func TestObjImporter(t *testing.T) { + // This test relies on gccgo being around. + gpath := gccgoPath() + if gpath == "" { + t.Skip("This test needs gccgo") + } + + verout, err := testenv.Command(t, gpath, "--version").CombinedOutput() + if err != nil { + t.Logf("%s", verout) + t.Fatal(err) + } + vers := regexp.MustCompile(`(\d+)\.(\d+)`).FindSubmatch(verout) + if len(vers) == 0 { + t.Fatalf("could not find version number in %s", verout) + } + major, err := strconv.Atoi(string(vers[1])) + if err != nil { + t.Fatal(err) + } + minor, err := strconv.Atoi(string(vers[2])) + if err != nil { + t.Fatal(err) + } + t.Logf("gccgo version %d.%d", major, minor) + + tmpdir := t.TempDir() + initmap := make(map[*types.Package]InitData) + imp := GetImporter([]string{tmpdir}, initmap) + + artmpdir := t.TempDir() + arinitmap := make(map[*types.Package]InitData) + arimp := GetImporter([]string{artmpdir}, arinitmap) + + for _, test := range importerTests { + if major < test.gccgoVersion { + // Support for type aliases was added in GCC 7. + t.Logf("skipping %q: not supported before gccgo version %d", test.pkgpath, test.gccgoVersion) + continue + } + + gofile := filepath.Join("testdata", test.pkgpath+".go") + if _, err := os.Stat(gofile); os.IsNotExist(err) { + continue + } + ofile := filepath.Join(tmpdir, test.pkgpath+".o") + afile := filepath.Join(artmpdir, "lib"+test.pkgpath+".a") + + cmd := testenv.Command(t, gpath, "-fgo-pkgpath="+test.pkgpath, "-c", "-o", ofile, gofile) + out, err := cmd.CombinedOutput() + if err != nil { + t.Logf("%s", out) + t.Fatalf("gccgo %s failed: %s", gofile, err) + } + + runImporterTest(t, imp, initmap, &test) + + cmd = testenv.Command(t, "ar", "cr", afile, ofile) + out, err = cmd.CombinedOutput() + if err != nil { + t.Logf("%s", out) + t.Fatalf("ar cr %s %s failed: %s", afile, ofile, err) + } + + runImporterTest(t, arimp, arinitmap, &test) + + if err = os.Remove(ofile); err != nil { + t.Fatal(err) + } + if err = os.Remove(afile); err != nil { + t.Fatal(err) + } + } +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/parser.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/parser.go new file mode 100644 index 0000000000000000000000000000000000000000..e8ee74783b9e96f5c23623d9dfe9e1c247b450f6 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/parser.go @@ -0,0 +1,1285 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package gccgoimporter + +import ( + "errors" + "fmt" + "go/constant" + "go/token" + "go/types" + "io" + "strconv" + "strings" + "text/scanner" + "unicode/utf8" +) + +type parser struct { + scanner *scanner.Scanner + version string // format version + tok rune // current token + lit string // literal string; only valid for Ident, Int, String tokens + pkgpath string // package path of imported package + pkgname string // name of imported package + pkg *types.Package // reference to imported package + imports map[string]*types.Package // package path -> package object + typeList []types.Type // type number -> type + typeData []string // unparsed type data (v3 and later) + fixups []fixupRecord // fixups to apply at end of parsing + initdata InitData // package init priority data + aliases map[int]string // maps saved type number to alias name +} + +// When reading export data it's possible to encounter a defined type +// N1 with an underlying defined type N2 while we are still reading in +// that defined type N2; see issues #29006 and #29198 for instances +// of this. Example: +// +// type N1 N2 +// type N2 struct { +// ... +// p *N1 +// } +// +// To handle such cases, the parser generates a fixup record (below) and +// delays setting of N1's underlying type until parsing is complete, at +// which point fixups are applied. + +type fixupRecord struct { + toUpdate *types.Named // type to modify when fixup is processed + target types.Type // type that was incomplete when fixup was created +} + +func (p *parser) init(filename string, src io.Reader, imports map[string]*types.Package) { + p.scanner = new(scanner.Scanner) + p.initScanner(filename, src) + p.imports = imports + p.aliases = make(map[int]string) + p.typeList = make([]types.Type, 1 /* type numbers start at 1 */, 16) +} + +func (p *parser) initScanner(filename string, src io.Reader) { + p.scanner.Init(src) + p.scanner.Error = func(_ *scanner.Scanner, msg string) { p.error(msg) } + p.scanner.Mode = scanner.ScanIdents | scanner.ScanInts | scanner.ScanFloats | scanner.ScanStrings + p.scanner.Whitespace = 1<<'\t' | 1<<' ' + p.scanner.Filename = filename // for good error messages + p.next() +} + +type importError struct { + pos scanner.Position + err error +} + +func (e importError) Error() string { + return fmt.Sprintf("import error %s (byte offset = %d): %s", e.pos, e.pos.Offset, e.err) +} + +func (p *parser) error(err any) { + if s, ok := err.(string); ok { + err = errors.New(s) + } + // panic with a runtime.Error if err is not an error + panic(importError{p.scanner.Pos(), err.(error)}) +} + +func (p *parser) errorf(format string, args ...any) { + p.error(fmt.Errorf(format, args...)) +} + +func (p *parser) expect(tok rune) string { + lit := p.lit + if p.tok != tok { + p.errorf("expected %s, got %s (%s)", scanner.TokenString(tok), scanner.TokenString(p.tok), lit) + } + p.next() + return lit +} + +func (p *parser) expectEOL() { + if p.version == "v1" || p.version == "v2" { + p.expect(';') + } + p.expect('\n') +} + +func (p *parser) expectKeyword(keyword string) { + lit := p.expect(scanner.Ident) + if lit != keyword { + p.errorf("expected keyword %s, got %q", keyword, lit) + } +} + +func (p *parser) parseString() string { + str, err := strconv.Unquote(p.expect(scanner.String)) + if err != nil { + p.error(err) + } + return str +} + +// unquotedString = { unquotedStringChar } . +// unquotedStringChar = . +func (p *parser) parseUnquotedString() string { + if p.tok == scanner.EOF { + p.error("unexpected EOF") + } + var b strings.Builder + b.WriteString(p.scanner.TokenText()) + // This loop needs to examine each character before deciding whether to consume it. If we see a semicolon, + // we need to let it be consumed by p.next(). + for ch := p.scanner.Peek(); ch != '\n' && ch != ';' && ch != scanner.EOF && p.scanner.Whitespace&(1<" . (optional and ignored) + p.next() + p.expectKeyword("esc") + p.expect(':') + p.expect(scanner.Int) + p.expect('>') + } + if p.tok == '.' { + p.next() + p.expect('.') + p.expect('.') + isVariadic = true + } + typ := p.parseType(pkg) + if isVariadic { + typ = types.NewSlice(typ) + } + param = types.NewParam(token.NoPos, pkg, name, typ) + return +} + +// Var = Name Type . +func (p *parser) parseVar(pkg *types.Package) *types.Var { + name := p.parseName() + v := types.NewVar(token.NoPos, pkg, name, p.parseType(pkg)) + if name[0] == '.' || name[0] == '<' { + // This is an unexported variable, + // or a variable defined in a different package. + // We only want to record exported variables. + return nil + } + return v +} + +// Conversion = "convert" "(" Type "," ConstValue ")" . +func (p *parser) parseConversion(pkg *types.Package) (val constant.Value, typ types.Type) { + p.expectKeyword("convert") + p.expect('(') + typ = p.parseType(pkg) + p.expect(',') + val, _ = p.parseConstValue(pkg) + p.expect(')') + return +} + +// ConstValue = string | "false" | "true" | ["-"] (int ["'"] | FloatOrComplex) | Conversion . +// FloatOrComplex = float ["i" | ("+"|"-") float "i"] . +func (p *parser) parseConstValue(pkg *types.Package) (val constant.Value, typ types.Type) { + // v3 changed to $false, $true, $convert, to avoid confusion + // with variable names in inline function bodies. + if p.tok == '$' { + p.next() + if p.tok != scanner.Ident { + p.errorf("expected identifier after '$', got %s (%q)", scanner.TokenString(p.tok), p.lit) + } + } + + switch p.tok { + case scanner.String: + str := p.parseString() + val = constant.MakeString(str) + typ = types.Typ[types.UntypedString] + return + + case scanner.Ident: + b := false + switch p.lit { + case "false": + case "true": + b = true + + case "convert": + return p.parseConversion(pkg) + + default: + p.errorf("expected const value, got %s (%q)", scanner.TokenString(p.tok), p.lit) + } + + p.next() + val = constant.MakeBool(b) + typ = types.Typ[types.UntypedBool] + return + } + + sign := "" + if p.tok == '-' { + p.next() + sign = "-" + } + + switch p.tok { + case scanner.Int: + val = constant.MakeFromLiteral(sign+p.lit, token.INT, 0) + if val == nil { + p.error("could not parse integer literal") + } + + p.next() + if p.tok == '\'' { + p.next() + typ = types.Typ[types.UntypedRune] + } else { + typ = types.Typ[types.UntypedInt] + } + + case scanner.Float: + re := sign + p.lit + p.next() + + var im string + switch p.tok { + case '+': + p.next() + im = p.expect(scanner.Float) + + case '-': + p.next() + im = "-" + p.expect(scanner.Float) + + case scanner.Ident: + // re is in fact the imaginary component. Expect "i" below. + im = re + re = "0" + + default: + val = constant.MakeFromLiteral(re, token.FLOAT, 0) + if val == nil { + p.error("could not parse float literal") + } + typ = types.Typ[types.UntypedFloat] + return + } + + p.expectKeyword("i") + reval := constant.MakeFromLiteral(re, token.FLOAT, 0) + if reval == nil { + p.error("could not parse real component of complex literal") + } + imval := constant.MakeFromLiteral(im+"i", token.IMAG, 0) + if imval == nil { + p.error("could not parse imag component of complex literal") + } + val = constant.BinaryOp(reval, token.ADD, imval) + typ = types.Typ[types.UntypedComplex] + + default: + p.errorf("expected const value, got %s (%q)", scanner.TokenString(p.tok), p.lit) + } + + return +} + +// Const = Name [Type] "=" ConstValue . +func (p *parser) parseConst(pkg *types.Package) *types.Const { + name := p.parseName() + var typ types.Type + if p.tok == '<' { + typ = p.parseType(pkg) + } + p.expect('=') + val, vtyp := p.parseConstValue(pkg) + if typ == nil { + typ = vtyp + } + return types.NewConst(token.NoPos, pkg, name, typ, val) +} + +// reserved is a singleton type used to fill type map slots that have +// been reserved (i.e., for which a type number has been parsed) but +// which don't have their actual type yet. When the type map is updated, +// the actual type must replace a reserved entry (or we have an internal +// error). Used for self-verification only - not required for correctness. +var reserved = new(struct{ types.Type }) + +// reserve reserves the type map entry n for future use. +func (p *parser) reserve(n int) { + // Notes: + // - for pre-V3 export data, the type numbers we see are + // guaranteed to be in increasing order, so we append a + // reserved entry onto the list. + // - for V3+ export data, type numbers can appear in + // any order, however the 'types' section tells us the + // total number of types, hence typeList is pre-allocated. + if len(p.typeData) == 0 { + if n != len(p.typeList) { + p.errorf("invalid type number %d (out of sync)", n) + } + p.typeList = append(p.typeList, reserved) + } else { + if p.typeList[n] != nil { + p.errorf("previously visited type number %d", n) + } + p.typeList[n] = reserved + } +} + +// update sets the type map entries for the entries in nlist to t. +// An entry in nlist can be a type number in p.typeList, +// used to resolve named types, or it can be a *types.Pointer, +// used to resolve pointers to named types in case they are referenced +// by embedded fields. +func (p *parser) update(t types.Type, nlist []any) { + if t == reserved { + p.errorf("internal error: update(%v) invoked on reserved", nlist) + } + if t == nil { + p.errorf("internal error: update(%v) invoked on nil", nlist) + } + for _, n := range nlist { + switch n := n.(type) { + case int: + if p.typeList[n] == t { + continue + } + if p.typeList[n] != reserved { + p.errorf("internal error: update(%v): %d not reserved", nlist, n) + } + p.typeList[n] = t + case *types.Pointer: + if *n != (types.Pointer{}) { + elem := n.Elem() + if elem == t { + continue + } + p.errorf("internal error: update: pointer already set to %v, expected %v", elem, t) + } + *n = *types.NewPointer(t) + default: + p.errorf("internal error: %T on nlist", n) + } + } +} + +// NamedType = TypeName [ "=" ] Type { Method } . +// TypeName = ExportedName . +// Method = "func" "(" Param ")" Name ParamList ResultList [InlineBody] ";" . +func (p *parser) parseNamedType(nlist []any) types.Type { + pkg, name := p.parseExportedName() + scope := pkg.Scope() + obj := scope.Lookup(name) + if obj != nil && obj.Type() == nil { + p.errorf("%v has nil type", obj) + } + + if p.tok == scanner.Ident && p.lit == "notinheap" { + p.next() + // The go/types package has no way of recording that + // this type is marked notinheap. Presumably no user + // of this package actually cares. + } + + // type alias + if p.tok == '=' { + p.next() + p.aliases[nlist[len(nlist)-1].(int)] = name + if obj != nil { + // use the previously imported (canonical) type + t := obj.Type() + p.update(t, nlist) + p.parseType(pkg) // discard + return t + } + t := p.parseType(pkg, nlist...) + obj = types.NewTypeName(token.NoPos, pkg, name, t) + scope.Insert(obj) + return t + } + + // defined type + if obj == nil { + // A named type may be referred to before the underlying type + // is known - set it up. + tname := types.NewTypeName(token.NoPos, pkg, name, nil) + types.NewNamed(tname, nil, nil) + scope.Insert(tname) + obj = tname + } + + // use the previously imported (canonical), or newly created type + t := obj.Type() + p.update(t, nlist) + + nt, ok := t.(*types.Named) + if !ok { + // This can happen for unsafe.Pointer, which is a TypeName holding a Basic type. + pt := p.parseType(pkg) + if pt != t { + p.error("unexpected underlying type for non-named TypeName") + } + return t + } + + underlying := p.parseType(pkg) + if nt.Underlying() == nil { + if underlying.Underlying() == nil { + fix := fixupRecord{toUpdate: nt, target: underlying} + p.fixups = append(p.fixups, fix) + } else { + nt.SetUnderlying(underlying.Underlying()) + } + } + + if p.tok == '\n' { + p.next() + // collect associated methods + for p.tok == scanner.Ident { + p.expectKeyword("func") + if p.tok == '/' { + // Skip a /*nointerface*/ or /*asm ID */ comment. + p.expect('/') + p.expect('*') + if p.expect(scanner.Ident) == "asm" { + p.parseUnquotedString() + } + p.expect('*') + p.expect('/') + } + p.expect('(') + receiver, _ := p.parseParam(pkg) + p.expect(')') + name := p.parseName() + params, isVariadic := p.parseParamList(pkg) + results := p.parseResultList(pkg) + p.skipInlineBody() + p.expectEOL() + + sig := types.NewSignatureType(receiver, nil, nil, params, results, isVariadic) + nt.AddMethod(types.NewFunc(token.NoPos, pkg, name, sig)) + } + } + + return nt +} + +func (p *parser) parseInt64() int64 { + lit := p.expect(scanner.Int) + n, err := strconv.ParseInt(lit, 10, 64) + if err != nil { + p.error(err) + } + return n +} + +func (p *parser) parseInt() int { + lit := p.expect(scanner.Int) + n, err := strconv.ParseInt(lit, 10, 0 /* int */) + if err != nil { + p.error(err) + } + return int(n) +} + +// ArrayOrSliceType = "[" [ int ] "]" Type . +func (p *parser) parseArrayOrSliceType(pkg *types.Package, nlist []any) types.Type { + p.expect('[') + if p.tok == ']' { + p.next() + + t := new(types.Slice) + p.update(t, nlist) + + *t = *types.NewSlice(p.parseType(pkg)) + return t + } + + t := new(types.Array) + p.update(t, nlist) + + len := p.parseInt64() + p.expect(']') + + *t = *types.NewArray(p.parseType(pkg), len) + return t +} + +// MapType = "map" "[" Type "]" Type . +func (p *parser) parseMapType(pkg *types.Package, nlist []any) types.Type { + p.expectKeyword("map") + + t := new(types.Map) + p.update(t, nlist) + + p.expect('[') + key := p.parseType(pkg) + p.expect(']') + elem := p.parseType(pkg) + + *t = *types.NewMap(key, elem) + return t +} + +// ChanType = "chan" ["<-" | "-<"] Type . +func (p *parser) parseChanType(pkg *types.Package, nlist []any) types.Type { + p.expectKeyword("chan") + + t := new(types.Chan) + p.update(t, nlist) + + dir := types.SendRecv + switch p.tok { + case '-': + p.next() + p.expect('<') + dir = types.SendOnly + + case '<': + // don't consume '<' if it belongs to Type + if p.scanner.Peek() == '-' { + p.next() + p.expect('-') + dir = types.RecvOnly + } + } + + *t = *types.NewChan(dir, p.parseType(pkg)) + return t +} + +// StructType = "struct" "{" { Field } "}" . +func (p *parser) parseStructType(pkg *types.Package, nlist []any) types.Type { + p.expectKeyword("struct") + + t := new(types.Struct) + p.update(t, nlist) + + var fields []*types.Var + var tags []string + + p.expect('{') + for p.tok != '}' && p.tok != scanner.EOF { + field, tag := p.parseField(pkg) + p.expect(';') + fields = append(fields, field) + tags = append(tags, tag) + } + p.expect('}') + + *t = *types.NewStruct(fields, tags) + return t +} + +// ParamList = "(" [ { Parameter "," } Parameter ] ")" . +func (p *parser) parseParamList(pkg *types.Package) (*types.Tuple, bool) { + var list []*types.Var + isVariadic := false + + p.expect('(') + for p.tok != ')' && p.tok != scanner.EOF { + if len(list) > 0 { + p.expect(',') + } + par, variadic := p.parseParam(pkg) + list = append(list, par) + if variadic { + if isVariadic { + p.error("... not on final argument") + } + isVariadic = true + } + } + p.expect(')') + + return types.NewTuple(list...), isVariadic +} + +// ResultList = Type | ParamList . +func (p *parser) parseResultList(pkg *types.Package) *types.Tuple { + switch p.tok { + case '<': + p.next() + if p.tok == scanner.Ident && p.lit == "inl" { + return nil + } + taa, _ := p.parseTypeAfterAngle(pkg) + return types.NewTuple(types.NewParam(token.NoPos, pkg, "", taa)) + + case '(': + params, _ := p.parseParamList(pkg) + return params + + default: + return nil + } +} + +// FunctionType = ParamList ResultList . +func (p *parser) parseFunctionType(pkg *types.Package, nlist []any) *types.Signature { + t := new(types.Signature) + p.update(t, nlist) + + params, isVariadic := p.parseParamList(pkg) + results := p.parseResultList(pkg) + + *t = *types.NewSignatureType(nil, nil, nil, params, results, isVariadic) + return t +} + +// Func = Name FunctionType [InlineBody] . +func (p *parser) parseFunc(pkg *types.Package) *types.Func { + if p.tok == '/' { + // Skip an /*asm ID */ comment. + p.expect('/') + p.expect('*') + if p.expect(scanner.Ident) == "asm" { + p.parseUnquotedString() + } + p.expect('*') + p.expect('/') + } + + name := p.parseName() + f := types.NewFunc(token.NoPos, pkg, name, p.parseFunctionType(pkg, nil)) + p.skipInlineBody() + + if name[0] == '.' || name[0] == '<' || strings.ContainsRune(name, '$') { + // This is an unexported function, + // or a function defined in a different package, + // or a type$equal or type$hash function. + // We only want to record exported functions. + return nil + } + + return f +} + +// InterfaceType = "interface" "{" { ("?" Type | Func) ";" } "}" . +func (p *parser) parseInterfaceType(pkg *types.Package, nlist []any) types.Type { + p.expectKeyword("interface") + + t := new(types.Interface) + p.update(t, nlist) + + var methods []*types.Func + var embeddeds []types.Type + + p.expect('{') + for p.tok != '}' && p.tok != scanner.EOF { + if p.tok == '?' { + p.next() + embeddeds = append(embeddeds, p.parseType(pkg)) + } else { + method := p.parseFunc(pkg) + if method != nil { + methods = append(methods, method) + } + } + p.expect(';') + } + p.expect('}') + + *t = *types.NewInterfaceType(methods, embeddeds) + return t +} + +// PointerType = "*" ("any" | Type) . +func (p *parser) parsePointerType(pkg *types.Package, nlist []any) types.Type { + p.expect('*') + if p.tok == scanner.Ident { + p.expectKeyword("any") + t := types.Typ[types.UnsafePointer] + p.update(t, nlist) + return t + } + + t := new(types.Pointer) + p.update(t, nlist) + + *t = *types.NewPointer(p.parseType(pkg, t)) + + return t +} + +// TypeSpec = NamedType | MapType | ChanType | StructType | InterfaceType | PointerType | ArrayOrSliceType | FunctionType . +func (p *parser) parseTypeSpec(pkg *types.Package, nlist []any) types.Type { + switch p.tok { + case scanner.String: + return p.parseNamedType(nlist) + + case scanner.Ident: + switch p.lit { + case "map": + return p.parseMapType(pkg, nlist) + + case "chan": + return p.parseChanType(pkg, nlist) + + case "struct": + return p.parseStructType(pkg, nlist) + + case "interface": + return p.parseInterfaceType(pkg, nlist) + } + + case '*': + return p.parsePointerType(pkg, nlist) + + case '[': + return p.parseArrayOrSliceType(pkg, nlist) + + case '(': + return p.parseFunctionType(pkg, nlist) + } + + p.errorf("expected type name or literal, got %s", scanner.TokenString(p.tok)) + return nil +} + +const ( + // From gofrontend/go/export.h + // Note that these values are negative in the gofrontend and have been made positive + // in the gccgoimporter. + gccgoBuiltinINT8 = 1 + gccgoBuiltinINT16 = 2 + gccgoBuiltinINT32 = 3 + gccgoBuiltinINT64 = 4 + gccgoBuiltinUINT8 = 5 + gccgoBuiltinUINT16 = 6 + gccgoBuiltinUINT32 = 7 + gccgoBuiltinUINT64 = 8 + gccgoBuiltinFLOAT32 = 9 + gccgoBuiltinFLOAT64 = 10 + gccgoBuiltinINT = 11 + gccgoBuiltinUINT = 12 + gccgoBuiltinUINTPTR = 13 + gccgoBuiltinBOOL = 15 + gccgoBuiltinSTRING = 16 + gccgoBuiltinCOMPLEX64 = 17 + gccgoBuiltinCOMPLEX128 = 18 + gccgoBuiltinERROR = 19 + gccgoBuiltinBYTE = 20 + gccgoBuiltinRUNE = 21 + gccgoBuiltinANY = 22 +) + +func lookupBuiltinType(typ int) types.Type { + return [...]types.Type{ + gccgoBuiltinINT8: types.Typ[types.Int8], + gccgoBuiltinINT16: types.Typ[types.Int16], + gccgoBuiltinINT32: types.Typ[types.Int32], + gccgoBuiltinINT64: types.Typ[types.Int64], + gccgoBuiltinUINT8: types.Typ[types.Uint8], + gccgoBuiltinUINT16: types.Typ[types.Uint16], + gccgoBuiltinUINT32: types.Typ[types.Uint32], + gccgoBuiltinUINT64: types.Typ[types.Uint64], + gccgoBuiltinFLOAT32: types.Typ[types.Float32], + gccgoBuiltinFLOAT64: types.Typ[types.Float64], + gccgoBuiltinINT: types.Typ[types.Int], + gccgoBuiltinUINT: types.Typ[types.Uint], + gccgoBuiltinUINTPTR: types.Typ[types.Uintptr], + gccgoBuiltinBOOL: types.Typ[types.Bool], + gccgoBuiltinSTRING: types.Typ[types.String], + gccgoBuiltinCOMPLEX64: types.Typ[types.Complex64], + gccgoBuiltinCOMPLEX128: types.Typ[types.Complex128], + gccgoBuiltinERROR: types.Universe.Lookup("error").Type(), + gccgoBuiltinBYTE: types.Universe.Lookup("byte").Type(), + gccgoBuiltinRUNE: types.Universe.Lookup("rune").Type(), + gccgoBuiltinANY: types.Universe.Lookup("any").Type(), + }[typ] +} + +// Type = "<" "type" ( "-" int | int [ TypeSpec ] ) ">" . +// +// parseType updates the type map to t for all type numbers n. +func (p *parser) parseType(pkg *types.Package, n ...any) types.Type { + p.expect('<') + t, _ := p.parseTypeAfterAngle(pkg, n...) + return t +} + +// (*parser).Type after reading the "<". +func (p *parser) parseTypeAfterAngle(pkg *types.Package, n ...any) (t types.Type, n1 int) { + p.expectKeyword("type") + + n1 = 0 + switch p.tok { + case scanner.Int: + n1 = p.parseInt() + if p.tok == '>' { + if len(p.typeData) > 0 && p.typeList[n1] == nil { + p.parseSavedType(pkg, n1, n) + } + t = p.typeList[n1] + if len(p.typeData) == 0 && t == reserved { + p.errorf("invalid type cycle, type %d not yet defined (nlist=%v)", n1, n) + } + p.update(t, n) + } else { + p.reserve(n1) + t = p.parseTypeSpec(pkg, append(n, n1)) + } + + case '-': + p.next() + n1 := p.parseInt() + t = lookupBuiltinType(n1) + p.update(t, n) + + default: + p.errorf("expected type number, got %s (%q)", scanner.TokenString(p.tok), p.lit) + return nil, 0 + } + + if t == nil || t == reserved { + p.errorf("internal error: bad return from parseType(%v)", n) + } + + p.expect('>') + return +} + +// parseTypeExtended is identical to parseType, but if the type in +// question is a saved type, returns the index as well as the type +// pointer (index returned is zero if we parsed a builtin). +func (p *parser) parseTypeExtended(pkg *types.Package, n ...any) (t types.Type, n1 int) { + p.expect('<') + t, n1 = p.parseTypeAfterAngle(pkg, n...) + return +} + +// InlineBody = "" .{NN} +// Reports whether a body was skipped. +func (p *parser) skipInlineBody() { + // We may or may not have seen the '<' already, depending on + // whether the function had a result type or not. + if p.tok == '<' { + p.next() + p.expectKeyword("inl") + } else if p.tok != scanner.Ident || p.lit != "inl" { + return + } else { + p.next() + } + + p.expect(':') + want := p.parseInt() + p.expect('>') + + defer func(w uint64) { + p.scanner.Whitespace = w + }(p.scanner.Whitespace) + p.scanner.Whitespace = 0 + + got := 0 + for got < want { + r := p.scanner.Next() + if r == scanner.EOF { + p.error("unexpected EOF") + } + got += utf8.RuneLen(r) + } +} + +// Types = "types" maxp1 exportedp1 (offset length)* . +func (p *parser) parseTypes(pkg *types.Package) { + maxp1 := p.parseInt() + exportedp1 := p.parseInt() + p.typeList = make([]types.Type, maxp1, maxp1) + + type typeOffset struct { + offset int + length int + } + var typeOffsets []typeOffset + + total := 0 + for i := 1; i < maxp1; i++ { + len := p.parseInt() + typeOffsets = append(typeOffsets, typeOffset{total, len}) + total += len + } + + defer func(w uint64) { + p.scanner.Whitespace = w + }(p.scanner.Whitespace) + p.scanner.Whitespace = 0 + + // We should now have p.tok pointing to the final newline. + // The next runes from the scanner should be the type data. + + var sb strings.Builder + for sb.Len() < total { + r := p.scanner.Next() + if r == scanner.EOF { + p.error("unexpected EOF") + } + sb.WriteRune(r) + } + allTypeData := sb.String() + + p.typeData = []string{""} // type 0, unused + for _, to := range typeOffsets { + p.typeData = append(p.typeData, allTypeData[to.offset:to.offset+to.length]) + } + + for i := 1; i < exportedp1; i++ { + p.parseSavedType(pkg, i, nil) + } +} + +// parseSavedType parses one saved type definition. +func (p *parser) parseSavedType(pkg *types.Package, i int, nlist []any) { + defer func(s *scanner.Scanner, tok rune, lit string) { + p.scanner = s + p.tok = tok + p.lit = lit + }(p.scanner, p.tok, p.lit) + + p.scanner = new(scanner.Scanner) + p.initScanner(p.scanner.Filename, strings.NewReader(p.typeData[i])) + p.expectKeyword("type") + id := p.parseInt() + if id != i { + p.errorf("type ID mismatch: got %d, want %d", id, i) + } + if p.typeList[i] == reserved { + p.errorf("internal error: %d already reserved in parseSavedType", i) + } + if p.typeList[i] == nil { + p.reserve(i) + p.parseTypeSpec(pkg, append(nlist, i)) + } + if p.typeList[i] == nil || p.typeList[i] == reserved { + p.errorf("internal error: parseSavedType(%d,%v) reserved/nil", i, nlist) + } +} + +// PackageInit = unquotedString unquotedString int . +func (p *parser) parsePackageInit() PackageInit { + name := p.parseUnquotedString() + initfunc := p.parseUnquotedString() + priority := -1 + if p.version == "v1" { + priority = p.parseInt() + } + return PackageInit{Name: name, InitFunc: initfunc, Priority: priority} +} + +// Create the package if we have parsed both the package path and package name. +func (p *parser) maybeCreatePackage() { + if p.pkgname != "" && p.pkgpath != "" { + p.pkg = p.getPkg(p.pkgpath, p.pkgname) + } +} + +// InitDataDirective = ( "v1" | "v2" | "v3" ) ";" | +// +// "priority" int ";" | +// "init" { PackageInit } ";" | +// "checksum" unquotedString ";" . +func (p *parser) parseInitDataDirective() { + if p.tok != scanner.Ident { + // unexpected token kind; panic + p.expect(scanner.Ident) + } + + switch p.lit { + case "v1", "v2", "v3": + p.version = p.lit + p.next() + p.expect(';') + p.expect('\n') + + case "priority": + p.next() + p.initdata.Priority = p.parseInt() + p.expectEOL() + + case "init": + p.next() + for p.tok != '\n' && p.tok != ';' && p.tok != scanner.EOF { + p.initdata.Inits = append(p.initdata.Inits, p.parsePackageInit()) + } + p.expectEOL() + + case "init_graph": + p.next() + // The graph data is thrown away for now. + for p.tok != '\n' && p.tok != ';' && p.tok != scanner.EOF { + p.parseInt64() + p.parseInt64() + } + p.expectEOL() + + case "checksum": + // Don't let the scanner try to parse the checksum as a number. + defer func(mode uint) { + p.scanner.Mode = mode + }(p.scanner.Mode) + p.scanner.Mode &^= scanner.ScanInts | scanner.ScanFloats + p.next() + p.parseUnquotedString() + p.expectEOL() + + default: + p.errorf("unexpected identifier: %q", p.lit) + } +} + +// Directive = InitDataDirective | +// +// "package" unquotedString [ unquotedString ] [ unquotedString ] ";" | +// "pkgpath" unquotedString ";" | +// "prefix" unquotedString ";" | +// "import" unquotedString unquotedString string ";" | +// "indirectimport" unquotedString unquotedstring ";" | +// "func" Func ";" | +// "type" Type ";" | +// "var" Var ";" | +// "const" Const ";" . +func (p *parser) parseDirective() { + if p.tok != scanner.Ident { + // unexpected token kind; panic + p.expect(scanner.Ident) + } + + switch p.lit { + case "v1", "v2", "v3", "priority", "init", "init_graph", "checksum": + p.parseInitDataDirective() + + case "package": + p.next() + p.pkgname = p.parseUnquotedString() + p.maybeCreatePackage() + if p.version != "v1" && p.tok != '\n' && p.tok != ';' { + p.parseUnquotedString() + p.parseUnquotedString() + } + p.expectEOL() + + case "pkgpath": + p.next() + p.pkgpath = p.parseUnquotedString() + p.maybeCreatePackage() + p.expectEOL() + + case "prefix": + p.next() + p.pkgpath = p.parseUnquotedString() + p.expectEOL() + + case "import": + p.next() + pkgname := p.parseUnquotedString() + pkgpath := p.parseUnquotedString() + p.getPkg(pkgpath, pkgname) + p.parseString() + p.expectEOL() + + case "indirectimport": + p.next() + pkgname := p.parseUnquotedString() + pkgpath := p.parseUnquotedString() + p.getPkg(pkgpath, pkgname) + p.expectEOL() + + case "types": + p.next() + p.parseTypes(p.pkg) + p.expectEOL() + + case "func": + p.next() + fun := p.parseFunc(p.pkg) + if fun != nil { + p.pkg.Scope().Insert(fun) + } + p.expectEOL() + + case "type": + p.next() + p.parseType(p.pkg) + p.expectEOL() + + case "var": + p.next() + v := p.parseVar(p.pkg) + if v != nil { + p.pkg.Scope().Insert(v) + } + p.expectEOL() + + case "const": + p.next() + c := p.parseConst(p.pkg) + p.pkg.Scope().Insert(c) + p.expectEOL() + + default: + p.errorf("unexpected identifier: %q", p.lit) + } +} + +// Package = { Directive } . +func (p *parser) parsePackage() *types.Package { + for p.tok != scanner.EOF { + p.parseDirective() + } + for _, f := range p.fixups { + if f.target.Underlying() == nil { + p.errorf("internal error: fixup can't be applied, loop required") + } + f.toUpdate.SetUnderlying(f.target.Underlying()) + } + p.fixups = nil + for _, typ := range p.typeList { + if it, ok := typ.(*types.Interface); ok { + it.Complete() + } + } + p.pkg.MarkComplete() + return p.pkg +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/parser_test.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/parser_test.go new file mode 100644 index 0000000000000000000000000000000000000000..00128b44d2687e9369843e45685b02c0031a7a12 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/parser_test.go @@ -0,0 +1,78 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package gccgoimporter + +import ( + "bytes" + "go/types" + "strings" + "testing" + "text/scanner" +) + +var typeParserTests = []struct { + id, typ, want, underlying, methods string +}{ + {id: "foo", typ: "", want: "int8"}, + {id: "foo", typ: ">", want: "*error"}, + {id: "foo", typ: "", want: "unsafe.Pointer"}, + {id: "foo", typ: ">>", want: "foo.Bar", underlying: "*foo.Bar"}, + {id: "foo", typ: "\nfunc (? ) M ();\n>", want: "bar.Foo", underlying: "int8", methods: "func (bar.Foo).M()"}, + {id: "foo", typ: ">", want: "bar.foo", underlying: "int8"}, + {id: "foo", typ: ">", want: "[]int8"}, + {id: "foo", typ: ">", want: "[42]int8"}, + {id: "foo", typ: "] >", want: "map[int8]int16"}, + {id: "foo", typ: ">", want: "chan int8"}, + {id: "foo", typ: ">", want: "<-chan int8"}, + {id: "foo", typ: ">", want: "chan<- int8"}, + {id: "foo", typ: "; I16 \"i16\"; }>", want: "struct{I8 int8; I16 int16 \"i16\"}"}, + {id: "foo", typ: ", b ) ; Bar (? , ? ...) (? , ? ); Baz (); }>", want: "interface{Bar(int16, ...int8) (int16, int8); Baz(); Foo(a int8, b int16) int8}"}, + {id: "foo", typ: ") >", want: "func(int8) int16"}, +} + +func TestTypeParser(t *testing.T) { + for _, test := range typeParserTests { + var p parser + p.init("test.gox", strings.NewReader(test.typ), make(map[string]*types.Package)) + p.version = "v2" + p.pkgname = test.id + p.pkgpath = test.id + p.maybeCreatePackage() + typ := p.parseType(p.pkg) + + if p.tok != scanner.EOF { + t.Errorf("expected full parse, stopped at %q", p.lit) + } + + // interfaces must be explicitly completed + if ityp, _ := typ.(*types.Interface); ityp != nil { + ityp.Complete() + } + + got := typ.String() + if got != test.want { + t.Errorf("got type %q, expected %q", got, test.want) + } + + if test.underlying != "" { + underlying := typ.Underlying().String() + if underlying != test.underlying { + t.Errorf("got underlying type %q, expected %q", underlying, test.underlying) + } + } + + if test.methods != "" { + nt := typ.(*types.Named) + var buf bytes.Buffer + for i := 0; i != nt.NumMethods(); i++ { + buf.WriteString(nt.Method(i).String()) + } + methods := buf.String() + if methods != test.methods { + t.Errorf("got methods %q, expected %q", methods, test.methods) + } + } + } +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/aliases.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/aliases.go new file mode 100644 index 0000000000000000000000000000000000000000..cfb59b3e315ba0721cde687eaccd8664b99d973b --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/aliases.go @@ -0,0 +1,65 @@ +package aliases + +type ( + T0 [10]int + T1 []byte + T2 struct { + x int + } + T3 interface { + m() T2 + } + T4 func(int, T0) chan T2 +) + +// basic aliases +type ( + Ai = int + A0 = T0 + A1 = T1 + A2 = T2 + A3 = T3 + A4 = T4 + + A10 = [10]int + A11 = []byte + A12 = struct { + x int + } + A13 = interface { + m() A2 + } + A14 = func(int, A0) chan A2 +) + +// alias receiver types +func (T0) m1() {} +func (A0) m2() {} + +// alias receiver types (long type declaration chains) +type ( + V0 = V1 + V1 = (V2) + V2 = (V3) + V3 = T0 +) + +func (V1) n() {} + +// cycles +type C0 struct { + f1 C1 + f2 C2 +} + +type ( + C1 *C0 + C2 = C1 +) + +type ( + C5 struct { + f *C6 + } + C6 = C5 +) diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/aliases.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/aliases.gox new file mode 100644 index 0000000000000000000000000000000000000000..2428c0687436824a2f80750e0017e7cd11b07fc4 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/aliases.gox @@ -0,0 +1,33 @@ +v2; +package aliases; +prefix go; +package aliases go.aliases go.aliases; +type > + func (? ) .go.aliases.m1 (); + func (? ) .go.aliases.m2 (); + func (? >>>) .go.aliases.n (); +>>; +type >>>; +type >>; +type >>; +type ; }>>; +type ; }>>>; }>>; +type , ? ) >>>; +type ; +type ; }>>>; +type , ? ) >>>>; +type >; +type >>; .go.aliases.f2 >; }>>; +type ; +type ; +type >>; }>>; +type ; +type ; +type ; +type ; +type ; +type ; +type >; +type ; +type ; +type ; diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/complexnums.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/complexnums.go new file mode 100644 index 0000000000000000000000000000000000000000..a51b6b01c0be3ac95ea5436aecbead5b69f21cc5 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/complexnums.go @@ -0,0 +1,6 @@ +package complexnums + +const NN = -1 - 1i +const NP = -1 + 1i +const PN = 1 - 1i +const PP = 1 + 1i diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/complexnums.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/complexnums.gox new file mode 100644 index 0000000000000000000000000000000000000000..b66524f80edd51d9837b59cae36f73a9fa4f4e18 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/complexnums.gox @@ -0,0 +1,8 @@ +v1; +package complexnums; +pkgpath complexnums; +priority 1; +const NN = -0.1E1-0.1E1i ; +const NP = -0.1E1+0.1E1i ; +const PN = 0.1E1-0.1E1i ; +const PP = 0.1E1+0.1E1i ; diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/conversions.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/conversions.go new file mode 100644 index 0000000000000000000000000000000000000000..653927ad670456cc4ea593abb7fb5b4f12e7f15f --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/conversions.go @@ -0,0 +1,5 @@ +package conversions + +type Units string + +const Bits = Units("bits") diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/conversions.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/conversions.gox new file mode 100644 index 0000000000000000000000000000000000000000..7de6cdad2ceb9c21d7bc0f43cc65c7f81c277e73 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/conversions.gox @@ -0,0 +1,6 @@ +v2; +package conversions; +prefix go; +package conversions go.conversions go.conversions; +const Bits > = convert(, "bits"); +type ; diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/escapeinfo.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/escapeinfo.go new file mode 100644 index 0000000000000000000000000000000000000000..103ad9549425a64ab94220d1299fc567ead0a37b --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/escapeinfo.go @@ -0,0 +1,13 @@ +// Test case for escape info in export data. To compile and extract .gox file: +// gccgo -fgo-optimize-allocs -c escapeinfo.go +// objcopy -j .go_export escapeinfo.o escapeinfo.gox + +package escapeinfo + +type T struct{ data []byte } + +func NewT(data []byte) *T { + return &T{data} +} + +func (*T) Read(p []byte) {} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/escapeinfo.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/escapeinfo.gox new file mode 100644 index 0000000000000000000000000000000000000000..94ce0393fc0353bc2647ff1e3babc16c50d848cb --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/escapeinfo.gox @@ -0,0 +1,9 @@ +v2; +package escapeinfo; +prefix go; +package escapeinfo go.escapeinfo go.escapeinfo; +func NewT (data >) >; }> + func (? >) Read (p >); +>>; +type ; +checksum 3500838130783C0059CD0C81527F60E9738E3ACE; diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/imports.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/imports.go new file mode 100644 index 0000000000000000000000000000000000000000..7907316a607fc48a91acf63318a863d481a2de86 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/imports.go @@ -0,0 +1,5 @@ +package imports + +import "fmt" + +var Hello = fmt.Sprintf("Hello, world") diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/imports.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/imports.gox new file mode 100644 index 0000000000000000000000000000000000000000..958a4f5b82109a94bee63ebdca66c6aea0b89dda --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/imports.gox @@ -0,0 +1,7 @@ +v1; +package imports; +pkgpath imports; +priority 7; +import fmt fmt "fmt"; +init imports imports..import 7 math math..import 1 runtime runtime..import 1 strconv strconv..import 2 io io..import 3 reflect reflect..import 3 syscall syscall..import 3 time time..import 4 os os..import 5 fmt fmt..import 6; +var Hello ; diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue27856.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue27856.go new file mode 100644 index 0000000000000000000000000000000000000000..bf361e1cd803beb0b2a0af2ca2bb8a45ab92f0be --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue27856.go @@ -0,0 +1,9 @@ +package lib + +type M struct { + E E +} +type F struct { + _ *M +} +type E = F diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue27856.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue27856.gox new file mode 100644 index 0000000000000000000000000000000000000000..6665e64021b9517de0ac044f8a746ca49b6ea280 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue27856.gox @@ -0,0 +1,9 @@ +v2; +package main; +pkgpath main; +import runtime runtime "runtime"; +init runtime runtime..import sys runtime_internal_sys..import; +init_graph 0 1; +type ; }>>>; }>>>; +type ; +type ; diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue29198.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue29198.go new file mode 100644 index 0000000000000000000000000000000000000000..75c2162d20454913d0d0c77c52728395b7bcb9d0 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue29198.go @@ -0,0 +1,37 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package server + +import ( + "context" + "errors" +) + +type A struct { + x int +} + +func (a *A) AMethod(y int) *Server { + return nil +} + +// FooServer is a server that provides Foo services +type FooServer Server + +func (f *FooServer) WriteEvents(ctx context.Context, x int) error { + return errors.New("hey!") +} + +type Server struct { + FooServer *FooServer + user string + ctx context.Context +} + +func New(sctx context.Context, u string) (*Server, error) { + s := &Server{user: u, ctx: sctx} + s.FooServer = (*FooServer)(s) + return s, nil +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue29198.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue29198.gox new file mode 100644 index 0000000000000000000000000000000000000000..905c86637ebf35d417db6cdd1ebc64513ef3b9d2 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue29198.gox @@ -0,0 +1,86 @@ +v2; +package server; +pkgpath issue29198; +import context context "context"; +import errors errors "errors"; +init context context..import fmt fmt..import poll internal_poll..import testlog internal_testlog..import io io..import os os..import reflect reflect..import runtime runtime..import sys runtime_internal_sys..import strconv strconv..import sync sync..import syscall syscall..import time time..import unicode unicode..import; +init_graph 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 2 4 2 7 2 8 2 10 2 11 2 12 4 7 4 8 4 10 5 2 5 3 5 4 5 7 5 8 5 10 5 11 5 12 6 7 6 8 6 9 6 10 6 13 7 8 9 7 9 8 10 7 10 8 11 7 11 8 11 10 12 7 12 8 12 10 12 11; +type ; }> + func (a >) AMethod (y ) + func (f >) WriteEvents (ctx ; .time.ext ; .time.loc ; .time.zone ; .time.offset ; .time.isDST ; }>>>; .time.tx ; .time.index ; .time.isstd ; .time.isutc ; }>>>; .time.cacheStart ; .time.cacheEnd ; .time.cacheZone >; }> + func (l >) String () ; + func (l ) .time.lookupFirstZone () ; + func (l ) .time.get () ; + func (l ) .time.lookup (sec ) (name , offset , isDST , start , end ); + func (l ) .time.lookupName (name , unix ) (offset , ok ); + func (l ) .time.firstZoneUsed () ; +>>; }> + func (t ) In (loc ) ; + func (t ) .time.date (full ) (year , month + func (m ) String () ; +>, day , yday ); + func (t ) Sub (u ) + func (d ) Truncate (m ) ; + func (d ) String () ; + func (d ) Round (m ) ; + func (d ) Seconds () ; + func (d ) Nanoseconds () ; + func (d ) Minutes () ; + func (d ) Hours () ; +>; + func (t ) Add (d ) ; + func (t ) UTC () ; + func (t ) AddDate (years , months , days ) ; + func (t ) MarshalBinary () (? >, ? ); + func (t ) Nanosecond () ; + func (t ) Round (d ) ; + func (t ) Minute () ; + func (t ) Clock () (hour , min , sec ); + func (t ) ISOWeek () (year , week ); + func (t ) Day () ; + func (t >) .time.mono () ; + func (t ) UnixNano () ; + func (t ) .time.sec () ; + func (t ) Second () ; + func (t ) Before (u ) ; + func (t ) UnmarshalBinary (data >) ; + func (t ) Month () ; + func (t ) YearDay () ; + func (t ) Location () ; + func (t ) Zone () (name , offset ); + func (t ) Local () ; + func (t ) .time.setLoc (loc ); + func (t ) Truncate (d ) ; + func (t ) MarshalJSON () (? >, ? ); + func (t ) AppendFormat (b >, layout ) >; + func (t ) GobDecode (data >) ; + func (t ) UnmarshalJSON (data >) ; + func (t ) MarshalText () (? >, ? ); + func (t ) GobEncode () (? >, ? ); + func (t ) .time.stripMono (); + func (t ) After (u ) ; + func (t ) Hour () ; + func (t ) UnmarshalText (data >) ; + func (t ) Equal (u ) ; + func (t ) .time.setMono (m ); + func (t ) Year () ; + func (t ) IsZero () ; + func (t ) .time.addSec (d ); + func (t ) Weekday () + func (d ) String () ; +>; + func (t ) String () ; + func (t ) .time.nsec () ; + func (t ) Format (layout ) ; + func (t ) .time.unixSec () ; + func (t ) Unix () ; + func (t ) .time.abs () ; + func (t ) .time.locabs () (name , offset , abs ); + func (t ) Date () (year , month , day ); +>, ok ); Done () >; Err () ; Value (key ) ; }>>, x ) ; +>>; .issue29198.user ; .issue29198.ctx ; }>>>; +>; +type ; +func New (sctx , u ) (? >, ? ); +type ; +checksum 86C8D76B2582F55A8BD2CA9E00060358EC1CE214; diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue30628.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue30628.go new file mode 100644 index 0000000000000000000000000000000000000000..8fd7c13d7ba1de29be76a75c759030f0311ec4de --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue30628.go @@ -0,0 +1,18 @@ +package issue30628 + +import ( + "os" + "sync" +) + +const numR = int32(os.O_TRUNC + 5) + +type Apple struct { + hey sync.RWMutex + x int + RQ [numR]struct { + Count uintptr + NumBytes uintptr + Last uintptr + } +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue30628.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue30628.gox new file mode 100644 index 0000000000000000000000000000000000000000..0ff6259dd09cd56671b8b1b2c8232032b1d11450 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue30628.gox @@ -0,0 +1,28 @@ +v3; +package issue30628 +pkgpath issue30628 +import os os "os" +import sync sync "sync" +init cpu internal..z2fcpu..import poll internal..z2fpoll..import testlog internal..z2ftestlog..import io io..import os os..import runtime runtime..import sys runtime..z2finternal..z2fsys..import sync sync..import syscall syscall..import time time..import +init_graph 1 0 1 3 1 5 1 6 1 7 1 8 1 9 3 0 3 5 3 6 3 7 4 0 4 1 4 2 4 3 4 5 4 6 4 7 4 8 4 9 5 0 5 6 7 0 7 5 7 6 8 0 8 5 8 6 8 7 9 0 9 5 9 6 9 7 9 8 +types 13 2 24 84 208 17 30 41 147 86 17 64 25 75 +type 1 "Apple" +type 2 struct { .issue30628.hey ; .issue30628.x ; RQ ; } +type 3 "sync.RWMutex" + func (rw ) Lock () + func (rw ) RLocker () ($ret8 ) + func (rw ) RUnlock () + func (rw ) Unlock () + func (rw ) RLock () +type 4 * +type 5 "sync.Locker" +type 6 interface { Lock (); Unlock (); } +type 7 struct { .sync.w ; .sync.writerSem ; .sync.readerSem ; .sync.readerCount ; .sync.readerWait ; } +type 8 "sync.Mutex" + func (m ) Unlock () + func (m ) Lock () +type 9 * +type 10 struct { .sync.state ; .sync.sema ; } +type 11 [517 ] +type 12 struct { Count ; NumBytes ; Last ; } +checksum 199DCF6D3EE2FCF39F715B4E42B5F87F5B15D3AF diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue31540.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue31540.go new file mode 100644 index 0000000000000000000000000000000000000000..2c6799ec408c68e656a6ee0fa8149de6c3740360 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue31540.go @@ -0,0 +1,26 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue31540 + +type Y struct { + q int +} + +type Z map[int]int + +type X = map[Y]Z + +type A1 = X + +type A2 = A1 + +type S struct { + b int + A2 +} + +func Hallo() S { + return S{} +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue31540.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue31540.gox new file mode 100644 index 0000000000000000000000000000000000000000..abdc696cafdc5a9acb58bb54e971240d60998ff8 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue31540.gox @@ -0,0 +1,16 @@ +v3; +package issue31540 +pkgpath issue31540 +types 11 7 23 23 20 22 20 21 57 31 45 36 +type 1 "A1" = +type 2 "A2" = +type 3 "S" +type 4 "X" = +type 5 "Y" +type 6 "Z" +type 7 struct { .go.mapalias.b ; ? ; } +type 8 map [] +type 9 struct { .go.mapalias.q ; } +type 10 map [] +func Hallo () +checksum C3FAF2524A90BC11225EE65D059BF27DFB69134B diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue34182.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue34182.go new file mode 100644 index 0000000000000000000000000000000000000000..2a5c333a05791fa399a7cf2b870a3a26e0276eb9 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue34182.go @@ -0,0 +1,17 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue34182 + +type T1 struct { + f *T2 +} + +type T2 struct { + f T3 +} + +type T3 struct { + *T2 +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue34182.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue34182.gox new file mode 100644 index 0000000000000000000000000000000000000000..671a7d62d6f62bcaaaee1c6cb194a5a0c38da087 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/issue34182.gox @@ -0,0 +1,13 @@ +v3; +package issue34182 +pkgpath issue34182 +init issue34182 ~go.issue34182 +types 8 4 21 21 21 17 30 45 45 +type 1 "T1" +type 2 "T2" +type 3 "T3" +type 4 * +type 5 struct { ? ; } +type 6 struct { .go.issue34182.f ; } +type 7 struct { .go.issue34182.f ; } +checksum FF02C49BAF44B06C087ED4E573F7CC880C79C208 diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/libimportsar.a b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/libimportsar.a new file mode 100644 index 0000000000000000000000000000000000000000..6f30758151dbc3ebbf037c54b55f4e84fb055277 Binary files /dev/null and b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/libimportsar.a differ diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/nointerface.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/nointerface.go new file mode 100644 index 0000000000000000000000000000000000000000..6a545f24933fddb33e1fae7cb40fc89cc415707e --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/nointerface.go @@ -0,0 +1,12 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package nointerface + +type I int + +//go:nointerface +func (p *I) Get() int { return int(*p) } + +func (p *I) Set(v int) { *p = I(v) } diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/nointerface.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/nointerface.gox new file mode 100644 index 0000000000000000000000000000000000000000..7b73d179e393c16076dbd72c8f734bbf16f77f89 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/nointerface.gox @@ -0,0 +1,8 @@ +v3; +package nointerface +pkgpath nointerface +types 3 2 133 17 +type 1 "I" + func /*nointerface*/ (p ) Get () + func (p ) Set (v ) +type 2 * diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/notinheap.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/notinheap.go new file mode 100644 index 0000000000000000000000000000000000000000..b1ac967227b1bc36396e474536f6c63cddbfc764 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/notinheap.go @@ -0,0 +1,4 @@ +package notinheap + +//go:notinheap +type S struct{} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/notinheap.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/notinheap.gox new file mode 100644 index 0000000000000000000000000000000000000000..cc438e75e0bf2d773789f9d28b2ff0d70b0a1e96 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/notinheap.gox @@ -0,0 +1,7 @@ +v3; +package notinheap +pkgpath notinheap +init notinheap ~notinheap +types 3 2 30 18 +type 1 "S" notinheap +type 2 struct { } diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/pointer.go b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/pointer.go new file mode 100644 index 0000000000000000000000000000000000000000..4ebc67137d68bce06a609f6680341db7043d2a48 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/pointer.go @@ -0,0 +1,3 @@ +package pointer + +type Int8Ptr *int8 diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/pointer.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/pointer.gox new file mode 100644 index 0000000000000000000000000000000000000000..d96ebbdd1418933ac6919ec05efca99ae0508345 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/pointer.gox @@ -0,0 +1,4 @@ +v1; +package pointer; +pkgpath pointer; +type >>; diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/time.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/time.gox new file mode 100644 index 0000000000000000000000000000000000000000..a6822ea19859bef114e34b24b05ddca7c8966833 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/time.gox @@ -0,0 +1,142 @@ +v2; +package time; +pkgpath time; +import errors errors "errors"; +import sync sync "sync"; +import syscall syscall "syscall"; +init time time..import runtime runtime..import sync sync..import syscall syscall..import; +init_graph 0 1 0 2 0 3 2 1 3 1 3 2; +const ANSIC = "Mon Jan _2 15:04:05 2006"; +func After (d + func (d ) String () ; + func (d ) Nanoseconds () ; + func (d ) Seconds () ; + func (d ) Minutes () ; + func (d ) Hours () ; +>) ; .time.nsec ; .time.loc ; .time.zone ; .time.offset ; .time.isDST ; }>>>; .time.tx ; .time.index ; .time.isstd ; .time.isutc ; }>>>; .time.cacheStart ; .time.cacheEnd ; .time.cacheZone >; }> + func (l >) .time.get () ; + func (l ) String () ; + func (l ) .time.lookup (sec ) (name , offset , isDST , start , end ); + func (l ) .time.lookupFirstZone () ; + func (l ) .time.firstZoneUsed () ; + func (l ) .time.lookupName (name , unix ) (offset , isDST , ok ); +>>; }> + func (t ) String () ; + func (t ) Format (layout ) ; + func (t ) AppendFormat (b >, layout ) >; + func (t ) After (u ) ; + func (t ) Before (u ) ; + func (t ) Equal (u ) ; + func (t ) IsZero () ; + func (t ) .time.abs () ; + func (t ) .time.locabs () (name , offset , abs ); + func (t ) Date () (year , month + func (m ) String () ; +>, day ); + func (t ) Year () ; + func (t ) Month () ; + func (t ) Day () ; + func (t ) Weekday () + func (d ) String () ; +>; + func (t ) ISOWeek () (year , week ); + func (t ) Clock () (hour , min , sec ); + func (t ) Hour () ; + func (t ) Minute () ; + func (t ) Second () ; + func (t ) Nanosecond () ; + func (t ) YearDay () ; + func (t ) Add (d ) ; + func (t ) Sub (u ) ; + func (t ) AddDate (years , months , days ) ; + func (t ) .time.date (full ) (year , month , day , yday ); + func (t ) UTC () ; + func (t ) Local () ; + func (t ) In (loc >) ; + func (t ) Location () >; + func (t ) Zone () (name , offset ); + func (t ) Unix () ; + func (t ) UnixNano () ; + func (t ) MarshalBinary () (? >, ? ); + func (t >) UnmarshalBinary (data >) ; + func (t ) GobEncode () (? >, ? ); + func (t ) GobDecode (data >) ; + func (t ) MarshalJSON () (? >, ? ); + func (t ) UnmarshalJSON (data >) ; + func (t ) MarshalText () (? >, ? ); + func (t ) UnmarshalText (data >) ; + func (t ) Truncate (d ) ; + func (t ) Round (d ) ; +>>; +func AfterFunc (d , f ) >; .time.r ; .time.when ; .time.period ; .time.f , ? )>; .time.arg ; .time.seq ; }>>; }> + func (t >) Stop () ; + func (t ) Reset (d ) ; +>>; +const April = 4 ; +const August = 8 ; +func Date (year , month , day , hour , min , sec , nsec , loc >) ; +const December = 12 ; +type ; +const February = 2 ; +func FixedZone (name , offset ) ; +const Friday = 5 ; +const Hour = 3600000000000 ; +const January = 1 ; +const July = 7 ; +const June = 6 ; +const Kitchen = "3:04PM"; +func LoadLocation (name ) (? , ? ); +var Local ; +type ; +var LocationSource ) (? >, ? )>; +const March = 3 ; +const May = 5 ; +const Microsecond = 1000 ; +const Millisecond = 1000000 ; +const Minute = 60000000000 ; +const Monday = 1 ; +type ; +const Nanosecond = 1 ; +func NewTicker (d ) >; .time.r ; }> + func (t >) Stop (); +>>; +func NewTimer (d ) ; +const November = 11 ; +func Now () ; +const October = 10 ; +func Parse (layout , value ) (? , ? ); +func ParseDuration (s ) (? , ? ); +type ; Value ; LayoutElem ; ValueElem ; Message ; }> + func (e >) Error () ; +>; +func ParseInLocation (layout , value , loc >) (? , ? ); +const RFC1123 = "Mon, 02 Jan 2006 15:04:05 MST"; +const RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700"; +const RFC3339 = "2006-01-02T15:04:05Z07:00"; +const RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00"; +const RFC822 = "02 Jan 06 15:04 MST"; +const RFC822Z = "02 Jan 06 15:04 -0700"; +const RFC850 = "Monday, 02-Jan-06 15:04:05 MST"; +const RubyDate = "Mon Jan 02 15:04:05 -0700 2006"; +const Saturday = 6 ; +const Second = 1000000000 ; +const September = 9 ; +func Since (t ) ; +func Sleep (d ); +const Stamp = "Jan _2 15:04:05"; +const StampMicro = "Jan _2 15:04:05.000000"; +const StampMilli = "Jan _2 15:04:05.000"; +const StampNano = "Jan _2 15:04:05.000000000"; +const Sunday = 0 ; +const Thursday = 4 ; +func Tick (d ) >; +type ; +type ; +type ; +const Tuesday = 2 ; +var UTC ; +func Unix (sec , nsec ) ; +const UnixDate = "Mon Jan _2 15:04:05 MST 2006"; +const Wednesday = 3 ; +type ; +checksum C04E7F45B20C621A25DC74E9B13EA4FF6732E226; diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/unicode.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/unicode.gox new file mode 100644 index 0000000000000000000000000000000000000000..ae1a6f758b4d807567569126b1fe2df57a3152cb --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/unicode.gox @@ -0,0 +1,273 @@ +v2; +package unicode; +pkgpath unicode; +init unicode unicode..import; +var ASCII_Hex_Digit ; Hi ; Stride ; }>>>; R32 ; Hi ; Stride ; }>>>; LatinOffset ; }>>>; +var Adlam ; +var Ahom ; +var Anatolian_Hieroglyphs ; +var Arabic ; +var Armenian ; +var Avestan ; +var AzeriCase ; Hi ; Delta >>; }>>> + func (special ) ToUpper (r ) ; + func (special ) ToTitle (r ) ; + func (special ) ToLower (r ) ; +>; +var Balinese ; +var Bamum ; +var Bassa_Vah ; +var Batak ; +var Bengali ; +var Bhaiksuki ; +var Bidi_Control ; +var Bopomofo ; +var Brahmi ; +var Braille ; +var Buginese ; +var Buhid ; +var C ; +var Canadian_Aboriginal ; +var Carian ; +type ; +var CaseRanges >; +var Categories ] >; +var Caucasian_Albanian ; +var Cc ; +var Cf ; +var Chakma ; +var Cham ; +var Cherokee ; +var Co ; +var Common ; +var Coptic ; +var Cs ; +var Cuneiform ; +var Cypriot ; +var Cyrillic ; +var Dash ; +var Deprecated ; +var Deseret ; +var Devanagari ; +var Diacritic ; +var Digit ; +var Duployan ; +var Egyptian_Hieroglyphs ; +var Elbasan ; +var Ethiopic ; +var Extender ; +var FoldCategory ] >; +var FoldScript ] >; +var Georgian ; +var Glagolitic ; +var Gothic ; +var Grantha ; +var GraphicRanges >>; +var Greek ; +var Gujarati ; +var Gurmukhi ; +var Han ; +var Hangul ; +var Hanunoo ; +var Hatran ; +var Hebrew ; +var Hex_Digit ; +var Hiragana ; +var Hyphen ; +var IDS_Binary_Operator ; +var IDS_Trinary_Operator ; +var Ideographic ; +var Imperial_Aramaic ; +func In (r , ranges ...>) ; +var Inherited ; +var Inscriptional_Pahlavi ; +var Inscriptional_Parthian ; +func Is (rangeTab , r ) ; +func IsControl (r ) ; +func IsDigit (r ) ; +func IsGraphic (r ) ; +func IsLetter (r ) ; +func IsLower (r ) ; +func IsMark (r ) ; +func IsNumber (r ) ; +func IsOneOf (ranges >>, r ) ; +func IsPrint (r ) ; +func IsPunct (r ) ; +func IsSpace (r ) ; +func IsSymbol (r ) ; +func IsTitle (r ) ; +func IsUpper (r ) ; +var Javanese ; +var Join_Control ; +var Kaithi ; +var Kannada ; +var Katakana ; +var Kayah_Li ; +var Kharoshthi ; +var Khmer ; +var Khojki ; +var Khudawadi ; +var L ; +var Lao ; +var Latin ; +var Lepcha ; +var Letter ; +var Limbu ; +var Linear_A ; +var Linear_B ; +var Lisu ; +var Ll ; +var Lm ; +var Lo ; +var Logical_Order_Exception ; +var Lower ; +const LowerCase = 1 ; +var Lt ; +var Lu ; +var Lycian ; +var Lydian ; +var M ; +var Mahajani ; +var Malayalam ; +var Mandaic ; +var Manichaean ; +var Marchen ; +var Mark ; +const MaxASCII = 127' ; +const MaxCase = 3 ; +const MaxLatin1 = 255' ; +const MaxRune = 1114111' ; +var Mc ; +var Me ; +var Meetei_Mayek ; +var Mende_Kikakui ; +var Meroitic_Cursive ; +var Meroitic_Hieroglyphs ; +var Miao ; +var Mn ; +var Modi ; +var Mongolian ; +var Mro ; +var Multani ; +var Myanmar ; +var N ; +var Nabataean ; +var Nd ; +var New_Tai_Lue ; +var Newa ; +var Nko ; +var Nl ; +var No ; +var Noncharacter_Code_Point ; +var Number ; +var Ogham ; +var Ol_Chiki ; +var Old_Hungarian ; +var Old_Italic ; +var Old_North_Arabian ; +var Old_Permic ; +var Old_Persian ; +var Old_South_Arabian ; +var Old_Turkic ; +var Oriya ; +var Osage ; +var Osmanya ; +var Other ; +var Other_Alphabetic ; +var Other_Default_Ignorable_Code_Point ; +var Other_Grapheme_Extend ; +var Other_ID_Continue ; +var Other_ID_Start ; +var Other_Lowercase ; +var Other_Math ; +var Other_Uppercase ; +var P ; +var Pahawh_Hmong ; +var Palmyrene ; +var Pattern_Syntax ; +var Pattern_White_Space ; +var Pau_Cin_Hau ; +var Pc ; +var Pd ; +var Pe ; +var Pf ; +var Phags_Pa ; +var Phoenician ; +var Pi ; +var Po ; +var Prepended_Concatenation_Mark ; +var PrintRanges >>; +var Properties ] >; +var Ps ; +var Psalter_Pahlavi ; +var Punct ; +var Quotation_Mark ; +var Radical ; +type ; +type ; +type ; +var Rejang ; +const ReplacementChar = 65533' ; +var Runic ; +var S ; +var STerm ; +var Samaritan ; +var Saurashtra ; +var Sc ; +var Scripts ] >; +var Sentence_Terminal ; +var Sharada ; +var Shavian ; +var Siddham ; +var SignWriting ; +func SimpleFold (r ) ; +var Sinhala ; +var Sk ; +var Sm ; +var So ; +var Soft_Dotted ; +var Sora_Sompeng ; +var Space ; +type ; +var Sundanese ; +var Syloti_Nagri ; +var Symbol ; +var Syriac ; +var Tagalog ; +var Tagbanwa ; +var Tai_Le ; +var Tai_Tham ; +var Tai_Viet ; +var Takri ; +var Tamil ; +var Tangut ; +var Telugu ; +var Terminal_Punctuation ; +var Thaana ; +var Thai ; +var Tibetan ; +var Tifinagh ; +var Tirhuta ; +var Title ; +const TitleCase = 2 ; +func To (_case , r ) ; +func ToLower (r ) ; +func ToTitle (r ) ; +func ToUpper (r ) ; +var TurkishCase ; +var Ugaritic ; +var Unified_Ideograph ; +var Upper ; +const UpperCase = 0 ; +const UpperLower = 1114112' ; +var Vai ; +var Variation_Selector ; +const Version = "9.0.0"; +var Warang_Citi ; +var White_Space ; +var Yi ; +var Z ; +var Zl ; +var Zp ; +var Zs ; +checksum 7643975C0BE2732C7557F1B2A70796673C11DF4A; diff --git a/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/v1reflect.gox b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/v1reflect.gox new file mode 100644 index 0000000000000000000000000000000000000000..d693fe631b53ee3ac530c76d6ce35782421db9a0 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gccgoimporter/testdata/v1reflect.gox @@ -0,0 +1,184 @@ +v1; +package reflect; +pkgpath reflect; +priority 3; +import math math "math"; +import runtime runtime "runtime"; +import strconv strconv "strconv"; +import sync sync "sync"; +import unsafe unsafe "unsafe"; +init reflect reflect..import 3 math math..import 1 runtime runtime..import 1 strconv strconv..import 2; +func Append (s ; .reflect.align ; .reflect.fieldAlign ; .reflect._ ; .reflect.size ; .reflect.hash ; .reflect.hashfn >, ? )>; .reflect.equalfn , ? , ? )>; .reflect.string >; ? >; .reflect.pkgPath >; .reflect.methods >; .reflect.pkgPath >; .reflect.mtyp >>; .reflect.typ ; .reflect.tfn ; }>>>; }> + func (t >) .reflect.uncommon () ; + func (t ) PkgPath () ; + func (t ) Name () ; + func (t ) Method (i ) (m ; PkgPath ; Type ; FieldAlign () ; Method (? ) ; MethodByName (? ) (? , ? ); NumMethod () ; Name () ; PkgPath () ; Size () ; String () ; .reflect.rawString () ; Kind () + func (k ) String () ; +>; Implements (u ) ; AssignableTo (u ) ; Bits () ; ChanDir () + func (d ) String () ; +>; IsVariadic () ; Elem () ; Field (i ) ; PkgPath ; Type ; Tag + func (tag ) Get (key ) ; +>; Offset ; Index >; Anonymous ; }>>; FieldByIndex (index >) ; FieldByName (name ) (? , ? ); FieldByNameFunc (match ) >) (? , ? ); In (i ) ; Key () ; Len () ; NumField () ; NumIn () ; NumOut () ; Out (i ) ; .reflect.runtimeType () >; .reflect.common () >; .reflect.uncommon () >; }>>; Func ; Index ; }>>); + func (t ) NumMethod () ; + func (t ) MethodByName (name ) (m , ok ); +>>; .reflect.ptrToThis ; }> + func (t >) .reflect.toType () ; + func (t ) .reflect.rawString () ; + func (t ) String () ; + func (t ) Size () ; + func (t ) Bits () ; + func (t ) Align () ; + func (t ) FieldAlign () ; + func (t ) Kind () ; + func (t ) .reflect.common () ; + func (t ) NumMethod () ; + func (t ) Method (i ) (m ); + func (t ) MethodByName (name ) (m , ok ); + func (t ) PkgPath () ; + func (t ) Name () ; + func (t ) ChanDir () ; + func (t ) IsVariadic () ; + func (t ) Elem () ; + func (t ) Field (i ) ; + func (t ) FieldByIndex (index >) ; + func (t ) FieldByName (name ) (? , ? ); + func (t ) FieldByNameFunc (match ) >) (? , ? ); + func (t ) In (i ) ; + func (t ) Key () ; + func (t ) Len () ; + func (t ) NumField () ; + func (t ) NumIn () ; + func (t ) NumOut () ; + func (t ) Out (i ) ; + func (t ) .reflect.runtimeType () ; + func (ct ) .reflect.ptrTo () ; + func (t ) Implements (u ) ; + func (t ) AssignableTo (u ) ; +>>; .reflect.val ; ? + func (f ) .reflect.kind () ; + func (f ) .reflect.mustBe (expected ); + func (f ) .reflect.mustBeExported (); + func (f ) .reflect.mustBeAssignable (); +>; }> + func (v ) .reflect.iword () >; + func (v ) Addr () ; + func (v ) Bool () ; + func (v ) Bytes () >; + func (v ) CanAddr () ; + func (v ) CanSet () ; + func (v ) Call (in >) >; + func (v ) CallSlice (in >) >; + func (v ) .reflect.call (method , in >) >; + func (v ) Cap () ; + func (v ) Close (); + func (v ) Complex () ; + func (v ) Elem () ; + func (v ) Field (i ) ; + func (v ) FieldByIndex (index >) ; + func (v ) FieldByName (name ) ; + func (v ) FieldByNameFunc (match ) >) ; + func (v ) Float () ; + func (v ) Index (i ) ; + func (v ) Int () ; + func (v ) CanInterface () ; + func (v ) Interface () (i ); + func (v ) InterfaceData () >; + func (v ) IsNil () ; + func (v ) IsValid () ; + func (v ) Kind () ; + func (v ) Len () ; + func (v ) MapIndex (key ) ; + func (v ) MapKeys () >; + func (v ) Method (i ) ; + func (v ) NumMethod () ; + func (v ) MethodByName (name ) ; + func (v ) NumField () ; + func (v ) OverflowComplex (x ) ; + func (v ) OverflowFloat (x ) ; + func (v ) OverflowInt (x ) ; + func (v ) OverflowUint (x ) ; + func (v ) Pointer () ; + func (v ) Recv () (x , ok ); + func (v ) .reflect.recv (nb ) (val , ok ); + func (v ) Send (x ); + func (v ) .reflect.send (x , nb ) (selected ); + func (v ) Set (x ); + func (v ) SetBool (x ); + func (v ) SetBytes (x >); + func (v ) SetComplex (x ); + func (v ) SetFloat (x ); + func (v ) SetInt (x ); + func (v ) SetLen (n ); + func (v ) SetMapIndex (key , val ); + func (v ) SetUint (x ); + func (v ) SetPointer (x ); + func (v ) SetString (x ); + func (v ) Slice (beg , end ) ; + func (v ) String () ; + func (v ) TryRecv () (x , ok ); + func (v ) TrySend (x ) ; + func (v ) Type () ; + func (v ) Uint () ; + func (v ) UnsafeAddr () ; + func (v ) .reflect.assignTo (context , dst , target >) ; +>, x ...) ; +func AppendSlice (s , t ) ; +const Array = 17 ; +const Bool = 1 ; +const BothDir = 3 ; +const Chan = 18 ; +type ; +const Complex128 = 16 ; +const Complex64 = 15 ; +func Copy (dst , src ) ; +func DeepEqual (a1 , a2 ) ; +const Float32 = 13 ; +const Float64 = 14 ; +const Func = 19 ; +func Indirect (v ) ; +const Int = 2 ; +const Int16 = 4 ; +const Int32 = 5 ; +const Int64 = 6 ; +const Int8 = 3 ; +const Interface = 20 ; +const Invalid = 0 ; +type ; +func MakeChan (typ , buffer ) ; +func MakeMap (typ ) ; +func MakeSlice (typ , len , cap ) ; +const Map = 21 ; +type ; +func Method$equal (key1 , key2 , key_size ) ; +func Method$hash (key , key_size ) ; +func New (typ ) ; +func NewAt (typ , p ) ; +const Ptr = 22 ; +func PtrTo (t ) ; +const RecvDir = 1 ; +const SendDir = 2 ; +const Slice = 23 ; +type ; Len ; Cap ; }>>; +const String = 24 ; +type ; Len ; }>>; +const Struct = 25 ; +type ; +type ; +type ; +func TypeOf (i ) ; +const Uint = 7 ; +const Uint16 = 9 ; +const Uint32 = 10 ; +const Uint64 = 11 ; +const Uint8 = 8 ; +const Uintptr = 12 ; +const UnsafePointer = 26 ; +type ; +type ; Kind ; }> + func (e >) Error () ; +>; +func ValueError$equal (key1 , key2 , key_size ) ; +func ValueError$hash (key , key_size ) ; +func ValueOf (i ) ; +func Zero (typ ) ; +checksum DD7720796E91D9D24ED12B75BDEA2A714D47B095; diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/exportdata.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/exportdata.go new file mode 100644 index 0000000000000000000000000000000000000000..4aa22d7c923969877ffd7b0af91795725a6636d5 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/exportdata.go @@ -0,0 +1,92 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file implements FindExportData. + +package gcimporter + +import ( + "bufio" + "fmt" + "io" + "strconv" + "strings" +) + +func readGopackHeader(r *bufio.Reader) (name string, size int, err error) { + // See $GOROOT/include/ar.h. + hdr := make([]byte, 16+12+6+6+8+10+2) + _, err = io.ReadFull(r, hdr) + if err != nil { + return + } + // leave for debugging + if false { + fmt.Printf("header: %s", hdr) + } + s := strings.TrimSpace(string(hdr[16+12+6+6+8:][:10])) + size, err = strconv.Atoi(s) + if err != nil || hdr[len(hdr)-2] != '`' || hdr[len(hdr)-1] != '\n' { + err = fmt.Errorf("invalid archive header") + return + } + name = strings.TrimSpace(string(hdr[:16])) + return +} + +// FindExportData positions the reader r at the beginning of the +// export data section of an underlying GC-created object/archive +// file by reading from it. The reader must be positioned at the +// start of the file before calling this function. The hdr result +// is the string before the export data, either "$$" or "$$B". +func FindExportData(r *bufio.Reader) (hdr string, size int, err error) { + // Read first line to make sure this is an object file. + line, err := r.ReadSlice('\n') + if err != nil { + err = fmt.Errorf("can't find export data (%v)", err) + return + } + + if string(line) == "!\n" { + // Archive file. Scan to __.PKGDEF. + var name string + if name, size, err = readGopackHeader(r); err != nil { + return + } + + // First entry should be __.PKGDEF. + if name != "__.PKGDEF" { + err = fmt.Errorf("go archive is missing __.PKGDEF") + return + } + + // Read first line of __.PKGDEF data, so that line + // is once again the first line of the input. + if line, err = r.ReadSlice('\n'); err != nil { + err = fmt.Errorf("can't find export data (%v)", err) + return + } + } + + // Now at __.PKGDEF in archive or still at beginning of file. + // Either way, line should begin with "go object ". + if !strings.HasPrefix(string(line), "go object ") { + err = fmt.Errorf("not a Go object file") + return + } + size -= len(line) + + // Skip over object header to export data. + // Begins after first line starting with $$. + for line[0] != '$' { + if line, err = r.ReadSlice('\n'); err != nil { + err = fmt.Errorf("can't find export data (%v)", err) + return + } + size -= len(line) + } + hdr = string(line) + + return +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/gcimporter.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/gcimporter.go new file mode 100644 index 0000000000000000000000000000000000000000..15ff93f1d911553872f7c8cea16014d4f748ccff --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/gcimporter.go @@ -0,0 +1,258 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package gcimporter implements Import for gc-generated object files. +package gcimporter // import "go/internal/gcimporter" + +import ( + "bufio" + "bytes" + "errors" + "fmt" + "go/build" + "go/token" + "go/types" + "internal/pkgbits" + "internal/saferio" + "io" + "os" + "os/exec" + "path/filepath" + "strings" + "sync" +) + +// debugging/development support +const debug = false + +var exportMap sync.Map // package dir → func() (string, error) + +// lookupGorootExport returns the location of the export data +// (normally found in the build cache, but located in GOROOT/pkg +// in prior Go releases) for the package located in pkgDir. +// +// (We use the package's directory instead of its import path +// mainly to simplify handling of the packages in src/vendor +// and cmd/vendor.) +func lookupGorootExport(pkgDir string) (string, error) { + f, ok := exportMap.Load(pkgDir) + if !ok { + var ( + listOnce sync.Once + exportPath string + err error + ) + f, _ = exportMap.LoadOrStore(pkgDir, func() (string, error) { + listOnce.Do(func() { + cmd := exec.Command(filepath.Join(build.Default.GOROOT, "bin", "go"), "list", "-export", "-f", "{{.Export}}", pkgDir) + cmd.Dir = build.Default.GOROOT + cmd.Env = append(os.Environ(), "PWD="+cmd.Dir, "GOROOT="+build.Default.GOROOT) + var output []byte + output, err = cmd.Output() + if err != nil { + if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 { + err = errors.New(string(ee.Stderr)) + } + return + } + + exports := strings.Split(string(bytes.TrimSpace(output)), "\n") + if len(exports) != 1 { + err = fmt.Errorf("go list reported %d exports; expected 1", len(exports)) + return + } + + exportPath = exports[0] + }) + + return exportPath, err + }) + } + + return f.(func() (string, error))() +} + +var pkgExts = [...]string{".a", ".o"} // a file from the build cache will have no extension + +// FindPkg returns the filename and unique package id for an import +// path based on package information provided by build.Import (using +// the build.Default build.Context). A relative srcDir is interpreted +// relative to the current working directory. +func FindPkg(path, srcDir string) (filename, id string, err error) { + if path == "" { + return "", "", errors.New("path is empty") + } + + var noext string + switch { + default: + // "x" -> "$GOPATH/pkg/$GOOS_$GOARCH/x.ext", "x" + // Don't require the source files to be present. + if abs, err := filepath.Abs(srcDir); err == nil { // see issue 14282 + srcDir = abs + } + var bp *build.Package + bp, err = build.Import(path, srcDir, build.FindOnly|build.AllowBinary) + if bp.PkgObj == "" { + if bp.Goroot && bp.Dir != "" { + filename, err = lookupGorootExport(bp.Dir) + if err == nil { + _, err = os.Stat(filename) + } + if err == nil { + return filename, bp.ImportPath, nil + } + } + goto notfound + } else { + noext = strings.TrimSuffix(bp.PkgObj, ".a") + } + id = bp.ImportPath + + case build.IsLocalImport(path): + // "./x" -> "/this/directory/x.ext", "/this/directory/x" + noext = filepath.Join(srcDir, path) + id = noext + + case filepath.IsAbs(path): + // for completeness only - go/build.Import + // does not support absolute imports + // "/x" -> "/x.ext", "/x" + noext = path + id = path + } + + if false { // for debugging + if path != id { + fmt.Printf("%s -> %s\n", path, id) + } + } + + // try extensions + for _, ext := range pkgExts { + filename = noext + ext + f, statErr := os.Stat(filename) + if statErr == nil && !f.IsDir() { + return filename, id, nil + } + if err == nil { + err = statErr + } + } + +notfound: + if err == nil { + return "", path, fmt.Errorf("can't find import: %q", path) + } + return "", path, fmt.Errorf("can't find import: %q: %w", path, err) +} + +// Import imports a gc-generated package given its import path and srcDir, adds +// the corresponding package object to the packages map, and returns the object. +// The packages map must contain all packages already imported. +func Import(fset *token.FileSet, packages map[string]*types.Package, path, srcDir string, lookup func(path string) (io.ReadCloser, error)) (pkg *types.Package, err error) { + var rc io.ReadCloser + var id string + if lookup != nil { + // With custom lookup specified, assume that caller has + // converted path to a canonical import path for use in the map. + if path == "unsafe" { + return types.Unsafe, nil + } + id = path + + // No need to re-import if the package was imported completely before. + if pkg = packages[id]; pkg != nil && pkg.Complete() { + return + } + f, err := lookup(path) + if err != nil { + return nil, err + } + rc = f + } else { + var filename string + filename, id, err = FindPkg(path, srcDir) + if filename == "" { + if path == "unsafe" { + return types.Unsafe, nil + } + return nil, err + } + + // no need to re-import if the package was imported completely before + if pkg = packages[id]; pkg != nil && pkg.Complete() { + return + } + + // open file + f, err := os.Open(filename) + if err != nil { + return nil, err + } + defer func() { + if err != nil { + // add file name to error + err = fmt.Errorf("%s: %v", filename, err) + } + }() + rc = f + } + defer rc.Close() + + buf := bufio.NewReader(rc) + hdr, size, err := FindExportData(buf) + if err != nil { + return + } + + switch hdr { + case "$$\n": + err = fmt.Errorf("import %q: old textual export format no longer supported (recompile library)", path) + + case "$$B\n": + var exportFormat byte + if exportFormat, err = buf.ReadByte(); err != nil { + return + } + size-- + + // The unified export format starts with a 'u'; the indexed export + // format starts with an 'i'; and the older binary export format + // starts with a 'c', 'd', or 'v' (from "version"). Select + // appropriate importer. + switch exportFormat { + case 'u': + var data []byte + var r io.Reader = buf + if size >= 0 { + if data, err = saferio.ReadData(r, uint64(size)); err != nil { + return + } + } else if data, err = io.ReadAll(r); err != nil { + return + } + s := string(data) + s = s[:strings.LastIndex(s, "\n$$\n")] + + input := pkgbits.NewPkgDecoder(id, s) + pkg = readUnifiedPackage(fset, nil, packages, input) + case 'i': + pkg, err = iImportData(fset, packages, buf, id) + default: + err = fmt.Errorf("import %q: old binary export format no longer supported (recompile library)", path) + } + + default: + err = fmt.Errorf("import %q: unknown export data header: %q", path, hdr) + } + + return +} + +type byPath []*types.Package + +func (a byPath) Len() int { return len(a) } +func (a byPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a byPath) Less(i, j int) bool { return a[i].Path() < a[j].Path() } diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/gcimporter_test.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/gcimporter_test.go new file mode 100644 index 0000000000000000000000000000000000000000..07ab13518681cea6a9d6fb5039bc1bdcdfe46827 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/gcimporter_test.go @@ -0,0 +1,752 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package gcimporter_test + +import ( + "bytes" + "fmt" + "internal/testenv" + "os" + "os/exec" + "path" + "path/filepath" + "runtime" + "strings" + "testing" + "time" + + "go/ast" + "go/build" + "go/importer" + "go/parser" + "go/token" + "go/types" + + . "go/internal/gcimporter" +) + +func TestMain(m *testing.M) { + build.Default.GOROOT = testenv.GOROOT(nil) + os.Exit(m.Run()) +} + +// compile runs the compiler on filename, with dirname as the working directory, +// and writes the output file to outdirname. +// compile gives the resulting package a packagepath of testdata/. +func compile(t *testing.T, dirname, filename, outdirname string, packageFiles map[string]string, pkgImports ...string) string { + // filename must end with ".go" + basename, ok := strings.CutSuffix(filepath.Base(filename), ".go") + if !ok { + t.Fatalf("filename doesn't end in .go: %s", filename) + } + objname := basename + ".o" + outname := filepath.Join(outdirname, objname) + + importcfgfile := os.DevNull + if len(packageFiles) > 0 || len(pkgImports) > 0 { + importcfgfile = filepath.Join(outdirname, basename) + ".importcfg" + testenv.WriteImportcfg(t, importcfgfile, packageFiles, pkgImports...) + } + + pkgpath := path.Join("testdata", basename) + cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-p", pkgpath, "-D", "testdata", "-importcfg", importcfgfile, "-o", outname, filename) + cmd.Dir = dirname + out, err := cmd.CombinedOutput() + if err != nil { + t.Logf("%s", out) + t.Fatalf("go tool compile %s failed: %s", filename, err) + } + return outname +} + +func testPath(t *testing.T, path, srcDir string) *types.Package { + t0 := time.Now() + fset := token.NewFileSet() + pkg, err := Import(fset, make(map[string]*types.Package), path, srcDir, nil) + if err != nil { + t.Errorf("testPath(%s): %s", path, err) + return nil + } + t.Logf("testPath(%s): %v", path, time.Since(t0)) + return pkg +} + +var pkgExts = [...]string{".a", ".o"} // keep in sync with gcimporter.go + +func mktmpdir(t *testing.T) string { + tmpdir, err := os.MkdirTemp("", "gcimporter_test") + if err != nil { + t.Fatal("mktmpdir:", err) + } + if err := os.Mkdir(filepath.Join(tmpdir, "testdata"), 0700); err != nil { + os.RemoveAll(tmpdir) + t.Fatal("mktmpdir:", err) + } + return tmpdir +} + +func TestImportTestdata(t *testing.T) { + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + testenv.MustHaveGoBuild(t) + + testfiles := map[string][]string{ + "exports.go": {"go/ast", "go/token"}, + "generics.go": nil, + } + if true /* was goexperiment.Unified */ { + // TODO(mdempsky): Fix test below to flatten the transitive + // Package.Imports graph. Unified IR is more precise about + // recreating the package import graph. + testfiles["exports.go"] = []string{"go/ast"} + } + + for testfile, wantImports := range testfiles { + tmpdir := mktmpdir(t) + defer os.RemoveAll(tmpdir) + + compile(t, "testdata", testfile, filepath.Join(tmpdir, "testdata"), nil, wantImports...) + path := "./testdata/" + strings.TrimSuffix(testfile, ".go") + + if pkg := testPath(t, path, tmpdir); pkg != nil { + // The package's Imports list must include all packages + // explicitly imported by testfile, plus all packages + // referenced indirectly via exported objects in testfile. + got := fmt.Sprint(pkg.Imports()) + for _, want := range wantImports { + if !strings.Contains(got, want) { + t.Errorf(`Package("exports").Imports() = %s, does not contain %s`, got, want) + } + } + } + } +} + +func TestImportTypeparamTests(t *testing.T) { + if testing.Short() { + t.Skipf("in short mode, skipping test that requires export data for all of std") + } + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + // cmd/distpack removes the GOROOT/test directory, so skip if it isn't there. + // cmd/distpack also requires the presence of GOROOT/VERSION, so use that to + // avoid false-positive skips. + gorootTest := filepath.Join(testenv.GOROOT(t), "test") + if _, err := os.Stat(gorootTest); os.IsNotExist(err) { + if _, err := os.Stat(filepath.Join(testenv.GOROOT(t), "VERSION")); err == nil { + t.Skipf("skipping: GOROOT/test not present") + } + } + + testenv.MustHaveGoBuild(t) + + tmpdir := mktmpdir(t) + defer os.RemoveAll(tmpdir) + + // Check go files in test/typeparam, except those that fail for a known + // reason. + rootDir := filepath.Join(gorootTest, "typeparam") + list, err := os.ReadDir(rootDir) + if err != nil { + t.Fatal(err) + } + + for _, entry := range list { + if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".go") { + // For now, only consider standalone go files. + continue + } + + t.Run(entry.Name(), func(t *testing.T) { + filename := filepath.Join(rootDir, entry.Name()) + src, err := os.ReadFile(filename) + if err != nil { + t.Fatal(err) + } + if !bytes.HasPrefix(src, []byte("// run")) && !bytes.HasPrefix(src, []byte("// compile")) { + // We're bypassing the logic of run.go here, so be conservative about + // the files we consider in an attempt to make this test more robust to + // changes in test/typeparams. + t.Skipf("not detected as a run test") + } + + // Compile and import, and compare the resulting package with the package + // that was type-checked directly. + compile(t, rootDir, entry.Name(), filepath.Join(tmpdir, "testdata"), nil, filename) + pkgName := strings.TrimSuffix(entry.Name(), ".go") + imported := importPkg(t, "./testdata/"+pkgName, tmpdir) + checked := checkFile(t, filename, src) + + seen := make(map[string]bool) + for _, name := range imported.Scope().Names() { + if !token.IsExported(name) { + continue // ignore synthetic names like .inittask and .dict.* + } + seen[name] = true + + importedObj := imported.Scope().Lookup(name) + got := types.ObjectString(importedObj, types.RelativeTo(imported)) + got = sanitizeObjectString(got) + + checkedObj := checked.Scope().Lookup(name) + if checkedObj == nil { + t.Fatalf("imported object %q was not type-checked", name) + } + want := types.ObjectString(checkedObj, types.RelativeTo(checked)) + want = sanitizeObjectString(want) + + if got != want { + t.Errorf("imported %q as %q, want %q", name, got, want) + } + } + + for _, name := range checked.Scope().Names() { + if !token.IsExported(name) || seen[name] { + continue + } + t.Errorf("did not import object %q", name) + } + }) + } +} + +// sanitizeObjectString removes type parameter debugging markers from an object +// string, to normalize it for comparison. +// TODO(rfindley): this should not be necessary. +func sanitizeObjectString(s string) string { + var runes []rune + for _, r := range s { + if '₀' <= r && r < '₀'+10 { + continue // trim type parameter subscripts + } + runes = append(runes, r) + } + return string(runes) +} + +func checkFile(t *testing.T, filename string, src []byte) *types.Package { + fset := token.NewFileSet() + f, err := parser.ParseFile(fset, filename, src, 0) + if err != nil { + t.Fatal(err) + } + config := types.Config{ + Importer: importer.Default(), + } + pkg, err := config.Check("", fset, []*ast.File{f}, nil) + if err != nil { + t.Fatal(err) + } + return pkg +} + +func TestVersionHandling(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + const dir = "./testdata/versions" + list, err := os.ReadDir(dir) + if err != nil { + t.Fatal(err) + } + + tmpdir := mktmpdir(t) + defer os.RemoveAll(tmpdir) + corruptdir := filepath.Join(tmpdir, "testdata", "versions") + if err := os.Mkdir(corruptdir, 0700); err != nil { + t.Fatal(err) + } + + fset := token.NewFileSet() + + for _, f := range list { + name := f.Name() + if !strings.HasSuffix(name, ".a") { + continue // not a package file + } + if strings.Contains(name, "corrupted") { + continue // don't process a leftover corrupted file + } + pkgpath := "./" + name[:len(name)-2] + + if testing.Verbose() { + t.Logf("importing %s", name) + } + + // test that export data can be imported + _, err := Import(fset, make(map[string]*types.Package), pkgpath, dir, nil) + if err != nil { + // ok to fail if it fails with a no longer supported error for select files + if strings.Contains(err.Error(), "no longer supported") { + switch name { + case "test_go1.7_0.a", "test_go1.7_1.a", + "test_go1.8_4.a", "test_go1.8_5.a", + "test_go1.11_6b.a", "test_go1.11_999b.a": + continue + } + // fall through + } + // ok to fail if it fails with a newer version error for select files + if strings.Contains(err.Error(), "newer version") { + switch name { + case "test_go1.11_999i.a": + continue + } + // fall through + } + t.Errorf("import %q failed: %v", pkgpath, err) + continue + } + + // create file with corrupted export data + // 1) read file + data, err := os.ReadFile(filepath.Join(dir, name)) + if err != nil { + t.Fatal(err) + } + // 2) find export data + i := bytes.Index(data, []byte("\n$$B\n")) + 5 + j := bytes.Index(data[i:], []byte("\n$$\n")) + i + if i < 0 || j < 0 || i > j { + t.Fatalf("export data section not found (i = %d, j = %d)", i, j) + } + // 3) corrupt the data (increment every 7th byte) + for k := j - 13; k >= i; k -= 7 { + data[k]++ + } + // 4) write the file + pkgpath += "_corrupted" + filename := filepath.Join(corruptdir, pkgpath) + ".a" + os.WriteFile(filename, data, 0666) + + // test that importing the corrupted file results in an error + _, err = Import(fset, make(map[string]*types.Package), pkgpath, corruptdir, nil) + if err == nil { + t.Errorf("import corrupted %q succeeded", pkgpath) + } else if msg := err.Error(); !strings.Contains(msg, "version skew") { + t.Errorf("import %q error incorrect (%s)", pkgpath, msg) + } + } +} + +func TestImportStdLib(t *testing.T) { + if testing.Short() { + t.Skip("the imports can be expensive, and this test is especially slow when the build cache is empty") + } + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + // Get list of packages in stdlib. Filter out test-only packages with {{if .GoFiles}} check. + var stderr bytes.Buffer + cmd := exec.Command("go", "list", "-f", "{{if .GoFiles}}{{.ImportPath}}{{end}}", "std") + cmd.Stderr = &stderr + out, err := cmd.Output() + if err != nil { + t.Fatalf("failed to run go list to determine stdlib packages: %v\nstderr:\n%v", err, stderr.String()) + } + pkgs := strings.Fields(string(out)) + + var nimports int + for _, pkg := range pkgs { + t.Run(pkg, func(t *testing.T) { + if testPath(t, pkg, filepath.Join(testenv.GOROOT(t), "src", path.Dir(pkg))) != nil { + nimports++ + } + }) + } + const minPkgs = 225 // 'GOOS=plan9 go1.18 list std | wc -l' reports 228; most other platforms have more. + if len(pkgs) < minPkgs { + t.Fatalf("too few packages (%d) were imported", nimports) + } + + t.Logf("tested %d imports", nimports) +} + +var importedObjectTests = []struct { + name string + want string +}{ + // non-interfaces + {"crypto.Hash", "type Hash uint"}, + {"go/ast.ObjKind", "type ObjKind int"}, + {"go/types.Qualifier", "type Qualifier func(*Package) string"}, + {"go/types.Comparable", "func Comparable(T Type) bool"}, + {"math.Pi", "const Pi untyped float"}, + {"math.Sin", "func Sin(x float64) float64"}, + {"go/ast.NotNilFilter", "func NotNilFilter(_ string, v reflect.Value) bool"}, + {"go/internal/gcimporter.FindPkg", "func FindPkg(path string, srcDir string) (filename string, id string, err error)"}, + + // interfaces + {"context.Context", "type Context interface{Deadline() (deadline time.Time, ok bool); Done() <-chan struct{}; Err() error; Value(key any) any}"}, + {"crypto.Decrypter", "type Decrypter interface{Decrypt(rand io.Reader, msg []byte, opts DecrypterOpts) (plaintext []byte, err error); Public() PublicKey}"}, + {"encoding.BinaryMarshaler", "type BinaryMarshaler interface{MarshalBinary() (data []byte, err error)}"}, + {"io.Reader", "type Reader interface{Read(p []byte) (n int, err error)}"}, + {"io.ReadWriter", "type ReadWriter interface{Reader; Writer}"}, + {"go/ast.Node", "type Node interface{End() go/token.Pos; Pos() go/token.Pos}"}, + {"go/types.Type", "type Type interface{String() string; Underlying() Type}"}, +} + +func TestImportedTypes(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + fset := token.NewFileSet() + for _, test := range importedObjectTests { + s := strings.Split(test.name, ".") + if len(s) != 2 { + t.Fatal("inconsistent test data") + } + importPath := s[0] + objName := s[1] + + pkg, err := Import(fset, make(map[string]*types.Package), importPath, ".", nil) + if err != nil { + t.Error(err) + continue + } + + obj := pkg.Scope().Lookup(objName) + if obj == nil { + t.Errorf("%s: object not found", test.name) + continue + } + + got := types.ObjectString(obj, types.RelativeTo(pkg)) + if got != test.want { + t.Errorf("%s: got %q; want %q", test.name, got, test.want) + } + + if named, _ := obj.Type().(*types.Named); named != nil { + verifyInterfaceMethodRecvs(t, named, 0) + } + } +} + +// verifyInterfaceMethodRecvs verifies that method receiver types +// are named if the methods belong to a named interface type. +func verifyInterfaceMethodRecvs(t *testing.T, named *types.Named, level int) { + // avoid endless recursion in case of an embedding bug that lead to a cycle + if level > 10 { + t.Errorf("%s: embeds itself", named) + return + } + + iface, _ := named.Underlying().(*types.Interface) + if iface == nil { + return // not an interface + } + + // check explicitly declared methods + for i := 0; i < iface.NumExplicitMethods(); i++ { + m := iface.ExplicitMethod(i) + recv := m.Type().(*types.Signature).Recv() + if recv == nil { + t.Errorf("%s: missing receiver type", m) + continue + } + if recv.Type() != named { + t.Errorf("%s: got recv type %s; want %s", m, recv.Type(), named) + } + } + + // check embedded interfaces (if they are named, too) + for i := 0; i < iface.NumEmbeddeds(); i++ { + // embedding of interfaces cannot have cycles; recursion will terminate + if etype, _ := iface.EmbeddedType(i).(*types.Named); etype != nil { + verifyInterfaceMethodRecvs(t, etype, level+1) + } + } +} + +func TestIssue5815(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + pkg := importPkg(t, "strings", ".") + + scope := pkg.Scope() + for _, name := range scope.Names() { + obj := scope.Lookup(name) + if obj.Pkg() == nil { + t.Errorf("no pkg for %s", obj) + } + if tname, _ := obj.(*types.TypeName); tname != nil { + named := tname.Type().(*types.Named) + for i := 0; i < named.NumMethods(); i++ { + m := named.Method(i) + if m.Pkg() == nil { + t.Errorf("no pkg for %s", m) + } + } + } + } +} + +// Smoke test to ensure that imported methods get the correct package. +func TestCorrectMethodPackage(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + imports := make(map[string]*types.Package) + fset := token.NewFileSet() + _, err := Import(fset, imports, "net/http", ".", nil) + if err != nil { + t.Fatal(err) + } + + mutex := imports["sync"].Scope().Lookup("Mutex").(*types.TypeName).Type() + mset := types.NewMethodSet(types.NewPointer(mutex)) // methods of *sync.Mutex + sel := mset.Lookup(nil, "Lock") + lock := sel.Obj().(*types.Func) + if got, want := lock.Pkg().Path(), "sync"; got != want { + t.Errorf("got package path %q; want %q", got, want) + } +} + +func TestIssue13566(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + tmpdir := mktmpdir(t) + defer os.RemoveAll(tmpdir) + testoutdir := filepath.Join(tmpdir, "testdata") + + // b.go needs to be compiled from the output directory so that the compiler can + // find the compiled package a. We pass the full path to compile() so that we + // don't have to copy the file to that directory. + bpath, err := filepath.Abs(filepath.Join("testdata", "b.go")) + if err != nil { + t.Fatal(err) + } + + compile(t, "testdata", "a.go", testoutdir, nil, "encoding/json") + compile(t, testoutdir, bpath, testoutdir, map[string]string{"testdata/a": filepath.Join(testoutdir, "a.o")}, "encoding/json") + + // import must succeed (test for issue at hand) + pkg := importPkg(t, "./testdata/b", tmpdir) + + // make sure all indirectly imported packages have names + for _, imp := range pkg.Imports() { + if imp.Name() == "" { + t.Errorf("no name for %s package", imp.Path()) + } + } +} + +func TestTypeNamingOrder(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + tmpdir := mktmpdir(t) + defer os.RemoveAll(tmpdir) + testoutdir := filepath.Join(tmpdir, "testdata") + + compile(t, "testdata", "g.go", testoutdir, nil) + + // import must succeed (test for issue at hand) + _ = importPkg(t, "./testdata/g", tmpdir) +} + +func TestIssue13898(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + // import go/internal/gcimporter which imports go/types partially + fset := token.NewFileSet() + imports := make(map[string]*types.Package) + _, err := Import(fset, imports, "go/internal/gcimporter", ".", nil) + if err != nil { + t.Fatal(err) + } + + // look for go/types package + var goTypesPkg *types.Package + for path, pkg := range imports { + if path == "go/types" { + goTypesPkg = pkg + break + } + } + if goTypesPkg == nil { + t.Fatal("go/types not found") + } + + // look for go/types.Object type + obj := lookupObj(t, goTypesPkg.Scope(), "Object") + typ, ok := obj.Type().(*types.Named) + if !ok { + t.Fatalf("go/types.Object type is %v; wanted named type", typ) + } + + // lookup go/types.Object.Pkg method + m, index, indirect := types.LookupFieldOrMethod(typ, false, nil, "Pkg") + if m == nil { + t.Fatalf("go/types.Object.Pkg not found (index = %v, indirect = %v)", index, indirect) + } + + // the method must belong to go/types + if m.Pkg().Path() != "go/types" { + t.Fatalf("found %v; want go/types", m.Pkg()) + } +} + +func TestIssue15517(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + tmpdir := mktmpdir(t) + defer os.RemoveAll(tmpdir) + + compile(t, "testdata", "p.go", filepath.Join(tmpdir, "testdata"), nil) + + // Multiple imports of p must succeed without redeclaration errors. + // We use an import path that's not cleaned up so that the eventual + // file path for the package is different from the package path; this + // will expose the error if it is present. + // + // (Issue: Both the textual and the binary importer used the file path + // of the package to be imported as key into the shared packages map. + // However, the binary importer then used the package path to identify + // the imported package to mark it as complete; effectively marking the + // wrong package as complete. By using an "unclean" package path, the + // file and package path are different, exposing the problem if present. + // The same issue occurs with vendoring.) + imports := make(map[string]*types.Package) + fset := token.NewFileSet() + for i := 0; i < 3; i++ { + if _, err := Import(fset, imports, "./././testdata/p", tmpdir, nil); err != nil { + t.Fatal(err) + } + } +} + +func TestIssue15920(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + compileAndImportPkg(t, "issue15920") +} + +func TestIssue20046(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + // "./issue20046".V.M must exist + pkg := compileAndImportPkg(t, "issue20046") + obj := lookupObj(t, pkg.Scope(), "V") + if m, index, indirect := types.LookupFieldOrMethod(obj.Type(), false, nil, "M"); m == nil { + t.Fatalf("V.M not found (index = %v, indirect = %v)", index, indirect) + } +} +func TestIssue25301(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + compileAndImportPkg(t, "issue25301") +} + +func TestIssue25596(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + compileAndImportPkg(t, "issue25596") +} + +func TestIssue57015(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // This package only handles gc export data. + if runtime.Compiler != "gc" { + t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) + } + + compileAndImportPkg(t, "issue57015") +} + +func importPkg(t *testing.T, path, srcDir string) *types.Package { + fset := token.NewFileSet() + pkg, err := Import(fset, make(map[string]*types.Package), path, srcDir, nil) + if err != nil { + t.Helper() + t.Fatal(err) + } + return pkg +} + +func compileAndImportPkg(t *testing.T, name string) *types.Package { + t.Helper() + tmpdir := mktmpdir(t) + defer os.RemoveAll(tmpdir) + compile(t, "testdata", name+".go", filepath.Join(tmpdir, "testdata"), nil) + return importPkg(t, "./testdata/"+name, tmpdir) +} + +func lookupObj(t *testing.T, scope *types.Scope, name string) types.Object { + if obj := scope.Lookup(name); obj != nil { + return obj + } + t.Helper() + t.Fatalf("%s not found", name) + return nil +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/iimport.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/iimport.go new file mode 100644 index 0000000000000000000000000000000000000000..9e3c945b5674c3b4069cc12d62bf2f73b91f1d2a --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/iimport.go @@ -0,0 +1,817 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Indexed package import. +// See cmd/compile/internal/gc/iexport.go for the export data format. + +package gcimporter + +import ( + "bufio" + "bytes" + "encoding/binary" + "fmt" + "go/constant" + "go/token" + "go/types" + "internal/saferio" + "io" + "math" + "math/big" + "sort" + "strings" +) + +type intReader struct { + *bufio.Reader + path string +} + +func (r *intReader) int64() int64 { + i, err := binary.ReadVarint(r.Reader) + if err != nil { + errorf("import %q: read varint error: %v", r.path, err) + } + return i +} + +func (r *intReader) uint64() uint64 { + i, err := binary.ReadUvarint(r.Reader) + if err != nil { + errorf("import %q: read varint error: %v", r.path, err) + } + return i +} + +// Keep this in sync with constants in iexport.go. +const ( + iexportVersionGo1_11 = 0 + iexportVersionPosCol = 1 + iexportVersionGenerics = 2 + iexportVersionGo1_18 = 2 + + iexportVersionCurrent = 2 +) + +type ident struct { + pkg *types.Package + name string +} + +const predeclReserved = 32 + +type itag uint64 + +const ( + // Types + definedType itag = iota + pointerType + sliceType + arrayType + chanType + mapType + signatureType + structType + interfaceType + typeParamType + instanceType + unionType +) + +// iImportData imports a package from the serialized package data +// and returns the number of bytes consumed and a reference to the package. +// If the export data version is not recognized or the format is otherwise +// compromised, an error is returned. +func iImportData(fset *token.FileSet, imports map[string]*types.Package, dataReader *bufio.Reader, path string) (pkg *types.Package, err error) { + const currentVersion = iexportVersionCurrent + version := int64(-1) + defer func() { + if e := recover(); e != nil { + if version > currentVersion { + err = fmt.Errorf("cannot import %q (%v), export data is newer version - update tool", path, e) + } else { + err = fmt.Errorf("cannot import %q (%v), possibly version skew - reinstall package", path, e) + } + } + }() + + r := &intReader{dataReader, path} + + version = int64(r.uint64()) + switch version { + case iexportVersionGo1_18, iexportVersionPosCol, iexportVersionGo1_11: + default: + errorf("unknown iexport format version %d", version) + } + + sLen := r.uint64() + dLen := r.uint64() + + if sLen > math.MaxUint64-dLen { + errorf("lengths out of range (%d, %d)", sLen, dLen) + } + + data, err := saferio.ReadData(r, sLen+dLen) + if err != nil { + errorf("cannot read %d bytes of stringData and declData: %s", sLen+dLen, err) + } + stringData := data[:sLen] + declData := data[sLen:] + + p := iimporter{ + exportVersion: version, + ipath: path, + version: int(version), + + stringData: stringData, + stringCache: make(map[uint64]string), + pkgCache: make(map[uint64]*types.Package), + + declData: declData, + pkgIndex: make(map[*types.Package]map[string]uint64), + typCache: make(map[uint64]types.Type), + // Separate map for typeparams, keyed by their package and unique + // name (name with subscript). + tparamIndex: make(map[ident]*types.TypeParam), + + fake: fakeFileSet{ + fset: fset, + files: make(map[string]*fileInfo), + }, + } + defer p.fake.setLines() // set lines for files in fset + + for i, pt := range predeclared { + p.typCache[uint64(i)] = pt + } + + pkgList := make([]*types.Package, r.uint64()) + for i := range pkgList { + pkgPathOff := r.uint64() + pkgPath := p.stringAt(pkgPathOff) + pkgName := p.stringAt(r.uint64()) + _ = r.uint64() // package height; unused by go/types + + if pkgPath == "" { + pkgPath = path + } + pkg := imports[pkgPath] + if pkg == nil { + pkg = types.NewPackage(pkgPath, pkgName) + imports[pkgPath] = pkg + } else if pkg.Name() != pkgName { + errorf("conflicting names %s and %s for package %q", pkg.Name(), pkgName, path) + } + + p.pkgCache[pkgPathOff] = pkg + + nameIndex := make(map[string]uint64) + for nSyms := r.uint64(); nSyms > 0; nSyms-- { + name := p.stringAt(r.uint64()) + nameIndex[name] = r.uint64() + } + + p.pkgIndex[pkg] = nameIndex + pkgList[i] = pkg + } + + localpkg := pkgList[0] + + names := make([]string, 0, len(p.pkgIndex[localpkg])) + for name := range p.pkgIndex[localpkg] { + names = append(names, name) + } + sort.Strings(names) + for _, name := range names { + p.doDecl(localpkg, name) + } + + // SetConstraint can't be called if the constraint type is not yet complete. + // When type params are created in the 'P' case of (*importReader).obj(), + // the associated constraint type may not be complete due to recursion. + // Therefore, we defer calling SetConstraint there, and call it here instead + // after all types are complete. + for _, d := range p.later { + d.t.SetConstraint(d.constraint) + } + + for _, typ := range p.interfaceList { + typ.Complete() + } + + // record all referenced packages as imports + list := append(([]*types.Package)(nil), pkgList[1:]...) + sort.Sort(byPath(list)) + localpkg.SetImports(list) + + // package was imported completely and without errors + localpkg.MarkComplete() + return localpkg, nil +} + +type setConstraintArgs struct { + t *types.TypeParam + constraint types.Type +} + +type iimporter struct { + exportVersion int64 + ipath string + version int + + stringData []byte + stringCache map[uint64]string + pkgCache map[uint64]*types.Package + + declData []byte + pkgIndex map[*types.Package]map[string]uint64 + typCache map[uint64]types.Type + tparamIndex map[ident]*types.TypeParam + + fake fakeFileSet + interfaceList []*types.Interface + + // Arguments for calls to SetConstraint that are deferred due to recursive types + later []setConstraintArgs +} + +func (p *iimporter) doDecl(pkg *types.Package, name string) { + // See if we've already imported this declaration. + if obj := pkg.Scope().Lookup(name); obj != nil { + return + } + + off, ok := p.pkgIndex[pkg][name] + if !ok { + errorf("%v.%v not in index", pkg, name) + } + + r := &importReader{p: p, currPkg: pkg} + r.declReader.Reset(p.declData[off:]) + + r.obj(name) +} + +func (p *iimporter) stringAt(off uint64) string { + if s, ok := p.stringCache[off]; ok { + return s + } + + slen, n := binary.Uvarint(p.stringData[off:]) + if n <= 0 { + errorf("varint failed") + } + spos := off + uint64(n) + s := string(p.stringData[spos : spos+slen]) + p.stringCache[off] = s + return s +} + +func (p *iimporter) pkgAt(off uint64) *types.Package { + if pkg, ok := p.pkgCache[off]; ok { + return pkg + } + path := p.stringAt(off) + errorf("missing package %q in %q", path, p.ipath) + return nil +} + +func (p *iimporter) typAt(off uint64, base *types.Named) types.Type { + if t, ok := p.typCache[off]; ok && canReuse(base, t) { + return t + } + + if off < predeclReserved { + errorf("predeclared type missing from cache: %v", off) + } + + r := &importReader{p: p} + r.declReader.Reset(p.declData[off-predeclReserved:]) + t := r.doType(base) + + if canReuse(base, t) { + p.typCache[off] = t + } + return t +} + +// canReuse reports whether the type rhs on the RHS of the declaration for def +// may be re-used. +// +// Specifically, if def is non-nil and rhs is an interface type with methods, it +// may not be re-used because we have a convention of setting the receiver type +// for interface methods to def. +func canReuse(def *types.Named, rhs types.Type) bool { + if def == nil { + return true + } + iface, _ := rhs.(*types.Interface) + if iface == nil { + return true + } + // Don't use iface.Empty() here as iface may not be complete. + return iface.NumEmbeddeds() == 0 && iface.NumExplicitMethods() == 0 +} + +type importReader struct { + p *iimporter + declReader bytes.Reader + currPkg *types.Package + prevFile string + prevLine int64 + prevColumn int64 +} + +func (r *importReader) obj(name string) { + tag := r.byte() + pos := r.pos() + + switch tag { + case 'A': + typ := r.typ() + + r.declare(types.NewTypeName(pos, r.currPkg, name, typ)) + + case 'C': + typ, val := r.value() + + r.declare(types.NewConst(pos, r.currPkg, name, typ, val)) + + case 'F', 'G': + var tparams []*types.TypeParam + if tag == 'G' { + tparams = r.tparamList() + } + sig := r.signature(nil, nil, tparams) + r.declare(types.NewFunc(pos, r.currPkg, name, sig)) + + case 'T', 'U': + // Types can be recursive. We need to setup a stub + // declaration before recurring. + obj := types.NewTypeName(pos, r.currPkg, name, nil) + named := types.NewNamed(obj, nil, nil) + // Declare obj before calling r.tparamList, so the new type name is recognized + // if used in the constraint of one of its own typeparams (see #48280). + r.declare(obj) + if tag == 'U' { + tparams := r.tparamList() + named.SetTypeParams(tparams) + } + + underlying := r.p.typAt(r.uint64(), named).Underlying() + named.SetUnderlying(underlying) + + if !isInterface(underlying) { + for n := r.uint64(); n > 0; n-- { + mpos := r.pos() + mname := r.ident() + recv := r.param() + + // If the receiver has any targs, set those as the + // rparams of the method (since those are the + // typeparams being used in the method sig/body). + targs := baseType(recv.Type()).TypeArgs() + var rparams []*types.TypeParam + if targs.Len() > 0 { + rparams = make([]*types.TypeParam, targs.Len()) + for i := range rparams { + rparams[i], _ = targs.At(i).(*types.TypeParam) + } + } + msig := r.signature(recv, rparams, nil) + + named.AddMethod(types.NewFunc(mpos, r.currPkg, mname, msig)) + } + } + + case 'P': + // We need to "declare" a typeparam in order to have a name that + // can be referenced recursively (if needed) in the type param's + // bound. + if r.p.exportVersion < iexportVersionGenerics { + errorf("unexpected type param type") + } + // Remove the "path" from the type param name that makes it unique, + // and revert any unique name used for blank typeparams. + name0 := tparamName(name) + tn := types.NewTypeName(pos, r.currPkg, name0, nil) + t := types.NewTypeParam(tn, nil) + // To handle recursive references to the typeparam within its + // bound, save the partial type in tparamIndex before reading the bounds. + id := ident{r.currPkg, name} + r.p.tparamIndex[id] = t + + var implicit bool + if r.p.exportVersion >= iexportVersionGo1_18 { + implicit = r.bool() + } + constraint := r.typ() + if implicit { + iface, _ := constraint.(*types.Interface) + if iface == nil { + errorf("non-interface constraint marked implicit") + } + iface.MarkImplicit() + } + // The constraint type may not be complete, if we + // are in the middle of a type recursion involving type + // constraints. So, we defer SetConstraint until we have + // completely set up all types in ImportData. + r.p.later = append(r.p.later, setConstraintArgs{t: t, constraint: constraint}) + + case 'V': + typ := r.typ() + + r.declare(types.NewVar(pos, r.currPkg, name, typ)) + + default: + errorf("unexpected tag: %v", tag) + } +} + +func (r *importReader) declare(obj types.Object) { + obj.Pkg().Scope().Insert(obj) +} + +func (r *importReader) value() (typ types.Type, val constant.Value) { + typ = r.typ() + if r.p.exportVersion >= iexportVersionGo1_18 { + // TODO: add support for using the kind + _ = constant.Kind(r.int64()) + } + + switch b := typ.Underlying().(*types.Basic); b.Info() & types.IsConstType { + case types.IsBoolean: + val = constant.MakeBool(r.bool()) + + case types.IsString: + val = constant.MakeString(r.string()) + + case types.IsInteger: + var x big.Int + r.mpint(&x, b) + val = constant.Make(&x) + + case types.IsFloat: + val = r.mpfloat(b) + + case types.IsComplex: + re := r.mpfloat(b) + im := r.mpfloat(b) + val = constant.BinaryOp(re, token.ADD, constant.MakeImag(im)) + + default: + errorf("unexpected type %v", typ) // panics + panic("unreachable") + } + + return +} + +func intSize(b *types.Basic) (signed bool, maxBytes uint) { + if (b.Info() & types.IsUntyped) != 0 { + return true, 64 + } + + switch b.Kind() { + case types.Float32, types.Complex64: + return true, 3 + case types.Float64, types.Complex128: + return true, 7 + } + + signed = (b.Info() & types.IsUnsigned) == 0 + switch b.Kind() { + case types.Int8, types.Uint8: + maxBytes = 1 + case types.Int16, types.Uint16: + maxBytes = 2 + case types.Int32, types.Uint32: + maxBytes = 4 + default: + maxBytes = 8 + } + + return +} + +func (r *importReader) mpint(x *big.Int, typ *types.Basic) { + signed, maxBytes := intSize(typ) + + maxSmall := 256 - maxBytes + if signed { + maxSmall = 256 - 2*maxBytes + } + if maxBytes == 1 { + maxSmall = 256 + } + + n, _ := r.declReader.ReadByte() + if uint(n) < maxSmall { + v := int64(n) + if signed { + v >>= 1 + if n&1 != 0 { + v = ^v + } + } + x.SetInt64(v) + return + } + + v := -n + if signed { + v = -(n &^ 1) >> 1 + } + if v < 1 || uint(v) > maxBytes { + errorf("weird decoding: %v, %v => %v", n, signed, v) + } + b := make([]byte, v) + io.ReadFull(&r.declReader, b) + x.SetBytes(b) + if signed && n&1 != 0 { + x.Neg(x) + } +} + +func (r *importReader) mpfloat(typ *types.Basic) constant.Value { + var mant big.Int + r.mpint(&mant, typ) + var f big.Float + f.SetInt(&mant) + if f.Sign() != 0 { + f.SetMantExp(&f, int(r.int64())) + } + return constant.Make(&f) +} + +func (r *importReader) ident() string { + return r.string() +} + +func (r *importReader) qualifiedIdent() (*types.Package, string) { + name := r.string() + pkg := r.pkg() + return pkg, name +} + +func (r *importReader) pos() token.Pos { + if r.p.version >= 1 { + r.posv1() + } else { + r.posv0() + } + + if r.prevFile == "" && r.prevLine == 0 && r.prevColumn == 0 { + return token.NoPos + } + return r.p.fake.pos(r.prevFile, int(r.prevLine), int(r.prevColumn)) +} + +func (r *importReader) posv0() { + delta := r.int64() + if delta != deltaNewFile { + r.prevLine += delta + } else if l := r.int64(); l == -1 { + r.prevLine += deltaNewFile + } else { + r.prevFile = r.string() + r.prevLine = l + } +} + +func (r *importReader) posv1() { + delta := r.int64() + r.prevColumn += delta >> 1 + if delta&1 != 0 { + delta = r.int64() + r.prevLine += delta >> 1 + if delta&1 != 0 { + r.prevFile = r.string() + } + } +} + +func (r *importReader) typ() types.Type { + return r.p.typAt(r.uint64(), nil) +} + +func isInterface(t types.Type) bool { + _, ok := t.(*types.Interface) + return ok +} + +func (r *importReader) pkg() *types.Package { return r.p.pkgAt(r.uint64()) } +func (r *importReader) string() string { return r.p.stringAt(r.uint64()) } + +func (r *importReader) doType(base *types.Named) types.Type { + switch k := r.kind(); k { + default: + errorf("unexpected kind tag in %q: %v", r.p.ipath, k) + return nil + + case definedType: + pkg, name := r.qualifiedIdent() + r.p.doDecl(pkg, name) + return pkg.Scope().Lookup(name).(*types.TypeName).Type() + case pointerType: + return types.NewPointer(r.typ()) + case sliceType: + return types.NewSlice(r.typ()) + case arrayType: + n := r.uint64() + return types.NewArray(r.typ(), int64(n)) + case chanType: + dir := chanDir(int(r.uint64())) + return types.NewChan(dir, r.typ()) + case mapType: + return types.NewMap(r.typ(), r.typ()) + case signatureType: + r.currPkg = r.pkg() + return r.signature(nil, nil, nil) + + case structType: + r.currPkg = r.pkg() + + fields := make([]*types.Var, r.uint64()) + tags := make([]string, len(fields)) + for i := range fields { + fpos := r.pos() + fname := r.ident() + ftyp := r.typ() + emb := r.bool() + tag := r.string() + + fields[i] = types.NewField(fpos, r.currPkg, fname, ftyp, emb) + tags[i] = tag + } + return types.NewStruct(fields, tags) + + case interfaceType: + r.currPkg = r.pkg() + + embeddeds := make([]types.Type, r.uint64()) + for i := range embeddeds { + _ = r.pos() + embeddeds[i] = r.typ() + } + + methods := make([]*types.Func, r.uint64()) + for i := range methods { + mpos := r.pos() + mname := r.ident() + + // TODO(mdempsky): Matches bimport.go, but I + // don't agree with this. + var recv *types.Var + if base != nil { + recv = types.NewVar(token.NoPos, r.currPkg, "", base) + } + + msig := r.signature(recv, nil, nil) + methods[i] = types.NewFunc(mpos, r.currPkg, mname, msig) + } + + typ := types.NewInterfaceType(methods, embeddeds) + r.p.interfaceList = append(r.p.interfaceList, typ) + return typ + + case typeParamType: + if r.p.exportVersion < iexportVersionGenerics { + errorf("unexpected type param type") + } + pkg, name := r.qualifiedIdent() + id := ident{pkg, name} + if t, ok := r.p.tparamIndex[id]; ok { + // We're already in the process of importing this typeparam. + return t + } + // Otherwise, import the definition of the typeparam now. + r.p.doDecl(pkg, name) + return r.p.tparamIndex[id] + + case instanceType: + if r.p.exportVersion < iexportVersionGenerics { + errorf("unexpected instantiation type") + } + // pos does not matter for instances: they are positioned on the original + // type. + _ = r.pos() + len := r.uint64() + targs := make([]types.Type, len) + for i := range targs { + targs[i] = r.typ() + } + baseType := r.typ() + // The imported instantiated type doesn't include any methods, so + // we must always use the methods of the base (orig) type. + // TODO provide a non-nil *Context + t, _ := types.Instantiate(nil, baseType, targs, false) + return t + + case unionType: + if r.p.exportVersion < iexportVersionGenerics { + errorf("unexpected instantiation type") + } + terms := make([]*types.Term, r.uint64()) + for i := range terms { + terms[i] = types.NewTerm(r.bool(), r.typ()) + } + return types.NewUnion(terms) + } +} + +func (r *importReader) kind() itag { + return itag(r.uint64()) +} + +func (r *importReader) signature(recv *types.Var, rparams, tparams []*types.TypeParam) *types.Signature { + params := r.paramList() + results := r.paramList() + variadic := params.Len() > 0 && r.bool() + return types.NewSignatureType(recv, rparams, tparams, params, results, variadic) +} + +func (r *importReader) tparamList() []*types.TypeParam { + n := r.uint64() + if n == 0 { + return nil + } + xs := make([]*types.TypeParam, n) + for i := range xs { + xs[i], _ = r.typ().(*types.TypeParam) + } + return xs +} + +func (r *importReader) paramList() *types.Tuple { + xs := make([]*types.Var, r.uint64()) + for i := range xs { + xs[i] = r.param() + } + return types.NewTuple(xs...) +} + +func (r *importReader) param() *types.Var { + pos := r.pos() + name := r.ident() + typ := r.typ() + return types.NewParam(pos, r.currPkg, name, typ) +} + +func (r *importReader) bool() bool { + return r.uint64() != 0 +} + +func (r *importReader) int64() int64 { + n, err := binary.ReadVarint(&r.declReader) + if err != nil { + errorf("readVarint: %v", err) + } + return n +} + +func (r *importReader) uint64() uint64 { + n, err := binary.ReadUvarint(&r.declReader) + if err != nil { + errorf("readUvarint: %v", err) + } + return n +} + +func (r *importReader) byte() byte { + x, err := r.declReader.ReadByte() + if err != nil { + errorf("declReader.ReadByte: %v", err) + } + return x +} + +func baseType(typ types.Type) *types.Named { + // pointer receivers are never types.Named types + if p, _ := typ.(*types.Pointer); p != nil { + typ = p.Elem() + } + // receiver base types are always (possibly generic) types.Named types + n, _ := typ.(*types.Named) + return n +} + +const blankMarker = "$" + +// tparamName returns the real name of a type parameter, after stripping its +// qualifying prefix and reverting blank-name encoding. See tparamExportName +// for details. +func tparamName(exportName string) string { + // Remove the "path" from the type param name that makes it unique. + ix := strings.LastIndex(exportName, ".") + if ix < 0 { + errorf("malformed type parameter export name %s: missing prefix", exportName) + } + name := exportName[ix+1:] + if strings.HasPrefix(name, blankMarker) { + return "_" + } + return name +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/support.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/support.go new file mode 100644 index 0000000000000000000000000000000000000000..7ed8c9a4043d1cf3e22af4678e30667c1c1757b0 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/support.go @@ -0,0 +1,183 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file implements support functionality for iimport.go. + +package gcimporter + +import ( + "fmt" + "go/token" + "go/types" + "internal/pkgbits" + "sync" +) + +func assert(b bool) { + if !b { + panic("assertion failed") + } +} + +func errorf(format string, args ...any) { + panic(fmt.Sprintf(format, args...)) +} + +// deltaNewFile is a magic line delta offset indicating a new file. +// We use -64 because it is rare; see issue 20080 and CL 41619. +// -64 is the smallest int that fits in a single byte as a varint. +const deltaNewFile = -64 + +// Synthesize a token.Pos +type fakeFileSet struct { + fset *token.FileSet + files map[string]*fileInfo +} + +type fileInfo struct { + file *token.File + lastline int +} + +const maxlines = 64 * 1024 + +func (s *fakeFileSet) pos(file string, line, column int) token.Pos { + // TODO(mdempsky): Make use of column. + + // Since we don't know the set of needed file positions, we reserve + // maxlines positions per file. We delay calling token.File.SetLines until + // all positions have been calculated (by way of fakeFileSet.setLines), so + // that we can avoid setting unnecessary lines. See also golang/go#46586. + f := s.files[file] + if f == nil { + f = &fileInfo{file: s.fset.AddFile(file, -1, maxlines)} + s.files[file] = f + } + + if line > maxlines { + line = 1 + } + if line > f.lastline { + f.lastline = line + } + + // Return a fake position assuming that f.file consists only of newlines. + return token.Pos(f.file.Base() + line - 1) +} + +func (s *fakeFileSet) setLines() { + fakeLinesOnce.Do(func() { + fakeLines = make([]int, maxlines) + for i := range fakeLines { + fakeLines[i] = i + } + }) + for _, f := range s.files { + f.file.SetLines(fakeLines[:f.lastline]) + } +} + +var ( + fakeLines []int + fakeLinesOnce sync.Once +) + +func chanDir(d int) types.ChanDir { + // tag values must match the constants in cmd/compile/internal/gc/go.go + switch d { + case 1 /* Crecv */ : + return types.RecvOnly + case 2 /* Csend */ : + return types.SendOnly + case 3 /* Cboth */ : + return types.SendRecv + default: + errorf("unexpected channel dir %d", d) + return 0 + } +} + +var predeclared = []types.Type{ + // basic types + types.Typ[types.Bool], + types.Typ[types.Int], + types.Typ[types.Int8], + types.Typ[types.Int16], + types.Typ[types.Int32], + types.Typ[types.Int64], + types.Typ[types.Uint], + types.Typ[types.Uint8], + types.Typ[types.Uint16], + types.Typ[types.Uint32], + types.Typ[types.Uint64], + types.Typ[types.Uintptr], + types.Typ[types.Float32], + types.Typ[types.Float64], + types.Typ[types.Complex64], + types.Typ[types.Complex128], + types.Typ[types.String], + + // basic type aliases + types.Universe.Lookup("byte").Type(), + types.Universe.Lookup("rune").Type(), + + // error + types.Universe.Lookup("error").Type(), + + // untyped types + types.Typ[types.UntypedBool], + types.Typ[types.UntypedInt], + types.Typ[types.UntypedRune], + types.Typ[types.UntypedFloat], + types.Typ[types.UntypedComplex], + types.Typ[types.UntypedString], + types.Typ[types.UntypedNil], + + // package unsafe + types.Typ[types.UnsafePointer], + + // invalid type + types.Typ[types.Invalid], // only appears in packages with errors + + // used internally by gc; never used by this package or in .a files + // not to be confused with the universe any + anyType{}, + + // comparable + types.Universe.Lookup("comparable").Type(), + + // any + types.Universe.Lookup("any").Type(), +} + +type anyType struct{} + +func (t anyType) Underlying() types.Type { return t } +func (t anyType) String() string { return "any" } + +// See cmd/compile/internal/noder.derivedInfo. +type derivedInfo struct { + idx pkgbits.Index + needed bool +} + +// See cmd/compile/internal/noder.typeInfo. +type typeInfo struct { + idx pkgbits.Index + derived bool +} + +// See cmd/compile/internal/types.SplitVargenSuffix. +func splitVargenSuffix(name string) (base, suffix string) { + i := len(name) + for i > 0 && name[i-1] >= '0' && name[i-1] <= '9' { + i-- + } + const dot = "·" + if i >= len(dot) && name[i-len(dot):i] == dot { + i -= len(dot) + return name[:i], name[i:] + } + return name, "" +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/a.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/a.go new file mode 100644 index 0000000000000000000000000000000000000000..56e4292cda9f3a0892677a20722c833165171290 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/a.go @@ -0,0 +1,14 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Input for TestIssue13566 + +package a + +import "encoding/json" + +type A struct { + a *A + json json.RawMessage +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/b.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/b.go new file mode 100644 index 0000000000000000000000000000000000000000..419667820078e47d4744ee7c809a8f63516c8a42 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/b.go @@ -0,0 +1,11 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Input for TestIssue13566 + +package b + +import "./a" + +type A a.A diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/exports.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/exports.go new file mode 100644 index 0000000000000000000000000000000000000000..3d5a8c9e39fe13507ae3061f4bf778337c825fb5 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/exports.go @@ -0,0 +1,91 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file is used to generate an object file which +// serves as test file for gcimporter_test.go. + +package exports + +import "go/ast" + +// Issue 3682: Correctly read dotted identifiers from export data. +const init1 = 0 + +func init() {} + +const ( + C0 int = 0 + C1 = 3.14159265 + C2 = 2.718281828i + C3 = -123.456e-789 + C4 = +123.456e+789 + C5 = 1234i + C6 = "foo\n" + C7 = `bar\n` + C8 = 42 + C9 int = 42 + C10 float64 = 42 +) + +type ( + T1 int + T2 [10]int + T3 []int + T4 *int + T5 chan int + T6a chan<- int + T6b chan (<-chan int) + T6c chan<- (chan int) + T7 <-chan *ast.File + T8 struct{} + T9 struct { + a int + b, c float32 + d []string `go:"tag"` + } + T10 struct { + T8 + T9 + _ *T10 + } + T11 map[int]string + T12 any + T13 interface { + m1() + m2(int) float32 + } + T14 interface { + T12 + T13 + m3(x ...struct{}) []T9 + } + T15 func() + T16 func(int) + T17 func(x int) + T18 func() float32 + T19 func() (x float32) + T20 func(...any) + T21 struct{ next *T21 } + T22 struct{ link *T23 } + T23 struct{ link *T22 } + T24 *T24 + T25 *T26 + T26 *T27 + T27 *T25 + T28 func(T28) T28 +) + +var ( + V0 int + V1 = -991.0 + V2 float32 = 1.2 +) + +func F1() {} +func F2(x int) {} +func F3() int { return 0 } +func F4() float32 { return 0 } +func F5(a, b, c int, u, v, w struct{ x, y T1 }, more ...any) (p, q, r chan<- T10) + +func (p *T1) M1() diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/g.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/g.go new file mode 100644 index 0000000000000000000000000000000000000000..301c1429e6c45dea8a09ad4566cd03e5b61aed65 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/g.go @@ -0,0 +1,23 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Input for TestTypeNamingOrder + +// ensures that the order in which "type A B" declarations are +// processed is correct; this was a problem for unified IR imports. + +package g + +type Client struct { + common service + A *AService + B *BService +} + +type service struct { + client *Client +} + +type AService service +type BService service diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/generics.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/generics.go new file mode 100644 index 0000000000000000000000000000000000000000..00bf04000fa06c717f8bad1ab238dd83a8047ebe --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/generics.go @@ -0,0 +1,29 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file is used to generate an object file which +// serves as test file for gcimporter_test.go. + +package generics + +type Any any + +var x any + +type T[A, B any] struct { + Left A + Right B +} + +var X T[int, string] = T[int, string]{1, "hi"} + +func ToInt[P interface{ ~int }](p P) int { return int(p) } + +var IntID = ToInt[int] + +type G[C comparable] int + +func ImplicitFunc[T ~int]() {} + +type ImplicitType[T ~int] int diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue15920.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue15920.go new file mode 100644 index 0000000000000000000000000000000000000000..c70f7d8267b2f9209cf5f52a0ca7fe1bcc303649 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue15920.go @@ -0,0 +1,11 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +// The underlying type of Error is the underlying type of error. +// Make sure we can import this again without problems. +type Error error + +func F() Error { return nil } diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue20046.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue20046.go new file mode 100644 index 0000000000000000000000000000000000000000..c63ee821c959dafda6799ccc8df77347221ad46a --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue20046.go @@ -0,0 +1,9 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +var V interface { + M() +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue25301.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue25301.go new file mode 100644 index 0000000000000000000000000000000000000000..e3dc98b4e1f9acdc9801c6a66e9305206f943cb5 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue25301.go @@ -0,0 +1,17 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue25301 + +type ( + A = interface { + M() + } + T interface { + A + } + S struct{} +) + +func (S) M() { println("m") } diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue25596.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue25596.go new file mode 100644 index 0000000000000000000000000000000000000000..8923373e5fa44d57d25ce1b4ccdc3a480360c74f --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue25596.go @@ -0,0 +1,13 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue25596 + +type E interface { + M() T +} + +type T interface { + E +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue57015.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue57015.go new file mode 100644 index 0000000000000000000000000000000000000000..b6be81191f94aed0695785c9cf6d87e7169e0bbf --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/issue57015.go @@ -0,0 +1,16 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue57015 + +type E error + +type X[T any] struct {} + +func F() X[interface { + E +}] { + panic(0) +} + diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/p.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/p.go new file mode 100644 index 0000000000000000000000000000000000000000..9e2e7057653725fc8ce963b5768828b3d9a88b42 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/p.go @@ -0,0 +1,13 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Input for TestIssue15517 + +package p + +const C = 0 + +var V int + +func F() {} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test.go new file mode 100644 index 0000000000000000000000000000000000000000..227fc092519212f30793e1266fe619858ac28bef --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test.go @@ -0,0 +1,28 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// To create a test case for a new export format version, +// build this package with the latest compiler and store +// the resulting .a file appropriately named in the versions +// directory. The VersionHandling test will pick it up. +// +// In the testdata/versions: +// +// go build -o test_go1.$X_$Y.a test.go +// +// with $X = Go version and $Y = export format version +// (add 'b' or 'i' to distinguish between binary and +// indexed format starting with 1.11 as long as both +// formats are supported). +// +// Make sure this source is extended such that it exercises +// whatever export format change has taken place. + +package test + +// Any release before and including Go 1.7 didn't encode +// the package for a blank struct field. +type BlankField struct { + _ int +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.11_0i.a b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.11_0i.a new file mode 100644 index 0000000000000000000000000000000000000000..b00fefed0462172f5f5370f9769ed19342fc0c16 Binary files /dev/null and b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.11_0i.a differ diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.11_6b.a b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.11_6b.a new file mode 100644 index 0000000000000000000000000000000000000000..c0a211e917435646f4fde78cd2f41aed4599ea0c Binary files /dev/null and b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.11_6b.a differ diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.11_999b.a b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.11_999b.a new file mode 100644 index 0000000000000000000000000000000000000000..c35d22dce691e67127e04ea74ddd8c97a57e22ff Binary files /dev/null and b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.11_999b.a differ diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.11_999i.a b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.11_999i.a new file mode 100644 index 0000000000000000000000000000000000000000..99401d7c37ca48fbca32f0448b71606b7f853ce4 Binary files /dev/null and b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.11_999i.a differ diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.7_0.a b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.7_0.a new file mode 100644 index 0000000000000000000000000000000000000000..edb6c3f25a159d65fd097bcf0b5bc6a2add86eee Binary files /dev/null and b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.7_0.a differ diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.7_1.a b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.7_1.a new file mode 100644 index 0000000000000000000000000000000000000000..554d04a72ac24d1fef11bf93bb08c81aba299de1 Binary files /dev/null and b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.7_1.a differ diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.8_4.a b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.8_4.a new file mode 100644 index 0000000000000000000000000000000000000000..26b8531650ad8f85885fcf62f8306e5f686a1dca Binary files /dev/null and b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.8_4.a differ diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.8_5.a b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.8_5.a new file mode 100644 index 0000000000000000000000000000000000000000..60e52efeab14ae29ea499d0430ca9ce2b20ff6d7 Binary files /dev/null and b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/testdata/versions/test_go1.8_5.a differ diff --git a/platform/dbops/binaries/go/go/src/go/internal/gcimporter/ureader.go b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/ureader.go new file mode 100644 index 0000000000000000000000000000000000000000..5397a2796f786900bd315ab98621b1b5a170bf03 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/gcimporter/ureader.go @@ -0,0 +1,657 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package gcimporter + +import ( + "go/token" + "go/types" + "internal/pkgbits" + "sort" +) + +// A pkgReader holds the shared state for reading a unified IR package +// description. +type pkgReader struct { + pkgbits.PkgDecoder + + fake fakeFileSet + + ctxt *types.Context + imports map[string]*types.Package // previously imported packages, indexed by path + + // lazily initialized arrays corresponding to the unified IR + // PosBase, Pkg, and Type sections, respectively. + posBases []string // position bases (i.e., file names) + pkgs []*types.Package + typs []types.Type + + // laterFns holds functions that need to be invoked at the end of + // import reading. + laterFns []func() + + // ifaces holds a list of constructed Interfaces, which need to have + // Complete called after importing is done. + ifaces []*types.Interface +} + +// later adds a function to be invoked at the end of import reading. +func (pr *pkgReader) later(fn func()) { + pr.laterFns = append(pr.laterFns, fn) +} + +// readUnifiedPackage reads a package description from the given +// unified IR export data decoder. +func readUnifiedPackage(fset *token.FileSet, ctxt *types.Context, imports map[string]*types.Package, input pkgbits.PkgDecoder) *types.Package { + pr := pkgReader{ + PkgDecoder: input, + + fake: fakeFileSet{ + fset: fset, + files: make(map[string]*fileInfo), + }, + + ctxt: ctxt, + imports: imports, + + posBases: make([]string, input.NumElems(pkgbits.RelocPosBase)), + pkgs: make([]*types.Package, input.NumElems(pkgbits.RelocPkg)), + typs: make([]types.Type, input.NumElems(pkgbits.RelocType)), + } + defer pr.fake.setLines() + + r := pr.newReader(pkgbits.RelocMeta, pkgbits.PublicRootIdx, pkgbits.SyncPublic) + pkg := r.pkg() + r.Bool() // TODO(mdempsky): Remove; was "has init" + + for i, n := 0, r.Len(); i < n; i++ { + // As if r.obj(), but avoiding the Scope.Lookup call, + // to avoid eager loading of imports. + r.Sync(pkgbits.SyncObject) + assert(!r.Bool()) + r.p.objIdx(r.Reloc(pkgbits.RelocObj)) + assert(r.Len() == 0) + } + + r.Sync(pkgbits.SyncEOF) + + for _, fn := range pr.laterFns { + fn() + } + + for _, iface := range pr.ifaces { + iface.Complete() + } + + // Imports() of pkg are all of the transitive packages that were loaded. + var imps []*types.Package + for _, imp := range pr.pkgs { + if imp != nil && imp != pkg { + imps = append(imps, imp) + } + } + sort.Sort(byPath(imps)) + pkg.SetImports(imps) + + pkg.MarkComplete() + return pkg +} + +// A reader holds the state for reading a single unified IR element +// within a package. +type reader struct { + pkgbits.Decoder + + p *pkgReader + + dict *readerDict +} + +// A readerDict holds the state for type parameters that parameterize +// the current unified IR element. +type readerDict struct { + // bounds is a slice of typeInfos corresponding to the underlying + // bounds of the element's type parameters. + bounds []typeInfo + + // tparams is a slice of the constructed TypeParams for the element. + tparams []*types.TypeParam + + // derived is a slice of types derived from tparams, which may be + // instantiated while reading the current element. + derived []derivedInfo + derivedTypes []types.Type // lazily instantiated from derived +} + +func (pr *pkgReader) newReader(k pkgbits.RelocKind, idx pkgbits.Index, marker pkgbits.SyncMarker) *reader { + return &reader{ + Decoder: pr.NewDecoder(k, idx, marker), + p: pr, + } +} + +func (pr *pkgReader) tempReader(k pkgbits.RelocKind, idx pkgbits.Index, marker pkgbits.SyncMarker) *reader { + return &reader{ + Decoder: pr.TempDecoder(k, idx, marker), + p: pr, + } +} + +func (pr *pkgReader) retireReader(r *reader) { + pr.RetireDecoder(&r.Decoder) +} + +// @@@ Positions + +func (r *reader) pos() token.Pos { + r.Sync(pkgbits.SyncPos) + if !r.Bool() { + return token.NoPos + } + + // TODO(mdempsky): Delta encoding. + posBase := r.posBase() + line := r.Uint() + col := r.Uint() + return r.p.fake.pos(posBase, int(line), int(col)) +} + +func (r *reader) posBase() string { + return r.p.posBaseIdx(r.Reloc(pkgbits.RelocPosBase)) +} + +func (pr *pkgReader) posBaseIdx(idx pkgbits.Index) string { + if b := pr.posBases[idx]; b != "" { + return b + } + + var filename string + { + r := pr.tempReader(pkgbits.RelocPosBase, idx, pkgbits.SyncPosBase) + + // Within types2, position bases have a lot more details (e.g., + // keeping track of where //line directives appeared exactly). + // + // For go/types, we just track the file name. + + filename = r.String() + + if r.Bool() { // file base + // Was: "b = token.NewTrimmedFileBase(filename, true)" + } else { // line base + pos := r.pos() + line := r.Uint() + col := r.Uint() + + // Was: "b = token.NewLineBase(pos, filename, true, line, col)" + _, _, _ = pos, line, col + } + pr.retireReader(r) + } + b := filename + pr.posBases[idx] = b + return b +} + +// @@@ Packages + +func (r *reader) pkg() *types.Package { + r.Sync(pkgbits.SyncPkg) + return r.p.pkgIdx(r.Reloc(pkgbits.RelocPkg)) +} + +func (pr *pkgReader) pkgIdx(idx pkgbits.Index) *types.Package { + // TODO(mdempsky): Consider using some non-nil pointer to indicate + // the universe scope, so we don't need to keep re-reading it. + if pkg := pr.pkgs[idx]; pkg != nil { + return pkg + } + + pkg := pr.newReader(pkgbits.RelocPkg, idx, pkgbits.SyncPkgDef).doPkg() + pr.pkgs[idx] = pkg + return pkg +} + +func (r *reader) doPkg() *types.Package { + path := r.String() + switch path { + case "": + path = r.p.PkgPath() + case "builtin": + return nil // universe + case "unsafe": + return types.Unsafe + } + + if pkg := r.p.imports[path]; pkg != nil { + return pkg + } + + name := r.String() + + pkg := types.NewPackage(path, name) + r.p.imports[path] = pkg + + return pkg +} + +// @@@ Types + +func (r *reader) typ() types.Type { + return r.p.typIdx(r.typInfo(), r.dict) +} + +func (r *reader) typInfo() typeInfo { + r.Sync(pkgbits.SyncType) + if r.Bool() { + return typeInfo{idx: pkgbits.Index(r.Len()), derived: true} + } + return typeInfo{idx: r.Reloc(pkgbits.RelocType), derived: false} +} + +func (pr *pkgReader) typIdx(info typeInfo, dict *readerDict) types.Type { + idx := info.idx + var where *types.Type + if info.derived { + where = &dict.derivedTypes[idx] + idx = dict.derived[idx].idx + } else { + where = &pr.typs[idx] + } + + if typ := *where; typ != nil { + return typ + } + + var typ types.Type + { + r := pr.tempReader(pkgbits.RelocType, idx, pkgbits.SyncTypeIdx) + r.dict = dict + + typ = r.doTyp() + assert(typ != nil) + pr.retireReader(r) + } + // See comment in pkgReader.typIdx explaining how this happens. + if prev := *where; prev != nil { + return prev + } + + *where = typ + return typ +} + +func (r *reader) doTyp() (res types.Type) { + switch tag := pkgbits.CodeType(r.Code(pkgbits.SyncType)); tag { + default: + errorf("unhandled type tag: %v", tag) + panic("unreachable") + + case pkgbits.TypeBasic: + return types.Typ[r.Len()] + + case pkgbits.TypeNamed: + obj, targs := r.obj() + name := obj.(*types.TypeName) + if len(targs) != 0 { + t, _ := types.Instantiate(r.p.ctxt, name.Type(), targs, false) + return t + } + return name.Type() + + case pkgbits.TypeTypeParam: + return r.dict.tparams[r.Len()] + + case pkgbits.TypeArray: + len := int64(r.Uint64()) + return types.NewArray(r.typ(), len) + case pkgbits.TypeChan: + dir := types.ChanDir(r.Len()) + return types.NewChan(dir, r.typ()) + case pkgbits.TypeMap: + return types.NewMap(r.typ(), r.typ()) + case pkgbits.TypePointer: + return types.NewPointer(r.typ()) + case pkgbits.TypeSignature: + return r.signature(nil, nil, nil) + case pkgbits.TypeSlice: + return types.NewSlice(r.typ()) + case pkgbits.TypeStruct: + return r.structType() + case pkgbits.TypeInterface: + return r.interfaceType() + case pkgbits.TypeUnion: + return r.unionType() + } +} + +func (r *reader) structType() *types.Struct { + fields := make([]*types.Var, r.Len()) + var tags []string + for i := range fields { + pos := r.pos() + pkg, name := r.selector() + ftyp := r.typ() + tag := r.String() + embedded := r.Bool() + + fields[i] = types.NewField(pos, pkg, name, ftyp, embedded) + if tag != "" { + for len(tags) < i { + tags = append(tags, "") + } + tags = append(tags, tag) + } + } + return types.NewStruct(fields, tags) +} + +func (r *reader) unionType() *types.Union { + terms := make([]*types.Term, r.Len()) + for i := range terms { + terms[i] = types.NewTerm(r.Bool(), r.typ()) + } + return types.NewUnion(terms) +} + +func (r *reader) interfaceType() *types.Interface { + methods := make([]*types.Func, r.Len()) + embeddeds := make([]types.Type, r.Len()) + implicit := len(methods) == 0 && len(embeddeds) == 1 && r.Bool() + + for i := range methods { + pos := r.pos() + pkg, name := r.selector() + mtyp := r.signature(nil, nil, nil) + methods[i] = types.NewFunc(pos, pkg, name, mtyp) + } + + for i := range embeddeds { + embeddeds[i] = r.typ() + } + + iface := types.NewInterfaceType(methods, embeddeds) + if implicit { + iface.MarkImplicit() + } + + // We need to call iface.Complete(), but if there are any embedded + // defined types, then we may not have set their underlying + // interface type yet. So we need to defer calling Complete until + // after we've called SetUnderlying everywhere. + // + // TODO(mdempsky): After CL 424876 lands, it should be safe to call + // iface.Complete() immediately. + r.p.ifaces = append(r.p.ifaces, iface) + + return iface +} + +func (r *reader) signature(recv *types.Var, rtparams, tparams []*types.TypeParam) *types.Signature { + r.Sync(pkgbits.SyncSignature) + + params := r.params() + results := r.params() + variadic := r.Bool() + + return types.NewSignatureType(recv, rtparams, tparams, params, results, variadic) +} + +func (r *reader) params() *types.Tuple { + r.Sync(pkgbits.SyncParams) + + params := make([]*types.Var, r.Len()) + for i := range params { + params[i] = r.param() + } + + return types.NewTuple(params...) +} + +func (r *reader) param() *types.Var { + r.Sync(pkgbits.SyncParam) + + pos := r.pos() + pkg, name := r.localIdent() + typ := r.typ() + + return types.NewParam(pos, pkg, name, typ) +} + +// @@@ Objects + +func (r *reader) obj() (types.Object, []types.Type) { + r.Sync(pkgbits.SyncObject) + + assert(!r.Bool()) + + pkg, name := r.p.objIdx(r.Reloc(pkgbits.RelocObj)) + obj := pkgScope(pkg).Lookup(name) + + targs := make([]types.Type, r.Len()) + for i := range targs { + targs[i] = r.typ() + } + + return obj, targs +} + +func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types.Package, string) { + + var objPkg *types.Package + var objName string + var tag pkgbits.CodeObj + { + rname := pr.tempReader(pkgbits.RelocName, idx, pkgbits.SyncObject1) + + objPkg, objName = rname.qualifiedIdent() + assert(objName != "") + + tag = pkgbits.CodeObj(rname.Code(pkgbits.SyncCodeObj)) + pr.retireReader(rname) + } + + if tag == pkgbits.ObjStub { + assert(objPkg == nil || objPkg == types.Unsafe) + return objPkg, objName + } + + // Ignore local types promoted to global scope (#55110). + if _, suffix := splitVargenSuffix(objName); suffix != "" { + return objPkg, objName + } + + if objPkg.Scope().Lookup(objName) == nil { + dict := pr.objDictIdx(idx) + + r := pr.newReader(pkgbits.RelocObj, idx, pkgbits.SyncObject1) + r.dict = dict + + declare := func(obj types.Object) { + objPkg.Scope().Insert(obj) + } + + switch tag { + default: + panic("weird") + + case pkgbits.ObjAlias: + pos := r.pos() + typ := r.typ() + declare(types.NewTypeName(pos, objPkg, objName, typ)) + + case pkgbits.ObjConst: + pos := r.pos() + typ := r.typ() + val := r.Value() + declare(types.NewConst(pos, objPkg, objName, typ, val)) + + case pkgbits.ObjFunc: + pos := r.pos() + tparams := r.typeParamNames() + sig := r.signature(nil, nil, tparams) + declare(types.NewFunc(pos, objPkg, objName, sig)) + + case pkgbits.ObjType: + pos := r.pos() + + obj := types.NewTypeName(pos, objPkg, objName, nil) + named := types.NewNamed(obj, nil, nil) + declare(obj) + + named.SetTypeParams(r.typeParamNames()) + + underlying := r.typ().Underlying() + + // If the underlying type is an interface, we need to + // duplicate its methods so we can replace the receiver + // parameter's type (#49906). + if iface, ok := underlying.(*types.Interface); ok && iface.NumExplicitMethods() != 0 { + methods := make([]*types.Func, iface.NumExplicitMethods()) + for i := range methods { + fn := iface.ExplicitMethod(i) + sig := fn.Type().(*types.Signature) + + recv := types.NewVar(fn.Pos(), fn.Pkg(), "", named) + methods[i] = types.NewFunc(fn.Pos(), fn.Pkg(), fn.Name(), types.NewSignature(recv, sig.Params(), sig.Results(), sig.Variadic())) + } + + embeds := make([]types.Type, iface.NumEmbeddeds()) + for i := range embeds { + embeds[i] = iface.EmbeddedType(i) + } + + newIface := types.NewInterfaceType(methods, embeds) + r.p.ifaces = append(r.p.ifaces, newIface) + underlying = newIface + } + + named.SetUnderlying(underlying) + + for i, n := 0, r.Len(); i < n; i++ { + named.AddMethod(r.method()) + } + + case pkgbits.ObjVar: + pos := r.pos() + typ := r.typ() + declare(types.NewVar(pos, objPkg, objName, typ)) + } + } + + return objPkg, objName +} + +func (pr *pkgReader) objDictIdx(idx pkgbits.Index) *readerDict { + + var dict readerDict + + { + r := pr.tempReader(pkgbits.RelocObjDict, idx, pkgbits.SyncObject1) + if implicits := r.Len(); implicits != 0 { + errorf("unexpected object with %v implicit type parameter(s)", implicits) + } + + dict.bounds = make([]typeInfo, r.Len()) + for i := range dict.bounds { + dict.bounds[i] = r.typInfo() + } + + dict.derived = make([]derivedInfo, r.Len()) + dict.derivedTypes = make([]types.Type, len(dict.derived)) + for i := range dict.derived { + dict.derived[i] = derivedInfo{r.Reloc(pkgbits.RelocType), r.Bool()} + } + + pr.retireReader(r) + } + // function references follow, but reader doesn't need those + + return &dict +} + +func (r *reader) typeParamNames() []*types.TypeParam { + r.Sync(pkgbits.SyncTypeParamNames) + + // Note: This code assumes it only processes objects without + // implement type parameters. This is currently fine, because + // reader is only used to read in exported declarations, which are + // always package scoped. + + if len(r.dict.bounds) == 0 { + return nil + } + + // Careful: Type parameter lists may have cycles. To allow for this, + // we construct the type parameter list in two passes: first we + // create all the TypeNames and TypeParams, then we construct and + // set the bound type. + + r.dict.tparams = make([]*types.TypeParam, len(r.dict.bounds)) + for i := range r.dict.bounds { + pos := r.pos() + pkg, name := r.localIdent() + + tname := types.NewTypeName(pos, pkg, name, nil) + r.dict.tparams[i] = types.NewTypeParam(tname, nil) + } + + typs := make([]types.Type, len(r.dict.bounds)) + for i, bound := range r.dict.bounds { + typs[i] = r.p.typIdx(bound, r.dict) + } + + // TODO(mdempsky): This is subtle, elaborate further. + // + // We have to save tparams outside of the closure, because + // typeParamNames() can be called multiple times with the same + // dictionary instance. + // + // Also, this needs to happen later to make sure SetUnderlying has + // been called. + // + // TODO(mdempsky): Is it safe to have a single "later" slice or do + // we need to have multiple passes? See comments on CL 386002 and + // go.dev/issue/52104. + tparams := r.dict.tparams + r.p.later(func() { + for i, typ := range typs { + tparams[i].SetConstraint(typ) + } + }) + + return r.dict.tparams +} + +func (r *reader) method() *types.Func { + r.Sync(pkgbits.SyncMethod) + pos := r.pos() + pkg, name := r.selector() + + rparams := r.typeParamNames() + sig := r.signature(r.param(), rparams, nil) + + _ = r.pos() // TODO(mdempsky): Remove; this is a hacker for linker.go. + return types.NewFunc(pos, pkg, name, sig) +} + +func (r *reader) qualifiedIdent() (*types.Package, string) { return r.ident(pkgbits.SyncSym) } +func (r *reader) localIdent() (*types.Package, string) { return r.ident(pkgbits.SyncLocalIdent) } +func (r *reader) selector() (*types.Package, string) { return r.ident(pkgbits.SyncSelector) } + +func (r *reader) ident(marker pkgbits.SyncMarker) (*types.Package, string) { + r.Sync(marker) + return r.pkg(), r.String() +} + +// pkgScope returns pkg.Scope(). +// If pkg is nil, it returns types.Universe instead. +// +// TODO(mdempsky): Remove after x/tools can depend on Go 1.19. +func pkgScope(pkg *types.Package) *types.Scope { + if pkg != nil { + return pkg.Scope() + } + return types.Universe +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/srcimporter/srcimporter.go b/platform/dbops/binaries/go/go/src/go/internal/srcimporter/srcimporter.go new file mode 100644 index 0000000000000000000000000000000000000000..c96427486e872eaee938efec7235139c9d4ba319 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/srcimporter/srcimporter.go @@ -0,0 +1,269 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package srcimporter implements importing directly +// from source files rather than installed packages. +package srcimporter // import "go/internal/srcimporter" + +import ( + "fmt" + "go/ast" + "go/build" + "go/parser" + "go/token" + "go/types" + "io" + "os" + "os/exec" + "path/filepath" + "strings" + "sync" + _ "unsafe" // for go:linkname +) + +// An Importer provides the context for importing packages from source code. +type Importer struct { + ctxt *build.Context + fset *token.FileSet + sizes types.Sizes + packages map[string]*types.Package +} + +// New returns a new Importer for the given context, file set, and map +// of packages. The context is used to resolve import paths to package paths, +// and identifying the files belonging to the package. If the context provides +// non-nil file system functions, they are used instead of the regular package +// os functions. The file set is used to track position information of package +// files; and imported packages are added to the packages map. +func New(ctxt *build.Context, fset *token.FileSet, packages map[string]*types.Package) *Importer { + return &Importer{ + ctxt: ctxt, + fset: fset, + sizes: types.SizesFor(ctxt.Compiler, ctxt.GOARCH), // uses go/types default if GOARCH not found + packages: packages, + } +} + +// Importing is a sentinel taking the place in Importer.packages +// for a package that is in the process of being imported. +var importing types.Package + +// Import(path) is a shortcut for ImportFrom(path, ".", 0). +func (p *Importer) Import(path string) (*types.Package, error) { + return p.ImportFrom(path, ".", 0) // use "." rather than "" (see issue #24441) +} + +// ImportFrom imports the package with the given import path resolved from the given srcDir, +// adds the new package to the set of packages maintained by the importer, and returns the +// package. Package path resolution and file system operations are controlled by the context +// maintained with the importer. The import mode must be zero but is otherwise ignored. +// Packages that are not comprised entirely of pure Go files may fail to import because the +// type checker may not be able to determine all exported entities (e.g. due to cgo dependencies). +func (p *Importer) ImportFrom(path, srcDir string, mode types.ImportMode) (*types.Package, error) { + if mode != 0 { + panic("non-zero import mode") + } + + if abs, err := p.absPath(srcDir); err == nil { // see issue #14282 + srcDir = abs + } + bp, err := p.ctxt.Import(path, srcDir, 0) + if err != nil { + return nil, err // err may be *build.NoGoError - return as is + } + + // package unsafe is known to the type checker + if bp.ImportPath == "unsafe" { + return types.Unsafe, nil + } + + // no need to re-import if the package was imported completely before + pkg := p.packages[bp.ImportPath] + if pkg != nil { + if pkg == &importing { + return nil, fmt.Errorf("import cycle through package %q", bp.ImportPath) + } + if !pkg.Complete() { + // Package exists but is not complete - we cannot handle this + // at the moment since the source importer replaces the package + // wholesale rather than augmenting it (see #19337 for details). + // Return incomplete package with error (see #16088). + return pkg, fmt.Errorf("reimported partially imported package %q", bp.ImportPath) + } + return pkg, nil + } + + p.packages[bp.ImportPath] = &importing + defer func() { + // clean up in case of error + // TODO(gri) Eventually we may want to leave a (possibly empty) + // package in the map in all cases (and use that package to + // identify cycles). See also issue 16088. + if p.packages[bp.ImportPath] == &importing { + p.packages[bp.ImportPath] = nil + } + }() + + var filenames []string + filenames = append(filenames, bp.GoFiles...) + filenames = append(filenames, bp.CgoFiles...) + + files, err := p.parseFiles(bp.Dir, filenames) + if err != nil { + return nil, err + } + + // type-check package files + var firstHardErr error + conf := types.Config{ + IgnoreFuncBodies: true, + // continue type-checking after the first error + Error: func(err error) { + if firstHardErr == nil && !err.(types.Error).Soft { + firstHardErr = err + } + }, + Importer: p, + Sizes: p.sizes, + } + if len(bp.CgoFiles) > 0 { + if p.ctxt.OpenFile != nil { + // cgo, gcc, pkg-config, etc. do not support + // build.Context's VFS. + conf.FakeImportC = true + } else { + setUsesCgo(&conf) + file, err := p.cgo(bp) + if err != nil { + return nil, fmt.Errorf("error processing cgo for package %q: %w", bp.ImportPath, err) + } + files = append(files, file) + } + } + + pkg, err = conf.Check(bp.ImportPath, p.fset, files, nil) + if err != nil { + // If there was a hard error it is possibly unsafe + // to use the package as it may not be fully populated. + // Do not return it (see also #20837, #20855). + if firstHardErr != nil { + pkg = nil + err = firstHardErr // give preference to first hard error over any soft error + } + return pkg, fmt.Errorf("type-checking package %q failed (%v)", bp.ImportPath, err) + } + if firstHardErr != nil { + // this can only happen if we have a bug in go/types + panic("package is not safe yet no error was returned") + } + + p.packages[bp.ImportPath] = pkg + return pkg, nil +} + +func (p *Importer) parseFiles(dir string, filenames []string) ([]*ast.File, error) { + // use build.Context's OpenFile if there is one + open := p.ctxt.OpenFile + if open == nil { + open = func(name string) (io.ReadCloser, error) { return os.Open(name) } + } + + files := make([]*ast.File, len(filenames)) + errors := make([]error, len(filenames)) + + var wg sync.WaitGroup + wg.Add(len(filenames)) + for i, filename := range filenames { + go func(i int, filepath string) { + defer wg.Done() + src, err := open(filepath) + if err != nil { + errors[i] = err // open provides operation and filename in error + return + } + files[i], errors[i] = parser.ParseFile(p.fset, filepath, src, parser.SkipObjectResolution) + src.Close() // ignore Close error - parsing may have succeeded which is all we need + }(i, p.joinPath(dir, filename)) + } + wg.Wait() + + // if there are errors, return the first one for deterministic results + for _, err := range errors { + if err != nil { + return nil, err + } + } + + return files, nil +} + +func (p *Importer) cgo(bp *build.Package) (*ast.File, error) { + tmpdir, err := os.MkdirTemp("", "srcimporter") + if err != nil { + return nil, err + } + defer os.RemoveAll(tmpdir) + + goCmd := "go" + if p.ctxt.GOROOT != "" { + goCmd = filepath.Join(p.ctxt.GOROOT, "bin", "go") + } + args := []string{goCmd, "tool", "cgo", "-objdir", tmpdir} + if bp.Goroot { + switch bp.ImportPath { + case "runtime/cgo": + args = append(args, "-import_runtime_cgo=false", "-import_syscall=false") + case "runtime/race": + args = append(args, "-import_syscall=false") + } + } + args = append(args, "--") + args = append(args, strings.Fields(os.Getenv("CGO_CPPFLAGS"))...) + args = append(args, bp.CgoCPPFLAGS...) + if len(bp.CgoPkgConfig) > 0 { + cmd := exec.Command("pkg-config", append([]string{"--cflags"}, bp.CgoPkgConfig...)...) + out, err := cmd.Output() + if err != nil { + return nil, fmt.Errorf("pkg-config --cflags: %w", err) + } + args = append(args, strings.Fields(string(out))...) + } + args = append(args, "-I", tmpdir) + args = append(args, strings.Fields(os.Getenv("CGO_CFLAGS"))...) + args = append(args, bp.CgoCFLAGS...) + args = append(args, bp.CgoFiles...) + + cmd := exec.Command(args[0], args[1:]...) + cmd.Dir = bp.Dir + if err := cmd.Run(); err != nil { + return nil, fmt.Errorf("go tool cgo: %w", err) + } + + return parser.ParseFile(p.fset, filepath.Join(tmpdir, "_cgo_gotypes.go"), nil, parser.SkipObjectResolution) +} + +// context-controlled file system operations + +func (p *Importer) absPath(path string) (string, error) { + // TODO(gri) This should be using p.ctxt.AbsPath which doesn't + // exist but probably should. See also issue #14282. + return filepath.Abs(path) +} + +func (p *Importer) isAbsPath(path string) bool { + if f := p.ctxt.IsAbsPath; f != nil { + return f(path) + } + return filepath.IsAbs(path) +} + +func (p *Importer) joinPath(elem ...string) string { + if f := p.ctxt.JoinPath; f != nil { + return f(elem...) + } + return filepath.Join(elem...) +} + +//go:linkname setUsesCgo go/types.srcimporter_setUsesCgo +func setUsesCgo(conf *types.Config) diff --git a/platform/dbops/binaries/go/go/src/go/internal/srcimporter/srcimporter_test.go b/platform/dbops/binaries/go/go/src/go/internal/srcimporter/srcimporter_test.go new file mode 100644 index 0000000000000000000000000000000000000000..61ae0c14532791397296692908c007d60bbcec32 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/srcimporter/srcimporter_test.go @@ -0,0 +1,252 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package srcimporter + +import ( + "flag" + "go/build" + "go/token" + "go/types" + "internal/testenv" + "os" + "path" + "path/filepath" + "strings" + "testing" + "time" +) + +func TestMain(m *testing.M) { + flag.Parse() + build.Default.GOROOT = testenv.GOROOT(nil) + os.Exit(m.Run()) +} + +const maxTime = 2 * time.Second + +var importer = New(&build.Default, token.NewFileSet(), make(map[string]*types.Package)) + +func doImport(t *testing.T, path, srcDir string) { + t0 := time.Now() + if _, err := importer.ImportFrom(path, srcDir, 0); err != nil { + // don't report an error if there's no buildable Go files + if _, nogo := err.(*build.NoGoError); !nogo { + t.Errorf("import %q failed (%v)", path, err) + } + return + } + t.Logf("import %q: %v", path, time.Since(t0)) +} + +// walkDir imports the all the packages with the given path +// prefix recursively. It returns the number of packages +// imported and whether importing was aborted because time +// has passed endTime. +func walkDir(t *testing.T, path string, endTime time.Time) (int, bool) { + if time.Now().After(endTime) { + t.Log("testing time used up") + return 0, true + } + + // ignore fake packages and testdata directories + if path == "builtin" || path == "unsafe" || strings.HasSuffix(path, "testdata") { + return 0, false + } + + list, err := os.ReadDir(filepath.Join(testenv.GOROOT(t), "src", path)) + if err != nil { + t.Fatalf("walkDir %s failed (%v)", path, err) + } + + nimports := 0 + hasGoFiles := false + for _, f := range list { + if f.IsDir() { + n, abort := walkDir(t, filepath.Join(path, f.Name()), endTime) + nimports += n + if abort { + return nimports, true + } + } else if strings.HasSuffix(f.Name(), ".go") { + hasGoFiles = true + } + } + + if hasGoFiles { + doImport(t, path, "") + nimports++ + } + + return nimports, false +} + +func TestImportStdLib(t *testing.T) { + if !testenv.HasSrc() { + t.Skip("no source code available") + } + + if testing.Short() && testenv.Builder() == "" { + t.Skip("skipping in -short mode") + } + dt := maxTime + nimports, _ := walkDir(t, "", time.Now().Add(dt)) // installed packages + t.Logf("tested %d imports", nimports) +} + +var importedObjectTests = []struct { + name string + want string +}{ + {"flag.Bool", "func Bool(name string, value bool, usage string) *bool"}, + {"io.Reader", "type Reader interface{Read(p []byte) (n int, err error)}"}, + {"io.ReadWriter", "type ReadWriter interface{Reader; Writer}"}, // go/types.gcCompatibilityMode is off => interface not flattened + {"math.Pi", "const Pi untyped float"}, + {"math.Sin", "func Sin(x float64) float64"}, + {"math/big.Int", "type Int struct{neg bool; abs nat}"}, + {"golang.org/x/text/unicode/norm.MaxSegmentSize", "const MaxSegmentSize untyped int"}, +} + +func TestImportedTypes(t *testing.T) { + if !testenv.HasSrc() { + t.Skip("no source code available") + } + + for _, test := range importedObjectTests { + i := strings.LastIndex(test.name, ".") + if i < 0 { + t.Fatal("invalid test data format") + } + importPath := test.name[:i] + objName := test.name[i+1:] + + pkg, err := importer.ImportFrom(importPath, ".", 0) + if err != nil { + t.Error(err) + continue + } + + obj := pkg.Scope().Lookup(objName) + if obj == nil { + t.Errorf("%s: object not found", test.name) + continue + } + + got := types.ObjectString(obj, types.RelativeTo(pkg)) + if got != test.want { + t.Errorf("%s: got %q; want %q", test.name, got, test.want) + } + + if named, _ := obj.Type().(*types.Named); named != nil { + verifyInterfaceMethodRecvs(t, named, 0) + } + } +} + +// verifyInterfaceMethodRecvs verifies that method receiver types +// are named if the methods belong to a named interface type. +func verifyInterfaceMethodRecvs(t *testing.T, named *types.Named, level int) { + // avoid endless recursion in case of an embedding bug that lead to a cycle + if level > 10 { + t.Errorf("%s: embeds itself", named) + return + } + + iface, _ := named.Underlying().(*types.Interface) + if iface == nil { + return // not an interface + } + + // check explicitly declared methods + for i := 0; i < iface.NumExplicitMethods(); i++ { + m := iface.ExplicitMethod(i) + recv := m.Type().(*types.Signature).Recv() + if recv == nil { + t.Errorf("%s: missing receiver type", m) + continue + } + if recv.Type() != named { + t.Errorf("%s: got recv type %s; want %s", m, recv.Type(), named) + } + } + + // check embedded interfaces (they are named, too) + for i := 0; i < iface.NumEmbeddeds(); i++ { + // embedding of interfaces cannot have cycles; recursion will terminate + verifyInterfaceMethodRecvs(t, iface.Embedded(i), level+1) + } +} + +func TestReimport(t *testing.T) { + if !testenv.HasSrc() { + t.Skip("no source code available") + } + + // Reimporting a partially imported (incomplete) package is not supported (see issue #19337). + // Make sure we recognize the situation and report an error. + + mathPkg := types.NewPackage("math", "math") // incomplete package + importer := New(&build.Default, token.NewFileSet(), map[string]*types.Package{mathPkg.Path(): mathPkg}) + _, err := importer.ImportFrom("math", ".", 0) + if err == nil || !strings.HasPrefix(err.Error(), "reimport") { + t.Errorf("got %v; want reimport error", err) + } +} + +func TestIssue20855(t *testing.T) { + if !testenv.HasSrc() { + t.Skip("no source code available") + } + + pkg, err := importer.ImportFrom("go/internal/srcimporter/testdata/issue20855", ".", 0) + if err == nil || !strings.Contains(err.Error(), "missing function body") { + t.Fatalf("got unexpected or no error: %v", err) + } + if pkg == nil { + t.Error("got no package despite no hard errors") + } +} + +func testImportPath(t *testing.T, pkgPath string) { + if !testenv.HasSrc() { + t.Skip("no source code available") + } + + pkgName := path.Base(pkgPath) + + pkg, err := importer.Import(pkgPath) + if err != nil { + t.Fatal(err) + } + + if pkg.Name() != pkgName { + t.Errorf("got %q; want %q", pkg.Name(), pkgName) + } + + if pkg.Path() != pkgPath { + t.Errorf("got %q; want %q", pkg.Path(), pkgPath) + } +} + +// TestIssue23092 tests relative imports. +func TestIssue23092(t *testing.T) { + testImportPath(t, "./testdata/issue23092") +} + +// TestIssue24392 tests imports against a path containing 'testdata'. +func TestIssue24392(t *testing.T) { + testImportPath(t, "go/internal/srcimporter/testdata/issue24392") +} + +func TestCgo(t *testing.T) { + testenv.MustHaveGoBuild(t) + testenv.MustHaveCGO(t) + + buildCtx := build.Default + importer := New(&buildCtx, token.NewFileSet(), make(map[string]*types.Package)) + _, err := importer.ImportFrom("cmd/cgo/internal/test", buildCtx.Dir, 0) + if err != nil { + t.Fatalf("Import failed: %v", err) + } +} diff --git a/platform/dbops/binaries/go/go/src/go/internal/srcimporter/testdata/issue20855/issue20855.go b/platform/dbops/binaries/go/go/src/go/internal/srcimporter/testdata/issue20855/issue20855.go new file mode 100644 index 0000000000000000000000000000000000000000..d55448b44cedb0e2379b8c00799479c08fbacc8b --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/srcimporter/testdata/issue20855/issue20855.go @@ -0,0 +1,7 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue20855 + +func init() // "missing function body" is a soft error diff --git a/platform/dbops/binaries/go/go/src/go/internal/srcimporter/testdata/issue23092/issue23092.go b/platform/dbops/binaries/go/go/src/go/internal/srcimporter/testdata/issue23092/issue23092.go new file mode 100644 index 0000000000000000000000000000000000000000..608698bfc51b3a4e4e0011541dbf4ebf28340147 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/srcimporter/testdata/issue23092/issue23092.go @@ -0,0 +1,5 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue23092 diff --git a/platform/dbops/binaries/go/go/src/go/internal/srcimporter/testdata/issue24392/issue24392.go b/platform/dbops/binaries/go/go/src/go/internal/srcimporter/testdata/issue24392/issue24392.go new file mode 100644 index 0000000000000000000000000000000000000000..8ad52218fc348624ae713f0f59a9f26e6b342c99 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/srcimporter/testdata/issue24392/issue24392.go @@ -0,0 +1,5 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue24392 diff --git a/platform/dbops/binaries/go/go/src/go/internal/typeparams/typeparams.go b/platform/dbops/binaries/go/go/src/go/internal/typeparams/typeparams.go new file mode 100644 index 0000000000000000000000000000000000000000..3f84f2f0d05afd28b9d10b8b146e09deee2ef505 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/internal/typeparams/typeparams.go @@ -0,0 +1,54 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package typeparams + +import ( + "go/ast" + "go/token" +) + +func PackIndexExpr(x ast.Expr, lbrack token.Pos, exprs []ast.Expr, rbrack token.Pos) ast.Expr { + switch len(exprs) { + case 0: + panic("internal error: PackIndexExpr with empty expr slice") + case 1: + return &ast.IndexExpr{ + X: x, + Lbrack: lbrack, + Index: exprs[0], + Rbrack: rbrack, + } + default: + return &ast.IndexListExpr{ + X: x, + Lbrack: lbrack, + Indices: exprs, + Rbrack: rbrack, + } + } +} + +// IndexExpr wraps an ast.IndexExpr or ast.IndexListExpr. +// +// Orig holds the original ast.Expr from which this IndexExpr was derived. +type IndexExpr struct { + Orig ast.Expr // the wrapped expr, which may be distinct from the IndexListExpr below. + *ast.IndexListExpr +} + +func UnpackIndexExpr(n ast.Node) *IndexExpr { + switch e := n.(type) { + case *ast.IndexExpr: + return &IndexExpr{e, &ast.IndexListExpr{ + X: e.X, + Lbrack: e.Lbrack, + Indices: []ast.Expr{e.Index}, + Rbrack: e.Rbrack, + }} + case *ast.IndexListExpr: + return &IndexExpr{e, e} + } + return nil +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/chans.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/chans.go2 new file mode 100644 index 0000000000000000000000000000000000000000..fad2bcec9d083ff6dde4c731628ac2a35ef093d3 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/chans.go2 @@ -0,0 +1,62 @@ +package chans + +import "runtime" + +// Ranger returns a Sender and a Receiver. The Receiver provides a +// Next method to retrieve values. The Sender provides a Send method +// to send values and a Close method to stop sending values. The Next +// method indicates when the Sender has been closed, and the Send +// method indicates when the Receiver has been freed. +// +// This is a convenient way to exit a goroutine sending values when +// the receiver stops reading them. +func Ranger[T any]() (*Sender[T], *Receiver[T]) { + c := make(chan T) + d := make(chan bool) + s := &Sender[T]{values: c, done: d} + r := &Receiver[T]{values: c, done: d} + runtime.SetFinalizer(r, r.finalize) + return s, r +} + +// A sender is used to send values to a Receiver. +type Sender[T any] struct { + values chan<- T + done <-chan bool +} + +// Send sends a value to the receiver. It returns whether any more +// values may be sent; if it returns false the value was not sent. +func (s *Sender[T]) Send(v T) bool { + select { + case s.values <- v: + return true + case <-s.done: + return false + } +} + +// Close tells the receiver that no more values will arrive. +// After Close is called, the Sender may no longer be used. +func (s *Sender[T]) Close() { + close(s.values) +} + +// A Receiver receives values from a Sender. +type Receiver[T any] struct { + values <-chan T + done chan<- bool +} + +// Next returns the next value from the channel. The bool result +// indicates whether the value is valid, or whether the Sender has +// been closed and no more values will be received. +func (r *Receiver[T]) Next() (T, bool) { + v, ok := <-r.values + return v, ok +} + +// finalize is a finalizer for the receiver. +func (r *Receiver[T]) finalize() { + close(r.done) +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/commas.src b/platform/dbops/binaries/go/go/src/go/parser/testdata/commas.src new file mode 100644 index 0000000000000000000000000000000000000000..2c52ae5ae4cf9dc1895a468d380ea92e323cdb4b --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/commas.src @@ -0,0 +1,19 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test case for error messages/parser synchronization +// after missing commas. + +package p + +var _ = []int{ + 0/* ERROR AFTER "missing ','" */ +} + +var _ = []int{ + 0, + 1, + 2, + 3/* ERROR AFTER "missing ','" */ +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t01.go b/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t01.go new file mode 100644 index 0000000000000000000000000000000000000000..5cfa0ccc00c148b32e011874c7cd1695355c743b --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t01.go @@ -0,0 +1,3 @@ +//go:build windows + +package none diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t02.go b/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t02.go new file mode 100644 index 0000000000000000000000000000000000000000..d91f9958757b09128a8d402fe310e19746c46f30 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t02.go @@ -0,0 +1,3 @@ +//go:build linux && go1.2 + +package go1_2 diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t03.go b/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t03.go new file mode 100644 index 0000000000000000000000000000000000000000..97fc9ae3af4d8e00f574e840850cb90798109ef3 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t03.go @@ -0,0 +1,3 @@ +//go:build linux && go1.2 || windows + +package none diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t04.go b/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t04.go new file mode 100644 index 0000000000000000000000000000000000000000..e81f9c03839ad4d38a62d6a20706c06790d5fcd7 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t04.go @@ -0,0 +1,5 @@ +// copyright notice + +//go:build (linux && go1.2) || (windows && go1.1) + +package go1_1 diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t05.go b/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t05.go new file mode 100644 index 0000000000000000000000000000000000000000..42c6b33d8366e1467c07f07f1d1226d0a6c14a13 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t05.go @@ -0,0 +1,3 @@ +//go:build linux && go1.2 && go1.4 + +package go1_4 diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t06.go b/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t06.go new file mode 100644 index 0000000000000000000000000000000000000000..22944de9446d14e455b63c4872529f7952ae68ef --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/goversion/t06.go @@ -0,0 +1,3 @@ +//go:build go1 + +package go1 diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/interface.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/interface.go2 new file mode 100644 index 0000000000000000000000000000000000000000..2ed9339c5204d6525b57bf9961bef8ae954c2d99 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/interface.go2 @@ -0,0 +1,76 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file contains test cases for interfaces containing +// constraint elements. + +package p + +type _ interface { + m() + ~int + ~int|string + E +} + +type _ interface { + m() + ~int + int | string + int | ~string + ~int | ~string +} + +type _ interface { + m() + ~int + T[int, string] | string + int | ~T[string, struct{}] + ~int | ~string +} + +type _ interface { + int + []byte + [10]int + struct{} + *int + func() + interface{} + map[string]int + chan T + chan<- T + <-chan T + T[int] +} + +type _ interface { + int | string + []byte | string + [10]int | string + struct{} | string + *int | string + func() | string + interface{} | string + map[string]int | string + chan T | string + chan<- T | string + <-chan T | string + T[int] | string +} + +type _ interface { + ~int | string + ~[]byte | string + ~[10]int | string + ~struct{} | string + ~*int | string + ~func() | string + ~interface{} | string + ~map[string]int | string + ~chan T | string + ~chan<- T | string + ~<-chan T | string + ~T[int] | string +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/issue11377.src b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue11377.src new file mode 100644 index 0000000000000000000000000000000000000000..a19b86e7abc844a338889e548a3466294a7e7c92 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue11377.src @@ -0,0 +1,27 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test case for go.dev/issue/11377: Better synchronization of +// parser after certain syntax errors. + +package p + +func bad1() { + if f()) /* ERROR "expected ';', found '\)'" */ { + return + } +} + +// There shouldn't be any errors down below. + +func F1() {} +func F2() {} +func F3() {} +func F4() {} +func F5() {} +func F6() {} +func F7() {} +func F8() {} +func F9() {} +func F10() {} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/issue23434.src b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue23434.src new file mode 100644 index 0000000000000000000000000000000000000000..f04ca1da894dd610b8ee06d24c4378c25d0e4a34 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue23434.src @@ -0,0 +1,25 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test case for go.dev/issue/23434: Better synchronization of +// parser after missing type. There should be exactly +// one error each time, with now follow errors. + +package p + +func g() { + m := make(map[string]! /* ERROR "expected type, found '!'" */ ) + for { + x := 1 + print(x) + } +} + +func f() { + m := make(map[string]) /* ERROR "expected type, found '\)'" */ + for { + x := 1 + print(x) + } +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/issue3106.src b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue3106.src new file mode 100644 index 0000000000000000000000000000000000000000..37dfb2a52f5a5a444ec574a415d620e762794932 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue3106.src @@ -0,0 +1,46 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test case for go.dev/issue/3106: Better synchronization of +// parser after certain syntax errors. + +package main + +func f() { + var m Mutex + c := MakeCond(&m) + percent := 0 + const step = 10 + for i := 0; i < 5; i++ { + go func() { + for { + // Emulates some useful work. + time.Sleep(1e8) + m.Lock() + defer + if /* ERROR "expected ';', found 'if'" */ percent == 100 { + m.Unlock() + break + } + percent++ + if percent % step == 0 { + //c.Signal() + } + m.Unlock() + } + }() + } + for { + m.Lock() + if percent == 0 || percent % step != 0 { + c.Wait() + } + fmt.Print(",") + if percent == 100 { + m.Unlock() + break + } + m.Unlock() + } +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/issue34946.src b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue34946.src new file mode 100644 index 0000000000000000000000000000000000000000..87b703d0c946a3ff05b016023aac4753331a7373 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue34946.src @@ -0,0 +1,22 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test case for go.dev/issue/34946: Better synchronization of +// parser for function declarations that start their +// body's opening { on a new line. + +package p + +// accept Allman/BSD-style declaration but complain +// (implicit semicolon between signature and body) +func _() int +{ /* ERROR "unexpected semicolon or newline before {" */ + { return 0 } +} + +func _() {} + +func _(); { /* ERROR "unexpected semicolon or newline before {" */ } + +func _() {} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/issue42951/not_a_file.go/invalid.go b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue42951/not_a_file.go/invalid.go new file mode 100644 index 0000000000000000000000000000000000000000..bb698be11cd01762a3fab336f936fc3deb8ddf5a --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue42951/not_a_file.go/invalid.go @@ -0,0 +1 @@ +This file should not be parsed by ParseDir. diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/issue44504.src b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue44504.src new file mode 100644 index 0000000000000000000000000000000000000000..c46c79f7da9335e2119f4478cb357a8726ec0378 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue44504.src @@ -0,0 +1,13 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test case for go.dev/issue/44504: panic due to duplicate resolution of slice/index +// operands. We should not try to resolve a LHS expression with invalid syntax. + +package p + +func _() { + var items []bool + items[] /* ERROR "operand" */ = false +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/issue49174.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue49174.go2 new file mode 100644 index 0000000000000000000000000000000000000000..77c195083ff044d0c383a4c994a9d2488887d0da --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue49174.go2 @@ -0,0 +1,8 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +func _[_ []int | int]() {} +func _[_ int | []int]() {} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/issue49175.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue49175.go2 new file mode 100644 index 0000000000000000000000000000000000000000..df303ada406cf580fba295532f25e446bad1ca85 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue49175.go2 @@ -0,0 +1,13 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type _[_ []t]t +type _[_ [1]t]t + +func _[_ []t]() {} +func _[_ [1]t]() {} + +type t [t /* ERROR "missing type parameter name or invalid array length" */ [0]]t diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/issue49482.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue49482.go2 new file mode 100644 index 0000000000000000000000000000000000000000..d8385bed4f524030ad3be8be076672530e5c79ee --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue49482.go2 @@ -0,0 +1,34 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type ( + // these need a comma to disambiguate + _[P *T,] struct{} + _[P *T, _ any] struct{} + _[P (*T),] struct{} + _[P (*T), _ any] struct{} + _[P (T),] struct{} + _[P (T), _ any] struct{} + + // these parse as name followed by type + _[P *struct{}] struct{} + _[P (*struct{})] struct{} + _[P ([]int)] struct{} + + // array declarations + _ [P(T)]struct{} + _ [P((T))]struct{} + _ [P * *T]struct{} + _ [P * T]struct{} + _ [P(*T)]struct{} + _ [P(**T)]struct{} + _ [P * T - T]struct{} + _ [P*T-T, /* ERROR "unexpected comma" */ ]struct{} + _ [10, /* ERROR "unexpected comma" */ ]struct{} + + _[P *struct{}|int] struct{} + _[P *struct{}|int|string] struct{} +) diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/issue50427.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue50427.go2 new file mode 100644 index 0000000000000000000000000000000000000000..15214594e2715300e4e5ffeb0a0340324ba5bd37 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue50427.go2 @@ -0,0 +1,19 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type T interface{ m[ /* ERROR "must have no type parameters" */ P any]() } + +func _(t T) { + var _ interface{ m[ /* ERROR "must have no type parameters" */ P any](); n() } = t +} + +type S struct{} + +func (S) m[ /* ERROR "must have no type parameters" */ P any]() {} + +func _(s S) { + var _ interface{ m[ /* ERROR "must have no type parameters" */ P any](); n() } = s +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/issue64534.src b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue64534.src new file mode 100644 index 0000000000000000000000000000000000000000..006cc934a165a46cd7986a3c37f44668d3d01d64 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/issue64534.src @@ -0,0 +1,10 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test case for go.dev/issue/64534. +// Parser should not panic during object resolution. + +package main + +func _[A /* ERROR "missing type parameter name" */ $(B](){}} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/linalg.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/linalg.go2 new file mode 100644 index 0000000000000000000000000000000000000000..7ccb19c08d3f1ff9dfde94113b618a6c3c627197 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/linalg.go2 @@ -0,0 +1,83 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package linalg + +import "math" + +// Numeric is type bound that matches any numeric type. +// It would likely be in a constraints package in the standard library. +type Numeric interface { + ~int|~int8|~int16|~int32|~int64| + ~uint|~uint8|~uint16|~uint32|~uint64|~uintptr| + ~float32|~float64| + ~complex64|~complex128 +} + +func DotProduct[T Numeric](s1, s2 []T) T { + if len(s1) != len(s2) { + panic("DotProduct: slices of unequal length") + } + var r T + for i := range s1 { + r += s1[i] * s2[i] + } + return r +} + +// NumericAbs matches numeric types with an Abs method. +type NumericAbs[T any] interface { + Numeric + + Abs() T +} + +// AbsDifference computes the absolute value of the difference of +// a and b, where the absolute value is determined by the Abs method. +func AbsDifference[T NumericAbs](a, b T) T { + d := a - b + return d.Abs() +} + +// OrderedNumeric is a type bound that matches numeric types that support the < operator. +type OrderedNumeric interface { + ~int|~int8|~int16|~int32|~int64| + ~uint|~uint8|~uint16|~uint32|~uint64|~uintptr| + ~float32|~float64 +} + +// Complex is a type bound that matches the two complex types, which do not have a < operator. +type Complex interface { + ~complex64|~complex128 +} + +// OrderedAbs is a helper type that defines an Abs method for +// ordered numeric types. +type OrderedAbs[T OrderedNumeric] T + +func (a OrderedAbs[T]) Abs() OrderedAbs[T] { + if a < 0 { + return -a + } + return a +} + +// ComplexAbs is a helper type that defines an Abs method for +// complex types. +type ComplexAbs[T Complex] T + +func (a ComplexAbs[T]) Abs() ComplexAbs[T] { + r := float64(real(a)) + i := float64(imag(a)) + d := math.Sqrt(r * r + i * i) + return ComplexAbs[T](complex(d, 0)) +} + +func OrderedAbsDifference[T OrderedNumeric](a, b T) T { + return T(AbsDifference(OrderedAbs[T](a), OrderedAbs[T](b))) +} + +func ComplexAbsDifference[T Complex](a, b T) T { + return T(AbsDifference(ComplexAbs[T](a), ComplexAbs[T](b))) +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/map.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/map.go2 new file mode 100644 index 0000000000000000000000000000000000000000..74c79ae44fc88f4f31d23636cdf2110e7071ddab --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/map.go2 @@ -0,0 +1,109 @@ +// Package orderedmap provides an ordered map, implemented as a binary tree. +package orderedmap + +import "chans" + +// Map is an ordered map. +type Map[K, V any] struct { + root *node[K, V] + compare func(K, K) int +} + +// node is the type of a node in the binary tree. +type node[K, V any] struct { + key K + val V + left, right *node[K, V] +} + +// New returns a new map. +func New[K, V any](compare func(K, K) int) *Map[K, V] { + return &Map[K, V]{compare: compare} +} + +// find looks up key in the map, and returns either a pointer +// to the node holding key, or a pointer to the location where +// such a node would go. +func (m *Map[K, V]) find(key K) **node[K, V] { + pn := &m.root + for *pn != nil { + switch cmp := m.compare(key, (*pn).key); { + case cmp < 0: + pn = &(*pn).left + case cmp > 0: + pn = &(*pn).right + default: + return pn + } + } + return pn +} + +// Insert inserts a new key/value into the map. +// If the key is already present, the value is replaced. +// Returns true if this is a new key, false if already present. +func (m *Map[K, V]) Insert(key K, val V) bool { + pn := m.find(key) + if *pn != nil { + (*pn).val = val + return false + } + *pn = &node[K, V]{key: key, val: val} + return true +} + +// Find returns the value associated with a key, or zero if not present. +// The found result reports whether the key was found. +func (m *Map[K, V]) Find(key K) (V, bool) { + pn := m.find(key) + if *pn == nil { + var zero V // see the discussion of zero values, above + return zero, false + } + return (*pn).val, true +} + +// keyValue is a pair of key and value used when iterating. +type keyValue[K, V any] struct { + key K + val V +} + +// InOrder returns an iterator that does an in-order traversal of the map. +func (m *Map[K, V]) InOrder() *Iterator[K, V] { + sender, receiver := chans.Ranger[keyValue[K, V]]() + var f func(*node[K, V]) bool + f = func(n *node[K, V]) bool { + if n == nil { + return true + } + // Stop sending values if sender.Send returns false, + // meaning that nothing is listening at the receiver end. + return f(n.left) && + // TODO + // sender.Send(keyValue[K, V]{n.key, n.val}) && + f(n.right) + } + go func() { + f(m.root) + sender.Close() + }() + return &Iterator{receiver} +} + +// Iterator is used to iterate over the map. +type Iterator[K, V any] struct { + r *chans.Receiver[keyValue[K, V]] +} + +// Next returns the next key and value pair, and a boolean indicating +// whether they are valid or whether we have reached the end. +func (it *Iterator[K, V]) Next() (K, V, bool) { + keyval, ok := it.r.Next() + if !ok { + var zerok K + var zerov V + return zerok, zerov, false + } + return keyval.key, keyval.val, true +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/metrics.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/metrics.go2 new file mode 100644 index 0000000000000000000000000000000000000000..ef1c66b241cbb0bb60a3ad7e4177c7716e108faa --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/metrics.go2 @@ -0,0 +1,58 @@ +package metrics + +import "sync" + +type Metric1[T comparable] struct { + mu sync.Mutex + m map[T]int +} + +func (m *Metric1[T]) Add(v T) { + m.mu.Lock() + defer m.mu.Unlock() + if m.m == nil { + m.m = make(map[T]int) + } + m[v]++ +} + +type key2[T1, T2 comparable] struct { + f1 T1 + f2 T2 +} + +type Metric2[T1, T2 cmp2] struct { + mu sync.Mutex + m map[key2[T1, T2]]int +} + +func (m *Metric2[T1, T2]) Add(v1 T1, v2 T2) { + m.mu.Lock() + defer m.mu.Unlock() + if m.m == nil { + m.m = make(map[key2[T1, T2]]int) + } + m[key[T1, T2]{v1, v2}]++ +} + +type key3[T1, T2, T3 comparable] struct { + f1 T1 + f2 T2 + f3 T3 +} + +type Metric3[T1, T2, T3 comparable] struct { + mu sync.Mutex + m map[key3[T1, T2, T3]]int +} + +func (m *Metric3[T1, T2, T3]) Add(v1 T1, v2 T2, v3 T3) { + m.mu.Lock() + defer m.mu.Unlock() + if m.m == nil { + m.m = make(map[key3]int) + } + m[key[T1, T2, T3]{v1, v2, v3}]++ +} + +// Repeat for the maximum number of permitted arguments. diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/resolution/issue45136.src b/platform/dbops/binaries/go/go/src/go/parser/testdata/resolution/issue45136.src new file mode 100644 index 0000000000000000000000000000000000000000..e1d63d837703c2e96c55c3fc6f16bbf3b8501bbd --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/resolution/issue45136.src @@ -0,0 +1,27 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue45136 + +type obj /* =@obj */ struct { + name /*=@name */ string +} + +func _() { + var foo /* =@foo */ = "foo" + obj /* @obj */ ["foo"] + obj /* @obj */ .run() + obj /* @obj */ { + name: foo /* @foo */, + } + obj /* @obj */ { + name: "bar", + }.run() + + var _ = File{key: obj /* @obj */ {}} + var _ = File{obj /* @obj */ {}} + + []obj /* @obj */ {foo /* @foo */} + x /* =@x1 */ := obj /* @obj */{} +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/resolution/issue45160.src b/platform/dbops/binaries/go/go/src/go/parser/testdata/resolution/issue45160.src new file mode 100644 index 0000000000000000000000000000000000000000..6be933b783a1207f4f5ea282b2dad606c8cc41d6 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/resolution/issue45160.src @@ -0,0 +1,25 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package issue45160 + +func mklink1 /* =@mklink1func */() {} + +func _() { + var tests /* =@tests */ = []dirLinkTest /* @dirLinkTest */ { + { + mklink1 /* @mklink1func */: func() {}, + mklink2: func(link /* =@link */, target /* =@target */ string) error { + return nil + }, + }, + } +} + +type dirLinkTest /* =@dirLinkTest */ struct { + mklink1 /* =@mklink1field */ func(string, string) error + mklink2 /* =@mklink2field */ func(string, string) error +} + +func mklink2 /* =@mklink2func */() {} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/resolution/resolution.src b/platform/dbops/binaries/go/go/src/go/parser/testdata/resolution/resolution.src new file mode 100644 index 0000000000000000000000000000000000000000..a880dd1c5e1f6067528a53d2f18795a646d3ddb8 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/resolution/resolution.src @@ -0,0 +1,63 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package resolution + +func f /* =@fdecl */(n /* =@narg */ ast.Node) bool { + if n /* =@ninit */, ok /* =@ok */ := n /* @narg */ .(*ast.SelectorExpr); ok /* @ok */ { + sel = n /* @ninit */ + } +} + +type c /* =@cdecl */ map[token.Pos]resolvedObj + +func (v /* =@vdecl */ c /* @cdecl */) Visit(node /* =@nodearg */ ast.Node) (w /* =@w */ ast.Visitor) {} + +const ( + basic /* =@basic */ = iota + labelOk // =@labelOk +) + +type T /* =@T */ int + +func _(count /* =@count */ T /* @T */) { + x /* =@x1 */ := c /* @cdecl */{} + switch x /* =@x2 */ := x /* @x1 */; x /* =@x3 */ := x /* @x2 */.(type) { + case c /* @cdecl */: + default: + } +loop /* =@loop */: + for { + if true { + break loop /* @loop */ + } + } + select { + case err /* =@err1 */ := <-_: + return err /* @err1 */ + case err /* =@err2 */ := <-_: + return err /* @err2 */ + } + + _ = func(p1 /* =@p1 */ int, p2 /* =@p2 */ p1) { + closed /* =@closed */ := p1 // @p1 + shadowed /* =@shadowed1 */ := p2 // @p2 + _ = func(shadowed /* =@shadowed2 */ p2 /* @p2 */) { + closed /* @closed */ = 1 + shadowed /* @shadowed2 */ = 2 + } + } +} + +func (r /* =@r */ c /* @cdecl */) m(_ r) c /* @cdecl */ { return r /* @r */ } + +var cycle /* =@cycle */ = cycle /* @cycle */ + 1 + +type chain /* =@chain */ struct { + next /* =@next */ *chain /* @chain */ +} + +func recursive /* =@recursive */() { + recursive /* @recursive */ () +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/resolution/typeparams.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/resolution/typeparams.go2 new file mode 100644 index 0000000000000000000000000000000000000000..0f894d7c9391c96486dff6794d79219c0b8d96a9 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/resolution/typeparams.go2 @@ -0,0 +1,51 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package resolution + +type List /* =@List */ [E /* =@E */ any] []E // @E + +type Pair /* =@Pair */ [L /* =@L */, R /* =@R */ any] struct { + Left /* =@Left */ L // @L + Right /* =@Right */ R // @R + L /* =@Lfield */ int +} + +var _ = Pair /* @Pair */ [int, string]{} + +type Addable /* =@Addable */ interface { + ~int64|~float64 +} + +func Add /* =@AddDecl */[T /* =@T */ Addable /* @Addable */](l /* =@l */, r /* =@r */ T /* @T */) T /* @T */ { + var t /* =@t */ T /* @T */ + return l /* @l */ + r /* @r */ + t /* @t */ +} + +type Receiver /* =@Receiver */[P /* =@P */ any] struct {} + +type RP /* =@RP1 */ struct{} + +// TODO(rFindley): make a decision on how/whether to resolve identifiers that +// refer to receiver type parameters, as is the case for the 'P' result +// parameter below. +// +// For now, we ensure that types are not incorrectly resolved when receiver +// type parameters are in scope. +func (r /* =@recv */ Receiver /* @Receiver */ [RP]) m(RP) RP {} + +func f /* =@f */[T1 /* =@T1 */ interface{~[]T2 /* @T2 */}, T2 /* =@T2 */ any]( + x /* =@x */ T1 /* @T1 */, T1 /* =@T1_duplicate */ y, // Note that this is a bug: + // the duplicate T1 should + // not be allowed. + ){ + // Note that duplicate short var declarations resolve to their alt declaration. + x /* @x */ := 0 + y /* =@y */ := 0 + T1 /* @T1 */ := 0 + var t1var /* =@t1var */ T1 /* @T1 */ +} + +// From go.dev/issue/39634 +func(*ph1[e, e])h(d) diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/set.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/set.go2 new file mode 100644 index 0000000000000000000000000000000000000000..0da6377cbdceba9ba4776933ad597e2c1700a4d4 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/set.go2 @@ -0,0 +1,31 @@ +// Package set implements sets of any type. +package set + +type Set[Elem comparable] map[Elem]struct{} + +func Make[Elem comparable]() Set[Elem] { + return make(Set(Elem)) +} + +func (s Set[Elem]) Add(v Elem) { + s[v] = struct{}{} +} + +func (s Set[Elem]) Delete(v Elem) { + delete(s, v) +} + +func (s Set[Elem]) Contains(v Elem) bool { + _, ok := s[v] + return ok +} + +func (s Set[Elem]) Len() int { + return len(s) +} + +func (s Set[Elem]) Iterate(f func(Elem)) { + for v := range s { + f(v) + } +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/slices.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/slices.go2 new file mode 100644 index 0000000000000000000000000000000000000000..e060212f295f0dbea1b95fdbbbaaf39a9e374a03 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/slices.go2 @@ -0,0 +1,31 @@ +// Package slices implements various slice algorithms. +package slices + +// Map turns a []T1 to a []T2 using a mapping function. +func Map[T1, T2 any](s []T1, f func(T1) T2) []T2 { + r := make([]T2, len(s)) + for i, v := range s { + r[i] = f(v) + } + return r +} + +// Reduce reduces a []T1 to a single value using a reduction function. +func Reduce[T1, T2 any](s []T1, initializer T2, f func(T2, T1) T2) T2 { + r := initializer + for _, v := range s { + r = f(r, v) + } + return r +} + +// Filter filters values from a slice using a filter function. +func Filter[T any](s []T, f func(T) bool) []T { + var r []T + for _, v := range s { + if f(v) { + r = append(r, v) + } + } + return r +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/sort.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/sort.go2 new file mode 100644 index 0000000000000000000000000000000000000000..88be79f9668870a71e9b0568107be33bcb76c63f --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/sort.go2 @@ -0,0 +1,27 @@ +package sort + +type orderedSlice[Elem comparable] []Elem + +func (s orderedSlice[Elem]) Len() int { return len(s) } +func (s orderedSlice[Elem]) Less(i, j int) bool { return s[i] < s[j] } +func (s orderedSlice[Elem]) Swap(i, j int) { s[i], s[j] = s[j], s[i] } + +// OrderedSlice sorts the slice s in ascending order. +// The elements of s must be ordered using the < operator. +func OrderedSlice[Elem comparable](s []Elem) { + sort.Sort(orderedSlice[Elem](s)) +} + +type sliceFn[Elem any] struct { + s []Elem + f func(Elem, Elem) bool +} + +func (s sliceFn[Elem]) Len() int { return len(s.s) } +func (s sliceFn[Elem]) Less(i, j int) bool { return s.f(s.s[i], s.s[j]) } +func (s sliceFn[Elem]) Swap(i, j int) { s.s[i], s.s[j] = s.s[j], s.s[i] } + +// SliceFn sorts the slice s according to the function f. +func SliceFn[Elem any](s []Elem, f func(Elem, Elem) bool) { + Sort(sliceFn[Elem]{s, f}) +} diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/tparams.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/tparams.go2 new file mode 100644 index 0000000000000000000000000000000000000000..3293b559bb70abd06dd4559bb277be3a5909da45 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/tparams.go2 @@ -0,0 +1,65 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type _[a, b] /* ERROR "missing type constraint" */ struct{} +type _[a t, b t, c] /* ERROR "missing type constraint" */ struct{} +type _ struct { + t [n]byte + t[a] + t[a,] + t[a, b] + t[a, b,] +} +type _ struct { + t [n, /* ERROR "unexpected comma; expecting ]" */ ]byte +} +type _ interface { + t[a] + t[a,] + m[ /* ERROR "method must have no type parameters" */ _ _, /* ERROR mixed */ _]() + t[a, b] + t[a, b,] +} + +func _[] /* ERROR "empty type parameter list" */ () +func _[a, b ] /* ERROR "missing type constraint" */ () +func _[a t, b t, c] /* ERROR "missing type constraint" */ () + +// TODO(rfindley) incorrect error message (see existing TODO in parser) +func f[a b, 0 /* ERROR "expected '\)', found 0" */ ] () + +// go.dev/issue/49482 +type ( + _[a *[]int] struct{} + _[a *t,] struct{} + _[a *t|[]int] struct{} + _[a *t|t,] struct{} + _[a *t|~t,] struct{} + _[a *struct{}|t] struct{} + _[a *t|struct{}] struct{} + _[a *struct{}|~t] struct{} +) + +// go.dev/issue/51488 +type ( + _[a *t|t,] struct{} + _[a *t|t, b t] struct{} + _[a *t|t] struct{} + _[a *[]t|t] struct{} + _[a ([]t)] struct{} + _[a ([]t)|t] struct{} +) + +// go.dev/issue/60812 +type ( + _ [t]struct{} + _ [[]t]struct{} + _ [[t]t]struct{} + _ [t /* ERROR "missing type parameter name or invalid array length" */ [t]]struct{} + _ [t t[t], t /* ERROR "missing type parameter name" */ [t]]struct{} + _ [t /* ERROR "missing type parameter name" */ [t], t t[t]]struct{} + _ [t /* ERROR "missing type parameter name" */ [t], t[t]]struct{} // report only first error +) diff --git a/platform/dbops/binaries/go/go/src/go/parser/testdata/typeset.go2 b/platform/dbops/binaries/go/go/src/go/parser/testdata/typeset.go2 new file mode 100644 index 0000000000000000000000000000000000000000..3d90d766393cd599484aec29eff0e0d467128a32 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/parser/testdata/typeset.go2 @@ -0,0 +1,72 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file contains test cases for typeset-only constraint elements. +// TODO(gri) gofmt once/if gofmt supports this notation. + +package p + +type ( + _[_ t] t + _[_ ~t] t + _[_ t|t] t + _[_ ~t|t] t + _[_ t|~t] t + _[_ ~t|~t] t + + _[_ t, _, _ t|t] t + _[_ t, _, _ ~t|t] t + _[_ t, _, _ t|~t] t + _[_ t, _, _ ~t|~t] t + + _[_ t.t] t + _[_ ~t.t] t + _[_ t.t|t.t] t + _[_ ~t.t|t.t] t + _[_ t.t|~t.t] t + _[_ ~t.t|~t.t] t + + _[_ t, _, _ t.t|t.t] t + _[_ t, _, _ ~t.t|t.t] t + _[_ t, _, _ t.t|~t.t] t + _[_ t, _, _ ~t.t|~t.t] t + + _[_ struct{}] t + _[_ ~struct{}] t + + _[_ struct{}|t] t + _[_ ~struct{}|t] t + _[_ struct{}|~t] t + _[_ ~struct{}|~t] t + + _[_ t|struct{}] t + _[_ ~t|struct{}] t + _[_ t|~struct{}] t + _[_ ~t|~struct{}] t +) + +// Single-expression type parameter lists and those that don't start +// with a (type parameter) name are considered array sizes. +// The term must be a valid expression (it could be a type incl. a +// tilde term) but the type-checker will complain. +type ( + _[t] t + _[t|t] t + + // These are invalid and the type-checker will complain. + _[~t] t + _[~t|t] t + _[t|~t] t + _[~t|~t] t +) + +type _[_ t, t] /* ERROR "missing type constraint" */ t +type _[_ ~t, t] /* ERROR "missing type constraint" */ t +type _[_ t, ~ /* ERROR "missing type parameter name" */ t] t +type _[_ ~t, ~ /* ERROR "missing type parameter name" */ t] t + +type _[_ t|t, t /* ERROR "missing type parameter name" */ |t] t +type _[_ ~t|t, t /* ERROR "missing type parameter name" */ |t] t +type _[_ t|t, ~ /* ERROR "missing type parameter name" */ t|t] t +type _[_ ~t|t, ~ /* ERROR "missing type parameter name" */ t|t] t diff --git a/platform/dbops/binaries/go/go/src/go/printer/testdata/alignment.golden b/platform/dbops/binaries/go/go/src/go/printer/testdata/alignment.golden new file mode 100644 index 0000000000000000000000000000000000000000..96086ed906861356cadcf504fd1b6f17bb376693 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/printer/testdata/alignment.golden @@ -0,0 +1,172 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package alignment + +// ---------------------------------------------------------------------------- +// Examples from issue #7335. + +func main() { + z := MyStruct{ + Foo: "foo", + Bar: "bar", + Name: "name", + LongName: "longname", + Baz: "baz", + } + y := MyStruct{ + Foo: "foo", + Bar: "bar", + NameXX: "name", + LongNameXXXXXXXXXXXXX: "longname", + Baz: "baz", + } + z := MyStruct{ + Foo: "foo", + Bar: "bar", + Name: "name", + LongNameXXXXXXXXXXXXX: "longname", + Baz: "baz", + } +} + +// ---------------------------------------------------------------------------- +// Examples from issue #10392. + +var kcfg = KubeletConfig{ + Address: s.Address, + AllowPrivileged: s.AllowPrivileged, + HostNetworkSources: hostNetworkSources, + HostnameOverride: s.HostnameOverride, + RootDirectory: s.RootDirectory, + ConfigFile: s.Config, + ManifestURL: s.ManifestURL, + FileCheckFrequency: s.FileCheckFrequency, + HTTPCheckFrequency: s.HTTPCheckFrequency, + PodInfraContainerImage: s.PodInfraContainerImage, + SyncFrequency: s.SyncFrequency, + RegistryPullQPS: s.RegistryPullQPS, + RegistryBurst: s.RegistryBurst, + MinimumGCAge: s.MinimumGCAge, + MaxPerPodContainerCount: s.MaxPerPodContainerCount, + MaxContainerCount: s.MaxContainerCount, + ClusterDomain: s.ClusterDomain, + ClusterDNS: s.ClusterDNS, + Runonce: s.RunOnce, + Port: s.Port, + ReadOnlyPort: s.ReadOnlyPort, + CadvisorInterface: cadvisorInterface, + EnableServer: s.EnableServer, + EnableDebuggingHandlers: s.EnableDebuggingHandlers, + DockerClient: dockertools.ConnectToDockerOrDie(s.DockerEndpoint), + KubeClient: client, + MasterServiceNamespace: s.MasterServiceNamespace, + VolumePlugins: ProbeVolumePlugins(), + NetworkPlugins: ProbeNetworkPlugins(), + NetworkPluginName: s.NetworkPluginName, + StreamingConnectionIdleTimeout: s.StreamingConnectionIdleTimeout, + TLSOptions: tlsOptions, + ImageGCPolicy: imageGCPolicy, imageGCPolicy, + Cloud: cloud, + NodeStatusUpdateFrequency: s.NodeStatusUpdateFrequency, +} + +var a = A{ + Long: 1, + LongLong: 1, + LongLongLong: 1, + LongLongLongLong: 1, + LongLongLongLongLong: 1, + LongLongLongLongLongLong: 1, + LongLongLongLongLongLongLong: 1, + LongLongLongLongLongLongLongLong: 1, + Short: 1, + LongLongLongLongLongLongLongLongLong: 3, +} + +// ---------------------------------------------------------------------------- +// Examples from issue #22852. + +var fmtMap = map[string]string{ + "1": "123", + "12": "123", + "123": "123", + "1234": "123", + "12345": "123", + "123456": "123", + "12345678901234567890123456789": "123", + "abcde": "123", + "123456789012345678901234567890": "123", + "1234567": "123", + "abcdefghijklmnopqrstuvwxyzabcd": "123", + "abcd": "123", +} + +type Fmt struct { + abcdefghijklmnopqrstuvwx string + abcdefghijklmnopqrstuvwxy string + abcdefghijklmnopqrstuvwxyz string + abcdefghijklmnopqrstuvwxyza string + abcdefghijklmnopqrstuvwxyzab string + abcdefghijklmnopqrstuvwxyzabc string + abcde string + abcdefghijklmnopqrstuvwxyzabcde string + abcdefg string +} + +func main() { + _ := Fmt{ + abcdefghijklmnopqrstuvwx: "foo", + abcdefghijklmnopqrstuvwxyza: "foo", + abcdefghijklmnopqrstuvwxyzab: "foo", + abcdefghijklmnopqrstuvwxyzabc: "foo", + abcde: "foo", + abcdefghijklmnopqrstuvwxyzabcde: "foo", + abcdefg: "foo", + abcdefghijklmnopqrstuvwxy: "foo", + abcdefghijklmnopqrstuvwxyz: "foo", + } +} + +// ---------------------------------------------------------------------------- +// Examples from issue #26352. + +var _ = map[int]string{ + 1: "", + + 12345678901234567890123456789: "", + 12345678901234567890123456789012345678: "", +} + +func f() { + _ = map[int]string{ + 1: "", + + 12345678901234567: "", + 12345678901234567890123456789012345678901: "", + } +} + +// ---------------------------------------------------------------------------- +// Examples from issue #26930. + +var _ = S{ + F1: []string{}, + F2____: []string{}, +} + +var _ = S{ + F1: []string{}, + F2____: []string{}, +} + +var _ = S{ + F1____: []string{}, + F2: []string{}, +} + +var _ = S{ + F1____: []string{}, + F2: []string{}, +} diff --git a/platform/dbops/binaries/go/go/src/go/printer/testdata/alignment.input b/platform/dbops/binaries/go/go/src/go/printer/testdata/alignment.input new file mode 100644 index 0000000000000000000000000000000000000000..323d2689e0b8c2eb1c99efc703c5eade787da04a --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/printer/testdata/alignment.input @@ -0,0 +1,179 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package alignment + +// ---------------------------------------------------------------------------- +// Examples from issue #7335. + +func main() { + z := MyStruct{ + Foo: "foo", + Bar: "bar", + Name: "name", + LongName: "longname", + Baz: "baz", + } + y := MyStruct{ + Foo: "foo", + Bar: "bar", + NameXX: "name", + LongNameXXXXXXXXXXXXX: "longname", + Baz: "baz", + } + z := MyStruct{ + Foo: "foo", + Bar: "bar", + Name: "name", + LongNameXXXXXXXXXXXXX: "longname", + Baz: "baz", + } +} + +// ---------------------------------------------------------------------------- +// Examples from issue #10392. + +var kcfg = KubeletConfig{ + Address: s.Address, + AllowPrivileged: s.AllowPrivileged, + HostNetworkSources: hostNetworkSources, + HostnameOverride: s.HostnameOverride, + RootDirectory: s.RootDirectory, + ConfigFile: s.Config, + ManifestURL: s.ManifestURL, + FileCheckFrequency: s.FileCheckFrequency, + HTTPCheckFrequency: s.HTTPCheckFrequency, + PodInfraContainerImage: s.PodInfraContainerImage, + SyncFrequency: s.SyncFrequency, + RegistryPullQPS: s.RegistryPullQPS, + RegistryBurst: s.RegistryBurst, + MinimumGCAge: s.MinimumGCAge, + MaxPerPodContainerCount: s.MaxPerPodContainerCount, + MaxContainerCount: s.MaxContainerCount, + ClusterDomain: s.ClusterDomain, + ClusterDNS: s.ClusterDNS, + Runonce: s.RunOnce, + Port: s.Port, + ReadOnlyPort: s.ReadOnlyPort, + CadvisorInterface: cadvisorInterface, + EnableServer: s.EnableServer, + EnableDebuggingHandlers: s.EnableDebuggingHandlers, + DockerClient: dockertools.ConnectToDockerOrDie(s.DockerEndpoint), + KubeClient: client, + MasterServiceNamespace: s.MasterServiceNamespace, + VolumePlugins: ProbeVolumePlugins(), + NetworkPlugins: ProbeNetworkPlugins(), + NetworkPluginName: s.NetworkPluginName, + StreamingConnectionIdleTimeout: s.StreamingConnectionIdleTimeout, + TLSOptions: tlsOptions, + ImageGCPolicy: imageGCPolicy,imageGCPolicy, + Cloud: cloud, + NodeStatusUpdateFrequency: s.NodeStatusUpdateFrequency, +} + +var a = A{ + Long: 1, + LongLong: 1, + LongLongLong: 1, + LongLongLongLong: 1, + LongLongLongLongLong: 1, + LongLongLongLongLongLong: 1, + LongLongLongLongLongLongLong: 1, + LongLongLongLongLongLongLongLong: 1, + Short: 1, + LongLongLongLongLongLongLongLongLong: 3, +} + +// ---------------------------------------------------------------------------- +// Examples from issue #22852. + +var fmtMap = map[string]string{ + "1": "123", + "12": "123", + "123": "123", + "1234": "123", + "12345": "123", + "123456": "123", + "12345678901234567890123456789": "123", + "abcde": "123", + "123456789012345678901234567890": "123", + "1234567": "123", + "abcdefghijklmnopqrstuvwxyzabcd": "123", + "abcd": "123", +} + +type Fmt struct { + abcdefghijklmnopqrstuvwx string + abcdefghijklmnopqrstuvwxy string + abcdefghijklmnopqrstuvwxyz string + abcdefghijklmnopqrstuvwxyza string + abcdefghijklmnopqrstuvwxyzab string + abcdefghijklmnopqrstuvwxyzabc string + abcde string + abcdefghijklmnopqrstuvwxyzabcde string + abcdefg string +} + +func main() { + _ := Fmt{ + abcdefghijklmnopqrstuvwx: "foo", + abcdefghijklmnopqrstuvwxyza: "foo", + abcdefghijklmnopqrstuvwxyzab: "foo", + abcdefghijklmnopqrstuvwxyzabc: "foo", + abcde: "foo", + abcdefghijklmnopqrstuvwxyzabcde: "foo", + abcdefg: "foo", + abcdefghijklmnopqrstuvwxy: "foo", + abcdefghijklmnopqrstuvwxyz: "foo", + } +} + +// ---------------------------------------------------------------------------- +// Examples from issue #26352. + +var _ = map[int]string{ + 1: "", + + 12345678901234567890123456789: "", + 12345678901234567890123456789012345678: "", +} + +func f() { + _ = map[int]string{ + 1: "", + + 12345678901234567: "", + 12345678901234567890123456789012345678901: "", + } +} + +// ---------------------------------------------------------------------------- +// Examples from issue #26930. + +var _ = S{ + F1: []string{ + }, + F2____: []string{}, +} + +var _ = S{ + F1: []string{ + + + }, + F2____: []string{}, +} + +var _ = S{ + F1____: []string{ + }, + F2: []string{}, +} + +var _ = S{ + F1____: []string{ + + }, + F2: []string{}, +} diff --git a/platform/dbops/binaries/go/go/src/go/printer/testdata/comments.golden b/platform/dbops/binaries/go/go/src/go/printer/testdata/comments.golden new file mode 100644 index 0000000000000000000000000000000000000000..1e5d17b4e1398d4f29304fc81295343ed37f46dd --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/printer/testdata/comments.golden @@ -0,0 +1,774 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This is a package for testing comment placement by go/printer. +package main + +import "fmt" // fmt + +const c0 = 0 // zero +const ( + c1 = iota // c1 + c2 // c2 +) + +// Alignment of comments in declarations> +const ( + _ T = iota // comment + _ // comment + _ // comment + _ = iota + 10 + _ // comments + + _ = 10 // comment + _ T = 20 // comment +) + +const ( + _____ = iota // foo + _ // bar + _ = 0 // bal + _ // bat +) + +const ( + _ T = iota // comment + _ // comment + _ // comment + _ = iota + 10 + _ // comment + _ = 10 + _ = 20 // comment + _ T = 0 // comment +) + +// The SZ struct; it is empty. +type SZ struct{} + +// The S0 struct; no field is exported. +type S0 struct { + int + x, y, z int // 3 unexported fields +} + +// The S1 struct; some fields are not exported. +type S1 struct { + S0 + A, B, C float // 3 exported fields + D, b, c int // 2 unexported fields +} + +// The S2 struct; all fields are exported. +type S2 struct { + S1 + A, B, C float // 3 exported fields +} + +// The IZ interface; it is empty. +type SZ interface{} + +// The I0 interface; no method is exported. +type I0 interface { + f(x int) int // unexported method +} + +// The I1 interface; some methods are not exported. +type I1 interface { + I0 + F(x float) float // exported methods + g(x int) int // unexported method +} + +// The I2 interface; all methods are exported. +type I2 interface { + I0 + F(x float) float // exported method + G(x float) float // exported method +} + +// The S3 struct; all comments except for the last one must appear in the export. +type S3 struct { + // lead comment for F1 + F1 int // line comment for F1 + // lead comment for F2 + F2 int // line comment for F2 + f3 int // f3 is not exported +} + +// Here is a comment. +// Here is an accidentally unindented line. +// More comment. +// +//dir:ect ive +type directiveCheck struct{} + +// This comment group should be separated +// with a newline from the next comment +// group. + +// This comment should NOT be associated with the next declaration. + +var x int // x +var () + +// This comment SHOULD be associated with f0. +func f0() { + const pi = 3.14 // pi + var s1 struct{} /* an empty struct */ /* foo */ + // a struct constructor + // -------------------- + var s2 struct{} = struct{}{} + x := pi +} + +// This comment should be associated with f1, with one blank line before the comment. +func f1() { + f0() + /* 1 */ + // 2 + /* 3 */ + /* 4 */ + f0() +} + +func _() { + // this comment should be properly indented +} + +func _(x int) int { + if x < 0 { // the tab printed before this comment's // must not affect the remaining lines + return -x // this statement should be properly indented + } + if x < 0 { /* the tab printed before this comment's /* must not affect the remaining lines */ + return -x // this statement should be properly indented + } + return x +} + +func typeswitch(x interface{}) { + switch v := x.(type) { + case bool, int, float: + case string: + default: + } + + switch x.(type) { + } + + switch v0, ok := x.(int); v := x.(type) { + } + + switch v0, ok := x.(int); x.(type) { + case byte: // this comment should be on the same line as the keyword + // this comment should be normally indented + _ = 0 + case bool, int, float: + // this comment should be indented + case string: + default: + // this comment should be indented + } + // this comment should not be indented +} + +// +// Indentation of comments after possibly indented multi-line constructs +// (test cases for issue 3147). +// + +func _() { + s := 1 + + 2 + // should be indented like s +} + +func _() { + s := 1 + + 2 // comment + // should be indented like s +} + +func _() { + s := 1 + + 2 // comment + // should be indented like s + _ = 0 +} + +func _() { + s := 1 + + 2 + // should be indented like s + _ = 0 +} + +func _() { + s := 1 + + 2 + + // should be indented like s +} + +func _() { + s := 1 + + 2 // comment + + // should be indented like s +} + +func _() { + s := 1 + + 2 // comment + + // should be indented like s + _ = 0 +} + +func _() { + s := 1 + + 2 + + // should be indented like s + _ = 0 +} + +// Test case from issue 3147. +func f() { + templateText := "a" + // A + "b" + // B + "c" // C + + // should be aligned with f() + f() +} + +// Modified test case from issue 3147. +func f() { + templateText := "a" + // A + "b" + // B + "c" // C + + // may not be aligned with f() (source is not aligned) + f() +} + +// +// Test cases for alignment of lines in general comments. +// + +func _() { + /* freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + aligned line */ +} + +func _() { + /* freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + aligned line */ +} + +func _() { + /* + freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line + aligned line */ +} + +func _() { + /* + freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line + aligned line */ +} + +func _() { + /* freestanding comment + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line */ +} + +func _() { + /* freestanding comment + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line */ +} + +func _() { + /* + freestanding comment + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line */ +} + +func _() { + /* + freestanding comment + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line */ +} + +// Issue 9751. +func _() { + /*a string + + b string*/ + + /*A string + + + + Z string*/ + + /*a string + + b string + + c string*/ + + { + /*a string + b string*/ + + /*a string + + b string*/ + + /*a string + + b string + + c string*/ + } + + { + /*a string + b string*/ + + /*a string + + b string*/ + + /*a string + + b string + + c string*/ + } + + /* + */ + + /* + + */ + + /* + + * line + + */ +} + +/* + * line + * of + * stars + */ + +/* another line + * of + * stars */ + +/* and another line + * of + * stars */ + +/* a line of + * stars */ + +/* and another line of + * stars */ + +/* a line of stars + */ + +/* and another line of + */ + +/* a line of stars + */ + +/* and another line of + */ + +/* +aligned in middle +here + not here +*/ + +/* +blank line in middle: + +with no leading spaces on blank line. +*/ + +/* + aligned in middle + here + not here +*/ + +/* + blank line in middle: + + with no leading spaces on blank line. +*/ + +func _() { + /* + * line + * of + * stars + */ + + /* + aligned in middle + here + not here + */ + + /* + blank line in middle: + + with no leading spaces on blank line. + */ +} + +// Some interesting interspersed comments. +// See below for more common cases. +func _( /* this */ x /* is */ /* an */ int) { +} + +func _( /* no params - extra blank before and after comment */ ) {} +func _(a, b int /* params - no extra blank after comment */) {} + +func _() { f( /* no args - extra blank before and after comment */ ) } +func _() { f(a, b /* args - no extra blank after comment */) } + +func _() { + f( /* no args - extra blank before and after comment */ ) + f(a, b /* args - no extra blank after comment */) +} + +func ( /* comment1 */ T /* comment2 */) _() {} + +func _() { /* "short-ish one-line functions with comments are formatted as multi-line functions */ } +func _() { x := 0; /* comment */ y = x /* comment */ } + +func _() { + _ = 0 + /* closing curly brace should be on new line */ +} + +func _() { + _ = []int{0, 1 /* don't introduce a newline after this comment - was issue 1365 */} +} + +// Test cases from issue 1542: +// Comments must not be placed before commas and cause invalid programs. +func _() { + var a = []int{1, 2 /*jasldf*/} + _ = a +} + +func _() { + var a = []int{1, 2}/*jasldf + */ + + _ = a +} + +func _() { + var a = []int{1, 2}// jasldf + + _ = a +} + +// Test cases from issues 11274, 15137: +// Semicolon must not be lost when multiple statements are on the same line with a comment. +func _() { + x := 0 /**/ + y := 1 +} + +func _() { + f() + f() + f() /* comment */ + f() + f() /* comment */ + f() + f() /* a */ /* b */ + f() + f() /* a */ /* b */ + f() + f() /* a */ /* b */ + f() +} + +func _() { + f() /* a */ /* b */ +} + +// Comments immediately adjacent to punctuation followed by a newline +// remain after the punctuation (looks better and permits alignment of +// comments). +func _() { + _ = T{ + 1, // comment after comma + 2, /* comment after comma */ + 3, // comment after comma + } + _ = T{ + 1, // comment after comma + 2, /* comment after comma */ + 3, // comment after comma + } + _ = T{ + /* comment before literal */ 1, + 2, /* comment before comma - ok to move after comma */ + 3, /* comment before comma - ok to move after comma */ + } + + for i = 0; // comment after semicolon + i < 9; /* comment after semicolon */ + i++ { // comment after opening curly brace + } + + // TODO(gri) the last comment in this example should be aligned */ + for i = 0; // comment after semicolon + i < 9; /* comment before semicolon - ok to move after semicolon */ + i++ /* comment before opening curly brace */ { + } +} + +// If there is no newline following punctuation, commas move before the punctuation. +// This way, commas interspersed in lists stay with the respective expression. +func f(x /* comment */, y int, z int /* comment */, u, v, w int /* comment */) { + f(x /* comment */, y) + f(x, /* comment */ + y) + f( + x, /* comment */ + ) +} + +func g( + x int, /* comment */ +) { +} + +type _ struct { + a, b /* comment */, c int +} + +type _ struct { + a, b /* comment */, c int +} + +func _() { + for a /* comment */, b := range x { + } +} + +//extern foo +func foo() {} + +//export bar +func bar() {} + +// Print line directives correctly. + +// The following is a legal line directive. +// +//line foo:1 +func _() { + _ = 0 + // The following is a legal line directive. It must not be indented: +//line foo:2 + _ = 1 + + // The following is not a legal line directive (it doesn't start in column 1): + //line foo:2 + _ = 2 + + // The following is not a legal line directive (missing colon): +//line foo -3 + _ = 3 +} + +// Line comments with tabs +func _() { + var finput *bufio.Reader // input file + var stderr *bufio.Writer + var ftable *bufio.Writer // y.go file + var foutput *bufio.Writer // y.output file + + var oflag string // -o [y.go] - y.go file + var vflag string // -v [y.output] - y.output file + var lflag bool // -l - disable line directives +} + +// Trailing white space in comments should be trimmed +func _() { + // This comment has 4 blanks following that should be trimmed: + /* Each line of this comment has blanks or tabs following that should be trimmed: + line 2: + line 3: + */ +} + +var _ = []T{ /* lone comment */ } + +var _ = []T{ + /* lone comment */ +} + +var _ = []T{ + // lone comments + // in composite lit +} + +var _ = [][]T{ + { + // lone comments + // in composite lit + }, +} + +// TODO: gofmt doesn't add these tabs; make it so that these golden +// tests run the printer in a way that it's exactly like gofmt. + +var _ = []T{ // lone comment +} + +var _ = []T{ // lone comments + // in composite lit +} + +func _() {} + +func _() {} + +/* This comment is the last entry in this file. It must be printed and should be followed by a newline */ diff --git a/platform/dbops/binaries/go/go/src/go/printer/testdata/comments.input b/platform/dbops/binaries/go/go/src/go/printer/testdata/comments.input new file mode 100644 index 0000000000000000000000000000000000000000..40aa55be068ae25b807f069313ae13c97418ec85 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/printer/testdata/comments.input @@ -0,0 +1,773 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This is a package for testing comment placement by go/printer. +// +package main + +import "fmt" // fmt + +const c0 = 0 // zero +const ( + c1 = iota // c1 + c2 // c2 +) + +// Alignment of comments in declarations> +const ( + _ T = iota // comment + _ // comment + _ // comment + _ = iota+10 + _ // comments + + _ = 10 // comment + _ T = 20 // comment +) + +const ( + _____ = iota // foo + _ // bar + _ = 0 // bal + _ // bat +) + +const ( + _ T = iota // comment + _ // comment + _ // comment + _ = iota + 10 + _ // comment + _ = 10 + _ = 20 // comment + _ T = 0 // comment +) + +// The SZ struct; it is empty. +type SZ struct {} + +// The S0 struct; no field is exported. +type S0 struct { + int + x, y, z int // 3 unexported fields +} + +// The S1 struct; some fields are not exported. +type S1 struct { + S0 + A, B, C float // 3 exported fields + D, b, c int // 2 unexported fields +} + +// The S2 struct; all fields are exported. +type S2 struct { + S1 + A, B, C float // 3 exported fields +} + +// The IZ interface; it is empty. +type SZ interface {} + +// The I0 interface; no method is exported. +type I0 interface { + f(x int) int // unexported method +} + +// The I1 interface; some methods are not exported. +type I1 interface { + I0 + F(x float) float // exported methods + g(x int) int // unexported method +} + +// The I2 interface; all methods are exported. +type I2 interface { + I0 + F(x float) float // exported method + G(x float) float // exported method +} + +// The S3 struct; all comments except for the last one must appear in the export. +type S3 struct { + // lead comment for F1 + F1 int // line comment for F1 + // lead comment for F2 + F2 int // line comment for F2 + f3 int // f3 is not exported +} + +// Here is a comment. +//Here is an accidentally unindented line. +//dir:ect ive +// More comment. +type directiveCheck struct{} + +// This comment group should be separated +// with a newline from the next comment +// group. + +// This comment should NOT be associated with the next declaration. + +var x int // x +var () + + +// This comment SHOULD be associated with f0. +func f0() { + const pi = 3.14 // pi + var s1 struct {} /* an empty struct */ /* foo */ + // a struct constructor + // -------------------- + var s2 struct {} = struct {}{} + x := pi +} +// +// This comment should be associated with f1, with one blank line before the comment. +// +func f1() { + f0() + /* 1 */ + // 2 + /* 3 */ + /* 4 */ + f0() +} + + +func _() { +// this comment should be properly indented +} + + +func _(x int) int { + if x < 0 { // the tab printed before this comment's // must not affect the remaining lines + return -x // this statement should be properly indented + } + if x < 0 { /* the tab printed before this comment's /* must not affect the remaining lines */ + return -x // this statement should be properly indented + } + return x +} + + +func typeswitch(x interface{}) { + switch v := x.(type) { + case bool, int, float: + case string: + default: + } + + switch x.(type) { + } + + switch v0, ok := x.(int); v := x.(type) { + } + + switch v0, ok := x.(int); x.(type) { + case byte: // this comment should be on the same line as the keyword + // this comment should be normally indented + _ = 0 + case bool, int, float: + // this comment should be indented + case string: + default: + // this comment should be indented + } + // this comment should not be indented +} + +// +// Indentation of comments after possibly indented multi-line constructs +// (test cases for issue 3147). +// + +func _() { + s := 1 + + 2 +// should be indented like s +} + +func _() { + s := 1 + + 2 // comment + // should be indented like s +} + +func _() { + s := 1 + + 2 // comment + // should be indented like s + _ = 0 +} + +func _() { + s := 1 + + 2 + // should be indented like s + _ = 0 +} + +func _() { + s := 1 + + 2 + +// should be indented like s +} + +func _() { + s := 1 + + 2 // comment + + // should be indented like s +} + +func _() { + s := 1 + + 2 // comment + + // should be indented like s + _ = 0 +} + +func _() { + s := 1 + + 2 + + // should be indented like s + _ = 0 +} + +// Test case from issue 3147. +func f() { + templateText := "a" + // A + "b" + // B + "c" // C + + // should be aligned with f() + f() +} + +// Modified test case from issue 3147. +func f() { + templateText := "a" + // A + "b" + // B + "c" // C + + // may not be aligned with f() (source is not aligned) + f() +} + +// +// Test cases for alignment of lines in general comments. +// + +func _() { + /* freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + aligned line */ +} + +func _() { + /* freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + aligned line */ +} + + +func _() { + /* + freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line + aligned line */ +} + +func _() { + /* + freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line + aligned line */ +} + +func _() { + /* freestanding comment + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line */ +} + +func _() { + /* freestanding comment + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line */ +} + + +func _() { + /* + freestanding comment + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line */ +} + +func _() { + /* + freestanding comment + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line + */ +} + +func _() { + /* + freestanding comment + aligned line */ +} + +// Issue 9751. +func _() { + /*a string + + b string*/ + + /*A string + + + + Z string*/ + + /*a string + + b string + + c string*/ + + { + /*a string +b string*/ + + /*a string + +b string*/ + + /*a string + +b string + +c string*/ + } + + { + /*a string + b string*/ + + /*a string + + b string*/ + + /*a string + + b string + + c string*/ + } + + /* + */ + + /* + + */ + + /* + + * line + + */ +} + +/* + * line + * of + * stars + */ + +/* another line + * of + * stars */ + +/* and another line + * of + * stars */ + +/* a line of + * stars */ + +/* and another line of + * stars */ + +/* a line of stars +*/ + +/* and another line of +*/ + +/* a line of stars + */ + +/* and another line of + */ + +/* +aligned in middle +here + not here +*/ + +/* +blank line in middle: + +with no leading spaces on blank line. +*/ + +/* + aligned in middle + here + not here +*/ + +/* + blank line in middle: + + with no leading spaces on blank line. +*/ + +func _() { + /* + * line + * of + * stars + */ + + /* + aligned in middle + here + not here + */ + + /* + blank line in middle: + + with no leading spaces on blank line. +*/ +} + + +// Some interesting interspersed comments. +// See below for more common cases. +func _(/* this */x/* is *//* an */ int) { +} + +func _(/* no params - extra blank before and after comment */) {} +func _(a, b int /* params - no extra blank after comment */) {} + +func _() { f(/* no args - extra blank before and after comment */) } +func _() { f(a, b /* args - no extra blank after comment */) } + +func _() { + f(/* no args - extra blank before and after comment */) + f(a, b /* args - no extra blank after comment */) +} + +func (/* comment1 */ T /* comment2 */) _() {} + +func _() { /* "short-ish one-line functions with comments are formatted as multi-line functions */ } +func _() { x := 0; /* comment */ y = x /* comment */ } + +func _() { + _ = 0 + /* closing curly brace should be on new line */ } + +func _() { + _ = []int{0, 1 /* don't introduce a newline after this comment - was issue 1365 */} +} + +// Test cases from issue 1542: +// Comments must not be placed before commas and cause invalid programs. +func _() { + var a = []int{1, 2, /*jasldf*/ + } + _ = a +} + +func _() { + var a = []int{1, 2, /*jasldf + */ + } + _ = a +} + +func _() { + var a = []int{1, 2, // jasldf + } + _ = a +} + +// Test cases from issues 11274, 15137: +// Semicolon must not be lost when multiple statements are on the same line with a comment. +func _() { + x := 0 /**/; y := 1 +} + +func _() { + f(); f() + f(); /* comment */ f() + f() /* comment */; f() + f(); /* a */ /* b */ f() + f() /* a */ /* b */; f() + f() /* a */; /* b */ f() +} + +func _() { + f() /* a */ /* b */ } + +// Comments immediately adjacent to punctuation followed by a newline +// remain after the punctuation (looks better and permits alignment of +// comments). +func _() { + _ = T{ + 1, // comment after comma + 2, /* comment after comma */ + 3 , // comment after comma + } + _ = T{ + 1 ,// comment after comma + 2 ,/* comment after comma */ + 3,// comment after comma + } + _ = T{ + /* comment before literal */1, + 2/* comment before comma - ok to move after comma */, + 3 /* comment before comma - ok to move after comma */ , + } + + for + i=0;// comment after semicolon + i<9;/* comment after semicolon */ + i++{// comment after opening curly brace + } + + // TODO(gri) the last comment in this example should be aligned */ + for + i=0;// comment after semicolon + i<9/* comment before semicolon - ok to move after semicolon */; + i++ /* comment before opening curly brace */ { + } +} + +// If there is no newline following punctuation, commas move before the punctuation. +// This way, commas interspersed in lists stay with the respective expression. +func f(x/* comment */, y int, z int /* comment */, u, v, w int /* comment */) { + f(x /* comment */, y) + f(x /* comment */, + y) + f( + x /* comment */, + ) +} + +func g( + x int /* comment */, +) {} + +type _ struct { + a, b /* comment */, c int +} + +type _ struct { a, b /* comment */, c int } + +func _() { + for a /* comment */, b := range x { + } +} + +//extern foo +func foo() {} + +//export bar +func bar() {} + +// Print line directives correctly. + +// The following is a legal line directive. +//line foo:1 +func _() { + _ = 0 +// The following is a legal line directive. It must not be indented: +//line foo:2 + _ = 1 + +// The following is not a legal line directive (it doesn't start in column 1): + //line foo:2 + _ = 2 + +// The following is not a legal line directive (missing colon): +//line foo -3 + _ = 3 +} + +// Line comments with tabs +func _() { +var finput *bufio.Reader // input file +var stderr *bufio.Writer +var ftable *bufio.Writer // y.go file +var foutput *bufio.Writer // y.output file + +var oflag string // -o [y.go] - y.go file +var vflag string // -v [y.output] - y.output file +var lflag bool // -l - disable line directives +} + +// Trailing white space in comments should be trimmed +func _() { +// This comment has 4 blanks following that should be trimmed: +/* Each line of this comment has blanks or tabs following that should be trimmed: + line 2: + line 3: +*/ +} + +var _ = []T{/* lone comment */} + +var _ = []T{ +/* lone comment */ +} + +var _ = []T{ +// lone comments +// in composite lit +} + +var _ = [][]T{ + { + // lone comments + // in composite lit + }, +} + +// TODO: gofmt doesn't add these tabs; make it so that these golden +// tests run the printer in a way that it's exactly like gofmt. + +var _ = []T{// lone comment +} + +var _ = []T{// lone comments +// in composite lit +} + +func _() {} + +// +func _() {} + +/* This comment is the last entry in this file. It must be printed and should be followed by a newline */ diff --git a/platform/dbops/binaries/go/go/src/go/printer/testdata/comments.x b/platform/dbops/binaries/go/go/src/go/printer/testdata/comments.x new file mode 100644 index 0000000000000000000000000000000000000000..5d088ab2c3802a9ef3b5b7a9d8af36dfcf7b2346 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/printer/testdata/comments.x @@ -0,0 +1,55 @@ +// This is a package for testing comment placement by go/printer. +package main + +// The SZ struct; it is empty. +type SZ struct{} + +// The S0 struct; no field is exported. +type S0 struct { + // contains filtered or unexported fields +} + +// The S1 struct; some fields are not exported. +type S1 struct { + S0 + A, B, C float // 3 exported fields + D int // 2 unexported fields + // contains filtered or unexported fields +} + +// The S2 struct; all fields are exported. +type S2 struct { + S1 + A, B, C float // 3 exported fields +} + +// The IZ interface; it is empty. +type SZ interface{} + +// The I0 interface; no method is exported. +type I0 interface { + // contains filtered or unexported methods +} + +// The I1 interface; some methods are not exported. +type I1 interface { + I0 + F(x float) float // exported methods + // contains filtered or unexported methods +} + +// The I2 interface; all methods are exported. +type I2 interface { + I0 + F(x float) float // exported method + G(x float) float // exported method +} + +// The S3 struct; all comments except for the last one must appear in the export. +type S3 struct { + // lead comment for F1 + F1 int // line comment for F1 + // lead comment for F2 + F2 int // line comment for F2 + // contains filtered or unexported fields +} diff --git a/platform/dbops/binaries/go/go/src/go/printer/testdata/comments2.golden b/platform/dbops/binaries/go/go/src/go/printer/testdata/comments2.golden new file mode 100644 index 0000000000000000000000000000000000000000..83213d1a9db50cf7977037581bc62eeb5edcb0a8 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/printer/testdata/comments2.golden @@ -0,0 +1,163 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This is a package for testing comment placement by go/printer. +package main + +// Test cases for idempotent comment formatting (was issue 1835). +/* +c1a +*/ +/* + c1b +*/ +/* foo +c1c +*/ +/* foo + c1d +*/ +/* +c1e +foo */ +/* + c1f + foo */ + +func f() { + /* + c2a + */ + /* + c2b + */ + /* foo + c2c + */ + /* foo + c2d + */ + /* + c2e + foo */ + /* + c2f + foo */ +} + +func g() { + /* + c3a + */ + /* + c3b + */ + /* foo + c3c + */ + /* foo + c3d + */ + /* + c3e + foo */ + /* + c3f + foo */ +} + +// Test case taken literally from issue 1835. +func main() { + /* + prints test 5 times + */ + for i := 0; i < 5; i++ { + println("test") + } +} + +func issue5623() { +L: + _ = yyyyyyyyyyyyyyyy // comment - should be aligned + _ = xxxxxxxxxxxxxxxxxxxxxxxxxxxx /* comment */ + + _ = yyyyyyyyyyyyyyyy /* comment - should be aligned */ + _ = xxxxxxxxxxxxxxxxxxxxxxxxxxxx // comment + +LLLLLLL: + _ = yyyyyyyyyyyyyyyy // comment - should be aligned + _ = xxxxxxxxxxxxxxxxxxxxxxxxxxxx // comment + +LL: +LLLLL: + _ = xxxxxxxxxxxxxxxxxxxxxxxxxxxx /* comment */ + _ = yyyyyyyyyyyyyyyy /* comment - should be aligned */ + + _ = xxxxxxxxxxxxxxxxxxxxxxxxxxxx // comment + _ = yyyyyyyyyyyyyyyy // comment - should be aligned + + // test case from issue +label: + mask := uint64(1)<>4 + _ = "foo" + s + _ = s + "foo" + _ = 'a' + 'b' + _ = len(s) / 2 + _ = len(t0.x) / a + + // spaces around expressions of different precedence or expressions containing spaces + _ = a + -b + _ = a - ^b + _ = a / *p + _ = a + b*c + _ = 1 + b*c + _ = a + 2*c + _ = a + c*2 + _ = 1 + 2*3 + _ = s[1 : 2*3] + _ = s[a : b-c] + _ = s[0:] + _ = s[a+b] + _ = s[:b-c] + _ = s[a+b:] + _ = a[a< b + _ = a >= b + _ = a < b + _ = a <= b + _ = a < b && c > d + _ = a < b || c > d + + // spaces around "long" operands + _ = a + longIdentifier1 + _ = longIdentifier1 + a + _ = longIdentifier1 + longIdentifier2*longIdentifier3 + _ = s + "a longer string" + + // some selected cases + _ = a + t0.x + _ = a + t0.x + t1.x*t2.x + _ = a + b + c + d + e + 2*3 + _ = a + b + c + 2*3 + d + e + _ = (a + b + c) * 2 + _ = a - b + c - d + (a + b + c) + d&e + _ = under_bar - 1 + _ = Open(dpath+"/file", O_WRONLY|O_CREAT, 0666) + _ = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx) + + // test case for issue 8021 + // want: + // ([]bool{})[([]int{})[((1)+(((1)+((((1)*(((1)+(1))+(1)))+(1))*(1)))+(1)))]] + _ = ([]bool{})[([]int{})[((1)+(((1)+((((1)*(((1)+(1))+(1)))+(1))*(1)))+(1)))]] + + // the parser does not restrict expressions that may appear as statements + true + 42 + "foo" + x + (x) + a + b + a + b + c + a + (b * c) + a + (b / c) + 1 + a + a + 1 + s[a] + x << 1 + (s[0] << 1) & 0xf + "foo" + s + x == y + x < y || z > 42 +} + +// slice expressions with cap +func _() { + _ = x[a:b:c] + _ = x[a : b : c+d] + _ = x[a : b+d : c] + _ = x[a : b+d : c+d] + _ = x[a+d : b : c] + _ = x[a+d : b : c+d] + _ = x[a+d : b+d : c] + _ = x[a+d : b+d : c+d] + + _ = x[:b:c] + _ = x[: b : c+d] + _ = x[: b+d : c] + _ = x[: b+d : c+d] +} + +func issue22111() { + _ = x[:] + + _ = x[:b] + _ = x[:b+1] + + _ = x[a:] + _ = x[a+1:] + + _ = x[a:b] + _ = x[a+1 : b] + _ = x[a : b+1] + _ = x[a+1 : b+1] + + _ = x[:b:c] + _ = x[: b+1 : c] + _ = x[: b : c+1] + _ = x[: b+1 : c+1] + + _ = x[a:b:c] + _ = x[a+1 : b : c] + _ = x[a : b+1 : c] + _ = x[a+1 : b+1 : c] + _ = x[a : b : c+1] + _ = x[a+1 : b : c+1] + _ = x[a : b+1 : c+1] + _ = x[a+1 : b+1 : c+1] +} + +func _() { + _ = a + b + _ = a + b + c + _ = a + b*c + _ = a + (b * c) + _ = (a + b) * c + _ = a + (b * c * d) + _ = a + (b*c + d) + + _ = 1 << x + _ = -1 << x + _ = 1<>4 + + b.buf = b.buf[0 : b.off+m+n] + b.buf = b.buf[0 : b.off+m*n] + f(b.buf[0 : b.off+m+n]) + + signed += ' ' * 8 + tw.octal(header[148:155], chksum) + + _ = x > 0 && i >= 0 + + x1, x0 := x>>w2, x&m2 + z0 = t1<>w2) >> w2 + q1, r1 := x1/d1, x1%d1 + r1 = r1*b2 | x0>>w2 + x1 = (x1 << z) | (x0 >> (uint(w) - z)) + x1 = x1<>(uint(w)-z) + + _ = buf[0 : len(buf)+1] + _ = buf[0 : n+1] + + a, b = b, a + a = b + c + a = b*c + d + _ = a*b + c + _ = a - b - c + _ = a - (b - c) + _ = a - b*c + _ = a - (b * c) + _ = a * b / c + _ = a / *b + _ = x[a|^b] + _ = x[a / *b] + _ = a & ^b + _ = a + +b + _ = a - -b + _ = x[a*-b] + _ = x[a + +b] + _ = x ^ y ^ z + _ = b[a>>24] ^ b[(a>>16)&0xFF] ^ b[(a>>8)&0xFF] ^ b[a&0xFF] + _ = len(longVariableName) * 2 + + _ = token(matchType + xlength<> 4 + _ = "foo"+s + _ = s+"foo" + _ = 'a'+'b' + _ = len(s)/2 + _ = len(t0.x)/a + + // spaces around expressions of different precedence or expressions containing spaces + _ = a + -b + _ = a - ^b + _ = a / *p + _ = a + b*c + _ = 1 + b*c + _ = a + 2*c + _ = a + c*2 + _ = 1 + 2*3 + _ = s[1 : 2*3] + _ = s[a : b-c] + _ = s[0:] + _ = s[a+b] + _ = s[: b-c] + _ = s[a+b :] + _ = a[a< b + _ = a >= b + _ = a < b + _ = a <= b + _ = a < b && c > d + _ = a < b || c > d + + // spaces around "long" operands + _ = a + longIdentifier1 + _ = longIdentifier1 + a + _ = longIdentifier1 + longIdentifier2 * longIdentifier3 + _ = s + "a longer string" + + // some selected cases + _ = a + t0.x + _ = a + t0.x + t1.x * t2.x + _ = a + b + c + d + e + 2*3 + _ = a + b + c + 2*3 + d + e + _ = (a+b+c)*2 + _ = a - b + c - d + (a+b+c) + d&e + _ = under_bar-1 + _ = Open(dpath + "/file", O_WRONLY | O_CREAT, 0666) + _ = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx) + + // test case for issue 8021 + // want: + // ([]bool{})[([]int{})[((1)+(((1)+((((1)*(((1)+(1))+(1)))+(1))*(1)))+(1)))]] + _ = ([]bool{})[([]int{})[((1) + (((((1) + (((((((1) * (((((1) + (1))) + (1))))) + (1))) * (1))))) + (1))))]] + + // the parser does not restrict expressions that may appear as statements + true + 42 + "foo" + x + (x) + a+b + a+b+c + a+(b*c) + a+(b/c) + 1+a + a+1 + s[a] + x<<1 + (s[0]<<1)&0xf + "foo"+s + x == y + x < y || z > 42 +} + + +// slice expressions with cap +func _() { + _ = x[a:b:c] + _ = x[a:b:c+d] + _ = x[a:b+d:c] + _ = x[a:b+d:c+d] + _ = x[a+d:b:c] + _ = x[a+d:b:c+d] + _ = x[a+d:b+d:c] + _ = x[a+d:b+d:c+d] + + _ = x[:b:c] + _ = x[:b:c+d] + _ = x[:b+d:c] + _ = x[:b+d:c+d] +} + +func issue22111() { + _ = x[:] + + _ = x[:b] + _ = x[:b+1] + + _ = x[a:] + _ = x[a+1:] + + _ = x[a:b] + _ = x[a+1:b] + _ = x[a:b+1] + _ = x[a+1:b+1] + + _ = x[:b:c] + _ = x[:b+1:c] + _ = x[:b:c+1] + _ = x[:b+1:c+1] + + _ = x[a:b:c] + _ = x[a+1:b:c] + _ = x[a:b+1:c] + _ = x[a+1:b+1:c] + _ = x[a:b:c+1] + _ = x[a+1:b:c+1] + _ = x[a:b+1:c+1] + _ = x[a+1:b+1:c+1] +} + +func _() { + _ = a+b + _ = a+b+c + _ = a+b*c + _ = a+(b*c) + _ = (a+b)*c + _ = a+(b*c*d) + _ = a+(b*c+d) + + _ = 1<>4 + + b.buf = b.buf[0:b.off+m+n] + b.buf = b.buf[0:b.off+m*n] + f(b.buf[0:b.off+m+n]) + + signed += ' '*8 + tw.octal(header[148:155], chksum) + + _ = x > 0 && i >= 0 + + x1, x0 := x>>w2, x&m2 + z0 = t1<>w2)>>w2 + q1, r1 := x1/d1, x1%d1 + r1 = r1*b2 | x0>>w2 + x1 = (x1<>(uint(w)-z)) + x1 = x1<>(uint(w)-z) + + _ = buf[0:len(buf)+1] + _ = buf[0:n+1] + + a,b = b,a + a = b+c + a = b*c+d + _ = a*b+c + _ = a-b-c + _ = a-(b-c) + _ = a-b*c + _ = a-(b*c) + _ = a*b/c + _ = a/ *b + _ = x[a|^b] + _ = x[a/ *b] + _ = a& ^b + _ = a+ +b + _ = a- -b + _ = x[a*-b] + _ = x[a+ +b] + _ = x^y^z + _ = b[a>>24] ^ b[(a>>16)&0xFF] ^ b[(a>>8)&0xFF] ^ b[a&0xFF] + _ = len(longVariableName)*2 + + _ = token(matchType + xlength< /tmp/16gig.txt + // tar -b 1 -c -f- /tmp/16gig.txt | dd bs=512 count=8 > writer-big.tar + &writerTest{ + file: "testdata/writer-big.tar", + entries: []*writerTestEntry{ + &writerTestEntry{ + header: &Header{ + Name: "tmp/16gig.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 16 << 30, + Mtime: 1254699560, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + // no contents + }, + }, + }, +} + +type untarTest struct { + file string + headers []*Header +} + +var untarTests = []*untarTest{ + &untarTest{ + file: "testdata/gnu.tar", + headers: []*Header{ + &Header{ + Name: "small.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 5, + Mtime: 1244428340, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + &Header{ + Name: "small2.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 11, + Mtime: 1244436044, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + }, + }, + &untarTest{ + file: "testdata/star.tar", + headers: []*Header{ + &Header{ + Name: "small.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 5, + Mtime: 1244592783, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + Atime: 1244592783, + Ctime: 1244592783, + }, + &Header{ + Name: "small2.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 11, + Mtime: 1244592783, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + Atime: 1244592783, + Ctime: 1244592783, + }, + }, + }, + &untarTest{ + file: "testdata/v7.tar", + headers: []*Header{ + &Header{ + Name: "small.txt", + Mode: 0444, + Uid: 73025, + Gid: 5000, + Size: 5, + Mtime: 1244593104, + Typeflag: '\x00', + }, + &Header{ + Name: "small2.txt", + Mode: 0444, + Uid: 73025, + Gid: 5000, + Size: 11, + Mtime: 1244593104, + Typeflag: '\x00', + }, + }, + }, +} + +var facts = map[int]string{ + 0: "1", + 1: "1", + 2: "2", + 10: "3628800", + 20: "2432902008176640000", + 100: "933262154439441526816992388562667004907159682643816214685929" + + "638952175999932299156089414639761565182862536979208272237582" + + "51185210916864000000000000000000000000", +} + +func usage() { + fmt.Fprintf(os.Stderr, + // TODO(gri): the 2nd string of this string list should not be indented + "usage: godoc package [name ...]\n"+ + " godoc -http=:6060\n") + flag.PrintDefaults() + os.Exit(2) +} + +func TestReader(t *testing.T) { +testLoop: + for i, test := range untarTests { + f, err := os.Open(test.file, os.O_RDONLY, 0444) + if err != nil { + t.Errorf("test %d: Unexpected error: %v", i, err) + continue + } + tr := NewReader(f) + for j, header := range test.headers { + hdr, err := tr.Next() + if err != nil || hdr == nil { + t.Errorf("test %d, entry %d: Didn't get entry: %v", i, j, err) + f.Close() + continue testLoop + } + if !reflect.DeepEqual(hdr, header) { + t.Errorf("test %d, entry %d: Incorrect header:\nhave %+v\nwant %+v", + i, j, *hdr, *header) + } + } + hdr, err := tr.Next() + if hdr != nil || err != nil { + t.Errorf("test %d: Unexpected entry or error: hdr=%v err=%v", i, err) + } + f.Close() + } +} + +// Respect line breaks in function calls. +func _() { + f(x) + f(x, + x) + f(x, + x, + ) + f( + x, + x) + f( + x, + x, + ) +} + +// Respect line breaks in function declarations. +func _(x T) {} +func _(x T, + y T) { +} +func _(x T, + y T, +) { +} +func _( + x T, + y T) { +} +func _( + x T, + y T, +) { +} + +// Example from issue #2597. +func ManageStatus0( + in <-chan *Status, + req <-chan Request, + stat chan<- *TargetInfo, + TargetHistorySize int) { +} + +func ManageStatus1( + in <-chan *Status, + req <-chan Request, + stat chan<- *TargetInfo, + TargetHistorySize int, +) { +} + +// Example from issue #9064. +func (y *y) xerrors() error { + _ = "xerror.test" //TODO- + _ = []byte(` +foo bar foo bar foo bar +`) //TODO- +} + +func _() { + _ = "abc" // foo + _ = `abc_0123456789_` // foo +} + +func _() { + _ = "abc" // foo + _ = `abc +0123456789 +` // foo +} + +// There should be exactly one linebreak after this comment. diff --git a/platform/dbops/binaries/go/go/src/go/printer/testdata/linebreaks.input b/platform/dbops/binaries/go/go/src/go/printer/testdata/linebreaks.input new file mode 100644 index 0000000000000000000000000000000000000000..9e714f3eff40f075a3f2ebd820bf6fa6a5fe64d3 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/printer/testdata/linebreaks.input @@ -0,0 +1,291 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package linebreaks + +import ( + "bytes" + "fmt" + "io" + "os" + "reflect" + "strings" + "testing" +) + +type writerTestEntry struct { + header *Header + contents string +} + +type writerTest struct { + file string // filename of expected output + entries []*writerTestEntry +} + +var writerTests = []*writerTest{ + &writerTest{ + file: "testdata/writer.tar", + entries: []*writerTestEntry{ + &writerTestEntry{ + header: &Header{ + Name: "small.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 5, + Mtime: 1246508266, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + contents: "Kilts", + }, + &writerTestEntry{ + header: &Header{ + Name: "small2.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 11, + Mtime: 1245217492, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + contents: "Google.com\n", + }, + }, + }, + // The truncated test file was produced using these commands: + // dd if=/dev/zero bs=1048576 count=16384 > /tmp/16gig.txt + // tar -b 1 -c -f- /tmp/16gig.txt | dd bs=512 count=8 > writer-big.tar + &writerTest{ + file: "testdata/writer-big.tar", + entries: []*writerTestEntry{ + &writerTestEntry{ + header: &Header{ + Name: "tmp/16gig.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 16 << 30, + Mtime: 1254699560, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + // no contents + }, + }, + }, +} + +type untarTest struct { + file string + headers []*Header +} + +var untarTests = []*untarTest{ + &untarTest{ + file: "testdata/gnu.tar", + headers: []*Header{ + &Header{ + Name: "small.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 5, + Mtime: 1244428340, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + &Header{ + Name: "small2.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 11, + Mtime: 1244436044, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + }, + }, + &untarTest{ + file: "testdata/star.tar", + headers: []*Header{ + &Header{ + Name: "small.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 5, + Mtime: 1244592783, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + Atime: 1244592783, + Ctime: 1244592783, + }, + &Header{ + Name: "small2.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 11, + Mtime: 1244592783, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + Atime: 1244592783, + Ctime: 1244592783, + }, + }, + }, + &untarTest{ + file: "testdata/v7.tar", + headers: []*Header{ + &Header{ + Name: "small.txt", + Mode: 0444, + Uid: 73025, + Gid: 5000, + Size: 5, + Mtime: 1244593104, + Typeflag: '\x00', + }, + &Header{ + Name: "small2.txt", + Mode: 0444, + Uid: 73025, + Gid: 5000, + Size: 11, + Mtime: 1244593104, + Typeflag: '\x00', + }, + }, + }, +} + +var facts = map[int] string { + 0: "1", + 1: "1", + 2: "2", + 10: "3628800", + 20: "2432902008176640000", + 100: "933262154439441526816992388562667004907159682643816214685929" + + "638952175999932299156089414639761565182862536979208272237582" + + "51185210916864000000000000000000000000", +} + +func usage() { + fmt.Fprintf(os.Stderr, + // TODO(gri): the 2nd string of this string list should not be indented + "usage: godoc package [name ...]\n" + + " godoc -http=:6060\n") + flag.PrintDefaults() + os.Exit(2) +} + +func TestReader(t *testing.T) { +testLoop: + for i, test := range untarTests { + f, err := os.Open(test.file, os.O_RDONLY, 0444) + if err != nil { + t.Errorf("test %d: Unexpected error: %v", i, err) + continue + } + tr := NewReader(f) + for j, header := range test.headers { + hdr, err := tr.Next() + if err != nil || hdr == nil { + t.Errorf("test %d, entry %d: Didn't get entry: %v", i, j, err) + f.Close() + continue testLoop + } + if !reflect.DeepEqual(hdr, header) { + t.Errorf("test %d, entry %d: Incorrect header:\nhave %+v\nwant %+v", + i, j, *hdr, *header) + } + } + hdr, err := tr.Next() + if hdr != nil || err != nil { + t.Errorf("test %d: Unexpected entry or error: hdr=%v err=%v", i, err) + } + f.Close() + } +} + +// Respect line breaks in function calls. +func _() { + f(x) + f(x, + x) + f(x, + x, + ) + f( + x, + x) + f( + x, + x, + ) +} + +// Respect line breaks in function declarations. +func _(x T) {} +func _(x T, + y T) {} +func _(x T, + y T, +) {} +func _( + x T, + y T) {} +func _( + x T, + y T, +) {} + +// Example from issue #2597. +func ManageStatus0( + in <-chan *Status, + req <-chan Request, + stat chan<- *TargetInfo, + TargetHistorySize int) { +} + +func ManageStatus1( + in <-chan *Status, + req <-chan Request, + stat chan<- *TargetInfo, + TargetHistorySize int, +) { +} + +// Example from issue #9064. +func (y *y) xerrors() error { + _ = "xerror.test" //TODO- + _ = []byte(` +foo bar foo bar foo bar +`) //TODO- +} + +func _() { + _ = "abc" // foo + _ = `abc_0123456789_` // foo +} + +func _() { + _ = "abc" // foo + _ = `abc +0123456789 +` // foo +} + +// There should be exactly one linebreak after this comment. diff --git a/platform/dbops/binaries/go/go/src/go/printer/testdata/parser.go b/platform/dbops/binaries/go/go/src/go/printer/testdata/parser.go new file mode 100644 index 0000000000000000000000000000000000000000..11795b42802a50cf6fbcaddc95cfc656ec37703f --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/printer/testdata/parser.go @@ -0,0 +1,2140 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package parser implements a parser for Go source files. Input may be +// provided in a variety of forms (see the various Parse* functions); the +// output is an abstract syntax tree (AST) representing the Go source. The +// parser is invoked through one of the Parse* functions. + +package parser + +import ( + "fmt" + "go/ast" + "go/scanner" + "go/token" +) + +// The mode parameter to the Parse* functions is a set of flags (or 0). +// They control the amount of source code parsed and other optional +// parser functionality. +const ( + PackageClauseOnly uint = 1 << iota // parsing stops after package clause + ImportsOnly // parsing stops after import declarations + ParseComments // parse comments and add them to AST + Trace // print a trace of parsed productions + DeclarationErrors // report declaration errors +) + +// The parser structure holds the parser's internal state. +type parser struct { + file *token.File + scanner.ErrorVector + scanner scanner.Scanner + + // Tracing/debugging + mode uint // parsing mode + trace bool // == (mode & Trace != 0) + indent uint // indentation used for tracing output + + // Comments + comments []*ast.CommentGroup + leadComment *ast.CommentGroup // last lead comment + lineComment *ast.CommentGroup // last line comment + + // Next token + pos token.Pos // token position + tok token.Token // one token look-ahead + lit string // token literal + + // Non-syntactic parser control + exprLev int // < 0: in control clause, >= 0: in expression + + // Ordinary identifier scopes + pkgScope *ast.Scope // pkgScope.Outer == nil + topScope *ast.Scope // top-most scope; may be pkgScope + unresolved []*ast.Ident // unresolved identifiers + imports []*ast.ImportSpec // list of imports + + // Label scope + // (maintained by open/close LabelScope) + labelScope *ast.Scope // label scope for current function + targetStack [][]*ast.Ident // stack of unresolved labels +} + +// scannerMode returns the scanner mode bits given the parser's mode bits. +func scannerMode(mode uint) uint { + var m uint = scanner.InsertSemis + if mode&ParseComments != 0 { + m |= scanner.ScanComments + } + return m +} + +func (p *parser) init(fset *token.FileSet, filename string, src []byte, mode uint) { + p.file = fset.AddFile(filename, fset.Base(), len(src)) + p.scanner.Init(p.file, src, p, scannerMode(mode)) + + p.mode = mode + p.trace = mode&Trace != 0 // for convenience (p.trace is used frequently) + + p.next() + + // set up the pkgScope here (as opposed to in parseFile) because + // there are other parser entry points (ParseExpr, etc.) + p.openScope() + p.pkgScope = p.topScope + + // for the same reason, set up a label scope + p.openLabelScope() +} + +// ---------------------------------------------------------------------------- +// Scoping support + +func (p *parser) openScope() { + p.topScope = ast.NewScope(p.topScope) +} + +func (p *parser) closeScope() { + p.topScope = p.topScope.Outer +} + +func (p *parser) openLabelScope() { + p.labelScope = ast.NewScope(p.labelScope) + p.targetStack = append(p.targetStack, nil) +} + +func (p *parser) closeLabelScope() { + // resolve labels + n := len(p.targetStack) - 1 + scope := p.labelScope + for _, ident := range p.targetStack[n] { + ident.Obj = scope.Lookup(ident.Name) + if ident.Obj == nil && p.mode&DeclarationErrors != 0 { + p.error(ident.Pos(), fmt.Sprintf("label %s undefined", ident.Name)) + } + } + // pop label scope + p.targetStack = p.targetStack[0:n] + p.labelScope = p.labelScope.Outer +} + +func (p *parser) declare(decl any, scope *ast.Scope, kind ast.ObjKind, idents ...*ast.Ident) { + for _, ident := range idents { + assert(ident.Obj == nil, "identifier already declared or resolved") + if ident.Name != "_" { + obj := ast.NewObj(kind, ident.Name) + // remember the corresponding declaration for redeclaration + // errors and global variable resolution/typechecking phase + obj.Decl = decl + if alt := scope.Insert(obj); alt != nil && p.mode&DeclarationErrors != 0 { + prevDecl := "" + if pos := alt.Pos(); pos.IsValid() { + prevDecl = fmt.Sprintf("\n\tprevious declaration at %s", p.file.Position(pos)) + } + p.error(ident.Pos(), fmt.Sprintf("%s redeclared in this block%s", ident.Name, prevDecl)) + } + ident.Obj = obj + } + } +} + +func (p *parser) shortVarDecl(idents []*ast.Ident) { + // Go spec: A short variable declaration may redeclare variables + // provided they were originally declared in the same block with + // the same type, and at least one of the non-blank variables is new. + n := 0 // number of new variables + for _, ident := range idents { + assert(ident.Obj == nil, "identifier already declared or resolved") + if ident.Name != "_" { + obj := ast.NewObj(ast.Var, ident.Name) + // short var declarations cannot have redeclaration errors + // and are not global => no need to remember the respective + // declaration + alt := p.topScope.Insert(obj) + if alt == nil { + n++ // new declaration + alt = obj + } + ident.Obj = alt + } + } + if n == 0 && p.mode&DeclarationErrors != 0 { + p.error(idents[0].Pos(), "no new variables on left side of :=") + } +} + +// The unresolved object is a sentinel to mark identifiers that have been added +// to the list of unresolved identifiers. The sentinel is only used for verifying +// internal consistency. +var unresolved = new(ast.Object) + +func (p *parser) resolve(x ast.Expr) { + // nothing to do if x is not an identifier or the blank identifier + ident, _ := x.(*ast.Ident) + if ident == nil { + return + } + assert(ident.Obj == nil, "identifier already declared or resolved") + if ident.Name == "_" { + return + } + // try to resolve the identifier + for s := p.topScope; s != nil; s = s.Outer { + if obj := s.Lookup(ident.Name); obj != nil { + ident.Obj = obj + return + } + } + // all local scopes are known, so any unresolved identifier + // must be found either in the file scope, package scope + // (perhaps in another file), or universe scope --- collect + // them so that they can be resolved later + ident.Obj = unresolved + p.unresolved = append(p.unresolved, ident) +} + +// ---------------------------------------------------------------------------- +// Parsing support + +func (p *parser) printTrace(a ...any) { + const dots = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " + + ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " + const n = uint(len(dots)) + pos := p.file.Position(p.pos) + fmt.Printf("%5d:%3d: ", pos.Line, pos.Column) + i := 2 * p.indent + for ; i > n; i -= n { + fmt.Print(dots) + } + fmt.Print(dots[0:i]) + fmt.Println(a...) +} + +func trace(p *parser, msg string) *parser { + p.printTrace(msg, "(") + p.indent++ + return p +} + +// Usage pattern: defer un(trace(p, "...")); +func un(p *parser) { + p.indent-- + p.printTrace(")") +} + +// Advance to the next token. +func (p *parser) next0() { + // Because of one-token look-ahead, print the previous token + // when tracing as it provides a more readable output. The + // very first token (!p.pos.IsValid()) is not initialized + // (it is token.ILLEGAL), so don't print it. + if p.trace && p.pos.IsValid() { + s := p.tok.String() + switch { + case p.tok.IsLiteral(): + p.printTrace(s, p.lit) + case p.tok.IsOperator(), p.tok.IsKeyword(): + p.printTrace("\"" + s + "\"") + default: + p.printTrace(s) + } + } + + p.pos, p.tok, p.lit = p.scanner.Scan() +} + +// Consume a comment and return it and the line on which it ends. +func (p *parser) consumeComment() (comment *ast.Comment, endline int) { + // /*-style comments may end on a different line than where they start. + // Scan the comment for '\n' chars and adjust endline accordingly. + endline = p.file.Line(p.pos) + if p.lit[1] == '*' { + // don't use range here - no need to decode Unicode code points + for i := 0; i < len(p.lit); i++ { + if p.lit[i] == '\n' { + endline++ + } + } + } + + comment = &ast.Comment{p.pos, p.lit} + p.next0() + + return +} + +// Consume a group of adjacent comments, add it to the parser's +// comments list, and return it together with the line at which +// the last comment in the group ends. An empty line or non-comment +// token terminates a comment group. +func (p *parser) consumeCommentGroup() (comments *ast.CommentGroup, endline int) { + var list []*ast.Comment + endline = p.file.Line(p.pos) + for p.tok == token.COMMENT && endline+1 >= p.file.Line(p.pos) { + var comment *ast.Comment + comment, endline = p.consumeComment() + list = append(list, comment) + } + + // add comment group to the comments list + comments = &ast.CommentGroup{list} + p.comments = append(p.comments, comments) + + return +} + +// Advance to the next non-comment token. In the process, collect +// any comment groups encountered, and remember the last lead and +// line comments. +// +// A lead comment is a comment group that starts and ends in a +// line without any other tokens and that is followed by a non-comment +// token on the line immediately after the comment group. +// +// A line comment is a comment group that follows a non-comment +// token on the same line, and that has no tokens after it on the line +// where it ends. +// +// Lead and line comments may be considered documentation that is +// stored in the AST. +func (p *parser) next() { + p.leadComment = nil + p.lineComment = nil + line := p.file.Line(p.pos) // current line + p.next0() + + if p.tok == token.COMMENT { + var comment *ast.CommentGroup + var endline int + + if p.file.Line(p.pos) == line { + // The comment is on same line as the previous token; it + // cannot be a lead comment but may be a line comment. + comment, endline = p.consumeCommentGroup() + if p.file.Line(p.pos) != endline { + // The next token is on a different line, thus + // the last comment group is a line comment. + p.lineComment = comment + } + } + + // consume successor comments, if any + endline = -1 + for p.tok == token.COMMENT { + comment, endline = p.consumeCommentGroup() + } + + if endline+1 == p.file.Line(p.pos) { + // The next token is following on the line immediately after the + // comment group, thus the last comment group is a lead comment. + p.leadComment = comment + } + } +} + +func (p *parser) error(pos token.Pos, msg string) { + p.Error(p.file.Position(pos), msg) +} + +func (p *parser) errorExpected(pos token.Pos, msg string) { + msg = "expected " + msg + if pos == p.pos { + // the error happened at the current position; + // make the error message more specific + if p.tok == token.SEMICOLON && p.lit[0] == '\n' { + msg += ", found newline" + } else { + msg += ", found '" + p.tok.String() + "'" + if p.tok.IsLiteral() { + msg += " " + p.lit + } + } + } + p.error(pos, msg) +} + +func (p *parser) expect(tok token.Token) token.Pos { + pos := p.pos + if p.tok != tok { + p.errorExpected(pos, "'"+tok.String()+"'") + } + p.next() // make progress + return pos +} + +func (p *parser) expectSemi() { + if p.tok != token.RPAREN && p.tok != token.RBRACE { + p.expect(token.SEMICOLON) + } +} + +func assert(cond bool, msg string) { + if !cond { + panic("go/parser internal error: " + msg) + } +} + +// ---------------------------------------------------------------------------- +// Identifiers + +func (p *parser) parseIdent() *ast.Ident { + pos := p.pos + name := "_" + if p.tok == token.IDENT { + name = p.lit + p.next() + } else { + p.expect(token.IDENT) // use expect() error handling + } + return &ast.Ident{pos, name, nil} +} + +func (p *parser) parseIdentList() (list []*ast.Ident) { + if p.trace { + defer un(trace(p, "IdentList")) + } + + list = append(list, p.parseIdent()) + for p.tok == token.COMMA { + p.next() + list = append(list, p.parseIdent()) + } + + return +} + +// ---------------------------------------------------------------------------- +// Common productions + +// If lhs is set, result list elements which are identifiers are not resolved. +func (p *parser) parseExprList(lhs bool) (list []ast.Expr) { + if p.trace { + defer un(trace(p, "ExpressionList")) + } + + list = append(list, p.parseExpr(lhs)) + for p.tok == token.COMMA { + p.next() + list = append(list, p.parseExpr(lhs)) + } + + return +} + +func (p *parser) parseLhsList() []ast.Expr { + list := p.parseExprList(true) + switch p.tok { + case token.DEFINE: + // lhs of a short variable declaration + p.shortVarDecl(p.makeIdentList(list)) + case token.COLON: + // lhs of a label declaration or a communication clause of a select + // statement (parseLhsList is not called when parsing the case clause + // of a switch statement): + // - labels are declared by the caller of parseLhsList + // - for communication clauses, if there is a stand-alone identifier + // followed by a colon, we have a syntax error; there is no need + // to resolve the identifier in that case + default: + // identifiers must be declared elsewhere + for _, x := range list { + p.resolve(x) + } + } + return list +} + +func (p *parser) parseRhsList() []ast.Expr { + return p.parseExprList(false) +} + +// ---------------------------------------------------------------------------- +// Types + +func (p *parser) parseType() ast.Expr { + if p.trace { + defer un(trace(p, "Type")) + } + + typ := p.tryType() + + if typ == nil { + pos := p.pos + p.errorExpected(pos, "type") + p.next() // make progress + return &ast.BadExpr{pos, p.pos} + } + + return typ +} + +// If the result is an identifier, it is not resolved. +func (p *parser) parseTypeName() ast.Expr { + if p.trace { + defer un(trace(p, "TypeName")) + } + + ident := p.parseIdent() + // don't resolve ident yet - it may be a parameter or field name + + if p.tok == token.PERIOD { + // ident is a package name + p.next() + p.resolve(ident) + sel := p.parseIdent() + return &ast.SelectorExpr{ident, sel} + } + + return ident +} + +func (p *parser) parseArrayType(ellipsisOk bool) ast.Expr { + if p.trace { + defer un(trace(p, "ArrayType")) + } + + lbrack := p.expect(token.LBRACK) + var len ast.Expr + if ellipsisOk && p.tok == token.ELLIPSIS { + len = &ast.Ellipsis{p.pos, nil} + p.next() + } else if p.tok != token.RBRACK { + len = p.parseRhs() + } + p.expect(token.RBRACK) + elt := p.parseType() + + return &ast.ArrayType{lbrack, len, elt} +} + +func (p *parser) makeIdentList(list []ast.Expr) []*ast.Ident { + idents := make([]*ast.Ident, len(list)) + for i, x := range list { + ident, isIdent := x.(*ast.Ident) + if !isIdent { + pos := x.(ast.Expr).Pos() + p.errorExpected(pos, "identifier") + ident = &ast.Ident{pos, "_", nil} + } + idents[i] = ident + } + return idents +} + +func (p *parser) parseFieldDecl(scope *ast.Scope) *ast.Field { + if p.trace { + defer un(trace(p, "FieldDecl")) + } + + doc := p.leadComment + + // fields + list, typ := p.parseVarList(false) + + // optional tag + var tag *ast.BasicLit + if p.tok == token.STRING { + tag = &ast.BasicLit{p.pos, p.tok, p.lit} + p.next() + } + + // analyze case + var idents []*ast.Ident + if typ != nil { + // IdentifierList Type + idents = p.makeIdentList(list) + } else { + // ["*"] TypeName (AnonymousField) + typ = list[0] // we always have at least one element + p.resolve(typ) + if n := len(list); n > 1 || !isTypeName(deref(typ)) { + pos := typ.Pos() + p.errorExpected(pos, "anonymous field") + typ = &ast.BadExpr{pos, list[n-1].End()} + } + } + + p.expectSemi() // call before accessing p.linecomment + + field := &ast.Field{doc, idents, typ, tag, p.lineComment} + p.declare(field, scope, ast.Var, idents...) + + return field +} + +func (p *parser) parseStructType() *ast.StructType { + if p.trace { + defer un(trace(p, "StructType")) + } + + pos := p.expect(token.STRUCT) + lbrace := p.expect(token.LBRACE) + scope := ast.NewScope(nil) // struct scope + var list []*ast.Field + for p.tok == token.IDENT || p.tok == token.MUL || p.tok == token.LPAREN { + // a field declaration cannot start with a '(' but we accept + // it here for more robust parsing and better error messages + // (parseFieldDecl will check and complain if necessary) + list = append(list, p.parseFieldDecl(scope)) + } + rbrace := p.expect(token.RBRACE) + + // TODO(gri): store struct scope in AST + return &ast.StructType{pos, &ast.FieldList{lbrace, list, rbrace}, false} +} + +func (p *parser) parsePointerType() *ast.StarExpr { + if p.trace { + defer un(trace(p, "PointerType")) + } + + star := p.expect(token.MUL) + base := p.parseType() + + return &ast.StarExpr{star, base} +} + +func (p *parser) tryVarType(isParam bool) ast.Expr { + if isParam && p.tok == token.ELLIPSIS { + pos := p.pos + p.next() + typ := p.tryIdentOrType(isParam) // don't use parseType so we can provide better error message + if typ == nil { + p.error(pos, "'...' parameter is missing type") + typ = &ast.BadExpr{pos, p.pos} + } + if p.tok != token.RPAREN { + p.error(pos, "can use '...' with last parameter type only") + } + return &ast.Ellipsis{pos, typ} + } + return p.tryIdentOrType(false) +} + +func (p *parser) parseVarType(isParam bool) ast.Expr { + typ := p.tryVarType(isParam) + if typ == nil { + pos := p.pos + p.errorExpected(pos, "type") + p.next() // make progress + typ = &ast.BadExpr{pos, p.pos} + } + return typ +} + +func (p *parser) parseVarList(isParam bool) (list []ast.Expr, typ ast.Expr) { + if p.trace { + defer un(trace(p, "VarList")) + } + + // a list of identifiers looks like a list of type names + for { + // parseVarType accepts any type (including parenthesized ones) + // even though the syntax does not permit them here: we + // accept them all for more robust parsing and complain + // afterwards + list = append(list, p.parseVarType(isParam)) + if p.tok != token.COMMA { + break + } + p.next() + } + + // if we had a list of identifiers, it must be followed by a type + typ = p.tryVarType(isParam) + if typ != nil { + p.resolve(typ) + } + + return +} + +func (p *parser) parseParameterList(scope *ast.Scope, ellipsisOk bool) (params []*ast.Field) { + if p.trace { + defer un(trace(p, "ParameterList")) + } + + list, typ := p.parseVarList(ellipsisOk) + if typ != nil { + // IdentifierList Type + idents := p.makeIdentList(list) + field := &ast.Field{nil, idents, typ, nil, nil} + params = append(params, field) + // Go spec: The scope of an identifier denoting a function + // parameter or result variable is the function body. + p.declare(field, scope, ast.Var, idents...) + if p.tok == token.COMMA { + p.next() + } + + for p.tok != token.RPAREN && p.tok != token.EOF { + idents := p.parseIdentList() + typ := p.parseVarType(ellipsisOk) + field := &ast.Field{nil, idents, typ, nil, nil} + params = append(params, field) + // Go spec: The scope of an identifier denoting a function + // parameter or result variable is the function body. + p.declare(field, scope, ast.Var, idents...) + if p.tok != token.COMMA { + break + } + p.next() + } + + } else { + // Type { "," Type } (anonymous parameters) + params = make([]*ast.Field, len(list)) + for i, x := range list { + p.resolve(x) + params[i] = &ast.Field{Type: x} + } + } + + return +} + +func (p *parser) parseParameters(scope *ast.Scope, ellipsisOk bool) *ast.FieldList { + if p.trace { + defer un(trace(p, "Parameters")) + } + + var params []*ast.Field + lparen := p.expect(token.LPAREN) + if p.tok != token.RPAREN { + params = p.parseParameterList(scope, ellipsisOk) + } + rparen := p.expect(token.RPAREN) + + return &ast.FieldList{lparen, params, rparen} +} + +func (p *parser) parseResult(scope *ast.Scope) *ast.FieldList { + if p.trace { + defer un(trace(p, "Result")) + } + + if p.tok == token.LPAREN { + return p.parseParameters(scope, false) + } + + typ := p.tryType() + if typ != nil { + list := make([]*ast.Field, 1) + list[0] = &ast.Field{Type: typ} + return &ast.FieldList{List: list} + } + + return nil +} + +func (p *parser) parseSignature(scope *ast.Scope) (params, results *ast.FieldList) { + if p.trace { + defer un(trace(p, "Signature")) + } + + params = p.parseParameters(scope, true) + results = p.parseResult(scope) + + return +} + +func (p *parser) parseFuncType() (*ast.FuncType, *ast.Scope) { + if p.trace { + defer un(trace(p, "FuncType")) + } + + pos := p.expect(token.FUNC) + scope := ast.NewScope(p.topScope) // function scope + params, results := p.parseSignature(scope) + + return &ast.FuncType{pos, params, results}, scope +} + +func (p *parser) parseMethodSpec(scope *ast.Scope) *ast.Field { + if p.trace { + defer un(trace(p, "MethodSpec")) + } + + doc := p.leadComment + var idents []*ast.Ident + var typ ast.Expr + x := p.parseTypeName() + if ident, isIdent := x.(*ast.Ident); isIdent && p.tok == token.LPAREN { + // method + idents = []*ast.Ident{ident} + scope := ast.NewScope(nil) // method scope + params, results := p.parseSignature(scope) + typ = &ast.FuncType{token.NoPos, params, results} + } else { + // embedded interface + typ = x + } + p.expectSemi() // call before accessing p.linecomment + + spec := &ast.Field{doc, idents, typ, nil, p.lineComment} + p.declare(spec, scope, ast.Fun, idents...) + + return spec +} + +func (p *parser) parseInterfaceType() *ast.InterfaceType { + if p.trace { + defer un(trace(p, "InterfaceType")) + } + + pos := p.expect(token.INTERFACE) + lbrace := p.expect(token.LBRACE) + scope := ast.NewScope(nil) // interface scope + var list []*ast.Field + for p.tok == token.IDENT { + list = append(list, p.parseMethodSpec(scope)) + } + rbrace := p.expect(token.RBRACE) + + // TODO(gri): store interface scope in AST + return &ast.InterfaceType{pos, &ast.FieldList{lbrace, list, rbrace}, false} +} + +func (p *parser) parseMapType() *ast.MapType { + if p.trace { + defer un(trace(p, "MapType")) + } + + pos := p.expect(token.MAP) + p.expect(token.LBRACK) + key := p.parseType() + p.expect(token.RBRACK) + value := p.parseType() + + return &ast.MapType{pos, key, value} +} + +func (p *parser) parseChanType() *ast.ChanType { + if p.trace { + defer un(trace(p, "ChanType")) + } + + pos := p.pos + dir := ast.SEND | ast.RECV + if p.tok == token.CHAN { + p.next() + if p.tok == token.ARROW { + p.next() + dir = ast.SEND + } + } else { + p.expect(token.ARROW) + p.expect(token.CHAN) + dir = ast.RECV + } + value := p.parseType() + + return &ast.ChanType{pos, dir, value} +} + +// If the result is an identifier, it is not resolved. +func (p *parser) tryIdentOrType(ellipsisOk bool) ast.Expr { + switch p.tok { + case token.IDENT: + return p.parseTypeName() + case token.LBRACK: + return p.parseArrayType(ellipsisOk) + case token.STRUCT: + return p.parseStructType() + case token.MUL: + return p.parsePointerType() + case token.FUNC: + typ, _ := p.parseFuncType() + return typ + case token.INTERFACE: + return p.parseInterfaceType() + case token.MAP: + return p.parseMapType() + case token.CHAN, token.ARROW: + return p.parseChanType() + case token.LPAREN: + lparen := p.pos + p.next() + typ := p.parseType() + rparen := p.expect(token.RPAREN) + return &ast.ParenExpr{lparen, typ, rparen} + } + + // no type found + return nil +} + +func (p *parser) tryType() ast.Expr { + typ := p.tryIdentOrType(false) + if typ != nil { + p.resolve(typ) + } + return typ +} + +// ---------------------------------------------------------------------------- +// Blocks + +func (p *parser) parseStmtList() (list []ast.Stmt) { + if p.trace { + defer un(trace(p, "StatementList")) + } + + for p.tok != token.CASE && p.tok != token.DEFAULT && p.tok != token.RBRACE && p.tok != token.EOF { + list = append(list, p.parseStmt()) + } + + return +} + +func (p *parser) parseBody(scope *ast.Scope) *ast.BlockStmt { + if p.trace { + defer un(trace(p, "Body")) + } + + lbrace := p.expect(token.LBRACE) + p.topScope = scope // open function scope + p.openLabelScope() + list := p.parseStmtList() + p.closeLabelScope() + p.closeScope() + rbrace := p.expect(token.RBRACE) + + return &ast.BlockStmt{lbrace, list, rbrace} +} + +func (p *parser) parseBlockStmt() *ast.BlockStmt { + if p.trace { + defer un(trace(p, "BlockStmt")) + } + + lbrace := p.expect(token.LBRACE) + p.openScope() + list := p.parseStmtList() + p.closeScope() + rbrace := p.expect(token.RBRACE) + + return &ast.BlockStmt{lbrace, list, rbrace} +} + +// ---------------------------------------------------------------------------- +// Expressions + +func (p *parser) parseFuncTypeOrLit() ast.Expr { + if p.trace { + defer un(trace(p, "FuncTypeOrLit")) + } + + typ, scope := p.parseFuncType() + if p.tok != token.LBRACE { + // function type only + return typ + } + + p.exprLev++ + body := p.parseBody(scope) + p.exprLev-- + + return &ast.FuncLit{typ, body} +} + +// parseOperand may return an expression or a raw type (incl. array +// types of the form [...]T. Callers must verify the result. +// If lhs is set and the result is an identifier, it is not resolved. +func (p *parser) parseOperand(lhs bool) ast.Expr { + if p.trace { + defer un(trace(p, "Operand")) + } + + switch p.tok { + case token.IDENT: + x := p.parseIdent() + if !lhs { + p.resolve(x) + } + return x + + case token.INT, token.FLOAT, token.IMAG, token.CHAR, token.STRING: + x := &ast.BasicLit{p.pos, p.tok, p.lit} + p.next() + return x + + case token.LPAREN: + lparen := p.pos + p.next() + p.exprLev++ + x := p.parseRhs() + p.exprLev-- + rparen := p.expect(token.RPAREN) + return &ast.ParenExpr{lparen, x, rparen} + + case token.FUNC: + return p.parseFuncTypeOrLit() + + default: + if typ := p.tryIdentOrType(true); typ != nil { + // could be type for composite literal or conversion + _, isIdent := typ.(*ast.Ident) + assert(!isIdent, "type cannot be identifier") + return typ + } + } + + pos := p.pos + p.errorExpected(pos, "operand") + p.next() // make progress + return &ast.BadExpr{pos, p.pos} +} + +func (p *parser) parseSelector(x ast.Expr) ast.Expr { + if p.trace { + defer un(trace(p, "Selector")) + } + + sel := p.parseIdent() + + return &ast.SelectorExpr{x, sel} +} + +func (p *parser) parseTypeAssertion(x ast.Expr) ast.Expr { + if p.trace { + defer un(trace(p, "TypeAssertion")) + } + + p.expect(token.LPAREN) + var typ ast.Expr + if p.tok == token.TYPE { + // type switch: typ == nil + p.next() + } else { + typ = p.parseType() + } + p.expect(token.RPAREN) + + return &ast.TypeAssertExpr{x, typ} +} + +func (p *parser) parseIndexOrSlice(x ast.Expr) ast.Expr { + if p.trace { + defer un(trace(p, "IndexOrSlice")) + } + + lbrack := p.expect(token.LBRACK) + p.exprLev++ + var low, high ast.Expr + isSlice := false + if p.tok != token.COLON { + low = p.parseRhs() + } + if p.tok == token.COLON { + isSlice = true + p.next() + if p.tok != token.RBRACK { + high = p.parseRhs() + } + } + p.exprLev-- + rbrack := p.expect(token.RBRACK) + + if isSlice { + return &ast.SliceExpr{x, lbrack, low, high, rbrack} + } + return &ast.IndexExpr{x, lbrack, low, rbrack} +} + +func (p *parser) parseCallOrConversion(fun ast.Expr) *ast.CallExpr { + if p.trace { + defer un(trace(p, "CallOrConversion")) + } + + lparen := p.expect(token.LPAREN) + p.exprLev++ + var list []ast.Expr + var ellipsis token.Pos + for p.tok != token.RPAREN && p.tok != token.EOF && !ellipsis.IsValid() { + list = append(list, p.parseRhs()) + if p.tok == token.ELLIPSIS { + ellipsis = p.pos + p.next() + } + if p.tok != token.COMMA { + break + } + p.next() + } + p.exprLev-- + rparen := p.expect(token.RPAREN) + + return &ast.CallExpr{fun, lparen, list, ellipsis, rparen} +} + +func (p *parser) parseElement(keyOk bool) ast.Expr { + if p.trace { + defer un(trace(p, "Element")) + } + + if p.tok == token.LBRACE { + return p.parseLiteralValue(nil) + } + + x := p.parseExpr(keyOk) // don't resolve if map key + if keyOk { + if p.tok == token.COLON { + colon := p.pos + p.next() + return &ast.KeyValueExpr{x, colon, p.parseElement(false)} + } + p.resolve(x) // not a map key + } + + return x +} + +func (p *parser) parseElementList() (list []ast.Expr) { + if p.trace { + defer un(trace(p, "ElementList")) + } + + for p.tok != token.RBRACE && p.tok != token.EOF { + list = append(list, p.parseElement(true)) + if p.tok != token.COMMA { + break + } + p.next() + } + + return +} + +func (p *parser) parseLiteralValue(typ ast.Expr) ast.Expr { + if p.trace { + defer un(trace(p, "LiteralValue")) + } + + lbrace := p.expect(token.LBRACE) + var elts []ast.Expr + p.exprLev++ + if p.tok != token.RBRACE { + elts = p.parseElementList() + } + p.exprLev-- + rbrace := p.expect(token.RBRACE) + return &ast.CompositeLit{typ, lbrace, elts, rbrace} +} + +// checkExpr checks that x is an expression (and not a type). +func (p *parser) checkExpr(x ast.Expr) ast.Expr { + switch t := ast.Unparen(x).(type) { + case *ast.BadExpr: + case *ast.Ident: + case *ast.BasicLit: + case *ast.FuncLit: + case *ast.CompositeLit: + case *ast.ParenExpr: + panic("unreachable") + case *ast.SelectorExpr: + case *ast.IndexExpr: + case *ast.SliceExpr: + case *ast.TypeAssertExpr: + if t.Type == nil { + // the form X.(type) is only allowed in type switch expressions + p.errorExpected(x.Pos(), "expression") + x = &ast.BadExpr{x.Pos(), x.End()} + } + case *ast.CallExpr: + case *ast.StarExpr: + case *ast.UnaryExpr: + if t.Op == token.RANGE { + // the range operator is only allowed at the top of a for statement + p.errorExpected(x.Pos(), "expression") + x = &ast.BadExpr{x.Pos(), x.End()} + } + case *ast.BinaryExpr: + default: + // all other nodes are not proper expressions + p.errorExpected(x.Pos(), "expression") + x = &ast.BadExpr{x.Pos(), x.End()} + } + return x +} + +// isTypeName reports whether x is a (qualified) TypeName. +func isTypeName(x ast.Expr) bool { + switch t := x.(type) { + case *ast.BadExpr: + case *ast.Ident: + case *ast.SelectorExpr: + _, isIdent := t.X.(*ast.Ident) + return isIdent + default: + return false // all other nodes are not type names + } + return true +} + +// isLiteralType reports whether x is a legal composite literal type. +func isLiteralType(x ast.Expr) bool { + switch t := x.(type) { + case *ast.BadExpr: + case *ast.Ident: + case *ast.SelectorExpr: + _, isIdent := t.X.(*ast.Ident) + return isIdent + case *ast.ArrayType: + case *ast.StructType: + case *ast.MapType: + default: + return false // all other nodes are not legal composite literal types + } + return true +} + +// If x is of the form *T, deref returns T, otherwise it returns x. +func deref(x ast.Expr) ast.Expr { + if p, isPtr := x.(*ast.StarExpr); isPtr { + x = p.X + } + return x +} + +// checkExprOrType checks that x is an expression or a type +// (and not a raw type such as [...]T). +func (p *parser) checkExprOrType(x ast.Expr) ast.Expr { + switch t := ast.Unparen(x).(type) { + case *ast.ParenExpr: + panic("unreachable") + case *ast.UnaryExpr: + if t.Op == token.RANGE { + // the range operator is only allowed at the top of a for statement + p.errorExpected(x.Pos(), "expression") + x = &ast.BadExpr{x.Pos(), x.End()} + } + case *ast.ArrayType: + if len, isEllipsis := t.Len.(*ast.Ellipsis); isEllipsis { + p.error(len.Pos(), "expected array length, found '...'") + x = &ast.BadExpr{x.Pos(), x.End()} + } + } + + // all other nodes are expressions or types + return x +} + +// If lhs is set and the result is an identifier, it is not resolved. +func (p *parser) parsePrimaryExpr(lhs bool) ast.Expr { + if p.trace { + defer un(trace(p, "PrimaryExpr")) + } + + x := p.parseOperand(lhs) +L: + for { + switch p.tok { + case token.PERIOD: + p.next() + if lhs { + p.resolve(x) + } + switch p.tok { + case token.IDENT: + x = p.parseSelector(p.checkExpr(x)) + case token.LPAREN: + x = p.parseTypeAssertion(p.checkExpr(x)) + default: + pos := p.pos + p.next() // make progress + p.errorExpected(pos, "selector or type assertion") + x = &ast.BadExpr{pos, p.pos} + } + case token.LBRACK: + if lhs { + p.resolve(x) + } + x = p.parseIndexOrSlice(p.checkExpr(x)) + case token.LPAREN: + if lhs { + p.resolve(x) + } + x = p.parseCallOrConversion(p.checkExprOrType(x)) + case token.LBRACE: + if isLiteralType(x) && (p.exprLev >= 0 || !isTypeName(x)) { + if lhs { + p.resolve(x) + } + x = p.parseLiteralValue(x) + } else { + break L + } + default: + break L + } + lhs = false // no need to try to resolve again + } + + return x +} + +// If lhs is set and the result is an identifier, it is not resolved. +func (p *parser) parseUnaryExpr(lhs bool) ast.Expr { + if p.trace { + defer un(trace(p, "UnaryExpr")) + } + + switch p.tok { + case token.ADD, token.SUB, token.NOT, token.XOR, token.AND, token.RANGE: + pos, op := p.pos, p.tok + p.next() + x := p.parseUnaryExpr(false) + return &ast.UnaryExpr{pos, op, p.checkExpr(x)} + + case token.ARROW: + // channel type or receive expression + pos := p.pos + p.next() + if p.tok == token.CHAN { + p.next() + value := p.parseType() + return &ast.ChanType{pos, ast.RECV, value} + } + + x := p.parseUnaryExpr(false) + return &ast.UnaryExpr{pos, token.ARROW, p.checkExpr(x)} + + case token.MUL: + // pointer type or unary "*" expression + pos := p.pos + p.next() + x := p.parseUnaryExpr(false) + return &ast.StarExpr{pos, p.checkExprOrType(x)} + } + + return p.parsePrimaryExpr(lhs) +} + +// If lhs is set and the result is an identifier, it is not resolved. +func (p *parser) parseBinaryExpr(lhs bool, prec1 int) ast.Expr { + if p.trace { + defer un(trace(p, "BinaryExpr")) + } + + x := p.parseUnaryExpr(lhs) + for prec := p.tok.Precedence(); prec >= prec1; prec-- { + for p.tok.Precedence() == prec { + pos, op := p.pos, p.tok + p.next() + if lhs { + p.resolve(x) + lhs = false + } + y := p.parseBinaryExpr(false, prec+1) + x = &ast.BinaryExpr{p.checkExpr(x), pos, op, p.checkExpr(y)} + } + } + + return x +} + +// If lhs is set and the result is an identifier, it is not resolved. +// TODO(gri): parseExpr may return a type or even a raw type ([..]int) - +// should reject when a type/raw type is obviously not allowed +func (p *parser) parseExpr(lhs bool) ast.Expr { + if p.trace { + defer un(trace(p, "Expression")) + } + + return p.parseBinaryExpr(lhs, token.LowestPrec+1) +} + +func (p *parser) parseRhs() ast.Expr { + return p.parseExpr(false) +} + +// ---------------------------------------------------------------------------- +// Statements + +func (p *parser) parseSimpleStmt(labelOk bool) ast.Stmt { + if p.trace { + defer un(trace(p, "SimpleStmt")) + } + + x := p.parseLhsList() + + switch p.tok { + case + token.DEFINE, token.ASSIGN, token.ADD_ASSIGN, + token.SUB_ASSIGN, token.MUL_ASSIGN, token.QUO_ASSIGN, + token.REM_ASSIGN, token.AND_ASSIGN, token.OR_ASSIGN, + token.XOR_ASSIGN, token.SHL_ASSIGN, token.SHR_ASSIGN, token.AND_NOT_ASSIGN: + // assignment statement + pos, tok := p.pos, p.tok + p.next() + y := p.parseRhsList() + return &ast.AssignStmt{x, pos, tok, y} + } + + if len(x) > 1 { + p.errorExpected(x[0].Pos(), "1 expression") + // continue with first expression + } + + switch p.tok { + case token.COLON: + // labeled statement + colon := p.pos + p.next() + if label, isIdent := x[0].(*ast.Ident); labelOk && isIdent { + // Go spec: The scope of a label is the body of the function + // in which it is declared and excludes the body of any nested + // function. + stmt := &ast.LabeledStmt{label, colon, p.parseStmt()} + p.declare(stmt, p.labelScope, ast.Lbl, label) + return stmt + } + p.error(x[0].Pos(), "illegal label declaration") + return &ast.BadStmt{x[0].Pos(), colon + 1} + + case token.ARROW: + // send statement + arrow := p.pos + p.next() // consume "<-" + y := p.parseRhs() + return &ast.SendStmt{x[0], arrow, y} + + case token.INC, token.DEC: + // increment or decrement + s := &ast.IncDecStmt{x[0], p.pos, p.tok} + p.next() // consume "++" or "--" + return s + } + + // expression + return &ast.ExprStmt{x[0]} +} + +func (p *parser) parseCallExpr() *ast.CallExpr { + x := p.parseRhs() + if call, isCall := x.(*ast.CallExpr); isCall { + return call + } + p.errorExpected(x.Pos(), "function/method call") + return nil +} + +func (p *parser) parseGoStmt() ast.Stmt { + if p.trace { + defer un(trace(p, "GoStmt")) + } + + pos := p.expect(token.GO) + call := p.parseCallExpr() + p.expectSemi() + if call == nil { + return &ast.BadStmt{pos, pos + 2} // len("go") + } + + return &ast.GoStmt{pos, call} +} + +func (p *parser) parseDeferStmt() ast.Stmt { + if p.trace { + defer un(trace(p, "DeferStmt")) + } + + pos := p.expect(token.DEFER) + call := p.parseCallExpr() + p.expectSemi() + if call == nil { + return &ast.BadStmt{pos, pos + 5} // len("defer") + } + + return &ast.DeferStmt{pos, call} +} + +func (p *parser) parseReturnStmt() *ast.ReturnStmt { + if p.trace { + defer un(trace(p, "ReturnStmt")) + } + + pos := p.pos + p.expect(token.RETURN) + var x []ast.Expr + if p.tok != token.SEMICOLON && p.tok != token.RBRACE { + x = p.parseRhsList() + } + p.expectSemi() + + return &ast.ReturnStmt{pos, x} +} + +func (p *parser) parseBranchStmt(tok token.Token) *ast.BranchStmt { + if p.trace { + defer un(trace(p, "BranchStmt")) + } + + pos := p.expect(tok) + var label *ast.Ident + if tok != token.FALLTHROUGH && p.tok == token.IDENT { + label = p.parseIdent() + // add to list of unresolved targets + n := len(p.targetStack) - 1 + p.targetStack[n] = append(p.targetStack[n], label) + } + p.expectSemi() + + return &ast.BranchStmt{pos, tok, label} +} + +func (p *parser) makeExpr(s ast.Stmt) ast.Expr { + if s == nil { + return nil + } + if es, isExpr := s.(*ast.ExprStmt); isExpr { + return p.checkExpr(es.X) + } + p.error(s.Pos(), "expected condition, found simple statement") + return &ast.BadExpr{s.Pos(), s.End()} +} + +func (p *parser) parseIfStmt() *ast.IfStmt { + if p.trace { + defer un(trace(p, "IfStmt")) + } + + pos := p.expect(token.IF) + p.openScope() + defer p.closeScope() + + var s ast.Stmt + var x ast.Expr + { + prevLev := p.exprLev + p.exprLev = -1 + if p.tok == token.SEMICOLON { + p.next() + x = p.parseRhs() + } else { + s = p.parseSimpleStmt(false) + if p.tok == token.SEMICOLON { + p.next() + x = p.parseRhs() + } else { + x = p.makeExpr(s) + s = nil + } + } + p.exprLev = prevLev + } + + body := p.parseBlockStmt() + var else_ ast.Stmt + if p.tok == token.ELSE { + p.next() + else_ = p.parseStmt() + } else { + p.expectSemi() + } + + return &ast.IfStmt{pos, s, x, body, else_} +} + +func (p *parser) parseTypeList() (list []ast.Expr) { + if p.trace { + defer un(trace(p, "TypeList")) + } + + list = append(list, p.parseType()) + for p.tok == token.COMMA { + p.next() + list = append(list, p.parseType()) + } + + return +} + +func (p *parser) parseCaseClause(exprSwitch bool) *ast.CaseClause { + if p.trace { + defer un(trace(p, "CaseClause")) + } + + pos := p.pos + var list []ast.Expr + if p.tok == token.CASE { + p.next() + if exprSwitch { + list = p.parseRhsList() + } else { + list = p.parseTypeList() + } + } else { + p.expect(token.DEFAULT) + } + + colon := p.expect(token.COLON) + p.openScope() + body := p.parseStmtList() + p.closeScope() + + return &ast.CaseClause{pos, list, colon, body} +} + +func isExprSwitch(s ast.Stmt) bool { + if s == nil { + return true + } + if e, ok := s.(*ast.ExprStmt); ok { + if a, ok := e.X.(*ast.TypeAssertExpr); ok { + return a.Type != nil // regular type assertion + } + return true + } + return false +} + +func (p *parser) parseSwitchStmt() ast.Stmt { + if p.trace { + defer un(trace(p, "SwitchStmt")) + } + + pos := p.expect(token.SWITCH) + p.openScope() + defer p.closeScope() + + var s1, s2 ast.Stmt + if p.tok != token.LBRACE { + prevLev := p.exprLev + p.exprLev = -1 + if p.tok != token.SEMICOLON { + s2 = p.parseSimpleStmt(false) + } + if p.tok == token.SEMICOLON { + p.next() + s1 = s2 + s2 = nil + if p.tok != token.LBRACE { + s2 = p.parseSimpleStmt(false) + } + } + p.exprLev = prevLev + } + + exprSwitch := isExprSwitch(s2) + lbrace := p.expect(token.LBRACE) + var list []ast.Stmt + for p.tok == token.CASE || p.tok == token.DEFAULT { + list = append(list, p.parseCaseClause(exprSwitch)) + } + rbrace := p.expect(token.RBRACE) + p.expectSemi() + body := &ast.BlockStmt{lbrace, list, rbrace} + + if exprSwitch { + return &ast.SwitchStmt{pos, s1, p.makeExpr(s2), body} + } + // type switch + // TODO(gri): do all the checks! + return &ast.TypeSwitchStmt{pos, s1, s2, body} +} + +func (p *parser) parseCommClause() *ast.CommClause { + if p.trace { + defer un(trace(p, "CommClause")) + } + + p.openScope() + pos := p.pos + var comm ast.Stmt + if p.tok == token.CASE { + p.next() + lhs := p.parseLhsList() + if p.tok == token.ARROW { + // SendStmt + if len(lhs) > 1 { + p.errorExpected(lhs[0].Pos(), "1 expression") + // continue with first expression + } + arrow := p.pos + p.next() + rhs := p.parseRhs() + comm = &ast.SendStmt{lhs[0], arrow, rhs} + } else { + // RecvStmt + pos := p.pos + tok := p.tok + var rhs ast.Expr + if tok == token.ASSIGN || tok == token.DEFINE { + // RecvStmt with assignment + if len(lhs) > 2 { + p.errorExpected(lhs[0].Pos(), "1 or 2 expressions") + // continue with first two expressions + lhs = lhs[0:2] + } + p.next() + rhs = p.parseRhs() + } else { + // rhs must be single receive operation + if len(lhs) > 1 { + p.errorExpected(lhs[0].Pos(), "1 expression") + // continue with first expression + } + rhs = lhs[0] + lhs = nil // there is no lhs + } + if x, isUnary := rhs.(*ast.UnaryExpr); !isUnary || x.Op != token.ARROW { + p.errorExpected(rhs.Pos(), "send or receive operation") + rhs = &ast.BadExpr{rhs.Pos(), rhs.End()} + } + if lhs != nil { + comm = &ast.AssignStmt{lhs, pos, tok, []ast.Expr{rhs}} + } else { + comm = &ast.ExprStmt{rhs} + } + } + } else { + p.expect(token.DEFAULT) + } + + colon := p.expect(token.COLON) + body := p.parseStmtList() + p.closeScope() + + return &ast.CommClause{pos, comm, colon, body} +} + +func (p *parser) parseSelectStmt() *ast.SelectStmt { + if p.trace { + defer un(trace(p, "SelectStmt")) + } + + pos := p.expect(token.SELECT) + lbrace := p.expect(token.LBRACE) + var list []ast.Stmt + for p.tok == token.CASE || p.tok == token.DEFAULT { + list = append(list, p.parseCommClause()) + } + rbrace := p.expect(token.RBRACE) + p.expectSemi() + body := &ast.BlockStmt{lbrace, list, rbrace} + + return &ast.SelectStmt{pos, body} +} + +func (p *parser) parseForStmt() ast.Stmt { + if p.trace { + defer un(trace(p, "ForStmt")) + } + + pos := p.expect(token.FOR) + p.openScope() + defer p.closeScope() + + var s1, s2, s3 ast.Stmt + if p.tok != token.LBRACE { + prevLev := p.exprLev + p.exprLev = -1 + if p.tok != token.SEMICOLON { + s2 = p.parseSimpleStmt(false) + } + if p.tok == token.SEMICOLON { + p.next() + s1 = s2 + s2 = nil + if p.tok != token.SEMICOLON { + s2 = p.parseSimpleStmt(false) + } + p.expectSemi() + if p.tok != token.LBRACE { + s3 = p.parseSimpleStmt(false) + } + } + p.exprLev = prevLev + } + + body := p.parseBlockStmt() + p.expectSemi() + + if as, isAssign := s2.(*ast.AssignStmt); isAssign { + // possibly a for statement with a range clause; check assignment operator + if as.Tok != token.ASSIGN && as.Tok != token.DEFINE { + p.errorExpected(as.TokPos, "'=' or ':='") + return &ast.BadStmt{pos, body.End()} + } + // check lhs + var key, value ast.Expr + switch len(as.Lhs) { + case 2: + key, value = as.Lhs[0], as.Lhs[1] + case 1: + key = as.Lhs[0] + default: + p.errorExpected(as.Lhs[0].Pos(), "1 or 2 expressions") + return &ast.BadStmt{pos, body.End()} + } + // check rhs + if len(as.Rhs) != 1 { + p.errorExpected(as.Rhs[0].Pos(), "1 expression") + return &ast.BadStmt{pos, body.End()} + } + if rhs, isUnary := as.Rhs[0].(*ast.UnaryExpr); isUnary && rhs.Op == token.RANGE { + // rhs is range expression + // (any short variable declaration was handled by parseSimpleStat above) + return &ast.RangeStmt{pos, key, value, as.TokPos, as.Tok, rhs.X, body} + } + p.errorExpected(s2.Pos(), "range clause") + return &ast.BadStmt{pos, body.End()} + } + + // regular for statement + return &ast.ForStmt{pos, s1, p.makeExpr(s2), s3, body} +} + +func (p *parser) parseStmt() (s ast.Stmt) { + if p.trace { + defer un(trace(p, "Statement")) + } + + switch p.tok { + case token.CONST, token.TYPE, token.VAR: + s = &ast.DeclStmt{p.parseDecl()} + case + // tokens that may start a top-level expression + token.IDENT, token.INT, token.FLOAT, token.CHAR, token.STRING, token.FUNC, token.LPAREN, // operand + token.LBRACK, token.STRUCT, // composite type + token.MUL, token.AND, token.ARROW, token.ADD, token.SUB, token.XOR: // unary operators + s = p.parseSimpleStmt(true) + // because of the required look-ahead, labeled statements are + // parsed by parseSimpleStmt - don't expect a semicolon after + // them + if _, isLabeledStmt := s.(*ast.LabeledStmt); !isLabeledStmt { + p.expectSemi() + } + case token.GO: + s = p.parseGoStmt() + case token.DEFER: + s = p.parseDeferStmt() + case token.RETURN: + s = p.parseReturnStmt() + case token.BREAK, token.CONTINUE, token.GOTO, token.FALLTHROUGH: + s = p.parseBranchStmt(p.tok) + case token.LBRACE: + s = p.parseBlockStmt() + p.expectSemi() + case token.IF: + s = p.parseIfStmt() + case token.SWITCH: + s = p.parseSwitchStmt() + case token.SELECT: + s = p.parseSelectStmt() + case token.FOR: + s = p.parseForStmt() + case token.SEMICOLON: + s = &ast.EmptyStmt{p.pos} + p.next() + case token.RBRACE: + // a semicolon may be omitted before a closing "}" + s = &ast.EmptyStmt{p.pos} + default: + // no statement found + pos := p.pos + p.errorExpected(pos, "statement") + p.next() // make progress + s = &ast.BadStmt{pos, p.pos} + } + + return +} + +// ---------------------------------------------------------------------------- +// Declarations + +type parseSpecFunction func(p *parser, doc *ast.CommentGroup, iota int) ast.Spec + +func parseImportSpec(p *parser, doc *ast.CommentGroup, _ int) ast.Spec { + if p.trace { + defer un(trace(p, "ImportSpec")) + } + + var ident *ast.Ident + switch p.tok { + case token.PERIOD: + ident = &ast.Ident{p.pos, ".", nil} + p.next() + case token.IDENT: + ident = p.parseIdent() + } + + var path *ast.BasicLit + if p.tok == token.STRING { + path = &ast.BasicLit{p.pos, p.tok, p.lit} + p.next() + } else { + p.expect(token.STRING) // use expect() error handling + } + p.expectSemi() // call before accessing p.linecomment + + // collect imports + spec := &ast.ImportSpec{doc, ident, path, p.lineComment} + p.imports = append(p.imports, spec) + + return spec +} + +func parseConstSpec(p *parser, doc *ast.CommentGroup, iota int) ast.Spec { + if p.trace { + defer un(trace(p, "ConstSpec")) + } + + idents := p.parseIdentList() + typ := p.tryType() + var values []ast.Expr + if typ != nil || p.tok == token.ASSIGN || iota == 0 { + p.expect(token.ASSIGN) + values = p.parseRhsList() + } + p.expectSemi() // call before accessing p.linecomment + + // Go spec: The scope of a constant or variable identifier declared inside + // a function begins at the end of the ConstSpec or VarSpec and ends at + // the end of the innermost containing block. + // (Global identifiers are resolved in a separate phase after parsing.) + spec := &ast.ValueSpec{doc, idents, typ, values, p.lineComment} + p.declare(spec, p.topScope, ast.Con, idents...) + + return spec +} + +func parseTypeSpec(p *parser, doc *ast.CommentGroup, _ int) ast.Spec { + if p.trace { + defer un(trace(p, "TypeSpec")) + } + + ident := p.parseIdent() + + // Go spec: The scope of a type identifier declared inside a function begins + // at the identifier in the TypeSpec and ends at the end of the innermost + // containing block. + // (Global identifiers are resolved in a separate phase after parsing.) + spec := &ast.TypeSpec{doc, ident, nil, nil} + p.declare(spec, p.topScope, ast.Typ, ident) + + spec.Type = p.parseType() + p.expectSemi() // call before accessing p.linecomment + spec.Comment = p.lineComment + + return spec +} + +func parseVarSpec(p *parser, doc *ast.CommentGroup, _ int) ast.Spec { + if p.trace { + defer un(trace(p, "VarSpec")) + } + + idents := p.parseIdentList() + typ := p.tryType() + var values []ast.Expr + if typ == nil || p.tok == token.ASSIGN { + p.expect(token.ASSIGN) + values = p.parseRhsList() + } + p.expectSemi() // call before accessing p.linecomment + + // Go spec: The scope of a constant or variable identifier declared inside + // a function begins at the end of the ConstSpec or VarSpec and ends at + // the end of the innermost containing block. + // (Global identifiers are resolved in a separate phase after parsing.) + spec := &ast.ValueSpec{doc, idents, typ, values, p.lineComment} + p.declare(spec, p.topScope, ast.Var, idents...) + + return spec +} + +func (p *parser) parseGenDecl(keyword token.Token, f parseSpecFunction) *ast.GenDecl { + if p.trace { + defer un(trace(p, "GenDecl("+keyword.String()+")")) + } + + doc := p.leadComment + pos := p.expect(keyword) + var lparen, rparen token.Pos + var list []ast.Spec + if p.tok == token.LPAREN { + lparen = p.pos + p.next() + for iota := 0; p.tok != token.RPAREN && p.tok != token.EOF; iota++ { + list = append(list, f(p, p.leadComment, iota)) + } + rparen = p.expect(token.RPAREN) + p.expectSemi() + } else { + list = append(list, f(p, nil, 0)) + } + + return &ast.GenDecl{doc, pos, keyword, lparen, list, rparen} +} + +func (p *parser) parseReceiver(scope *ast.Scope) *ast.FieldList { + if p.trace { + defer un(trace(p, "Receiver")) + } + + pos := p.pos + par := p.parseParameters(scope, false) + + // must have exactly one receiver + if par.NumFields() != 1 { + p.errorExpected(pos, "exactly one receiver") + // TODO determine a better range for BadExpr below + par.List = []*ast.Field{{Type: &ast.BadExpr{pos, pos}}} + return par + } + + // recv type must be of the form ["*"] identifier + recv := par.List[0] + base := deref(recv.Type) + if _, isIdent := base.(*ast.Ident); !isIdent { + p.errorExpected(base.Pos(), "(unqualified) identifier") + par.List = []*ast.Field{{Type: &ast.BadExpr{recv.Pos(), recv.End()}}} + } + + return par +} + +func (p *parser) parseFuncDecl() *ast.FuncDecl { + if p.trace { + defer un(trace(p, "FunctionDecl")) + } + + doc := p.leadComment + pos := p.expect(token.FUNC) + scope := ast.NewScope(p.topScope) // function scope + + var recv *ast.FieldList + if p.tok == token.LPAREN { + recv = p.parseReceiver(scope) + } + + ident := p.parseIdent() + + params, results := p.parseSignature(scope) + + var body *ast.BlockStmt + if p.tok == token.LBRACE { + body = p.parseBody(scope) + } + p.expectSemi() + + decl := &ast.FuncDecl{doc, recv, ident, &ast.FuncType{pos, params, results}, body} + if recv == nil { + // Go spec: The scope of an identifier denoting a constant, type, + // variable, or function (but not method) declared at top level + // (outside any function) is the package block. + // + // init() functions cannot be referred to and there may + // be more than one - don't put them in the pkgScope + if ident.Name != "init" { + p.declare(decl, p.pkgScope, ast.Fun, ident) + } + } + + return decl +} + +func (p *parser) parseDecl() ast.Decl { + if p.trace { + defer un(trace(p, "Declaration")) + } + + var f parseSpecFunction + switch p.tok { + case token.CONST: + f = parseConstSpec + + case token.TYPE: + f = parseTypeSpec + + case token.VAR: + f = parseVarSpec + + case token.FUNC: + return p.parseFuncDecl() + + default: + pos := p.pos + p.errorExpected(pos, "declaration") + p.next() // make progress + decl := &ast.BadDecl{pos, p.pos} + return decl + } + + return p.parseGenDecl(p.tok, f) +} + +func (p *parser) parseDeclList() (list []ast.Decl) { + if p.trace { + defer un(trace(p, "DeclList")) + } + + for p.tok != token.EOF { + list = append(list, p.parseDecl()) + } + + return +} + +// ---------------------------------------------------------------------------- +// Source files + +func (p *parser) parseFile() *ast.File { + if p.trace { + defer un(trace(p, "File")) + } + + // package clause + doc := p.leadComment + pos := p.expect(token.PACKAGE) + // Go spec: The package clause is not a declaration; + // the package name does not appear in any scope. + ident := p.parseIdent() + if ident.Name == "_" { + p.error(p.pos, "invalid package name _") + } + p.expectSemi() + + var decls []ast.Decl + + // Don't bother parsing the rest if we had errors already. + // Likely not a Go source file at all. + + if p.ErrorCount() == 0 && p.mode&PackageClauseOnly == 0 { + // import decls + for p.tok == token.IMPORT { + decls = append(decls, p.parseGenDecl(token.IMPORT, parseImportSpec)) + } + + if p.mode&ImportsOnly == 0 { + // rest of package body + for p.tok != token.EOF { + decls = append(decls, p.parseDecl()) + } + } + } + + assert(p.topScope == p.pkgScope, "imbalanced scopes") + + // resolve global identifiers within the same file + i := 0 + for _, ident := range p.unresolved { + // i <= index for current ident + assert(ident.Obj == unresolved, "object already resolved") + ident.Obj = p.pkgScope.Lookup(ident.Name) // also removes unresolved sentinel + if ident.Obj == nil { + p.unresolved[i] = ident + i++ + } + } + + // TODO(gri): store p.imports in AST + return &ast.File{doc, pos, ident, decls, p.pkgScope, p.imports, p.unresolved[0:i], p.comments} +} diff --git a/platform/dbops/binaries/go/go/src/go/printer/testdata/slow.golden b/platform/dbops/binaries/go/go/src/go/printer/testdata/slow.golden new file mode 100644 index 0000000000000000000000000000000000000000..43a15cb1d0815757dd8f3b61804e77143fb5ce3b --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/printer/testdata/slow.golden @@ -0,0 +1,85 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package deepequal_test + +import ( + "testing" + "google3/spam/archer/frontend/deepequal" +) + +func TestTwoNilValues(t *testing.T) { + if err := deepequal.Check(nil, nil); err != nil { + t.Errorf("expected nil, saw %v", err) + } +} + +type Foo struct { + bar *Bar + bang *Bar +} + +type Bar struct { + baz *Baz + foo []*Foo +} + +type Baz struct { + entries map[int]interface{} + whatever string +} + +func newFoo() *Foo { + return &Foo{bar: &Bar{baz: &Baz{ + entries: map[int]interface{}{ + 42: &Foo{}, + 21: &Bar{}, + 11: &Baz{whatever: "it's just a test"}}}}, + bang: &Bar{foo: []*Foo{ + &Foo{bar: &Bar{baz: &Baz{ + entries: map[int]interface{}{ + 43: &Foo{}, + 22: &Bar{}, + 13: &Baz{whatever: "this is nuts"}}}}, + bang: &Bar{foo: []*Foo{ + &Foo{bar: &Bar{baz: &Baz{ + entries: map[int]interface{}{ + 61: &Foo{}, + 71: &Bar{}, + 11: &Baz{whatever: "no, it's Go"}}}}, + bang: &Bar{foo: []*Foo{ + &Foo{bar: &Bar{baz: &Baz{ + entries: map[int]interface{}{ + 0: &Foo{}, + -2: &Bar{}, + -11: &Baz{whatever: "we need to go deeper"}}}}, + bang: &Bar{foo: []*Foo{ + &Foo{bar: &Bar{baz: &Baz{ + entries: map[int]interface{}{ + -2: &Foo{}, + -5: &Bar{}, + -7: &Baz{whatever: "are you serious?"}}}}, + bang: &Bar{foo: []*Foo{}}}, + &Foo{bar: &Bar{baz: &Baz{ + entries: map[int]interface{}{ + -100: &Foo{}, + 50: &Bar{}, + 20: &Baz{whatever: "na, not really ..."}}}}, + bang: &Bar{foo: []*Foo{}}}}}}}}}, + &Foo{bar: &Bar{baz: &Baz{ + entries: map[int]interface{}{ + 2: &Foo{}, + 1: &Bar{}, + -1: &Baz{whatever: "... it's just a test."}}}}, + bang: &Bar{foo: []*Foo{}}}}}}}}} +} + +func TestElaborate(t *testing.T) { + a := newFoo() + b := newFoo() + + if err := deepequal.Check(a, b); err != nil { + t.Errorf("expected nil, saw %v", err) + } +} diff --git a/platform/dbops/binaries/go/go/src/go/printer/testdata/slow.input b/platform/dbops/binaries/go/go/src/go/printer/testdata/slow.input new file mode 100644 index 0000000000000000000000000000000000000000..0e5a23d88605b9ce0a96e3833f80d4f3e3ad2a2e --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/printer/testdata/slow.input @@ -0,0 +1,85 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package deepequal_test + +import ( + "testing" + "google3/spam/archer/frontend/deepequal" +) + +func TestTwoNilValues(t *testing.T) { + if err := deepequal.Check(nil, nil); err != nil { + t.Errorf("expected nil, saw %v", err) + } +} + +type Foo struct { + bar *Bar + bang *Bar +} + +type Bar struct { + baz *Baz + foo []*Foo +} + +type Baz struct { + entries map[int]interface{} + whatever string +} + +func newFoo() (*Foo) { +return &Foo{bar: &Bar{ baz: &Baz{ +entries: map[int]interface{}{ +42: &Foo{}, +21: &Bar{}, +11: &Baz{ whatever: "it's just a test" }}}}, + bang: &Bar{foo: []*Foo{ +&Foo{bar: &Bar{ baz: &Baz{ +entries: map[int]interface{}{ +43: &Foo{}, +22: &Bar{}, +13: &Baz{ whatever: "this is nuts" }}}}, + bang: &Bar{foo: []*Foo{ +&Foo{bar: &Bar{ baz: &Baz{ +entries: map[int]interface{}{ +61: &Foo{}, +71: &Bar{}, +11: &Baz{ whatever: "no, it's Go" }}}}, + bang: &Bar{foo: []*Foo{ +&Foo{bar: &Bar{ baz: &Baz{ +entries: map[int]interface{}{ +0: &Foo{}, +-2: &Bar{}, +-11: &Baz{ whatever: "we need to go deeper" }}}}, + bang: &Bar{foo: []*Foo{ +&Foo{bar: &Bar{ baz: &Baz{ +entries: map[int]interface{}{ +-2: &Foo{}, +-5: &Bar{}, +-7: &Baz{ whatever: "are you serious?" }}}}, + bang: &Bar{foo: []*Foo{}}}, +&Foo{bar: &Bar{ baz: &Baz{ +entries: map[int]interface{}{ +-100: &Foo{}, +50: &Bar{}, +20: &Baz{ whatever: "na, not really ..." }}}}, + bang: &Bar{foo: []*Foo{}}}}}}}}}, +&Foo{bar: &Bar{ baz: &Baz{ +entries: map[int]interface{}{ +2: &Foo{}, +1: &Bar{}, +-1: &Baz{ whatever: "... it's just a test." }}}}, + bang: &Bar{foo: []*Foo{}}}}}}}}} +} + +func TestElaborate(t *testing.T) { + a := newFoo() + b := newFoo() + + if err := deepequal.Check(a, b); err != nil { + t.Errorf("expected nil, saw %v", err) + } +} diff --git a/platform/dbops/binaries/go/go/src/go/printer/testdata/statements.golden b/platform/dbops/binaries/go/go/src/go/printer/testdata/statements.golden new file mode 100644 index 0000000000000000000000000000000000000000..4b13460473553fb269a568595296d457104427f7 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/printer/testdata/statements.golden @@ -0,0 +1,644 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package statements + +var expr bool + +func use(x interface{}) {} + +// Formatting of multi-line return statements. +func _f() { + return + return x, y, z + return T{} + return T{1, 2, 3}, + x, y, z + return T{1, 2, 3}, + x, y, + z + return T{1, + 2, + 3} + return T{1, + 2, + 3, + } + return T{ + 1, + 2, + 3} + return T{ + 1, + 2, + 3, + } + return T{ + 1, + T{1, 2, 3}, + 3, + } + return T{ + 1, + T{1, + 2, 3}, + 3, + } + return T{ + 1, + T{1, + 2, + 3}, + 3, + } + return T{ + 1, + 2, + }, nil + return T{ + 1, + 2, + }, + T{ + x: 3, + y: 4, + }, nil + return T{ + 1, + 2, + }, + nil + return T{ + 1, + 2, + }, + T{ + x: 3, + y: 4, + }, + nil + return x + y + + z + return func() {} + return func() { + _ = 0 + }, T{ + 1, 2, + } + return func() { + _ = 0 + } + return func() T { + return T{ + 1, 2, + } + } +} + +// Formatting of multi-line returns: test cases from issue 1207. +func F() (*T, os.Error) { + return &T{ + X: 1, + Y: 2, + }, + nil +} + +func G() (*T, *T, os.Error) { + return &T{ + X: 1, + Y: 2, + }, + &T{ + X: 3, + Y: 4, + }, + nil +} + +func _() interface{} { + return &fileStat{ + name: basename(file.name), + size: mkSize(d.FileSizeHigh, d.FileSizeLow), + modTime: mkModTime(d.LastWriteTime), + mode: mkMode(d.FileAttributes), + sys: mkSysFromFI(&d), + }, nil +} + +// Formatting of if-statement headers. +func _() { + if true { + } + if true { + } // no semicolon printed + if expr { + } + if expr { + } // no semicolon printed + if expr { + } // no parens printed + if expr { + } // no semicolon and parens printed + if x := expr; true { + use(x) + } + if x := expr; expr { + use(x) + } +} + +// Formatting of switch-statement headers. +func _() { + switch { + } + switch { + } // no semicolon printed + switch expr { + } + switch expr { + } // no semicolon printed + switch expr { + } // no parens printed + switch expr { + } // no semicolon and parens printed + switch x := expr; { + default: + use( + x) + } + switch x := expr; expr { + default: + use(x) + } +} + +// Formatting of switch statement bodies. +func _() { + switch { + } + + switch x := 0; x { + case 1: + use(x) + use(x) // followed by an empty line + + case 2: // followed by an empty line + + use(x) // followed by an empty line + + case 3: // no empty lines + use(x) + use(x) + } + + switch x { + case 0: + use(x) + case 1: // this comment should have no effect on the previous or next line + use(x) + } + + switch x := 0; x { + case 1: + x = 0 + // this comment should be indented + case 2: + x = 0 + // this comment should not be indented, it is aligned with the next case + case 3: + x = 0 + /* indented comment + aligned + aligned + */ + // bla + /* and more */ + case 4: + x = 0 + /* not indented comment + aligned + aligned + */ + // bla + /* and more */ + case 5: + } +} + +// Formatting of selected select statements. +func _() { + select {} + select { /* this comment should not be tab-aligned because the closing } is on the same line */ + } + select { /* this comment should be tab-aligned */ + } + select { // this comment should be tab-aligned + } + select { + case <-c: + } +} + +// Formatting of for-statement headers for single-line for-loops. +func _() { + for { + } + for expr { + } + for expr { + } // no parens printed + for { + } // no semicolons printed + for x := expr; ; { + use(x) + } + for expr { + } // no semicolons printed + for expr { + } // no semicolons and parens printed + for ; ; expr = false { + } + for x := expr; expr; { + use(x) + } + for x := expr; ; expr = false { + use(x) + } + for ; expr; expr = false { + } + for x := expr; expr; expr = false { + use(x) + } + for x := range []int{} { + use(x) + } + for x := range []int{} { + use(x) + } // no parens printed +} + +// Formatting of for-statement headers for multi-line for-loops. +func _() { + for { + } + for expr { + } + for expr { + } // no parens printed + for { + } // no semicolons printed + for x := expr; ; { + use(x) + } + for expr { + } // no semicolons printed + for expr { + } // no semicolons and parens printed + for ; ; expr = false { + } + for x := expr; expr; { + use(x) + } + for x := expr; ; expr = false { + use(x) + } + for ; expr; expr = false { + } + for x := expr; expr; expr = false { + use(x) + } + for range []int{} { + println("foo") + } + for x := range []int{} { + use(x) + } + for x := range []int{} { + use(x) + } // no parens printed +} + +// Formatting of selected short single- and multi-line statements. +func _() { + if cond { + } + if cond { + } // multiple lines + if cond { + } else { + } // else clause always requires multiple lines + + for { + } + for i := 0; i < len(a); 1++ { + } + for i := 0; i < len(a); 1++ { + a[i] = i + } + for i := 0; i < len(a); 1++ { + a[i] = i + } // multiple lines + + for range a { + } + for _ = range a { + } + for _, _ = range a { + } + for i := range a { + } + for i := range a { + a[i] = i + } + for i := range a { + a[i] = i + } // multiple lines + + go func() { + for { + a <- <-b + } + }() + defer func() { + if x := recover(); x != nil { + err = fmt.Sprintf("error: %s", x.msg) + } + }() +} + +// Don't remove mandatory parentheses around composite literals in control clauses. +func _() { + // strip parentheses - no composite literals or composite literals don't start with a type name + if x { + } + if x { + } + if []T{} { + } + if []T{} { + } + if []T{} { + } + + for x { + } + for x { + } + for []T{} { + } + for []T{} { + } + for []T{} { + } + + switch x { + } + switch x { + } + switch []T{} { + } + switch []T{} { + } + + for _ = range []T{T{42}} { + } + + // leave parentheses - composite literals start with a type name + if (T{}) { + } + if (T{}) { + } + if (T{}) { + } + + for (T{}) { + } + for (T{}) { + } + for (T{}) { + } + + switch (T{}) { + } + switch (T{}) { + } + + for _ = range (T1{T{42}}) { + } + + if x == (T{42}[0]) { + } + if (x == T{42}[0]) { + } + if x == (T{42}[0]) { + } + if x == (T{42}[0]) { + } + if x == (T{42}[0]) { + } + if x == a+b*(T{42}[0]) { + } + if (x == a+b*T{42}[0]) { + } + if x == a+b*(T{42}[0]) { + } + if x == a+(b*(T{42}[0])) { + } + if x == a+b*(T{42}[0]) { + } + if (a + b*(T{42}[0])) == x { + } + if (a + b*(T{42}[0])) == x { + } + + if struct{ x bool }{false}.x { + } + if (struct{ x bool }{false}.x) == false { + } + if struct{ x bool }{false}.x == false { + } +} + +// Extra empty lines inside functions. Do respect source code line +// breaks between statement boundaries but print at most one empty +// line at a time. +func _() { + + const _ = 0 + + const _ = 1 + type _ int + type _ float + + var _ = 0 + var x = 1 + + // Each use(x) call below should have at most one empty line before and after. + // Known bug: The first use call may have more than one empty line before + // (see go/printer/nodes.go, func linebreak). + + use(x) + + if x < x { + + use(x) + + } else { + + use(x) + + } +} + +// Formatting around labels. +func _() { +L: +} + +func _() { + // this comment should be indented +L: // no semicolon needed +} + +func _() { + switch 0 { + case 0: + L0: + ; // semicolon required + case 1: + L1: + ; // semicolon required + default: + L2: // no semicolon needed + } +} + +func _() { + f() +L1: + f() +L2: + ; +L3: +} + +func _() { + // this comment should be indented +L: +} + +func _() { +L: + _ = 0 +} + +func _() { + // this comment should be indented +L: + _ = 0 +} + +func _() { + for { + L1: + _ = 0 + L2: + _ = 0 + } +} + +func _() { + // this comment should be indented + for { + L1: + _ = 0 + L2: + _ = 0 + } +} + +func _() { + if true { + _ = 0 + } + _ = 0 // the indentation here should not be affected by the long label name +AnOverlongLabel: + _ = 0 + + if true { + _ = 0 + } + _ = 0 + +L: + _ = 0 +} + +func _() { + for { + goto L + } +L: + + MoreCode() +} + +func _() { + for { + goto L + } +L: // A comment on the same line as the label, followed by a single empty line. + // Known bug: There may be more than one empty line before MoreCode() + // (see go/printer/nodes.go, func linebreak). + + MoreCode() +} + +func _() { + for { + goto L + } +L: + + // There should be a single empty line before this comment. + MoreCode() +} + +func _() { + for { + goto AVeryLongLabelThatShouldNotAffectFormatting + } +AVeryLongLabelThatShouldNotAffectFormatting: + // There should be a single empty line after this comment. + + // There should be a single empty line before this comment. + MoreCode() +} + +// Formatting of empty statements. +func _() { + +} + +func _() { +} + +func _() { +} + +func _() { + f() +} + +func _() { +L: + ; +} + +func _() { +L: + ; + f() +} diff --git a/platform/dbops/binaries/go/go/src/go/printer/testdata/statements.input b/platform/dbops/binaries/go/go/src/go/printer/testdata/statements.input new file mode 100644 index 0000000000000000000000000000000000000000..cade1576bf7845852c9b8e45eab0203ec6587e3e --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/printer/testdata/statements.input @@ -0,0 +1,555 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package statements + +var expr bool + +func use(x interface{}) {} + +// Formatting of multi-line return statements. +func _f() { + return + return x, y, z + return T{} + return T{1, 2, 3}, + x, y, z + return T{1, 2, 3}, + x, y, + z + return T{1, + 2, + 3} + return T{1, + 2, + 3, + } + return T{ + 1, + 2, + 3} + return T{ + 1, + 2, + 3, + } + return T{ + 1, + T{1, 2, 3}, + 3, + } + return T{ + 1, + T{1, + 2, 3}, + 3, + } + return T{ + 1, + T{1, + 2, + 3}, + 3, + } + return T{ + 1, + 2, + }, nil + return T{ + 1, + 2, + }, + T{ + x: 3, + y: 4, + }, nil + return T{ + 1, + 2, + }, + nil + return T{ + 1, + 2, + }, + T{ + x: 3, + y: 4, + }, + nil + return x + y + + z + return func() {} + return func() { + _ = 0 + }, T{ + 1, 2, + } + return func() { + _ = 0 + } + return func() T { + return T { + 1, 2, + } + } +} + +// Formatting of multi-line returns: test cases from issue 1207. +func F() (*T, os.Error) { + return &T{ + X: 1, + Y: 2, + }, + nil +} + +func G() (*T, *T, os.Error) { + return &T{ + X: 1, + Y: 2, + }, + &T{ + X: 3, + Y: 4, + }, + nil +} + +func _() interface{} { + return &fileStat{ + name: basename(file.name), + size: mkSize(d.FileSizeHigh, d.FileSizeLow), + modTime: mkModTime(d.LastWriteTime), + mode: mkMode(d.FileAttributes), + sys: mkSysFromFI(&d), + }, nil +} + +// Formatting of if-statement headers. +func _() { + if true {} + if; true {} // no semicolon printed + if expr{} + if;expr{} // no semicolon printed + if (expr){} // no parens printed + if;((expr)){} // no semicolon and parens printed + if x:=expr;true{ + use(x)} + if x:=expr; expr {use(x)} +} + + +// Formatting of switch-statement headers. +func _() { + switch {} + switch;{} // no semicolon printed + switch expr {} + switch;expr{} // no semicolon printed + switch (expr) {} // no parens printed + switch;((expr)){} // no semicolon and parens printed + switch x := expr; { default:use( +x) + } + switch x := expr; expr {default:use(x)} +} + + +// Formatting of switch statement bodies. +func _() { + switch { + } + + switch x := 0; x { + case 1: + use(x) + use(x) // followed by an empty line + + case 2: // followed by an empty line + + use(x) // followed by an empty line + + case 3: // no empty lines + use(x) + use(x) + } + + switch x { + case 0: + use(x) + case 1: // this comment should have no effect on the previous or next line + use(x) + } + + switch x := 0; x { + case 1: + x = 0 + // this comment should be indented + case 2: + x = 0 + // this comment should not be indented, it is aligned with the next case + case 3: + x = 0 + /* indented comment + aligned + aligned + */ + // bla + /* and more */ + case 4: + x = 0 + /* not indented comment + aligned + aligned + */ + // bla + /* and more */ + case 5: + } +} + + +// Formatting of selected select statements. +func _() { + select { + } + select { /* this comment should not be tab-aligned because the closing } is on the same line */ } + select { /* this comment should be tab-aligned */ + } + select { // this comment should be tab-aligned + } + select { case <-c: } +} + + +// Formatting of for-statement headers for single-line for-loops. +func _() { + for{} + for expr {} + for (expr) {} // no parens printed + for;;{} // no semicolons printed + for x :=expr;; {use( x)} + for; expr;{} // no semicolons printed + for; ((expr));{} // no semicolons and parens printed + for; ; expr = false {} + for x :=expr; expr; {use(x)} + for x := expr;; expr=false {use(x)} + for;expr;expr =false {} + for x := expr;expr;expr = false { use(x) } + for x := range []int{} { use(x) } + for x := range (([]int{})) { use(x) } // no parens printed +} + + +// Formatting of for-statement headers for multi-line for-loops. +func _() { + for{ + } + for expr { + } + for (expr) { + } // no parens printed + for;;{ + } // no semicolons printed + for x :=expr;; {use( x) + } + for; expr;{ + } // no semicolons printed + for; ((expr));{ + } // no semicolons and parens printed + for; ; expr = false { + } + for x :=expr; expr; {use(x) + } + for x := expr;; expr=false {use(x) + } + for;expr;expr =false { + } + for x := expr;expr;expr = false { + use(x) + } + for range []int{} { + println("foo")} + for x := range []int{} { + use(x) } + for x := range (([]int{})) { + use(x) } // no parens printed +} + + +// Formatting of selected short single- and multi-line statements. +func _() { + if cond {} + if cond { + } // multiple lines + if cond {} else {} // else clause always requires multiple lines + + for {} + for i := 0; i < len(a); 1++ {} + for i := 0; i < len(a); 1++ { a[i] = i } + for i := 0; i < len(a); 1++ { a[i] = i + } // multiple lines + + for range a{} + for _ = range a{} + for _, _ = range a{} + for i := range a {} + for i := range a { a[i] = i } + for i := range a { a[i] = i + } // multiple lines + + go func() { for { a <- <-b } }() + defer func() { if x := recover(); x != nil { err = fmt.Sprintf("error: %s", x.msg) } }() +} + + +// Don't remove mandatory parentheses around composite literals in control clauses. +func _() { + // strip parentheses - no composite literals or composite literals don't start with a type name + if (x) {} + if (((x))) {} + if ([]T{}) {} + if (([]T{})) {} + if ; (((([]T{})))) {} + + for (x) {} + for (((x))) {} + for ([]T{}) {} + for (([]T{})) {} + for ; (((([]T{})))) ; {} + + switch (x) {} + switch (((x))) {} + switch ([]T{}) {} + switch ; (((([]T{})))) {} + + for _ = range ((([]T{T{42}}))) {} + + // leave parentheses - composite literals start with a type name + if (T{}) {} + if ((T{})) {} + if ; ((((T{})))) {} + + for (T{}) {} + for ((T{})) {} + for ; ((((T{})))) ; {} + + switch (T{}) {} + switch ; ((((T{})))) {} + + for _ = range (((T1{T{42}}))) {} + + if x == (T{42}[0]) {} + if (x == T{42}[0]) {} + if (x == (T{42}[0])) {} + if (x == (((T{42}[0])))) {} + if (((x == (T{42}[0])))) {} + if x == a + b*(T{42}[0]) {} + if (x == a + b*T{42}[0]) {} + if (x == a + b*(T{42}[0])) {} + if (x == a + ((b * (T{42}[0])))) {} + if (((x == a + b * (T{42}[0])))) {} + if (((a + b * (T{42}[0])) == x)) {} + if (((a + b * (T{42}[0])))) == x {} + + if (struct{x bool}{false}.x) {} + if (struct{x bool}{false}.x) == false {} + if (struct{x bool}{false}.x == false) {} +} + + +// Extra empty lines inside functions. Do respect source code line +// breaks between statement boundaries but print at most one empty +// line at a time. +func _() { + + const _ = 0 + + const _ = 1 + type _ int + type _ float + + var _ = 0 + var x = 1 + + // Each use(x) call below should have at most one empty line before and after. + // Known bug: The first use call may have more than one empty line before + // (see go/printer/nodes.go, func linebreak). + + + + use(x) + + if x < x { + + use(x) + + } else { + + use(x) + + } +} + + +// Formatting around labels. +func _() { + L: +} + + +func _() { + // this comment should be indented + L: ; // no semicolon needed +} + + +func _() { + switch 0 { + case 0: + L0: ; // semicolon required + case 1: + L1: ; // semicolon required + default: + L2: ; // no semicolon needed + } +} + + +func _() { + f() +L1: + f() +L2: + ; +L3: +} + + +func _() { + // this comment should be indented + L: +} + + +func _() { + L: _ = 0 +} + + +func _() { + // this comment should be indented + L: _ = 0 +} + + +func _() { + for { + L1: _ = 0 + L2: + _ = 0 + } +} + + +func _() { + // this comment should be indented + for { + L1: _ = 0 + L2: + _ = 0 + } +} + + +func _() { + if true { + _ = 0 + } + _ = 0 // the indentation here should not be affected by the long label name +AnOverlongLabel: + _ = 0 + + if true { + _ = 0 + } + _ = 0 + +L: _ = 0 +} + + +func _() { + for { + goto L + } +L: + + MoreCode() +} + + +func _() { + for { + goto L + } +L: // A comment on the same line as the label, followed by a single empty line. + // Known bug: There may be more than one empty line before MoreCode() + // (see go/printer/nodes.go, func linebreak). + + + + + MoreCode() +} + + +func _() { + for { + goto L + } +L: + + + + + // There should be a single empty line before this comment. + MoreCode() +} + + +func _() { + for { + goto AVeryLongLabelThatShouldNotAffectFormatting + } +AVeryLongLabelThatShouldNotAffectFormatting: + // There should be a single empty line after this comment. + + // There should be a single empty line before this comment. + MoreCode() +} + + +// Formatting of empty statements. +func _() { + ;;;;;;;;;;;;;;;;;;;;;;;;; +} + +func _() {;;;;;;;;;;;;;;;;;;;;;;;;; +} + +func _() {;;;;;;;;;;;;;;;;;;;;;;;;;} + +func _() { +f();;;;;;;;;;;;;;;;;;;;;;;;; +} + +func _() { +L:;;;;;;;;;;;; +} + +func _() { +L:;;;;;;;;;;;; + f() +} diff --git a/platform/dbops/binaries/go/go/src/go/types/testdata/local/issue47996.go b/platform/dbops/binaries/go/go/src/go/types/testdata/local/issue47996.go new file mode 100644 index 0000000000000000000000000000000000000000..4d2892082382ff27bb181ec7c093177a84dfb494 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/types/testdata/local/issue47996.go @@ -0,0 +1,9 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +// don't crash +// TODO(gri) make this test work for go/types +// func T[P] m() {} diff --git a/platform/dbops/binaries/go/go/src/go/types/testdata/local/shifts.go b/platform/dbops/binaries/go/go/src/go/types/testdata/local/shifts.go new file mode 100644 index 0000000000000000000000000000000000000000..790daa3529795abbbff0287f5775816a97e6c671 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/types/testdata/local/shifts.go @@ -0,0 +1,27 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The following shift tests are disabled in the shared +// testdata/check/shifts.go file because they don't work +// correctly with types2 at the moment. See go.dev/issue/52080. +// Make sure we keep testing them with go/types. +// +// TODO(gri) Once go.dev/issue/52080 is fixed, this file can be +// deleted in favor of the re-enabled tests +// in the shared file. + +package p + +func _() { + var s uint + + _ = int32(0x80000000 /* ERROR "overflows int32" */ << s) + // TODO(rfindley) Eliminate the redundant error here. + _ = int32(( /* ERROR "truncated to int32" */ 0x80000000 /* ERROR "truncated to int32" */ + 0i) << s) + + _ = int(1 + 0i<<0) + _ = int((1 + 0i) << s) + _ = int(1.0 << s) + _ = int(complex(1, 0) << s) +} diff --git a/platform/dbops/binaries/go/go/src/go/types/testdata/manual.go b/platform/dbops/binaries/go/go/src/go/types/testdata/manual.go new file mode 100644 index 0000000000000000000000000000000000000000..57dcc227a5980279cc165f7154b3f81cfde1cfd5 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/go/types/testdata/manual.go @@ -0,0 +1,8 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file is tested when running "go test -run Manual" +// without source arguments. Use for one-off debugging. + +package p diff --git a/platform/dbops/binaries/go/go/src/hash/adler32/adler32.go b/platform/dbops/binaries/go/go/src/hash/adler32/adler32.go new file mode 100644 index 0000000000000000000000000000000000000000..07695e947a165765f7e3fe5adc4a54860bad36d8 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/adler32/adler32.go @@ -0,0 +1,138 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package adler32 implements the Adler-32 checksum. +// +// It is defined in RFC 1950: +// +// Adler-32 is composed of two sums accumulated per byte: s1 is +// the sum of all bytes, s2 is the sum of all s1 values. Both sums +// are done modulo 65521. s1 is initialized to 1, s2 to zero. The +// Adler-32 checksum is stored as s2*65536 + s1 in most- +// significant-byte first (network) order. +package adler32 + +import ( + "errors" + "hash" +) + +const ( + // mod is the largest prime that is less than 65536. + mod = 65521 + // nmax is the largest n such that + // 255 * n * (n+1) / 2 + (n+1) * (mod-1) <= 2^32-1. + // It is mentioned in RFC 1950 (search for "5552"). + nmax = 5552 +) + +// The size of an Adler-32 checksum in bytes. +const Size = 4 + +// digest represents the partial evaluation of a checksum. +// The low 16 bits are s1, the high 16 bits are s2. +type digest uint32 + +func (d *digest) Reset() { *d = 1 } + +// New returns a new hash.Hash32 computing the Adler-32 checksum. Its +// Sum method will lay the value out in big-endian byte order. The +// returned Hash32 also implements [encoding.BinaryMarshaler] and +// [encoding.BinaryUnmarshaler] to marshal and unmarshal the internal +// state of the hash. +func New() hash.Hash32 { + d := new(digest) + d.Reset() + return d +} + +func (d *digest) Size() int { return Size } + +func (d *digest) BlockSize() int { return 4 } + +const ( + magic = "adl\x01" + marshaledSize = len(magic) + 4 +) + +func (d *digest) MarshalBinary() ([]byte, error) { + b := make([]byte, 0, marshaledSize) + b = append(b, magic...) + b = appendUint32(b, uint32(*d)) + return b, nil +} + +func (d *digest) UnmarshalBinary(b []byte) error { + if len(b) < len(magic) || string(b[:len(magic)]) != magic { + return errors.New("hash/adler32: invalid hash state identifier") + } + if len(b) != marshaledSize { + return errors.New("hash/adler32: invalid hash state size") + } + *d = digest(readUint32(b[len(magic):])) + return nil +} + +// appendUint32 is semantically the same as [binary.BigEndian.AppendUint32] +// We copied this function because we can not import "encoding/binary" here. +func appendUint32(b []byte, x uint32) []byte { + return append(b, + byte(x>>24), + byte(x>>16), + byte(x>>8), + byte(x), + ) +} + +// readUint32 is semantically the same as [binary.BigEndian.Uint32] +// We copied this function because we can not import "encoding/binary" here. +func readUint32(b []byte) uint32 { + _ = b[3] + return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24 +} + +// Add p to the running checksum d. +func update(d digest, p []byte) digest { + s1, s2 := uint32(d&0xffff), uint32(d>>16) + for len(p) > 0 { + var q []byte + if len(p) > nmax { + p, q = p[:nmax], p[nmax:] + } + for len(p) >= 4 { + s1 += uint32(p[0]) + s2 += s1 + s1 += uint32(p[1]) + s2 += s1 + s1 += uint32(p[2]) + s2 += s1 + s1 += uint32(p[3]) + s2 += s1 + p = p[4:] + } + for _, x := range p { + s1 += uint32(x) + s2 += s1 + } + s1 %= mod + s2 %= mod + p = q + } + return digest(s2<<16 | s1) +} + +func (d *digest) Write(p []byte) (nn int, err error) { + *d = update(*d, p) + return len(p), nil +} + +func (d *digest) Sum32() uint32 { return uint32(*d) } + +func (d *digest) Sum(in []byte) []byte { + s := uint32(*d) + return append(in, byte(s>>24), byte(s>>16), byte(s>>8), byte(s)) +} + +// Checksum returns the Adler-32 checksum of data. +func Checksum(data []byte) uint32 { return uint32(update(1, data)) } diff --git a/platform/dbops/binaries/go/go/src/hash/adler32/adler32_test.go b/platform/dbops/binaries/go/go/src/hash/adler32/adler32_test.go new file mode 100644 index 0000000000000000000000000000000000000000..6bac80250762652e0396a19403cda4a063005323 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/adler32/adler32_test.go @@ -0,0 +1,140 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package adler32 + +import ( + "encoding" + "io" + "strings" + "testing" +) + +var golden = []struct { + out uint32 + in string + halfState string // marshaled hash state after first half of in written, used by TestGoldenMarshal +}{ + {0x00000001, "", "adl\x01\x00\x00\x00\x01"}, + {0x00620062, "a", "adl\x01\x00\x00\x00\x01"}, + {0x012600c4, "ab", "adl\x01\x00b\x00b"}, + {0x024d0127, "abc", "adl\x01\x00b\x00b"}, + {0x03d8018b, "abcd", "adl\x01\x01&\x00\xc4"}, + {0x05c801f0, "abcde", "adl\x01\x01&\x00\xc4"}, + {0x081e0256, "abcdef", "adl\x01\x02M\x01'"}, + {0x0adb02bd, "abcdefg", "adl\x01\x02M\x01'"}, + {0x0e000325, "abcdefgh", "adl\x01\x03\xd8\x01\x8b"}, + {0x118e038e, "abcdefghi", "adl\x01\x03\xd8\x01\x8b"}, + {0x158603f8, "abcdefghij", "adl\x01\x05\xc8\x01\xf0"}, + {0x3f090f02, "Discard medicine more than two years old.", "adl\x01NU\a\x87"}, + {0x46d81477, "He who has a shady past knows that nice guys finish last.", "adl\x01\x89\x8e\t\xe9"}, + {0x40ee0ee1, "I wouldn't marry him with a ten foot pole.", "adl\x01R\t\ag"}, + {0x16661315, "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave", "adl\x01\u007f\xbb\t\x10"}, + {0x5b2e1480, "The days of the digital watch are numbered. -Tom Stoppard", "adl\x01\x99:\n~"}, + {0x8c3c09ea, "Nepal premier won't resign.", "adl\x01\"\x05\x05\x05"}, + {0x45ac18fd, "For every action there is an equal and opposite government program.", "adl\x01\xcc\xfa\f\x00"}, + {0x53c61462, "His money is twice tainted: 'taint yours and 'taint mine.", "adl\x01\x93\xa9\n\b"}, + {0x7e511e63, "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977", "adl\x01e\xf5\x10\x14"}, + {0xe4801a6a, "It's a tiny change to the code and not completely disgusting. - Bob Manchek", "adl\x01\xee\x00\f\xb2"}, + {0x61b507df, "size: a.out: bad magic", "adl\x01\x1a\xfc\x04\x1d"}, + {0xb8631171, "The major problem is with sendmail. -Mark Horton", "adl\x01mi\b\xdc"}, + {0x8b5e1904, "Give me a rock, paper and scissors and I will move the world. CCFestoon", "adl\x01\xe3\n\f\x9f"}, + {0x7cc6102b, "If the enemy is within range, then so are you.", "adl\x01_\xe0\b\x1e"}, + {0x700318e7, "It's well we cannot hear the screams/That we create in others' dreams.", "adl\x01ۘ\f\x87"}, + {0x1e601747, "You remind me of a TV show, but that's all right: I watch it anyway.", "adl\x01\xcc}\v\x83"}, + {0xb55b0b09, "C is as portable as Stonehedge!!", "adl\x01,^\x05\xad"}, + {0x39111dd0, "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley", "adl\x01M\xd1\x0e\xc8"}, + {0x91dd304f, "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule", "adl\x01#\xd8\x17\xd7"}, + {0x2e5d1316, "How can you write a big system without C++? -Paul Glick", "adl\x01\x8fU\n\x0f"}, + {0xd0201df6, "'Invariant assertions' is the most elegant programming technique! -Tom Szymanski", "adl\x01/\x98\x0e\xc4"}, + {0x211297c8, strings.Repeat("\xff", 5548) + "8", "adl\x01\x9a\xa6\xcb\xc1"}, + {0xbaa198c8, strings.Repeat("\xff", 5549) + "9", "adl\x01gu\xcc\xc0"}, + {0x553499be, strings.Repeat("\xff", 5550) + "0", "adl\x01gu\xcc\xc0"}, + {0xf0c19abe, strings.Repeat("\xff", 5551) + "1", "adl\x015CͿ"}, + {0x8d5c9bbe, strings.Repeat("\xff", 5552) + "2", "adl\x015CͿ"}, + {0x2af69cbe, strings.Repeat("\xff", 5553) + "3", "adl\x01\x04\x10ξ"}, + {0xc9809dbe, strings.Repeat("\xff", 5554) + "4", "adl\x01\x04\x10ξ"}, + {0x69189ebe, strings.Repeat("\xff", 5555) + "5", "adl\x01\xd3\xcdϽ"}, + {0x86af0001, strings.Repeat("\x00", 1e5), "adl\x01\xc3P\x00\x01"}, + {0x79660b4d, strings.Repeat("a", 1e5), "adl\x01\x81k\x05\xa7"}, + {0x110588ee, strings.Repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1e4), "adl\x01e\xd2\xc4p"}, +} + +// checksum is a slow but simple implementation of the Adler-32 checksum. +// It is a straight port of the sample code in RFC 1950 section 9. +func checksum(p []byte) uint32 { + s1, s2 := uint32(1), uint32(0) + for _, x := range p { + s1 = (s1 + uint32(x)) % mod + s2 = (s2 + s1) % mod + } + return s2<<16 | s1 +} + +func TestGolden(t *testing.T) { + for _, g := range golden { + in := g.in + if len(in) > 220 { + in = in[:100] + "..." + in[len(in)-100:] + } + p := []byte(g.in) + if got := checksum(p); got != g.out { + t.Errorf("simple implementation: checksum(%q) = 0x%x want 0x%x", in, got, g.out) + continue + } + if got := Checksum(p); got != g.out { + t.Errorf("optimized implementation: Checksum(%q) = 0x%x want 0x%x", in, got, g.out) + continue + } + } +} + +func TestGoldenMarshal(t *testing.T) { + for _, g := range golden { + h := New() + h2 := New() + + io.WriteString(h, g.in[:len(g.in)/2]) + + state, err := h.(encoding.BinaryMarshaler).MarshalBinary() + if err != nil { + t.Errorf("could not marshal: %v", err) + continue + } + + if string(state) != g.halfState { + t.Errorf("checksum(%q) state = %q, want %q", g.in, state, g.halfState) + continue + } + + if err := h2.(encoding.BinaryUnmarshaler).UnmarshalBinary(state); err != nil { + t.Errorf("could not unmarshal: %v", err) + continue + } + + io.WriteString(h, g.in[len(g.in)/2:]) + io.WriteString(h2, g.in[len(g.in)/2:]) + + if h.Sum32() != h2.Sum32() { + t.Errorf("checksum(%q) = 0x%x != marshaled (0x%x)", g.in, h.Sum32(), h2.Sum32()) + } + } +} + +func BenchmarkAdler32KB(b *testing.B) { + b.SetBytes(1024) + data := make([]byte, 1024) + for i := range data { + data[i] = byte(i) + } + h := New() + in := make([]byte, 0, h.Size()) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + h.Reset() + h.Write(data) + h.Sum(in) + } +} diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/crc32.go b/platform/dbops/binaries/go/go/src/hash/crc32/crc32.go new file mode 100644 index 0000000000000000000000000000000000000000..170f05cf8a172e25aa95142063f0aa975a5590f0 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/crc32.go @@ -0,0 +1,268 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package crc32 implements the 32-bit cyclic redundancy check, or CRC-32, +// checksum. See https://en.wikipedia.org/wiki/Cyclic_redundancy_check for +// information. +// +// Polynomials are represented in LSB-first form also known as reversed representation. +// +// See https://en.wikipedia.org/wiki/Mathematics_of_cyclic_redundancy_checks#Reversed_representations_and_reciprocal_polynomials +// for information. +package crc32 + +import ( + "errors" + "hash" + "sync" + "sync/atomic" +) + +// The size of a CRC-32 checksum in bytes. +const Size = 4 + +// Predefined polynomials. +const ( + // IEEE is by far and away the most common CRC-32 polynomial. + // Used by ethernet (IEEE 802.3), v.42, fddi, gzip, zip, png, ... + IEEE = 0xedb88320 + + // Castagnoli's polynomial, used in iSCSI. + // Has better error detection characteristics than IEEE. + // https://dx.doi.org/10.1109/26.231911 + Castagnoli = 0x82f63b78 + + // Koopman's polynomial. + // Also has better error detection characteristics than IEEE. + // https://dx.doi.org/10.1109/DSN.2002.1028931 + Koopman = 0xeb31d82e +) + +// Table is a 256-word table representing the polynomial for efficient processing. +type Table [256]uint32 + +// This file makes use of functions implemented in architecture-specific files. +// The interface that they implement is as follows: +// +// // archAvailableIEEE reports whether an architecture-specific CRC32-IEEE +// // algorithm is available. +// archAvailableIEEE() bool +// +// // archInitIEEE initializes the architecture-specific CRC3-IEEE algorithm. +// // It can only be called if archAvailableIEEE() returns true. +// archInitIEEE() +// +// // archUpdateIEEE updates the given CRC32-IEEE. It can only be called if +// // archInitIEEE() was previously called. +// archUpdateIEEE(crc uint32, p []byte) uint32 +// +// // archAvailableCastagnoli reports whether an architecture-specific +// // CRC32-C algorithm is available. +// archAvailableCastagnoli() bool +// +// // archInitCastagnoli initializes the architecture-specific CRC32-C +// // algorithm. It can only be called if archAvailableCastagnoli() returns +// // true. +// archInitCastagnoli() +// +// // archUpdateCastagnoli updates the given CRC32-C. It can only be called +// // if archInitCastagnoli() was previously called. +// archUpdateCastagnoli(crc uint32, p []byte) uint32 + +// castagnoliTable points to a lazily initialized Table for the Castagnoli +// polynomial. MakeTable will always return this value when asked to make a +// Castagnoli table so we can compare against it to find when the caller is +// using this polynomial. +var castagnoliTable *Table +var castagnoliTable8 *slicing8Table +var updateCastagnoli func(crc uint32, p []byte) uint32 +var castagnoliOnce sync.Once +var haveCastagnoli atomic.Bool + +func castagnoliInit() { + castagnoliTable = simpleMakeTable(Castagnoli) + + if archAvailableCastagnoli() { + archInitCastagnoli() + updateCastagnoli = archUpdateCastagnoli + } else { + // Initialize the slicing-by-8 table. + castagnoliTable8 = slicingMakeTable(Castagnoli) + updateCastagnoli = func(crc uint32, p []byte) uint32 { + return slicingUpdate(crc, castagnoliTable8, p) + } + } + + haveCastagnoli.Store(true) +} + +// IEEETable is the table for the [IEEE] polynomial. +var IEEETable = simpleMakeTable(IEEE) + +// ieeeTable8 is the slicing8Table for IEEE +var ieeeTable8 *slicing8Table +var updateIEEE func(crc uint32, p []byte) uint32 +var ieeeOnce sync.Once + +func ieeeInit() { + if archAvailableIEEE() { + archInitIEEE() + updateIEEE = archUpdateIEEE + } else { + // Initialize the slicing-by-8 table. + ieeeTable8 = slicingMakeTable(IEEE) + updateIEEE = func(crc uint32, p []byte) uint32 { + return slicingUpdate(crc, ieeeTable8, p) + } + } +} + +// MakeTable returns a [Table] constructed from the specified polynomial. +// The contents of this [Table] must not be modified. +func MakeTable(poly uint32) *Table { + switch poly { + case IEEE: + ieeeOnce.Do(ieeeInit) + return IEEETable + case Castagnoli: + castagnoliOnce.Do(castagnoliInit) + return castagnoliTable + default: + return simpleMakeTable(poly) + } +} + +// digest represents the partial evaluation of a checksum. +type digest struct { + crc uint32 + tab *Table +} + +// New creates a new [hash.Hash32] computing the CRC-32 checksum using the +// polynomial represented by the [Table]. Its Sum method will lay the +// value out in big-endian byte order. The returned Hash32 also +// implements [encoding.BinaryMarshaler] and [encoding.BinaryUnmarshaler] to +// marshal and unmarshal the internal state of the hash. +func New(tab *Table) hash.Hash32 { + if tab == IEEETable { + ieeeOnce.Do(ieeeInit) + } + return &digest{0, tab} +} + +// NewIEEE creates a new [hash.Hash32] computing the CRC-32 checksum using +// the [IEEE] polynomial. Its Sum method will lay the value out in +// big-endian byte order. The returned Hash32 also implements +// [encoding.BinaryMarshaler] and [encoding.BinaryUnmarshaler] to marshal +// and unmarshal the internal state of the hash. +func NewIEEE() hash.Hash32 { return New(IEEETable) } + +func (d *digest) Size() int { return Size } + +func (d *digest) BlockSize() int { return 1 } + +func (d *digest) Reset() { d.crc = 0 } + +const ( + magic = "crc\x01" + marshaledSize = len(magic) + 4 + 4 +) + +func (d *digest) MarshalBinary() ([]byte, error) { + b := make([]byte, 0, marshaledSize) + b = append(b, magic...) + b = appendUint32(b, tableSum(d.tab)) + b = appendUint32(b, d.crc) + return b, nil +} + +func (d *digest) UnmarshalBinary(b []byte) error { + if len(b) < len(magic) || string(b[:len(magic)]) != magic { + return errors.New("hash/crc32: invalid hash state identifier") + } + if len(b) != marshaledSize { + return errors.New("hash/crc32: invalid hash state size") + } + if tableSum(d.tab) != readUint32(b[4:]) { + return errors.New("hash/crc32: tables do not match") + } + d.crc = readUint32(b[8:]) + return nil +} + +// appendUint32 is semantically the same as [binary.BigEndian.AppendUint32] +// We copied this function because we can not import "encoding/binary" here. +func appendUint32(b []byte, x uint32) []byte { + return append(b, + byte(x>>24), + byte(x>>16), + byte(x>>8), + byte(x), + ) +} + +// readUint32 is semantically the same as [binary.BigEndian.Uint32] +// We copied this function because we can not import "encoding/binary" here. +func readUint32(b []byte) uint32 { + _ = b[3] + return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24 +} + +func update(crc uint32, tab *Table, p []byte, checkInitIEEE bool) uint32 { + switch { + case haveCastagnoli.Load() && tab == castagnoliTable: + return updateCastagnoli(crc, p) + case tab == IEEETable: + if checkInitIEEE { + ieeeOnce.Do(ieeeInit) + } + return updateIEEE(crc, p) + default: + return simpleUpdate(crc, tab, p) + } +} + +// Update returns the result of adding the bytes in p to the crc. +func Update(crc uint32, tab *Table, p []byte) uint32 { + // Unfortunately, because IEEETable is exported, IEEE may be used without a + // call to MakeTable. We have to make sure it gets initialized in that case. + return update(crc, tab, p, true) +} + +func (d *digest) Write(p []byte) (n int, err error) { + // We only create digest objects through New() which takes care of + // initialization in this case. + d.crc = update(d.crc, d.tab, p, false) + return len(p), nil +} + +func (d *digest) Sum32() uint32 { return d.crc } + +func (d *digest) Sum(in []byte) []byte { + s := d.Sum32() + return append(in, byte(s>>24), byte(s>>16), byte(s>>8), byte(s)) +} + +// Checksum returns the CRC-32 checksum of data +// using the polynomial represented by the [Table]. +func Checksum(data []byte, tab *Table) uint32 { return Update(0, tab, data) } + +// ChecksumIEEE returns the CRC-32 checksum of data +// using the [IEEE] polynomial. +func ChecksumIEEE(data []byte) uint32 { + ieeeOnce.Do(ieeeInit) + return updateIEEE(0, data) +} + +// tableSum returns the IEEE checksum of table t. +func tableSum(t *Table) uint32 { + var a [1024]byte + b := a[:0] + if t != nil { + for _, x := range t { + b = appendUint32(b, x) + } + } + return ChecksumIEEE(b) +} diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/crc32_amd64.go b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_amd64.go new file mode 100644 index 0000000000000000000000000000000000000000..6be129f5ddd4c0a7d51edb62d32429b6785acbf6 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_amd64.go @@ -0,0 +1,225 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// AMD64-specific hardware-assisted CRC32 algorithms. See crc32.go for a +// description of the interface that each architecture-specific file +// implements. + +package crc32 + +import ( + "internal/cpu" + "unsafe" +) + +// This file contains the code to call the SSE 4.2 version of the Castagnoli +// and IEEE CRC. + +// castagnoliSSE42 is defined in crc32_amd64.s and uses the SSE 4.2 CRC32 +// instruction. +// +//go:noescape +func castagnoliSSE42(crc uint32, p []byte) uint32 + +// castagnoliSSE42Triple is defined in crc32_amd64.s and uses the SSE 4.2 CRC32 +// instruction. +// +//go:noescape +func castagnoliSSE42Triple( + crcA, crcB, crcC uint32, + a, b, c []byte, + rounds uint32, +) (retA uint32, retB uint32, retC uint32) + +// ieeeCLMUL is defined in crc_amd64.s and uses the PCLMULQDQ +// instruction as well as SSE 4.1. +// +//go:noescape +func ieeeCLMUL(crc uint32, p []byte) uint32 + +const castagnoliK1 = 168 +const castagnoliK2 = 1344 + +type sse42Table [4]Table + +var castagnoliSSE42TableK1 *sse42Table +var castagnoliSSE42TableK2 *sse42Table + +func archAvailableCastagnoli() bool { + return cpu.X86.HasSSE42 +} + +func archInitCastagnoli() { + if !cpu.X86.HasSSE42 { + panic("arch-specific Castagnoli not available") + } + castagnoliSSE42TableK1 = new(sse42Table) + castagnoliSSE42TableK2 = new(sse42Table) + // See description in updateCastagnoli. + // t[0][i] = CRC(i000, O) + // t[1][i] = CRC(0i00, O) + // t[2][i] = CRC(00i0, O) + // t[3][i] = CRC(000i, O) + // where O is a sequence of K zeros. + var tmp [castagnoliK2]byte + for b := 0; b < 4; b++ { + for i := 0; i < 256; i++ { + val := uint32(i) << uint32(b*8) + castagnoliSSE42TableK1[b][i] = castagnoliSSE42(val, tmp[:castagnoliK1]) + castagnoliSSE42TableK2[b][i] = castagnoliSSE42(val, tmp[:]) + } + } +} + +// castagnoliShift computes the CRC32-C of K1 or K2 zeroes (depending on the +// table given) with the given initial crc value. This corresponds to +// CRC(crc, O) in the description in updateCastagnoli. +func castagnoliShift(table *sse42Table, crc uint32) uint32 { + return table[3][crc>>24] ^ + table[2][(crc>>16)&0xFF] ^ + table[1][(crc>>8)&0xFF] ^ + table[0][crc&0xFF] +} + +func archUpdateCastagnoli(crc uint32, p []byte) uint32 { + if !cpu.X86.HasSSE42 { + panic("not available") + } + + // This method is inspired from the algorithm in Intel's white paper: + // "Fast CRC Computation for iSCSI Polynomial Using CRC32 Instruction" + // The same strategy of splitting the buffer in three is used but the + // combining calculation is different; the complete derivation is explained + // below. + // + // -- The basic idea -- + // + // The CRC32 instruction (available in SSE4.2) can process 8 bytes at a + // time. In recent Intel architectures the instruction takes 3 cycles; + // however the processor can pipeline up to three instructions if they + // don't depend on each other. + // + // Roughly this means that we can process three buffers in about the same + // time we can process one buffer. + // + // The idea is then to split the buffer in three, CRC the three pieces + // separately and then combine the results. + // + // Combining the results requires precomputed tables, so we must choose a + // fixed buffer length to optimize. The longer the length, the faster; but + // only buffers longer than this length will use the optimization. We choose + // two cutoffs and compute tables for both: + // - one around 512: 168*3=504 + // - one around 4KB: 1344*3=4032 + // + // -- The nitty gritty -- + // + // Let CRC(I, X) be the non-inverted CRC32-C of the sequence X (with + // initial non-inverted CRC I). This function has the following properties: + // (a) CRC(I, AB) = CRC(CRC(I, A), B) + // (b) CRC(I, A xor B) = CRC(I, A) xor CRC(0, B) + // + // Say we want to compute CRC(I, ABC) where A, B, C are three sequences of + // K bytes each, where K is a fixed constant. Let O be the sequence of K zero + // bytes. + // + // CRC(I, ABC) = CRC(I, ABO xor C) + // = CRC(I, ABO) xor CRC(0, C) + // = CRC(CRC(I, AB), O) xor CRC(0, C) + // = CRC(CRC(I, AO xor B), O) xor CRC(0, C) + // = CRC(CRC(I, AO) xor CRC(0, B), O) xor CRC(0, C) + // = CRC(CRC(CRC(I, A), O) xor CRC(0, B), O) xor CRC(0, C) + // + // The castagnoliSSE42Triple function can compute CRC(I, A), CRC(0, B), + // and CRC(0, C) efficiently. We just need to find a way to quickly compute + // CRC(uvwx, O) given a 4-byte initial value uvwx. We can precompute these + // values; since we can't have a 32-bit table, we break it up into four + // 8-bit tables: + // + // CRC(uvwx, O) = CRC(u000, O) xor + // CRC(0v00, O) xor + // CRC(00w0, O) xor + // CRC(000x, O) + // + // We can compute tables corresponding to the four terms for all 8-bit + // values. + + crc = ^crc + + // If a buffer is long enough to use the optimization, process the first few + // bytes to align the buffer to an 8 byte boundary (if necessary). + if len(p) >= castagnoliK1*3 { + delta := int(uintptr(unsafe.Pointer(&p[0])) & 7) + if delta != 0 { + delta = 8 - delta + crc = castagnoliSSE42(crc, p[:delta]) + p = p[delta:] + } + } + + // Process 3*K2 at a time. + for len(p) >= castagnoliK2*3 { + // Compute CRC(I, A), CRC(0, B), and CRC(0, C). + crcA, crcB, crcC := castagnoliSSE42Triple( + crc, 0, 0, + p, p[castagnoliK2:], p[castagnoliK2*2:], + castagnoliK2/24) + + // CRC(I, AB) = CRC(CRC(I, A), O) xor CRC(0, B) + crcAB := castagnoliShift(castagnoliSSE42TableK2, crcA) ^ crcB + // CRC(I, ABC) = CRC(CRC(I, AB), O) xor CRC(0, C) + crc = castagnoliShift(castagnoliSSE42TableK2, crcAB) ^ crcC + p = p[castagnoliK2*3:] + } + + // Process 3*K1 at a time. + for len(p) >= castagnoliK1*3 { + // Compute CRC(I, A), CRC(0, B), and CRC(0, C). + crcA, crcB, crcC := castagnoliSSE42Triple( + crc, 0, 0, + p, p[castagnoliK1:], p[castagnoliK1*2:], + castagnoliK1/24) + + // CRC(I, AB) = CRC(CRC(I, A), O) xor CRC(0, B) + crcAB := castagnoliShift(castagnoliSSE42TableK1, crcA) ^ crcB + // CRC(I, ABC) = CRC(CRC(I, AB), O) xor CRC(0, C) + crc = castagnoliShift(castagnoliSSE42TableK1, crcAB) ^ crcC + p = p[castagnoliK1*3:] + } + + // Use the simple implementation for what's left. + crc = castagnoliSSE42(crc, p) + return ^crc +} + +func archAvailableIEEE() bool { + return cpu.X86.HasPCLMULQDQ && cpu.X86.HasSSE41 +} + +var archIeeeTable8 *slicing8Table + +func archInitIEEE() { + if !cpu.X86.HasPCLMULQDQ || !cpu.X86.HasSSE41 { + panic("not available") + } + // We still use slicing-by-8 for small buffers. + archIeeeTable8 = slicingMakeTable(IEEE) +} + +func archUpdateIEEE(crc uint32, p []byte) uint32 { + if !cpu.X86.HasPCLMULQDQ || !cpu.X86.HasSSE41 { + panic("not available") + } + + if len(p) >= 64 { + left := len(p) & 15 + do := len(p) - left + crc = ^ieeeCLMUL(^crc, p[:do]) + p = p[do:] + } + if len(p) == 0 { + return crc + } + return slicingUpdate(crc, archIeeeTable8, p) +} diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/crc32_amd64.s b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_amd64.s new file mode 100644 index 0000000000000000000000000000000000000000..6af6c253a79003316e23605da9af65a4c30ecc92 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_amd64.s @@ -0,0 +1,279 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "textflag.h" + +// castagnoliSSE42 updates the (non-inverted) crc with the given buffer. +// +// func castagnoliSSE42(crc uint32, p []byte) uint32 +TEXT ·castagnoliSSE42(SB),NOSPLIT,$0 + MOVL crc+0(FP), AX // CRC value + MOVQ p+8(FP), SI // data pointer + MOVQ p_len+16(FP), CX // len(p) + + // If there are fewer than 8 bytes to process, skip alignment. + CMPQ CX, $8 + JL less_than_8 + + MOVQ SI, BX + ANDQ $7, BX + JZ aligned + + // Process the first few bytes to 8-byte align the input. + + // BX = 8 - BX. We need to process this many bytes to align. + SUBQ $1, BX + XORQ $7, BX + + BTQ $0, BX + JNC align_2 + + CRC32B (SI), AX + DECQ CX + INCQ SI + +align_2: + BTQ $1, BX + JNC align_4 + + CRC32W (SI), AX + + SUBQ $2, CX + ADDQ $2, SI + +align_4: + BTQ $2, BX + JNC aligned + + CRC32L (SI), AX + + SUBQ $4, CX + ADDQ $4, SI + +aligned: + // The input is now 8-byte aligned and we can process 8-byte chunks. + CMPQ CX, $8 + JL less_than_8 + + CRC32Q (SI), AX + ADDQ $8, SI + SUBQ $8, CX + JMP aligned + +less_than_8: + // We may have some bytes left over; process 4 bytes, then 2, then 1. + BTQ $2, CX + JNC less_than_4 + + CRC32L (SI), AX + ADDQ $4, SI + +less_than_4: + BTQ $1, CX + JNC less_than_2 + + CRC32W (SI), AX + ADDQ $2, SI + +less_than_2: + BTQ $0, CX + JNC done + + CRC32B (SI), AX + +done: + MOVL AX, ret+32(FP) + RET + +// castagnoliSSE42Triple updates three (non-inverted) crcs with (24*rounds) +// bytes from each buffer. +// +// func castagnoliSSE42Triple( +// crc1, crc2, crc3 uint32, +// a, b, c []byte, +// rounds uint32, +// ) (retA uint32, retB uint32, retC uint32) +TEXT ·castagnoliSSE42Triple(SB),NOSPLIT,$0 + MOVL crcA+0(FP), AX + MOVL crcB+4(FP), CX + MOVL crcC+8(FP), DX + + MOVQ a+16(FP), R8 // data pointer + MOVQ b+40(FP), R9 // data pointer + MOVQ c+64(FP), R10 // data pointer + + MOVL rounds+88(FP), R11 + +loop: + CRC32Q (R8), AX + CRC32Q (R9), CX + CRC32Q (R10), DX + + CRC32Q 8(R8), AX + CRC32Q 8(R9), CX + CRC32Q 8(R10), DX + + CRC32Q 16(R8), AX + CRC32Q 16(R9), CX + CRC32Q 16(R10), DX + + ADDQ $24, R8 + ADDQ $24, R9 + ADDQ $24, R10 + + DECQ R11 + JNZ loop + + MOVL AX, retA+96(FP) + MOVL CX, retB+100(FP) + MOVL DX, retC+104(FP) + RET + +// CRC32 polynomial data +// +// These constants are lifted from the +// Linux kernel, since they avoid the costly +// PSHUFB 16 byte reversal proposed in the +// original Intel paper. +DATA r2r1<>+0(SB)/8, $0x154442bd4 +DATA r2r1<>+8(SB)/8, $0x1c6e41596 +DATA r4r3<>+0(SB)/8, $0x1751997d0 +DATA r4r3<>+8(SB)/8, $0x0ccaa009e +DATA rupoly<>+0(SB)/8, $0x1db710641 +DATA rupoly<>+8(SB)/8, $0x1f7011641 +DATA r5<>+0(SB)/8, $0x163cd6124 + +GLOBL r2r1<>(SB),RODATA,$16 +GLOBL r4r3<>(SB),RODATA,$16 +GLOBL rupoly<>(SB),RODATA,$16 +GLOBL r5<>(SB),RODATA,$8 + +// Based on https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/fast-crc-computation-generic-polynomials-pclmulqdq-paper.pdf +// len(p) must be at least 64, and must be a multiple of 16. + +// func ieeeCLMUL(crc uint32, p []byte) uint32 +TEXT ·ieeeCLMUL(SB),NOSPLIT,$0 + MOVL crc+0(FP), X0 // Initial CRC value + MOVQ p+8(FP), SI // data pointer + MOVQ p_len+16(FP), CX // len(p) + + MOVOU (SI), X1 + MOVOU 16(SI), X2 + MOVOU 32(SI), X3 + MOVOU 48(SI), X4 + PXOR X0, X1 + ADDQ $64, SI // buf+=64 + SUBQ $64, CX // len-=64 + CMPQ CX, $64 // Less than 64 bytes left + JB remain64 + + MOVOA r2r1<>+0(SB), X0 +loopback64: + MOVOA X1, X5 + MOVOA X2, X6 + MOVOA X3, X7 + MOVOA X4, X8 + + PCLMULQDQ $0, X0, X1 + PCLMULQDQ $0, X0, X2 + PCLMULQDQ $0, X0, X3 + PCLMULQDQ $0, X0, X4 + + /* Load next early */ + MOVOU (SI), X11 + MOVOU 16(SI), X12 + MOVOU 32(SI), X13 + MOVOU 48(SI), X14 + + PCLMULQDQ $0x11, X0, X5 + PCLMULQDQ $0x11, X0, X6 + PCLMULQDQ $0x11, X0, X7 + PCLMULQDQ $0x11, X0, X8 + + PXOR X5, X1 + PXOR X6, X2 + PXOR X7, X3 + PXOR X8, X4 + + PXOR X11, X1 + PXOR X12, X2 + PXOR X13, X3 + PXOR X14, X4 + + ADDQ $0x40, DI + ADDQ $64, SI // buf+=64 + SUBQ $64, CX // len-=64 + CMPQ CX, $64 // Less than 64 bytes left? + JGE loopback64 + + /* Fold result into a single register (X1) */ +remain64: + MOVOA r4r3<>+0(SB), X0 + + MOVOA X1, X5 + PCLMULQDQ $0, X0, X1 + PCLMULQDQ $0x11, X0, X5 + PXOR X5, X1 + PXOR X2, X1 + + MOVOA X1, X5 + PCLMULQDQ $0, X0, X1 + PCLMULQDQ $0x11, X0, X5 + PXOR X5, X1 + PXOR X3, X1 + + MOVOA X1, X5 + PCLMULQDQ $0, X0, X1 + PCLMULQDQ $0x11, X0, X5 + PXOR X5, X1 + PXOR X4, X1 + + /* If there is less than 16 bytes left we are done */ + CMPQ CX, $16 + JB finish + + /* Encode 16 bytes */ +remain16: + MOVOU (SI), X10 + MOVOA X1, X5 + PCLMULQDQ $0, X0, X1 + PCLMULQDQ $0x11, X0, X5 + PXOR X5, X1 + PXOR X10, X1 + SUBQ $16, CX + ADDQ $16, SI + CMPQ CX, $16 + JGE remain16 + +finish: + /* Fold final result into 32 bits and return it */ + PCMPEQB X3, X3 + PCLMULQDQ $1, X1, X0 + PSRLDQ $8, X1 + PXOR X0, X1 + + MOVOA X1, X2 + MOVQ r5<>+0(SB), X0 + + /* Creates 32 bit mask. Note that we don't care about upper half. */ + PSRLQ $32, X3 + + PSRLDQ $4, X2 + PAND X3, X1 + PCLMULQDQ $0, X0, X1 + PXOR X2, X1 + + MOVOA rupoly<>+0(SB), X0 + + MOVOA X1, X2 + PAND X3, X1 + PCLMULQDQ $0x10, X0, X1 + PAND X3, X1 + PCLMULQDQ $0, X0, X1 + PXOR X2, X1 + + PEXTRD $1, X1, AX + MOVL AX, ret+32(FP) + + RET diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/crc32_arm64.go b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_arm64.go new file mode 100644 index 0000000000000000000000000000000000000000..9674b76a273fe9127b882134789843d92c663fae --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_arm64.go @@ -0,0 +1,50 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// ARM64-specific hardware-assisted CRC32 algorithms. See crc32.go for a +// description of the interface that each architecture-specific file +// implements. + +package crc32 + +import "internal/cpu" + +func castagnoliUpdate(crc uint32, p []byte) uint32 +func ieeeUpdate(crc uint32, p []byte) uint32 + +func archAvailableCastagnoli() bool { + return cpu.ARM64.HasCRC32 +} + +func archInitCastagnoli() { + if !cpu.ARM64.HasCRC32 { + panic("arch-specific crc32 instruction for Castagnoli not available") + } +} + +func archUpdateCastagnoli(crc uint32, p []byte) uint32 { + if !cpu.ARM64.HasCRC32 { + panic("arch-specific crc32 instruction for Castagnoli not available") + } + + return ^castagnoliUpdate(^crc, p) +} + +func archAvailableIEEE() bool { + return cpu.ARM64.HasCRC32 +} + +func archInitIEEE() { + if !cpu.ARM64.HasCRC32 { + panic("arch-specific crc32 instruction for IEEE not available") + } +} + +func archUpdateIEEE(crc uint32, p []byte) uint32 { + if !cpu.ARM64.HasCRC32 { + panic("arch-specific crc32 instruction for IEEE not available") + } + + return ^ieeeUpdate(^crc, p) +} diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/crc32_arm64.s b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_arm64.s new file mode 100644 index 0000000000000000000000000000000000000000..85a113f9de7114522a56bf37c29a6316f5a030a0 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_arm64.s @@ -0,0 +1,97 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "textflag.h" + +// castagnoliUpdate updates the non-inverted crc with the given data. + +// func castagnoliUpdate(crc uint32, p []byte) uint32 +TEXT ·castagnoliUpdate(SB),NOSPLIT,$0-36 + MOVWU crc+0(FP), R9 // CRC value + MOVD p+8(FP), R13 // data pointer + MOVD p_len+16(FP), R11 // len(p) + +update: + CMP $16, R11 + BLT less_than_16 + LDP.P 16(R13), (R8, R10) + CRC32CX R8, R9 + CRC32CX R10, R9 + SUB $16, R11 + + JMP update + +less_than_16: + TBZ $3, R11, less_than_8 + + MOVD.P 8(R13), R10 + CRC32CX R10, R9 + +less_than_8: + TBZ $2, R11, less_than_4 + + MOVWU.P 4(R13), R10 + CRC32CW R10, R9 + +less_than_4: + TBZ $1, R11, less_than_2 + + MOVHU.P 2(R13), R10 + CRC32CH R10, R9 + +less_than_2: + TBZ $0, R11, done + + MOVBU (R13), R10 + CRC32CB R10, R9 + +done: + MOVWU R9, ret+32(FP) + RET + +// ieeeUpdate updates the non-inverted crc with the given data. + +// func ieeeUpdate(crc uint32, p []byte) uint32 +TEXT ·ieeeUpdate(SB),NOSPLIT,$0-36 + MOVWU crc+0(FP), R9 // CRC value + MOVD p+8(FP), R13 // data pointer + MOVD p_len+16(FP), R11 // len(p) + +update: + CMP $16, R11 + BLT less_than_16 + LDP.P 16(R13), (R8, R10) + CRC32X R8, R9 + CRC32X R10, R9 + SUB $16, R11 + + JMP update + +less_than_16: + TBZ $3, R11, less_than_8 + + MOVD.P 8(R13), R10 + CRC32X R10, R9 + +less_than_8: + TBZ $2, R11, less_than_4 + + MOVWU.P 4(R13), R10 + CRC32W R10, R9 + +less_than_4: + TBZ $1, R11, less_than_2 + + MOVHU.P 2(R13), R10 + CRC32H R10, R9 + +less_than_2: + TBZ $0, R11, done + + MOVBU (R13), R10 + CRC32B R10, R9 + +done: + MOVWU R9, ret+32(FP) + RET diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/crc32_generic.go b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_generic.go new file mode 100644 index 0000000000000000000000000000000000000000..abacbb663d45380e8aff449c2022f75d3499d9cb --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_generic.go @@ -0,0 +1,89 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file contains CRC32 algorithms that are not specific to any architecture +// and don't use hardware acceleration. +// +// The simple (and slow) CRC32 implementation only uses a 256*4 bytes table. +// +// The slicing-by-8 algorithm is a faster implementation that uses a bigger +// table (8*256*4 bytes). + +package crc32 + +// simpleMakeTable allocates and constructs a Table for the specified +// polynomial. The table is suitable for use with the simple algorithm +// (simpleUpdate). +func simpleMakeTable(poly uint32) *Table { + t := new(Table) + simplePopulateTable(poly, t) + return t +} + +// simplePopulateTable constructs a Table for the specified polynomial, suitable +// for use with simpleUpdate. +func simplePopulateTable(poly uint32, t *Table) { + for i := 0; i < 256; i++ { + crc := uint32(i) + for j := 0; j < 8; j++ { + if crc&1 == 1 { + crc = (crc >> 1) ^ poly + } else { + crc >>= 1 + } + } + t[i] = crc + } +} + +// simpleUpdate uses the simple algorithm to update the CRC, given a table that +// was previously computed using simpleMakeTable. +func simpleUpdate(crc uint32, tab *Table, p []byte) uint32 { + crc = ^crc + for _, v := range p { + crc = tab[byte(crc)^v] ^ (crc >> 8) + } + return ^crc +} + +// Use slicing-by-8 when payload >= this value. +const slicing8Cutoff = 16 + +// slicing8Table is array of 8 Tables, used by the slicing-by-8 algorithm. +type slicing8Table [8]Table + +// slicingMakeTable constructs a slicing8Table for the specified polynomial. The +// table is suitable for use with the slicing-by-8 algorithm (slicingUpdate). +func slicingMakeTable(poly uint32) *slicing8Table { + t := new(slicing8Table) + simplePopulateTable(poly, &t[0]) + for i := 0; i < 256; i++ { + crc := t[0][i] + for j := 1; j < 8; j++ { + crc = t[0][crc&0xFF] ^ (crc >> 8) + t[j][i] = crc + } + } + return t +} + +// slicingUpdate uses the slicing-by-8 algorithm to update the CRC, given a +// table that was previously computed using slicingMakeTable. +func slicingUpdate(crc uint32, tab *slicing8Table, p []byte) uint32 { + if len(p) >= slicing8Cutoff { + crc = ^crc + for len(p) > 8 { + crc ^= uint32(p[0]) | uint32(p[1])<<8 | uint32(p[2])<<16 | uint32(p[3])<<24 + crc = tab[0][p[7]] ^ tab[1][p[6]] ^ tab[2][p[5]] ^ tab[3][p[4]] ^ + tab[4][crc>>24] ^ tab[5][(crc>>16)&0xFF] ^ + tab[6][(crc>>8)&0xFF] ^ tab[7][crc&0xFF] + p = p[8:] + } + crc = ^crc + } + if len(p) == 0 { + return crc + } + return simpleUpdate(crc, &tab[0], p) +} diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/crc32_otherarch.go b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_otherarch.go new file mode 100644 index 0000000000000000000000000000000000000000..762515257da3849a1da490399a711127fefa1495 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_otherarch.go @@ -0,0 +1,15 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !amd64 && !s390x && !ppc64le && !arm64 + +package crc32 + +func archAvailableIEEE() bool { return false } +func archInitIEEE() { panic("not available") } +func archUpdateIEEE(crc uint32, p []byte) uint32 { panic("not available") } + +func archAvailableCastagnoli() bool { return false } +func archInitCastagnoli() { panic("not available") } +func archUpdateCastagnoli(crc uint32, p []byte) uint32 { panic("not available") } diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/crc32_ppc64le.go b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_ppc64le.go new file mode 100644 index 0000000000000000000000000000000000000000..c22e38e00947f834c3d08379f354be11df97ce54 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_ppc64le.go @@ -0,0 +1,88 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package crc32 + +import ( + "unsafe" +) + +const ( + vecMinLen = 16 + vecAlignMask = 15 // align to 16 bytes + crcIEEE = 1 + crcCast = 2 +) + +//go:noescape +func ppc64SlicingUpdateBy8(crc uint32, table8 *slicing8Table, p []byte) uint32 + +// this function requires the buffer to be 16 byte aligned and > 16 bytes long. +// +//go:noescape +func vectorCrc32(crc uint32, poly uint32, p []byte) uint32 + +var archCastagnoliTable8 *slicing8Table + +func archInitCastagnoli() { + archCastagnoliTable8 = slicingMakeTable(Castagnoli) +} + +func archUpdateCastagnoli(crc uint32, p []byte) uint32 { + if len(p) >= 4*vecMinLen { + // If not aligned then process the initial unaligned bytes + + if uint64(uintptr(unsafe.Pointer(&p[0])))&uint64(vecAlignMask) != 0 { + align := uint64(uintptr(unsafe.Pointer(&p[0]))) & uint64(vecAlignMask) + newlen := vecMinLen - align + crc = ppc64SlicingUpdateBy8(crc, archCastagnoliTable8, p[:newlen]) + p = p[newlen:] + } + // p should be aligned now + aligned := len(p) & ^vecAlignMask + crc = vectorCrc32(crc, crcCast, p[:aligned]) + p = p[aligned:] + } + if len(p) == 0 { + return crc + } + return ppc64SlicingUpdateBy8(crc, archCastagnoliTable8, p) +} + +func archAvailableIEEE() bool { + return true +} +func archAvailableCastagnoli() bool { + return true +} + +var archIeeeTable8 *slicing8Table + +func archInitIEEE() { + // We still use slicing-by-8 for small buffers. + archIeeeTable8 = slicingMakeTable(IEEE) +} + +// archUpdateIEEE calculates the checksum of p using vectorizedIEEE. +func archUpdateIEEE(crc uint32, p []byte) uint32 { + + // Check if vector code should be used. If not aligned, then handle those + // first up to the aligned bytes. + + if len(p) >= 4*vecMinLen { + if uint64(uintptr(unsafe.Pointer(&p[0])))&uint64(vecAlignMask) != 0 { + align := uint64(uintptr(unsafe.Pointer(&p[0]))) & uint64(vecAlignMask) + newlen := vecMinLen - align + crc = ppc64SlicingUpdateBy8(crc, archIeeeTable8, p[:newlen]) + p = p[newlen:] + } + aligned := len(p) & ^vecAlignMask + crc = vectorCrc32(crc, crcIEEE, p[:aligned]) + p = p[aligned:] + } + if len(p) == 0 { + return crc + } + return ppc64SlicingUpdateBy8(crc, archIeeeTable8, p) +} diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/crc32_ppc64le.s b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_ppc64le.s new file mode 100644 index 0000000000000000000000000000000000000000..84ef2133127dcf40ac8558da7dab0e65c6bafbef --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_ppc64le.s @@ -0,0 +1,705 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The vectorized implementation found below is a derived work +// from code written by Anton Blanchard found +// at https://github.com/antonblanchard/crc32-vpmsum. The original +// is dual licensed under GPL and Apache 2. As the copyright holder +// for the work, IBM has contributed this new work under +// the golang license. + +// Changes include porting to Go assembler with modifications for +// the Go ABI for ppc64le. + +#include "textflag.h" + +#define POWER8_OFFSET 132 + +#define off16 R16 +#define off32 R17 +#define off48 R18 +#define off64 R19 +#define off80 R20 +#define off96 R21 +#define off112 R22 + +#define const1 V24 +#define const2 V25 + +#define byteswap V26 +#define mask_32bit V27 +#define mask_64bit V28 +#define zeroes V29 + +#define MAX_SIZE 32*1024 +#define REFLECT + +TEXT ·ppc64SlicingUpdateBy8(SB), NOSPLIT|NOFRAME, $0-44 + MOVWZ crc+0(FP), R3 // incoming crc + MOVD table8+8(FP), R4 // *Table + MOVD p+16(FP), R5 + MOVD p_len+24(FP), R6 // p len + + CMP $0,R6 // len == 0? + BNE start + MOVW R3,ret+40(FP) // return crc + RET + +start: + NOR R3,R3,R7 // ^crc + MOVWZ R7,R7 // 32 bits + CMP R6,$16 + MOVD R6,CTR + BLT short + SRAD $3,R6,R8 // 8 byte chunks + MOVD R8,CTR + +loop: + MOVWZ 0(R5),R8 // 0-3 bytes of p ?Endian? + MOVWZ 4(R5),R9 // 4-7 bytes of p + MOVD R4,R10 // &tab[0] + XOR R7,R8,R7 // crc ^= byte[0:3] + RLDICL $40,R9,$56,R17 // p[7] + SLD $2,R17,R17 // p[7]*4 + RLDICL $40,R7,$56,R8 // crc>>24 + ADD R17,R10,R17 // &tab[0][p[7]] + SLD $2,R8,R8 // crc>>24*4 + RLDICL $48,R9,$56,R18 // p[6] + SLD $2,R18,R18 // p[6]*4 + ADD $1024,R10,R10 // tab[1] + MOVWZ 0(R17),R21 // tab[0][p[7]] + RLDICL $56,R9,$56,R19 // p[5] + ADD R10,R18,R18 // &tab[1][p[6]] + SLD $2,R19,R19 // p[5]*4:1 + MOVWZ 0(R18),R22 // tab[1][p[6]] + ADD $1024,R10,R10 // tab[2] + XOR R21,R22,R21 // xor done R22 + ADD R19,R10,R19 // &tab[2][p[5]] + ANDCC $255,R9,R20 // p[4] ?? + SLD $2,R20,R20 // p[4]*4 + MOVWZ 0(R19),R23 // tab[2][p[5]] + ADD $1024,R10,R10 // &tab[3] + ADD R20,R10,R20 // tab[3][p[4]] + XOR R21,R23,R21 // xor done R23 + ADD $1024,R10,R10 // &tab[4] + MOVWZ 0(R20),R24 // tab[3][p[4]] + ADD R10,R8,R23 // &tab[4][crc>>24] + XOR R21,R24,R21 // xor done R24 + MOVWZ 0(R23),R25 // tab[4][crc>>24] + RLDICL $48,R7,$56,R24 // crc>>16&0xFF + XOR R21,R25,R21 // xor done R25 + ADD $1024,R10,R10 // &tab[5] + SLD $2,R24,R24 // crc>>16&0xFF*4 + ADD R24,R10,R24 // &tab[5][crc>>16&0xFF] + MOVWZ 0(R24),R26 // tab[5][crc>>16&0xFF] + XOR R21,R26,R21 // xor done R26 + RLDICL $56,R7,$56,R25 // crc>>8 + ADD $1024,R10,R10 // &tab[6] + SLD $2,R25,R25 // crc>>8&FF*2 + ADD R25,R10,R25 // &tab[6][crc>>8&0xFF] + MOVBZ R7,R26 // crc&0xFF + ADD $1024,R10,R10 // &tab[7] + MOVWZ 0(R25),R27 // tab[6][crc>>8&0xFF] + SLD $2,R26,R26 // crc&0xFF*2 + XOR R21,R27,R21 // xor done R27 + ADD R26,R10,R26 // &tab[7][crc&0xFF] + ADD $8,R5 // p = p[8:] + MOVWZ 0(R26),R28 // tab[7][crc&0xFF] + XOR R21,R28,R21 // xor done R28 + MOVWZ R21,R7 // crc for next round + BC 16,0,loop // next 8 bytes + ANDCC $7,R6,R8 // any leftover bytes + BEQ done // none --> done + MOVD R8,CTR // byte count + PCALIGN $16 // align short loop +short: + MOVBZ 0(R5),R8 // get v + MOVBZ R7,R9 // byte(crc) -> R8 BE vs LE? + SRD $8,R7,R14 // crc>>8 + XOR R8,R9,R8 // byte(crc)^v -> R8 + ADD $1,R5 // ptr to next v + SLD $2,R8 // convert index-> bytes + ADD R8,R4,R9 // &tab[byte(crc)^v] + MOVWZ 0(R9),R10 // tab[byte(crc)^v] + XOR R10,R14,R7 // loop crc in R7 + BC 16,0,short +done: + NOR R7,R7,R7 // ^crc + MOVW R7,ret+40(FP) // return crc + RET + +#ifdef BYTESWAP_DATA +DATA ·byteswapcons+0(SB)/8,$0x0706050403020100 +DATA ·byteswapcons+8(SB)/8,$0x0f0e0d0c0b0a0908 + +GLOBL ·byteswapcons+0(SB),RODATA,$16 +#endif + +TEXT ·vectorCrc32(SB), NOSPLIT|NOFRAME, $0-36 + MOVWZ crc+0(FP), R3 // incoming crc + MOVWZ ctab+4(FP), R14 // crc poly id + MOVD p+8(FP), R4 + MOVD p_len+16(FP), R5 // p len + + // R3 = incoming crc + // R14 = constant table identifier + // R5 = address of bytes + // R6 = length of bytes + + // defines for index loads + + MOVD $16,off16 + MOVD $32,off32 + MOVD $48,off48 + MOVD $64,off64 + MOVD $80,off80 + MOVD $96,off96 + MOVD $112,off112 + MOVD $0,R15 + + MOVD R3,R10 // save initial crc + + NOR R3,R3,R3 // ^crc + MOVWZ R3,R3 // 32 bits + VXOR zeroes,zeroes,zeroes // clear the V reg + VSPLTISW $-1,V0 + VSLDOI $4,V29,V0,mask_32bit + VSLDOI $8,V29,V0,mask_64bit + + VXOR V8,V8,V8 + MTVSRD R3,VS40 // crc initial value VS40 = V8 + +#ifdef REFLECT + VSLDOI $8,zeroes,V8,V8 // or: VSLDOI V29,V8,V27,4 for top 32 bits? +#else + VSLDOI $4,V8,zeroes,V8 +#endif + +#ifdef BYTESWAP_DATA + MOVD $·byteswapcons(SB),R3 + LVX (R3),byteswap +#endif + + CMPU R5,$256 // length of bytes + BLT short + + RLDICR $0,R5,$56,R6 // chunk to process + + // First step for larger sizes +l1: MOVD $32768,R7 + MOVD R7,R9 + CMP R6,R7 // compare R6, R7 (MAX SIZE) + BGT top // less than MAX, just do remainder + MOVD R6,R7 +top: + SUB R7,R6,R6 + + // mainloop does 128 bytes at a time + SRD $7,R7 + + // determine the offset into the constants table to start with. + // Each constant is 128 bytes, used against 16 bytes of data. + SLD $4,R7,R8 + SRD $3,R9,R9 + SUB R8,R9,R8 + + // The last iteration is reduced in a separate step + ADD $-1,R7 + MOVD R7,CTR + + // Determine which constant table (depends on poly) + CMP R14,$1 + BNE castTable + MOVD $·IEEEConst(SB),R3 + BR startConst +castTable: + MOVD $·CastConst(SB),R3 + +startConst: + ADD R3,R8,R3 // starting point in constants table + + VXOR V0,V0,V0 // clear the V regs + VXOR V1,V1,V1 + VXOR V2,V2,V2 + VXOR V3,V3,V3 + VXOR V4,V4,V4 + VXOR V5,V5,V5 + VXOR V6,V6,V6 + VXOR V7,V7,V7 + + LVX (R3),const1 // loading constant values + + CMP R15,$1 // Identify warm up pass + BEQ next + + // First warm up pass: load the bytes to process + LVX (R4),V16 + LVX (R4+off16),V17 + LVX (R4+off32),V18 + LVX (R4+off48),V19 + LVX (R4+off64),V20 + LVX (R4+off80),V21 + LVX (R4+off96),V22 + LVX (R4+off112),V23 + ADD $128,R4 // bump up to next 128 bytes in buffer + + VXOR V16,V8,V16 // xor in initial CRC in V8 + +next: + BC 18,0,first_warm_up_done + + ADD $16,R3 // bump up to next constants + LVX (R3),const2 // table values + + VPMSUMD V16,const1,V8 // second warm up pass + LVX (R4),V16 // load from buffer + OR $0,R2,R2 + + VPMSUMD V17,const1,V9 // vpmsumd with constants + LVX (R4+off16),V17 // load next from buffer + OR $0,R2,R2 + + VPMSUMD V18,const1,V10 // vpmsumd with constants + LVX (R4+off32),V18 // load next from buffer + OR $0,R2,R2 + + VPMSUMD V19,const1,V11 // vpmsumd with constants + LVX (R4+off48),V19 // load next from buffer + OR $0,R2,R2 + + VPMSUMD V20,const1,V12 // vpmsumd with constants + LVX (R4+off64),V20 // load next from buffer + OR $0,R2,R2 + + VPMSUMD V21,const1,V13 // vpmsumd with constants + LVX (R4+off80),V21 // load next from buffer + OR $0,R2,R2 + + VPMSUMD V22,const1,V14 // vpmsumd with constants + LVX (R4+off96),V22 // load next from buffer + OR $0,R2,R2 + + VPMSUMD V23,const1,V15 // vpmsumd with constants + LVX (R4+off112),V23 // load next from buffer + + ADD $128,R4 // bump up to next 128 bytes in buffer + + BC 18,0,first_cool_down + +cool_top: + LVX (R3),const1 // constants + ADD $16,R3 // inc to next constants + OR $0,R2,R2 + + VXOR V0,V8,V0 // xor in previous vpmsumd + VPMSUMD V16,const2,V8 // vpmsumd with constants + LVX (R4),V16 // buffer + OR $0,R2,R2 + + VXOR V1,V9,V1 // xor in previous + VPMSUMD V17,const2,V9 // vpmsumd with constants + LVX (R4+off16),V17 // next in buffer + OR $0,R2,R2 + + VXOR V2,V10,V2 // xor in previous + VPMSUMD V18,const2,V10 // vpmsumd with constants + LVX (R4+off32),V18 // next in buffer + OR $0,R2,R2 + + VXOR V3,V11,V3 // xor in previous + VPMSUMD V19,const2,V11 // vpmsumd with constants + LVX (R4+off48),V19 // next in buffer + LVX (R3),const2 // get next constant + OR $0,R2,R2 + + VXOR V4,V12,V4 // xor in previous + VPMSUMD V20,const1,V12 // vpmsumd with constants + LVX (R4+off64),V20 // next in buffer + OR $0,R2,R2 + + VXOR V5,V13,V5 // xor in previous + VPMSUMD V21,const1,V13 // vpmsumd with constants + LVX (R4+off80),V21 // next in buffer + OR $0,R2,R2 + + VXOR V6,V14,V6 // xor in previous + VPMSUMD V22,const1,V14 // vpmsumd with constants + LVX (R4+off96),V22 // next in buffer + OR $0,R2,R2 + + VXOR V7,V15,V7 // xor in previous + VPMSUMD V23,const1,V15 // vpmsumd with constants + LVX (R4+off112),V23 // next in buffer + + ADD $128,R4 // bump up buffer pointer + BC 16,0,cool_top // are we done? + +first_cool_down: + + // load the constants + // xor in the previous value + // vpmsumd the result with constants + + LVX (R3),const1 + ADD $16,R3 + + VXOR V0,V8,V0 + VPMSUMD V16,const1,V8 + OR $0,R2,R2 + + VXOR V1,V9,V1 + VPMSUMD V17,const1,V9 + OR $0,R2,R2 + + VXOR V2,V10,V2 + VPMSUMD V18,const1,V10 + OR $0,R2,R2 + + VXOR V3,V11,V3 + VPMSUMD V19,const1,V11 + OR $0,R2,R2 + + VXOR V4,V12,V4 + VPMSUMD V20,const1,V12 + OR $0,R2,R2 + + VXOR V5,V13,V5 + VPMSUMD V21,const1,V13 + OR $0,R2,R2 + + VXOR V6,V14,V6 + VPMSUMD V22,const1,V14 + OR $0,R2,R2 + + VXOR V7,V15,V7 + VPMSUMD V23,const1,V15 + OR $0,R2,R2 + +second_cool_down: + + VXOR V0,V8,V0 + VXOR V1,V9,V1 + VXOR V2,V10,V2 + VXOR V3,V11,V3 + VXOR V4,V12,V4 + VXOR V5,V13,V5 + VXOR V6,V14,V6 + VXOR V7,V15,V7 + +#ifdef REFLECT + VSLDOI $4,V0,zeroes,V0 + VSLDOI $4,V1,zeroes,V1 + VSLDOI $4,V2,zeroes,V2 + VSLDOI $4,V3,zeroes,V3 + VSLDOI $4,V4,zeroes,V4 + VSLDOI $4,V5,zeroes,V5 + VSLDOI $4,V6,zeroes,V6 + VSLDOI $4,V7,zeroes,V7 +#endif + + LVX (R4),V8 + LVX (R4+off16),V9 + LVX (R4+off32),V10 + LVX (R4+off48),V11 + LVX (R4+off64),V12 + LVX (R4+off80),V13 + LVX (R4+off96),V14 + LVX (R4+off112),V15 + + ADD $128,R4 + + VXOR V0,V8,V16 + VXOR V1,V9,V17 + VXOR V2,V10,V18 + VXOR V3,V11,V19 + VXOR V4,V12,V20 + VXOR V5,V13,V21 + VXOR V6,V14,V22 + VXOR V7,V15,V23 + + MOVD $1,R15 + CMP $0,R6 + ADD $128,R6 + + BNE l1 + ANDCC $127,R5 + SUBC R5,$128,R6 + ADD R3,R6,R3 + + SRD $4,R5,R7 + MOVD R7,CTR + LVX (R3),V0 + LVX (R3+off16),V1 + LVX (R3+off32),V2 + LVX (R3+off48),V3 + LVX (R3+off64),V4 + LVX (R3+off80),V5 + LVX (R3+off96),V6 + LVX (R3+off112),V7 + + ADD $128,R3 + + VPMSUMW V16,V0,V0 + VPMSUMW V17,V1,V1 + VPMSUMW V18,V2,V2 + VPMSUMW V19,V3,V3 + VPMSUMW V20,V4,V4 + VPMSUMW V21,V5,V5 + VPMSUMW V22,V6,V6 + VPMSUMW V23,V7,V7 + + // now reduce the tail + + CMP $0,R7 + BEQ next1 + + LVX (R4),V16 + LVX (R3),V17 + VPMSUMW V16,V17,V16 + VXOR V0,V16,V0 + BC 18,0,next1 + + LVX (R4+off16),V16 + LVX (R3+off16),V17 + VPMSUMW V16,V17,V16 + VXOR V0,V16,V0 + BC 18,0,next1 + + LVX (R4+off32),V16 + LVX (R3+off32),V17 + VPMSUMW V16,V17,V16 + VXOR V0,V16,V0 + BC 18,0,next1 + + LVX (R4+off48),V16 + LVX (R3+off48),V17 + VPMSUMW V16,V17,V16 + VXOR V0,V16,V0 + BC 18,0,next1 + + LVX (R4+off64),V16 + LVX (R3+off64),V17 + VPMSUMW V16,V17,V16 + VXOR V0,V16,V0 + BC 18,0,next1 + + LVX (R4+off80),V16 + LVX (R3+off80),V17 + VPMSUMW V16,V17,V16 + VXOR V0,V16,V0 + BC 18,0,next1 + + LVX (R4+off96),V16 + LVX (R3+off96),V17 + VPMSUMW V16,V17,V16 + VXOR V0,V16,V0 + +next1: + VXOR V0,V1,V0 + VXOR V2,V3,V2 + VXOR V4,V5,V4 + VXOR V6,V7,V6 + VXOR V0,V2,V0 + VXOR V4,V6,V4 + VXOR V0,V4,V0 + +barrett_reduction: + + CMP R14,$1 + BNE barcstTable + MOVD $·IEEEBarConst(SB),R3 + BR startbarConst +barcstTable: + MOVD $·CastBarConst(SB),R3 + +startbarConst: + LVX (R3),const1 + LVX (R3+off16),const2 + + VSLDOI $8,V0,V0,V1 + VXOR V0,V1,V0 + +#ifdef REFLECT + VSPLTISB $1,V1 + VSL V0,V1,V0 +#endif + + VAND V0,mask_64bit,V0 + +#ifndef REFLECT + + VPMSUMD V0,const1,V1 + VSLDOI $8,zeroes,V1,V1 + VPMSUMD V1,const2,V1 + VXOR V0,V1,V0 + VSLDOI $8,V0,zeroes,V0 + +#else + + VAND V0,mask_32bit,V1 + VPMSUMD V1,const1,V1 + VAND V1,mask_32bit,V1 + VPMSUMD V1,const2,V1 + VXOR V0,V1,V0 + VSLDOI $4,V0,zeroes,V0 + +#endif + + MFVSRD VS32,R3 // VS32 = V0 + + NOR R3,R3,R3 // return ^crc + MOVW R3,ret+32(FP) + RET + +first_warm_up_done: + + LVX (R3),const1 + ADD $16,R3 + + VPMSUMD V16,const1,V8 + VPMSUMD V17,const1,V9 + VPMSUMD V18,const1,V10 + VPMSUMD V19,const1,V11 + VPMSUMD V20,const1,V12 + VPMSUMD V21,const1,V13 + VPMSUMD V22,const1,V14 + VPMSUMD V23,const1,V15 + + BR second_cool_down + +short: + CMP $0,R5 + BEQ zero + + // compute short constants + + CMP R14,$1 + BNE castshTable + MOVD $·IEEEConst(SB),R3 + ADD $4080,R3 + BR startshConst +castshTable: + MOVD $·CastConst(SB),R3 + ADD $4080,R3 + +startshConst: + SUBC R5,$256,R6 // sub from 256 + ADD R3,R6,R3 + + // calculate where to start + + SRD $4,R5,R7 + MOVD R7,CTR + + VXOR V19,V19,V19 + VXOR V20,V20,V20 + + LVX (R4),V0 + LVX (R3),V16 + VXOR V0,V8,V0 + VPMSUMW V0,V16,V0 + BC 18,0,v0 + + LVX (R4+off16),V1 + LVX (R3+off16),V17 + VPMSUMW V1,V17,V1 + BC 18,0,v1 + + LVX (R4+off32),V2 + LVX (R3+off32),V16 + VPMSUMW V2,V16,V2 + BC 18,0,v2 + + LVX (R4+off48),V3 + LVX (R3+off48),V17 + VPMSUMW V3,V17,V3 + BC 18,0,v3 + + LVX (R4+off64),V4 + LVX (R3+off64),V16 + VPMSUMW V4,V16,V4 + BC 18,0,v4 + + LVX (R4+off80),V5 + LVX (R3+off80),V17 + VPMSUMW V5,V17,V5 + BC 18,0,v5 + + LVX (R4+off96),V6 + LVX (R3+off96),V16 + VPMSUMW V6,V16,V6 + BC 18,0,v6 + + LVX (R4+off112),V7 + LVX (R3+off112),V17 + VPMSUMW V7,V17,V7 + BC 18,0,v7 + + ADD $128,R3 + ADD $128,R4 + + LVX (R4),V8 + LVX (R3),V16 + VPMSUMW V8,V16,V8 + BC 18,0,v8 + + LVX (R4+off16),V9 + LVX (R3+off16),V17 + VPMSUMW V9,V17,V9 + BC 18,0,v9 + + LVX (R4+off32),V10 + LVX (R3+off32),V16 + VPMSUMW V10,V16,V10 + BC 18,0,v10 + + LVX (R4+off48),V11 + LVX (R3+off48),V17 + VPMSUMW V11,V17,V11 + BC 18,0,v11 + + LVX (R4+off64),V12 + LVX (R3+off64),V16 + VPMSUMW V12,V16,V12 + BC 18,0,v12 + + LVX (R4+off80),V13 + LVX (R3+off80),V17 + VPMSUMW V13,V17,V13 + BC 18,0,v13 + + LVX (R4+off96),V14 + LVX (R3+off96),V16 + VPMSUMW V14,V16,V14 + BC 18,0,v14 + + LVX (R4+off112),V15 + LVX (R3+off112),V17 + VPMSUMW V15,V17,V15 + + VXOR V19,V15,V19 +v14: VXOR V20,V14,V20 +v13: VXOR V19,V13,V19 +v12: VXOR V20,V12,V20 +v11: VXOR V19,V11,V19 +v10: VXOR V20,V10,V20 +v9: VXOR V19,V9,V19 +v8: VXOR V20,V8,V20 +v7: VXOR V19,V7,V19 +v6: VXOR V20,V6,V20 +v5: VXOR V19,V5,V19 +v4: VXOR V20,V4,V20 +v3: VXOR V19,V3,V19 +v2: VXOR V20,V2,V20 +v1: VXOR V19,V1,V19 +v0: VXOR V20,V0,V20 + + VXOR V19,V20,V0 + + BR barrett_reduction + +zero: + // This case is the original crc, so just return it + MOVW R10,ret+32(FP) + RET diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/crc32_s390x.go b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_s390x.go new file mode 100644 index 0000000000000000000000000000000000000000..4e50b56c6f9597bb7176006728049e1e7cf37ec4 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_s390x.go @@ -0,0 +1,91 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package crc32 + +import "internal/cpu" + +const ( + vxMinLen = 64 + vxAlignMask = 15 // align to 16 bytes +) + +// hasVX reports whether the machine has the z/Architecture +// vector facility installed and enabled. +var hasVX = cpu.S390X.HasVX + +// vectorizedCastagnoli implements CRC32 using vector instructions. +// It is defined in crc32_s390x.s. +// +//go:noescape +func vectorizedCastagnoli(crc uint32, p []byte) uint32 + +// vectorizedIEEE implements CRC32 using vector instructions. +// It is defined in crc32_s390x.s. +// +//go:noescape +func vectorizedIEEE(crc uint32, p []byte) uint32 + +func archAvailableCastagnoli() bool { + return hasVX +} + +var archCastagnoliTable8 *slicing8Table + +func archInitCastagnoli() { + if !hasVX { + panic("not available") + } + // We still use slicing-by-8 for small buffers. + archCastagnoliTable8 = slicingMakeTable(Castagnoli) +} + +// archUpdateCastagnoli calculates the checksum of p using +// vectorizedCastagnoli. +func archUpdateCastagnoli(crc uint32, p []byte) uint32 { + if !hasVX { + panic("not available") + } + // Use vectorized function if data length is above threshold. + if len(p) >= vxMinLen { + aligned := len(p) & ^vxAlignMask + crc = vectorizedCastagnoli(crc, p[:aligned]) + p = p[aligned:] + } + if len(p) == 0 { + return crc + } + return slicingUpdate(crc, archCastagnoliTable8, p) +} + +func archAvailableIEEE() bool { + return hasVX +} + +var archIeeeTable8 *slicing8Table + +func archInitIEEE() { + if !hasVX { + panic("not available") + } + // We still use slicing-by-8 for small buffers. + archIeeeTable8 = slicingMakeTable(IEEE) +} + +// archUpdateIEEE calculates the checksum of p using vectorizedIEEE. +func archUpdateIEEE(crc uint32, p []byte) uint32 { + if !hasVX { + panic("not available") + } + // Use vectorized function if data length is above threshold. + if len(p) >= vxMinLen { + aligned := len(p) & ^vxAlignMask + crc = vectorizedIEEE(crc, p[:aligned]) + p = p[aligned:] + } + if len(p) == 0 { + return crc + } + return slicingUpdate(crc, archIeeeTable8, p) +} diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/crc32_s390x.s b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_s390x.s new file mode 100644 index 0000000000000000000000000000000000000000..8aabc602a7b7659381c823d82018b47707011109 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_s390x.s @@ -0,0 +1,230 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "textflag.h" + +// Vector register range containing CRC-32 constants + +#define CONST_PERM_LE2BE V9 +#define CONST_R2R1 V10 +#define CONST_R4R3 V11 +#define CONST_R5 V12 +#define CONST_RU_POLY V13 +#define CONST_CRC_POLY V14 + + +// The CRC-32 constant block contains reduction constants to fold and +// process particular chunks of the input data stream in parallel. +// +// Note that the constant definitions below are extended in order to compute +// intermediate results with a single VECTOR GALOIS FIELD MULTIPLY instruction. +// The rightmost doubleword can be 0 to prevent contribution to the result or +// can be multiplied by 1 to perform an XOR without the need for a separate +// VECTOR EXCLUSIVE OR instruction. +// +// The polynomials used are bit-reflected: +// +// IEEE: P'(x) = 0x0edb88320 +// Castagnoli: P'(x) = 0x082f63b78 + + +// IEEE polynomial constants +DATA ·crclecons+0(SB)/8, $0x0F0E0D0C0B0A0908 // LE-to-BE mask +DATA ·crclecons+8(SB)/8, $0x0706050403020100 +DATA ·crclecons+16(SB)/8, $0x00000001c6e41596 // R2 +DATA ·crclecons+24(SB)/8, $0x0000000154442bd4 // R1 +DATA ·crclecons+32(SB)/8, $0x00000000ccaa009e // R4 +DATA ·crclecons+40(SB)/8, $0x00000001751997d0 // R3 +DATA ·crclecons+48(SB)/8, $0x0000000000000000 +DATA ·crclecons+56(SB)/8, $0x0000000163cd6124 // R5 +DATA ·crclecons+64(SB)/8, $0x0000000000000000 +DATA ·crclecons+72(SB)/8, $0x00000001F7011641 // u' +DATA ·crclecons+80(SB)/8, $0x0000000000000000 +DATA ·crclecons+88(SB)/8, $0x00000001DB710641 // P'(x) << 1 + +GLOBL ·crclecons(SB),RODATA, $144 + +// Castagonli Polynomial constants +DATA ·crcclecons+0(SB)/8, $0x0F0E0D0C0B0A0908 // LE-to-BE mask +DATA ·crcclecons+8(SB)/8, $0x0706050403020100 +DATA ·crcclecons+16(SB)/8, $0x000000009e4addf8 // R2 +DATA ·crcclecons+24(SB)/8, $0x00000000740eef02 // R1 +DATA ·crcclecons+32(SB)/8, $0x000000014cd00bd6 // R4 +DATA ·crcclecons+40(SB)/8, $0x00000000f20c0dfe // R3 +DATA ·crcclecons+48(SB)/8, $0x0000000000000000 +DATA ·crcclecons+56(SB)/8, $0x00000000dd45aab8 // R5 +DATA ·crcclecons+64(SB)/8, $0x0000000000000000 +DATA ·crcclecons+72(SB)/8, $0x00000000dea713f1 // u' +DATA ·crcclecons+80(SB)/8, $0x0000000000000000 +DATA ·crcclecons+88(SB)/8, $0x0000000105ec76f0 // P'(x) << 1 + +GLOBL ·crcclecons(SB),RODATA, $144 + +// The CRC-32 function(s) use these calling conventions: +// +// Parameters: +// +// R2: Initial CRC value, typically ~0; and final CRC (return) value. +// R3: Input buffer pointer, performance might be improved if the +// buffer is on a doubleword boundary. +// R4: Length of the buffer, must be 64 bytes or greater. +// +// Register usage: +// +// R5: CRC-32 constant pool base pointer. +// V0: Initial CRC value and intermediate constants and results. +// V1..V4: Data for CRC computation. +// V5..V8: Next data chunks that are fetched from the input buffer. +// +// V9..V14: CRC-32 constants. + +// func vectorizedIEEE(crc uint32, p []byte) uint32 +TEXT ·vectorizedIEEE(SB),NOSPLIT,$0 + MOVWZ crc+0(FP), R2 // R2 stores the CRC value + MOVD p+8(FP), R3 // data pointer + MOVD p_len+16(FP), R4 // len(p) + + MOVD $·crclecons(SB), R5 + BR vectorizedBody<>(SB) + +// func vectorizedCastagnoli(crc uint32, p []byte) uint32 +TEXT ·vectorizedCastagnoli(SB),NOSPLIT,$0 + MOVWZ crc+0(FP), R2 // R2 stores the CRC value + MOVD p+8(FP), R3 // data pointer + MOVD p_len+16(FP), R4 // len(p) + + // R5: crc-32 constant pool base pointer, constant is used to reduce crc + MOVD $·crcclecons(SB), R5 + BR vectorizedBody<>(SB) + +TEXT vectorizedBody<>(SB),NOSPLIT,$0 + XOR $0xffffffff, R2 // NOTW R2 + VLM 0(R5), CONST_PERM_LE2BE, CONST_CRC_POLY + + // Load the initial CRC value into the rightmost word of V0 + VZERO V0 + VLVGF $3, R2, V0 + + // Crash if the input size is less than 64-bytes. + CMP R4, $64 + BLT crash + + // Load a 64-byte data chunk and XOR with CRC + VLM 0(R3), V1, V4 // 64-bytes into V1..V4 + + // Reflect the data if the CRC operation is in the bit-reflected domain + VPERM V1, V1, CONST_PERM_LE2BE, V1 + VPERM V2, V2, CONST_PERM_LE2BE, V2 + VPERM V3, V3, CONST_PERM_LE2BE, V3 + VPERM V4, V4, CONST_PERM_LE2BE, V4 + + VX V0, V1, V1 // V1 ^= CRC + ADD $64, R3 // BUF = BUF + 64 + ADD $(-64), R4 + + // Check remaining buffer size and jump to proper folding method + CMP R4, $64 + BLT less_than_64bytes + +fold_64bytes_loop: + // Load the next 64-byte data chunk into V5 to V8 + VLM 0(R3), V5, V8 + VPERM V5, V5, CONST_PERM_LE2BE, V5 + VPERM V6, V6, CONST_PERM_LE2BE, V6 + VPERM V7, V7, CONST_PERM_LE2BE, V7 + VPERM V8, V8, CONST_PERM_LE2BE, V8 + + + // Perform a GF(2) multiplication of the doublewords in V1 with + // the reduction constants in V0. The intermediate result is + // then folded (accumulated) with the next data chunk in V5 and + // stored in V1. Repeat this step for the register contents + // in V2, V3, and V4 respectively. + + VGFMAG CONST_R2R1, V1, V5, V1 + VGFMAG CONST_R2R1, V2, V6, V2 + VGFMAG CONST_R2R1, V3, V7, V3 + VGFMAG CONST_R2R1, V4, V8 ,V4 + + // Adjust buffer pointer and length for next loop + ADD $64, R3 // BUF = BUF + 64 + ADD $(-64), R4 // LEN = LEN - 64 + + CMP R4, $64 + BGE fold_64bytes_loop + +less_than_64bytes: + // Fold V1 to V4 into a single 128-bit value in V1 + VGFMAG CONST_R4R3, V1, V2, V1 + VGFMAG CONST_R4R3, V1, V3, V1 + VGFMAG CONST_R4R3, V1, V4, V1 + + // Check whether to continue with 64-bit folding + CMP R4, $16 + BLT final_fold + +fold_16bytes_loop: + VL 0(R3), V2 // Load next data chunk + VPERM V2, V2, CONST_PERM_LE2BE, V2 + + VGFMAG CONST_R4R3, V1, V2, V1 // Fold next data chunk + + // Adjust buffer pointer and size for folding next data chunk + ADD $16, R3 + ADD $-16, R4 + + // Process remaining data chunks + CMP R4 ,$16 + BGE fold_16bytes_loop + +final_fold: + VLEIB $7, $0x40, V9 + VSRLB V9, CONST_R4R3, V0 + VLEIG $0, $1, V0 + + VGFMG V0, V1, V1 + + VLEIB $7, $0x20, V9 // Shift by words + VSRLB V9, V1, V2 // Store remaining bits in V2 + VUPLLF V1, V1 // Split rightmost doubleword + VGFMAG CONST_R5, V1, V2, V1 // V1 = (V1 * R5) XOR V2 + + + // The input values to the Barret reduction are the degree-63 polynomial + // in V1 (R(x)), degree-32 generator polynomial, and the reduction + // constant u. The Barret reduction result is the CRC value of R(x) mod + // P(x). + // + // The Barret reduction algorithm is defined as: + // + // 1. T1(x) = floor( R(x) / x^32 ) GF2MUL u + // 2. T2(x) = floor( T1(x) / x^32 ) GF2MUL P(x) + // 3. C(x) = R(x) XOR T2(x) mod x^32 + // + // Note: To compensate the division by x^32, use the vector unpack + // instruction to move the leftmost word into the leftmost doubleword + // of the vector register. The rightmost doubleword is multiplied + // with zero to not contribute to the intermediate results. + + + // T1(x) = floor( R(x) / x^32 ) GF2MUL u + VUPLLF V1, V2 + VGFMG CONST_RU_POLY, V2, V2 + + + // Compute the GF(2) product of the CRC polynomial in VO with T1(x) in + // V2 and XOR the intermediate result, T2(x), with the value in V1. + // The final result is in the rightmost word of V2. + + VUPLLF V2, V2 + VGFMAG CONST_CRC_POLY, V2, V1, V2 + +done: + VLGVF $2, V2, R2 + XOR $0xffffffff, R2 // NOTW R2 + MOVWZ R2, ret + 32(FP) + RET + +crash: + MOVD $0, (R0) // input size is less than 64-bytes diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/crc32_table_ppc64le.s b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_table_ppc64le.s new file mode 100644 index 0000000000000000000000000000000000000000..453df12df4c36cfc4de904be846e932cfcdfc64f --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_table_ppc64le.s @@ -0,0 +1,3286 @@ +// autogenerated: do not edit! +// generated from crc32/gen_const_ppc64le.go + +#include "textflag.h" + + /* Reduce 262144 kbits to 1024 bits */ + /* x^261184 mod p(x), x^261120 mod p(x) */ +DATA ·IEEEConst+0(SB)/8,$0x0000000099ea94a8 +DATA ·IEEEConst+8(SB)/8,$0x00000001651797d2 + + /* x^260160 mod p(x), x^260096 mod p(x) */ +DATA ·IEEEConst+16(SB)/8,$0x00000000945a8420 +DATA ·IEEEConst+24(SB)/8,$0x0000000021e0d56c + + /* x^259136 mod p(x), x^259072 mod p(x) */ +DATA ·IEEEConst+32(SB)/8,$0x0000000030762706 +DATA ·IEEEConst+40(SB)/8,$0x000000000f95ecaa + + /* x^258112 mod p(x), x^258048 mod p(x) */ +DATA ·IEEEConst+48(SB)/8,$0x00000001a52fc582 +DATA ·IEEEConst+56(SB)/8,$0x00000001ebd224ac + + /* x^257088 mod p(x), x^257024 mod p(x) */ +DATA ·IEEEConst+64(SB)/8,$0x00000001a4a7167a +DATA ·IEEEConst+72(SB)/8,$0x000000000ccb97ca + + /* x^256064 mod p(x), x^256000 mod p(x) */ +DATA ·IEEEConst+80(SB)/8,$0x000000000c18249a +DATA ·IEEEConst+88(SB)/8,$0x00000001006ec8a8 + + /* x^255040 mod p(x), x^254976 mod p(x) */ +DATA ·IEEEConst+96(SB)/8,$0x00000000a924ae7c +DATA ·IEEEConst+104(SB)/8,$0x000000014f58f196 + + /* x^254016 mod p(x), x^253952 mod p(x) */ +DATA ·IEEEConst+112(SB)/8,$0x00000001e12ccc12 +DATA ·IEEEConst+120(SB)/8,$0x00000001a7192ca6 + + /* x^252992 mod p(x), x^252928 mod p(x) */ +DATA ·IEEEConst+128(SB)/8,$0x00000000a0b9d4ac +DATA ·IEEEConst+136(SB)/8,$0x000000019a64bab2 + + /* x^251968 mod p(x), x^251904 mod p(x) */ +DATA ·IEEEConst+144(SB)/8,$0x0000000095e8ddfe +DATA ·IEEEConst+152(SB)/8,$0x0000000014f4ed2e + + /* x^250944 mod p(x), x^250880 mod p(x) */ +DATA ·IEEEConst+160(SB)/8,$0x00000000233fddc4 +DATA ·IEEEConst+168(SB)/8,$0x000000011092b6a2 + + /* x^249920 mod p(x), x^249856 mod p(x) */ +DATA ·IEEEConst+176(SB)/8,$0x00000001b4529b62 +DATA ·IEEEConst+184(SB)/8,$0x00000000c8a1629c + + /* x^248896 mod p(x), x^248832 mod p(x) */ +DATA ·IEEEConst+192(SB)/8,$0x00000001a7fa0e64 +DATA ·IEEEConst+200(SB)/8,$0x000000017bf32e8e + + /* x^247872 mod p(x), x^247808 mod p(x) */ +DATA ·IEEEConst+208(SB)/8,$0x00000001b5334592 +DATA ·IEEEConst+216(SB)/8,$0x00000001f8cc6582 + + /* x^246848 mod p(x), x^246784 mod p(x) */ +DATA ·IEEEConst+224(SB)/8,$0x000000011f8ee1b4 +DATA ·IEEEConst+232(SB)/8,$0x000000008631ddf0 + + /* x^245824 mod p(x), x^245760 mod p(x) */ +DATA ·IEEEConst+240(SB)/8,$0x000000006252e632 +DATA ·IEEEConst+248(SB)/8,$0x000000007e5a76d0 + + /* x^244800 mod p(x), x^244736 mod p(x) */ +DATA ·IEEEConst+256(SB)/8,$0x00000000ab973e84 +DATA ·IEEEConst+264(SB)/8,$0x000000002b09b31c + + /* x^243776 mod p(x), x^243712 mod p(x) */ +DATA ·IEEEConst+272(SB)/8,$0x000000007734f5ec +DATA ·IEEEConst+280(SB)/8,$0x00000001b2df1f84 + + /* x^242752 mod p(x), x^242688 mod p(x) */ +DATA ·IEEEConst+288(SB)/8,$0x000000007c547798 +DATA ·IEEEConst+296(SB)/8,$0x00000001d6f56afc + + /* x^241728 mod p(x), x^241664 mod p(x) */ +DATA ·IEEEConst+304(SB)/8,$0x000000007ec40210 +DATA ·IEEEConst+312(SB)/8,$0x00000001b9b5e70c + + /* x^240704 mod p(x), x^240640 mod p(x) */ +DATA ·IEEEConst+320(SB)/8,$0x00000001ab1695a8 +DATA ·IEEEConst+328(SB)/8,$0x0000000034b626d2 + + /* x^239680 mod p(x), x^239616 mod p(x) */ +DATA ·IEEEConst+336(SB)/8,$0x0000000090494bba +DATA ·IEEEConst+344(SB)/8,$0x000000014c53479a + + /* x^238656 mod p(x), x^238592 mod p(x) */ +DATA ·IEEEConst+352(SB)/8,$0x00000001123fb816 +DATA ·IEEEConst+360(SB)/8,$0x00000001a6d179a4 + + /* x^237632 mod p(x), x^237568 mod p(x) */ +DATA ·IEEEConst+368(SB)/8,$0x00000001e188c74c +DATA ·IEEEConst+376(SB)/8,$0x000000015abd16b4 + + /* x^236608 mod p(x), x^236544 mod p(x) */ +DATA ·IEEEConst+384(SB)/8,$0x00000001c2d3451c +DATA ·IEEEConst+392(SB)/8,$0x00000000018f9852 + + /* x^235584 mod p(x), x^235520 mod p(x) */ +DATA ·IEEEConst+400(SB)/8,$0x00000000f55cf1ca +DATA ·IEEEConst+408(SB)/8,$0x000000001fb3084a + + /* x^234560 mod p(x), x^234496 mod p(x) */ +DATA ·IEEEConst+416(SB)/8,$0x00000001a0531540 +DATA ·IEEEConst+424(SB)/8,$0x00000000c53dfb04 + + /* x^233536 mod p(x), x^233472 mod p(x) */ +DATA ·IEEEConst+432(SB)/8,$0x0000000132cd7ebc +DATA ·IEEEConst+440(SB)/8,$0x00000000e10c9ad6 + + /* x^232512 mod p(x), x^232448 mod p(x) */ +DATA ·IEEEConst+448(SB)/8,$0x0000000073ab7f36 +DATA ·IEEEConst+456(SB)/8,$0x0000000025aa994a + + /* x^231488 mod p(x), x^231424 mod p(x) */ +DATA ·IEEEConst+464(SB)/8,$0x0000000041aed1c2 +DATA ·IEEEConst+472(SB)/8,$0x00000000fa3a74c4 + + /* x^230464 mod p(x), x^230400 mod p(x) */ +DATA ·IEEEConst+480(SB)/8,$0x0000000136c53800 +DATA ·IEEEConst+488(SB)/8,$0x0000000033eb3f40 + + /* x^229440 mod p(x), x^229376 mod p(x) */ +DATA ·IEEEConst+496(SB)/8,$0x0000000126835a30 +DATA ·IEEEConst+504(SB)/8,$0x000000017193f296 + + /* x^228416 mod p(x), x^228352 mod p(x) */ +DATA ·IEEEConst+512(SB)/8,$0x000000006241b502 +DATA ·IEEEConst+520(SB)/8,$0x0000000043f6c86a + + /* x^227392 mod p(x), x^227328 mod p(x) */ +DATA ·IEEEConst+528(SB)/8,$0x00000000d5196ad4 +DATA ·IEEEConst+536(SB)/8,$0x000000016b513ec6 + + /* x^226368 mod p(x), x^226304 mod p(x) */ +DATA ·IEEEConst+544(SB)/8,$0x000000009cfa769a +DATA ·IEEEConst+552(SB)/8,$0x00000000c8f25b4e + + /* x^225344 mod p(x), x^225280 mod p(x) */ +DATA ·IEEEConst+560(SB)/8,$0x00000000920e5df4 +DATA ·IEEEConst+568(SB)/8,$0x00000001a45048ec + + /* x^224320 mod p(x), x^224256 mod p(x) */ +DATA ·IEEEConst+576(SB)/8,$0x0000000169dc310e +DATA ·IEEEConst+584(SB)/8,$0x000000000c441004 + + /* x^223296 mod p(x), x^223232 mod p(x) */ +DATA ·IEEEConst+592(SB)/8,$0x0000000009fc331c +DATA ·IEEEConst+600(SB)/8,$0x000000000e17cad6 + + /* x^222272 mod p(x), x^222208 mod p(x) */ +DATA ·IEEEConst+608(SB)/8,$0x000000010d94a81e +DATA ·IEEEConst+616(SB)/8,$0x00000001253ae964 + + /* x^221248 mod p(x), x^221184 mod p(x) */ +DATA ·IEEEConst+624(SB)/8,$0x0000000027a20ab2 +DATA ·IEEEConst+632(SB)/8,$0x00000001d7c88ebc + + /* x^220224 mod p(x), x^220160 mod p(x) */ +DATA ·IEEEConst+640(SB)/8,$0x0000000114f87504 +DATA ·IEEEConst+648(SB)/8,$0x00000001e7ca913a + + /* x^219200 mod p(x), x^219136 mod p(x) */ +DATA ·IEEEConst+656(SB)/8,$0x000000004b076d96 +DATA ·IEEEConst+664(SB)/8,$0x0000000033ed078a + + /* x^218176 mod p(x), x^218112 mod p(x) */ +DATA ·IEEEConst+672(SB)/8,$0x00000000da4d1e74 +DATA ·IEEEConst+680(SB)/8,$0x00000000e1839c78 + + /* x^217152 mod p(x), x^217088 mod p(x) */ +DATA ·IEEEConst+688(SB)/8,$0x000000001b81f672 +DATA ·IEEEConst+696(SB)/8,$0x00000001322b267e + + /* x^216128 mod p(x), x^216064 mod p(x) */ +DATA ·IEEEConst+704(SB)/8,$0x000000009367c988 +DATA ·IEEEConst+712(SB)/8,$0x00000000638231b6 + + /* x^215104 mod p(x), x^215040 mod p(x) */ +DATA ·IEEEConst+720(SB)/8,$0x00000001717214ca +DATA ·IEEEConst+728(SB)/8,$0x00000001ee7f16f4 + + /* x^214080 mod p(x), x^214016 mod p(x) */ +DATA ·IEEEConst+736(SB)/8,$0x000000009f47d820 +DATA ·IEEEConst+744(SB)/8,$0x0000000117d9924a + + /* x^213056 mod p(x), x^212992 mod p(x) */ +DATA ·IEEEConst+752(SB)/8,$0x000000010d9a47d2 +DATA ·IEEEConst+760(SB)/8,$0x00000000e1a9e0c4 + + /* x^212032 mod p(x), x^211968 mod p(x) */ +DATA ·IEEEConst+768(SB)/8,$0x00000000a696c58c +DATA ·IEEEConst+776(SB)/8,$0x00000001403731dc + + /* x^211008 mod p(x), x^210944 mod p(x) */ +DATA ·IEEEConst+784(SB)/8,$0x000000002aa28ec6 +DATA ·IEEEConst+792(SB)/8,$0x00000001a5ea9682 + + /* x^209984 mod p(x), x^209920 mod p(x) */ +DATA ·IEEEConst+800(SB)/8,$0x00000001fe18fd9a +DATA ·IEEEConst+808(SB)/8,$0x0000000101c5c578 + + /* x^208960 mod p(x), x^208896 mod p(x) */ +DATA ·IEEEConst+816(SB)/8,$0x000000019d4fc1ae +DATA ·IEEEConst+824(SB)/8,$0x00000000dddf6494 + + /* x^207936 mod p(x), x^207872 mod p(x) */ +DATA ·IEEEConst+832(SB)/8,$0x00000001ba0e3dea +DATA ·IEEEConst+840(SB)/8,$0x00000000f1c3db28 + + /* x^206912 mod p(x), x^206848 mod p(x) */ +DATA ·IEEEConst+848(SB)/8,$0x0000000074b59a5e +DATA ·IEEEConst+856(SB)/8,$0x000000013112fb9c + + /* x^205888 mod p(x), x^205824 mod p(x) */ +DATA ·IEEEConst+864(SB)/8,$0x00000000f2b5ea98 +DATA ·IEEEConst+872(SB)/8,$0x00000000b680b906 + + /* x^204864 mod p(x), x^204800 mod p(x) */ +DATA ·IEEEConst+880(SB)/8,$0x0000000187132676 +DATA ·IEEEConst+888(SB)/8,$0x000000001a282932 + + /* x^203840 mod p(x), x^203776 mod p(x) */ +DATA ·IEEEConst+896(SB)/8,$0x000000010a8c6ad4 +DATA ·IEEEConst+904(SB)/8,$0x0000000089406e7e + + /* x^202816 mod p(x), x^202752 mod p(x) */ +DATA ·IEEEConst+912(SB)/8,$0x00000001e21dfe70 +DATA ·IEEEConst+920(SB)/8,$0x00000001def6be8c + + /* x^201792 mod p(x), x^201728 mod p(x) */ +DATA ·IEEEConst+928(SB)/8,$0x00000001da0050e4 +DATA ·IEEEConst+936(SB)/8,$0x0000000075258728 + + /* x^200768 mod p(x), x^200704 mod p(x) */ +DATA ·IEEEConst+944(SB)/8,$0x00000000772172ae +DATA ·IEEEConst+952(SB)/8,$0x000000019536090a + + /* x^199744 mod p(x), x^199680 mod p(x) */ +DATA ·IEEEConst+960(SB)/8,$0x00000000e47724aa +DATA ·IEEEConst+968(SB)/8,$0x00000000f2455bfc + + /* x^198720 mod p(x), x^198656 mod p(x) */ +DATA ·IEEEConst+976(SB)/8,$0x000000003cd63ac4 +DATA ·IEEEConst+984(SB)/8,$0x000000018c40baf4 + + /* x^197696 mod p(x), x^197632 mod p(x) */ +DATA ·IEEEConst+992(SB)/8,$0x00000001bf47d352 +DATA ·IEEEConst+1000(SB)/8,$0x000000004cd390d4 + + /* x^196672 mod p(x), x^196608 mod p(x) */ +DATA ·IEEEConst+1008(SB)/8,$0x000000018dc1d708 +DATA ·IEEEConst+1016(SB)/8,$0x00000001e4ece95a + + /* x^195648 mod p(x), x^195584 mod p(x) */ +DATA ·IEEEConst+1024(SB)/8,$0x000000002d4620a4 +DATA ·IEEEConst+1032(SB)/8,$0x000000001a3ee918 + + /* x^194624 mod p(x), x^194560 mod p(x) */ +DATA ·IEEEConst+1040(SB)/8,$0x0000000058fd1740 +DATA ·IEEEConst+1048(SB)/8,$0x000000007c652fb8 + + /* x^193600 mod p(x), x^193536 mod p(x) */ +DATA ·IEEEConst+1056(SB)/8,$0x00000000dadd9bfc +DATA ·IEEEConst+1064(SB)/8,$0x000000011c67842c + + /* x^192576 mod p(x), x^192512 mod p(x) */ +DATA ·IEEEConst+1072(SB)/8,$0x00000001ea2140be +DATA ·IEEEConst+1080(SB)/8,$0x00000000254f759c + + /* x^191552 mod p(x), x^191488 mod p(x) */ +DATA ·IEEEConst+1088(SB)/8,$0x000000009de128ba +DATA ·IEEEConst+1096(SB)/8,$0x000000007ece94ca + + /* x^190528 mod p(x), x^190464 mod p(x) */ +DATA ·IEEEConst+1104(SB)/8,$0x000000013ac3aa8e +DATA ·IEEEConst+1112(SB)/8,$0x0000000038f258c2 + + /* x^189504 mod p(x), x^189440 mod p(x) */ +DATA ·IEEEConst+1120(SB)/8,$0x0000000099980562 +DATA ·IEEEConst+1128(SB)/8,$0x00000001cdf17b00 + + /* x^188480 mod p(x), x^188416 mod p(x) */ +DATA ·IEEEConst+1136(SB)/8,$0x00000001c1579c86 +DATA ·IEEEConst+1144(SB)/8,$0x000000011f882c16 + + /* x^187456 mod p(x), x^187392 mod p(x) */ +DATA ·IEEEConst+1152(SB)/8,$0x0000000068dbbf94 +DATA ·IEEEConst+1160(SB)/8,$0x0000000100093fc8 + + /* x^186432 mod p(x), x^186368 mod p(x) */ +DATA ·IEEEConst+1168(SB)/8,$0x000000004509fb04 +DATA ·IEEEConst+1176(SB)/8,$0x00000001cd684f16 + + /* x^185408 mod p(x), x^185344 mod p(x) */ +DATA ·IEEEConst+1184(SB)/8,$0x00000001202f6398 +DATA ·IEEEConst+1192(SB)/8,$0x000000004bc6a70a + + /* x^184384 mod p(x), x^184320 mod p(x) */ +DATA ·IEEEConst+1200(SB)/8,$0x000000013aea243e +DATA ·IEEEConst+1208(SB)/8,$0x000000004fc7e8e4 + + /* x^183360 mod p(x), x^183296 mod p(x) */ +DATA ·IEEEConst+1216(SB)/8,$0x00000001b4052ae6 +DATA ·IEEEConst+1224(SB)/8,$0x0000000130103f1c + + /* x^182336 mod p(x), x^182272 mod p(x) */ +DATA ·IEEEConst+1232(SB)/8,$0x00000001cd2a0ae8 +DATA ·IEEEConst+1240(SB)/8,$0x0000000111b0024c + + /* x^181312 mod p(x), x^181248 mod p(x) */ +DATA ·IEEEConst+1248(SB)/8,$0x00000001fe4aa8b4 +DATA ·IEEEConst+1256(SB)/8,$0x000000010b3079da + + /* x^180288 mod p(x), x^180224 mod p(x) */ +DATA ·IEEEConst+1264(SB)/8,$0x00000001d1559a42 +DATA ·IEEEConst+1272(SB)/8,$0x000000010192bcc2 + + /* x^179264 mod p(x), x^179200 mod p(x) */ +DATA ·IEEEConst+1280(SB)/8,$0x00000001f3e05ecc +DATA ·IEEEConst+1288(SB)/8,$0x0000000074838d50 + + /* x^178240 mod p(x), x^178176 mod p(x) */ +DATA ·IEEEConst+1296(SB)/8,$0x0000000104ddd2cc +DATA ·IEEEConst+1304(SB)/8,$0x000000001b20f520 + + /* x^177216 mod p(x), x^177152 mod p(x) */ +DATA ·IEEEConst+1312(SB)/8,$0x000000015393153c +DATA ·IEEEConst+1320(SB)/8,$0x0000000050c3590a + + /* x^176192 mod p(x), x^176128 mod p(x) */ +DATA ·IEEEConst+1328(SB)/8,$0x0000000057e942c6 +DATA ·IEEEConst+1336(SB)/8,$0x00000000b41cac8e + + /* x^175168 mod p(x), x^175104 mod p(x) */ +DATA ·IEEEConst+1344(SB)/8,$0x000000012c633850 +DATA ·IEEEConst+1352(SB)/8,$0x000000000c72cc78 + + /* x^174144 mod p(x), x^174080 mod p(x) */ +DATA ·IEEEConst+1360(SB)/8,$0x00000000ebcaae4c +DATA ·IEEEConst+1368(SB)/8,$0x0000000030cdb032 + + /* x^173120 mod p(x), x^173056 mod p(x) */ +DATA ·IEEEConst+1376(SB)/8,$0x000000013ee532a6 +DATA ·IEEEConst+1384(SB)/8,$0x000000013e09fc32 + + /* x^172096 mod p(x), x^172032 mod p(x) */ +DATA ·IEEEConst+1392(SB)/8,$0x00000001bf0cbc7e +DATA ·IEEEConst+1400(SB)/8,$0x000000001ed624d2 + + /* x^171072 mod p(x), x^171008 mod p(x) */ +DATA ·IEEEConst+1408(SB)/8,$0x00000000d50b7a5a +DATA ·IEEEConst+1416(SB)/8,$0x00000000781aee1a + + /* x^170048 mod p(x), x^169984 mod p(x) */ +DATA ·IEEEConst+1424(SB)/8,$0x0000000002fca6e8 +DATA ·IEEEConst+1432(SB)/8,$0x00000001c4d8348c + + /* x^169024 mod p(x), x^168960 mod p(x) */ +DATA ·IEEEConst+1440(SB)/8,$0x000000007af40044 +DATA ·IEEEConst+1448(SB)/8,$0x0000000057a40336 + + /* x^168000 mod p(x), x^167936 mod p(x) */ +DATA ·IEEEConst+1456(SB)/8,$0x0000000016178744 +DATA ·IEEEConst+1464(SB)/8,$0x0000000085544940 + + /* x^166976 mod p(x), x^166912 mod p(x) */ +DATA ·IEEEConst+1472(SB)/8,$0x000000014c177458 +DATA ·IEEEConst+1480(SB)/8,$0x000000019cd21e80 + + /* x^165952 mod p(x), x^165888 mod p(x) */ +DATA ·IEEEConst+1488(SB)/8,$0x000000011b6ddf04 +DATA ·IEEEConst+1496(SB)/8,$0x000000013eb95bc0 + + /* x^164928 mod p(x), x^164864 mod p(x) */ +DATA ·IEEEConst+1504(SB)/8,$0x00000001f3e29ccc +DATA ·IEEEConst+1512(SB)/8,$0x00000001dfc9fdfc + + /* x^163904 mod p(x), x^163840 mod p(x) */ +DATA ·IEEEConst+1520(SB)/8,$0x0000000135ae7562 +DATA ·IEEEConst+1528(SB)/8,$0x00000000cd028bc2 + + /* x^162880 mod p(x), x^162816 mod p(x) */ +DATA ·IEEEConst+1536(SB)/8,$0x0000000190ef812c +DATA ·IEEEConst+1544(SB)/8,$0x0000000090db8c44 + + /* x^161856 mod p(x), x^161792 mod p(x) */ +DATA ·IEEEConst+1552(SB)/8,$0x0000000067a2c786 +DATA ·IEEEConst+1560(SB)/8,$0x000000010010a4ce + + /* x^160832 mod p(x), x^160768 mod p(x) */ +DATA ·IEEEConst+1568(SB)/8,$0x0000000048b9496c +DATA ·IEEEConst+1576(SB)/8,$0x00000001c8f4c72c + + /* x^159808 mod p(x), x^159744 mod p(x) */ +DATA ·IEEEConst+1584(SB)/8,$0x000000015a422de6 +DATA ·IEEEConst+1592(SB)/8,$0x000000001c26170c + + /* x^158784 mod p(x), x^158720 mod p(x) */ +DATA ·IEEEConst+1600(SB)/8,$0x00000001ef0e3640 +DATA ·IEEEConst+1608(SB)/8,$0x00000000e3fccf68 + + /* x^157760 mod p(x), x^157696 mod p(x) */ +DATA ·IEEEConst+1616(SB)/8,$0x00000001006d2d26 +DATA ·IEEEConst+1624(SB)/8,$0x00000000d513ed24 + + /* x^156736 mod p(x), x^156672 mod p(x) */ +DATA ·IEEEConst+1632(SB)/8,$0x00000001170d56d6 +DATA ·IEEEConst+1640(SB)/8,$0x00000000141beada + + /* x^155712 mod p(x), x^155648 mod p(x) */ +DATA ·IEEEConst+1648(SB)/8,$0x00000000a5fb613c +DATA ·IEEEConst+1656(SB)/8,$0x000000011071aea0 + + /* x^154688 mod p(x), x^154624 mod p(x) */ +DATA ·IEEEConst+1664(SB)/8,$0x0000000040bbf7fc +DATA ·IEEEConst+1672(SB)/8,$0x000000012e19080a + + /* x^153664 mod p(x), x^153600 mod p(x) */ +DATA ·IEEEConst+1680(SB)/8,$0x000000016ac3a5b2 +DATA ·IEEEConst+1688(SB)/8,$0x0000000100ecf826 + + /* x^152640 mod p(x), x^152576 mod p(x) */ +DATA ·IEEEConst+1696(SB)/8,$0x00000000abf16230 +DATA ·IEEEConst+1704(SB)/8,$0x0000000069b09412 + + /* x^151616 mod p(x), x^151552 mod p(x) */ +DATA ·IEEEConst+1712(SB)/8,$0x00000001ebe23fac +DATA ·IEEEConst+1720(SB)/8,$0x0000000122297bac + + /* x^150592 mod p(x), x^150528 mod p(x) */ +DATA ·IEEEConst+1728(SB)/8,$0x000000008b6a0894 +DATA ·IEEEConst+1736(SB)/8,$0x00000000e9e4b068 + + /* x^149568 mod p(x), x^149504 mod p(x) */ +DATA ·IEEEConst+1744(SB)/8,$0x00000001288ea478 +DATA ·IEEEConst+1752(SB)/8,$0x000000004b38651a + + /* x^148544 mod p(x), x^148480 mod p(x) */ +DATA ·IEEEConst+1760(SB)/8,$0x000000016619c442 +DATA ·IEEEConst+1768(SB)/8,$0x00000001468360e2 + + /* x^147520 mod p(x), x^147456 mod p(x) */ +DATA ·IEEEConst+1776(SB)/8,$0x0000000086230038 +DATA ·IEEEConst+1784(SB)/8,$0x00000000121c2408 + + /* x^146496 mod p(x), x^146432 mod p(x) */ +DATA ·IEEEConst+1792(SB)/8,$0x000000017746a756 +DATA ·IEEEConst+1800(SB)/8,$0x00000000da7e7d08 + + /* x^145472 mod p(x), x^145408 mod p(x) */ +DATA ·IEEEConst+1808(SB)/8,$0x0000000191b8f8f8 +DATA ·IEEEConst+1816(SB)/8,$0x00000001058d7652 + + /* x^144448 mod p(x), x^144384 mod p(x) */ +DATA ·IEEEConst+1824(SB)/8,$0x000000008e167708 +DATA ·IEEEConst+1832(SB)/8,$0x000000014a098a90 + + /* x^143424 mod p(x), x^143360 mod p(x) */ +DATA ·IEEEConst+1840(SB)/8,$0x0000000148b22d54 +DATA ·IEEEConst+1848(SB)/8,$0x0000000020dbe72e + + /* x^142400 mod p(x), x^142336 mod p(x) */ +DATA ·IEEEConst+1856(SB)/8,$0x0000000044ba2c3c +DATA ·IEEEConst+1864(SB)/8,$0x000000011e7323e8 + + /* x^141376 mod p(x), x^141312 mod p(x) */ +DATA ·IEEEConst+1872(SB)/8,$0x00000000b54d2b52 +DATA ·IEEEConst+1880(SB)/8,$0x00000000d5d4bf94 + + /* x^140352 mod p(x), x^140288 mod p(x) */ +DATA ·IEEEConst+1888(SB)/8,$0x0000000005a4fd8a +DATA ·IEEEConst+1896(SB)/8,$0x0000000199d8746c + + /* x^139328 mod p(x), x^139264 mod p(x) */ +DATA ·IEEEConst+1904(SB)/8,$0x0000000139f9fc46 +DATA ·IEEEConst+1912(SB)/8,$0x00000000ce9ca8a0 + + /* x^138304 mod p(x), x^138240 mod p(x) */ +DATA ·IEEEConst+1920(SB)/8,$0x000000015a1fa824 +DATA ·IEEEConst+1928(SB)/8,$0x00000000136edece + + /* x^137280 mod p(x), x^137216 mod p(x) */ +DATA ·IEEEConst+1936(SB)/8,$0x000000000a61ae4c +DATA ·IEEEConst+1944(SB)/8,$0x000000019b92a068 + + /* x^136256 mod p(x), x^136192 mod p(x) */ +DATA ·IEEEConst+1952(SB)/8,$0x0000000145e9113e +DATA ·IEEEConst+1960(SB)/8,$0x0000000071d62206 + + /* x^135232 mod p(x), x^135168 mod p(x) */ +DATA ·IEEEConst+1968(SB)/8,$0x000000006a348448 +DATA ·IEEEConst+1976(SB)/8,$0x00000000dfc50158 + + /* x^134208 mod p(x), x^134144 mod p(x) */ +DATA ·IEEEConst+1984(SB)/8,$0x000000004d80a08c +DATA ·IEEEConst+1992(SB)/8,$0x00000001517626bc + + /* x^133184 mod p(x), x^133120 mod p(x) */ +DATA ·IEEEConst+2000(SB)/8,$0x000000014b6837a0 +DATA ·IEEEConst+2008(SB)/8,$0x0000000148d1e4fa + + /* x^132160 mod p(x), x^132096 mod p(x) */ +DATA ·IEEEConst+2016(SB)/8,$0x000000016896a7fc +DATA ·IEEEConst+2024(SB)/8,$0x0000000094d8266e + + /* x^131136 mod p(x), x^131072 mod p(x) */ +DATA ·IEEEConst+2032(SB)/8,$0x000000014f187140 +DATA ·IEEEConst+2040(SB)/8,$0x00000000606c5e34 + + /* x^130112 mod p(x), x^130048 mod p(x) */ +DATA ·IEEEConst+2048(SB)/8,$0x000000019581b9da +DATA ·IEEEConst+2056(SB)/8,$0x000000019766beaa + + /* x^129088 mod p(x), x^129024 mod p(x) */ +DATA ·IEEEConst+2064(SB)/8,$0x00000001091bc984 +DATA ·IEEEConst+2072(SB)/8,$0x00000001d80c506c + + /* x^128064 mod p(x), x^128000 mod p(x) */ +DATA ·IEEEConst+2080(SB)/8,$0x000000001067223c +DATA ·IEEEConst+2088(SB)/8,$0x000000001e73837c + + /* x^127040 mod p(x), x^126976 mod p(x) */ +DATA ·IEEEConst+2096(SB)/8,$0x00000001ab16ea02 +DATA ·IEEEConst+2104(SB)/8,$0x0000000064d587de + + /* x^126016 mod p(x), x^125952 mod p(x) */ +DATA ·IEEEConst+2112(SB)/8,$0x000000013c4598a8 +DATA ·IEEEConst+2120(SB)/8,$0x00000000f4a507b0 + + /* x^124992 mod p(x), x^124928 mod p(x) */ +DATA ·IEEEConst+2128(SB)/8,$0x00000000b3735430 +DATA ·IEEEConst+2136(SB)/8,$0x0000000040e342fc + + /* x^123968 mod p(x), x^123904 mod p(x) */ +DATA ·IEEEConst+2144(SB)/8,$0x00000001bb3fc0c0 +DATA ·IEEEConst+2152(SB)/8,$0x00000001d5ad9c3a + + /* x^122944 mod p(x), x^122880 mod p(x) */ +DATA ·IEEEConst+2160(SB)/8,$0x00000001570ae19c +DATA ·IEEEConst+2168(SB)/8,$0x0000000094a691a4 + + /* x^121920 mod p(x), x^121856 mod p(x) */ +DATA ·IEEEConst+2176(SB)/8,$0x00000001ea910712 +DATA ·IEEEConst+2184(SB)/8,$0x00000001271ecdfa + + /* x^120896 mod p(x), x^120832 mod p(x) */ +DATA ·IEEEConst+2192(SB)/8,$0x0000000167127128 +DATA ·IEEEConst+2200(SB)/8,$0x000000009e54475a + + /* x^119872 mod p(x), x^119808 mod p(x) */ +DATA ·IEEEConst+2208(SB)/8,$0x0000000019e790a2 +DATA ·IEEEConst+2216(SB)/8,$0x00000000c9c099ee + + /* x^118848 mod p(x), x^118784 mod p(x) */ +DATA ·IEEEConst+2224(SB)/8,$0x000000003788f710 +DATA ·IEEEConst+2232(SB)/8,$0x000000009a2f736c + + /* x^117824 mod p(x), x^117760 mod p(x) */ +DATA ·IEEEConst+2240(SB)/8,$0x00000001682a160e +DATA ·IEEEConst+2248(SB)/8,$0x00000000bb9f4996 + + /* x^116800 mod p(x), x^116736 mod p(x) */ +DATA ·IEEEConst+2256(SB)/8,$0x000000007f0ebd2e +DATA ·IEEEConst+2264(SB)/8,$0x00000001db688050 + + /* x^115776 mod p(x), x^115712 mod p(x) */ +DATA ·IEEEConst+2272(SB)/8,$0x000000002b032080 +DATA ·IEEEConst+2280(SB)/8,$0x00000000e9b10af4 + + /* x^114752 mod p(x), x^114688 mod p(x) */ +DATA ·IEEEConst+2288(SB)/8,$0x00000000cfd1664a +DATA ·IEEEConst+2296(SB)/8,$0x000000012d4545e4 + + /* x^113728 mod p(x), x^113664 mod p(x) */ +DATA ·IEEEConst+2304(SB)/8,$0x00000000aa1181c2 +DATA ·IEEEConst+2312(SB)/8,$0x000000000361139c + + /* x^112704 mod p(x), x^112640 mod p(x) */ +DATA ·IEEEConst+2320(SB)/8,$0x00000000ddd08002 +DATA ·IEEEConst+2328(SB)/8,$0x00000001a5a1a3a8 + + /* x^111680 mod p(x), x^111616 mod p(x) */ +DATA ·IEEEConst+2336(SB)/8,$0x00000000e8dd0446 +DATA ·IEEEConst+2344(SB)/8,$0x000000006844e0b0 + + /* x^110656 mod p(x), x^110592 mod p(x) */ +DATA ·IEEEConst+2352(SB)/8,$0x00000001bbd94a00 +DATA ·IEEEConst+2360(SB)/8,$0x00000000c3762f28 + + /* x^109632 mod p(x), x^109568 mod p(x) */ +DATA ·IEEEConst+2368(SB)/8,$0x00000000ab6cd180 +DATA ·IEEEConst+2376(SB)/8,$0x00000001d26287a2 + + /* x^108608 mod p(x), x^108544 mod p(x) */ +DATA ·IEEEConst+2384(SB)/8,$0x0000000031803ce2 +DATA ·IEEEConst+2392(SB)/8,$0x00000001f6f0bba8 + + /* x^107584 mod p(x), x^107520 mod p(x) */ +DATA ·IEEEConst+2400(SB)/8,$0x0000000024f40b0c +DATA ·IEEEConst+2408(SB)/8,$0x000000002ffabd62 + + /* x^106560 mod p(x), x^106496 mod p(x) */ +DATA ·IEEEConst+2416(SB)/8,$0x00000001ba1d9834 +DATA ·IEEEConst+2424(SB)/8,$0x00000000fb4516b8 + + /* x^105536 mod p(x), x^105472 mod p(x) */ +DATA ·IEEEConst+2432(SB)/8,$0x0000000104de61aa +DATA ·IEEEConst+2440(SB)/8,$0x000000018cfa961c + + /* x^104512 mod p(x), x^104448 mod p(x) */ +DATA ·IEEEConst+2448(SB)/8,$0x0000000113e40d46 +DATA ·IEEEConst+2456(SB)/8,$0x000000019e588d52 + + /* x^103488 mod p(x), x^103424 mod p(x) */ +DATA ·IEEEConst+2464(SB)/8,$0x00000001415598a0 +DATA ·IEEEConst+2472(SB)/8,$0x00000001180f0bbc + + /* x^102464 mod p(x), x^102400 mod p(x) */ +DATA ·IEEEConst+2480(SB)/8,$0x00000000bf6c8c90 +DATA ·IEEEConst+2488(SB)/8,$0x00000000e1d9177a + + /* x^101440 mod p(x), x^101376 mod p(x) */ +DATA ·IEEEConst+2496(SB)/8,$0x00000001788b0504 +DATA ·IEEEConst+2504(SB)/8,$0x0000000105abc27c + + /* x^100416 mod p(x), x^100352 mod p(x) */ +DATA ·IEEEConst+2512(SB)/8,$0x0000000038385d02 +DATA ·IEEEConst+2520(SB)/8,$0x00000000972e4a58 + + /* x^99392 mod p(x), x^99328 mod p(x) */ +DATA ·IEEEConst+2528(SB)/8,$0x00000001b6c83844 +DATA ·IEEEConst+2536(SB)/8,$0x0000000183499a5e + + /* x^98368 mod p(x), x^98304 mod p(x) */ +DATA ·IEEEConst+2544(SB)/8,$0x0000000051061a8a +DATA ·IEEEConst+2552(SB)/8,$0x00000001c96a8cca + + /* x^97344 mod p(x), x^97280 mod p(x) */ +DATA ·IEEEConst+2560(SB)/8,$0x000000017351388a +DATA ·IEEEConst+2568(SB)/8,$0x00000001a1a5b60c + + /* x^96320 mod p(x), x^96256 mod p(x) */ +DATA ·IEEEConst+2576(SB)/8,$0x0000000132928f92 +DATA ·IEEEConst+2584(SB)/8,$0x00000000e4b6ac9c + + /* x^95296 mod p(x), x^95232 mod p(x) */ +DATA ·IEEEConst+2592(SB)/8,$0x00000000e6b4f48a +DATA ·IEEEConst+2600(SB)/8,$0x00000001807e7f5a + + /* x^94272 mod p(x), x^94208 mod p(x) */ +DATA ·IEEEConst+2608(SB)/8,$0x0000000039d15e90 +DATA ·IEEEConst+2616(SB)/8,$0x000000017a7e3bc8 + + /* x^93248 mod p(x), x^93184 mod p(x) */ +DATA ·IEEEConst+2624(SB)/8,$0x00000000312d6074 +DATA ·IEEEConst+2632(SB)/8,$0x00000000d73975da + + /* x^92224 mod p(x), x^92160 mod p(x) */ +DATA ·IEEEConst+2640(SB)/8,$0x000000017bbb2cc4 +DATA ·IEEEConst+2648(SB)/8,$0x000000017375d038 + + /* x^91200 mod p(x), x^91136 mod p(x) */ +DATA ·IEEEConst+2656(SB)/8,$0x000000016ded3e18 +DATA ·IEEEConst+2664(SB)/8,$0x00000000193680bc + + /* x^90176 mod p(x), x^90112 mod p(x) */ +DATA ·IEEEConst+2672(SB)/8,$0x00000000f1638b16 +DATA ·IEEEConst+2680(SB)/8,$0x00000000999b06f6 + + /* x^89152 mod p(x), x^89088 mod p(x) */ +DATA ·IEEEConst+2688(SB)/8,$0x00000001d38b9ecc +DATA ·IEEEConst+2696(SB)/8,$0x00000001f685d2b8 + + /* x^88128 mod p(x), x^88064 mod p(x) */ +DATA ·IEEEConst+2704(SB)/8,$0x000000018b8d09dc +DATA ·IEEEConst+2712(SB)/8,$0x00000001f4ecbed2 + + /* x^87104 mod p(x), x^87040 mod p(x) */ +DATA ·IEEEConst+2720(SB)/8,$0x00000000e7bc27d2 +DATA ·IEEEConst+2728(SB)/8,$0x00000000ba16f1a0 + + /* x^86080 mod p(x), x^86016 mod p(x) */ +DATA ·IEEEConst+2736(SB)/8,$0x00000000275e1e96 +DATA ·IEEEConst+2744(SB)/8,$0x0000000115aceac4 + + /* x^85056 mod p(x), x^84992 mod p(x) */ +DATA ·IEEEConst+2752(SB)/8,$0x00000000e2e3031e +DATA ·IEEEConst+2760(SB)/8,$0x00000001aeff6292 + + /* x^84032 mod p(x), x^83968 mod p(x) */ +DATA ·IEEEConst+2768(SB)/8,$0x00000001041c84d8 +DATA ·IEEEConst+2776(SB)/8,$0x000000009640124c + + /* x^83008 mod p(x), x^82944 mod p(x) */ +DATA ·IEEEConst+2784(SB)/8,$0x00000000706ce672 +DATA ·IEEEConst+2792(SB)/8,$0x0000000114f41f02 + + /* x^81984 mod p(x), x^81920 mod p(x) */ +DATA ·IEEEConst+2800(SB)/8,$0x000000015d5070da +DATA ·IEEEConst+2808(SB)/8,$0x000000009c5f3586 + + /* x^80960 mod p(x), x^80896 mod p(x) */ +DATA ·IEEEConst+2816(SB)/8,$0x0000000038f9493a +DATA ·IEEEConst+2824(SB)/8,$0x00000001878275fa + + /* x^79936 mod p(x), x^79872 mod p(x) */ +DATA ·IEEEConst+2832(SB)/8,$0x00000000a3348a76 +DATA ·IEEEConst+2840(SB)/8,$0x00000000ddc42ce8 + + /* x^78912 mod p(x), x^78848 mod p(x) */ +DATA ·IEEEConst+2848(SB)/8,$0x00000001ad0aab92 +DATA ·IEEEConst+2856(SB)/8,$0x0000000181d2c73a + + /* x^77888 mod p(x), x^77824 mod p(x) */ +DATA ·IEEEConst+2864(SB)/8,$0x000000019e85f712 +DATA ·IEEEConst+2872(SB)/8,$0x0000000141c9320a + + /* x^76864 mod p(x), x^76800 mod p(x) */ +DATA ·IEEEConst+2880(SB)/8,$0x000000005a871e76 +DATA ·IEEEConst+2888(SB)/8,$0x000000015235719a + + /* x^75840 mod p(x), x^75776 mod p(x) */ +DATA ·IEEEConst+2896(SB)/8,$0x000000017249c662 +DATA ·IEEEConst+2904(SB)/8,$0x00000000be27d804 + + /* x^74816 mod p(x), x^74752 mod p(x) */ +DATA ·IEEEConst+2912(SB)/8,$0x000000003a084712 +DATA ·IEEEConst+2920(SB)/8,$0x000000006242d45a + + /* x^73792 mod p(x), x^73728 mod p(x) */ +DATA ·IEEEConst+2928(SB)/8,$0x00000000ed438478 +DATA ·IEEEConst+2936(SB)/8,$0x000000009a53638e + + /* x^72768 mod p(x), x^72704 mod p(x) */ +DATA ·IEEEConst+2944(SB)/8,$0x00000000abac34cc +DATA ·IEEEConst+2952(SB)/8,$0x00000001001ecfb6 + + /* x^71744 mod p(x), x^71680 mod p(x) */ +DATA ·IEEEConst+2960(SB)/8,$0x000000005f35ef3e +DATA ·IEEEConst+2968(SB)/8,$0x000000016d7c2d64 + + /* x^70720 mod p(x), x^70656 mod p(x) */ +DATA ·IEEEConst+2976(SB)/8,$0x0000000047d6608c +DATA ·IEEEConst+2984(SB)/8,$0x00000001d0ce46c0 + + /* x^69696 mod p(x), x^69632 mod p(x) */ +DATA ·IEEEConst+2992(SB)/8,$0x000000002d01470e +DATA ·IEEEConst+3000(SB)/8,$0x0000000124c907b4 + + /* x^68672 mod p(x), x^68608 mod p(x) */ +DATA ·IEEEConst+3008(SB)/8,$0x0000000158bbc7b0 +DATA ·IEEEConst+3016(SB)/8,$0x0000000018a555ca + + /* x^67648 mod p(x), x^67584 mod p(x) */ +DATA ·IEEEConst+3024(SB)/8,$0x00000000c0a23e8e +DATA ·IEEEConst+3032(SB)/8,$0x000000006b0980bc + + /* x^66624 mod p(x), x^66560 mod p(x) */ +DATA ·IEEEConst+3040(SB)/8,$0x00000001ebd85c88 +DATA ·IEEEConst+3048(SB)/8,$0x000000008bbba964 + + /* x^65600 mod p(x), x^65536 mod p(x) */ +DATA ·IEEEConst+3056(SB)/8,$0x000000019ee20bb2 +DATA ·IEEEConst+3064(SB)/8,$0x00000001070a5a1e + + /* x^64576 mod p(x), x^64512 mod p(x) */ +DATA ·IEEEConst+3072(SB)/8,$0x00000001acabf2d6 +DATA ·IEEEConst+3080(SB)/8,$0x000000002204322a + + /* x^63552 mod p(x), x^63488 mod p(x) */ +DATA ·IEEEConst+3088(SB)/8,$0x00000001b7963d56 +DATA ·IEEEConst+3096(SB)/8,$0x00000000a27524d0 + + /* x^62528 mod p(x), x^62464 mod p(x) */ +DATA ·IEEEConst+3104(SB)/8,$0x000000017bffa1fe +DATA ·IEEEConst+3112(SB)/8,$0x0000000020b1e4ba + + /* x^61504 mod p(x), x^61440 mod p(x) */ +DATA ·IEEEConst+3120(SB)/8,$0x000000001f15333e +DATA ·IEEEConst+3128(SB)/8,$0x0000000032cc27fc + + /* x^60480 mod p(x), x^60416 mod p(x) */ +DATA ·IEEEConst+3136(SB)/8,$0x000000018593129e +DATA ·IEEEConst+3144(SB)/8,$0x0000000044dd22b8 + + /* x^59456 mod p(x), x^59392 mod p(x) */ +DATA ·IEEEConst+3152(SB)/8,$0x000000019cb32602 +DATA ·IEEEConst+3160(SB)/8,$0x00000000dffc9e0a + + /* x^58432 mod p(x), x^58368 mod p(x) */ +DATA ·IEEEConst+3168(SB)/8,$0x0000000142b05cc8 +DATA ·IEEEConst+3176(SB)/8,$0x00000001b7a0ed14 + + /* x^57408 mod p(x), x^57344 mod p(x) */ +DATA ·IEEEConst+3184(SB)/8,$0x00000001be49e7a4 +DATA ·IEEEConst+3192(SB)/8,$0x00000000c7842488 + + /* x^56384 mod p(x), x^56320 mod p(x) */ +DATA ·IEEEConst+3200(SB)/8,$0x0000000108f69d6c +DATA ·IEEEConst+3208(SB)/8,$0x00000001c02a4fee + + /* x^55360 mod p(x), x^55296 mod p(x) */ +DATA ·IEEEConst+3216(SB)/8,$0x000000006c0971f0 +DATA ·IEEEConst+3224(SB)/8,$0x000000003c273778 + + /* x^54336 mod p(x), x^54272 mod p(x) */ +DATA ·IEEEConst+3232(SB)/8,$0x000000005b16467a +DATA ·IEEEConst+3240(SB)/8,$0x00000001d63f8894 + + /* x^53312 mod p(x), x^53248 mod p(x) */ +DATA ·IEEEConst+3248(SB)/8,$0x00000001551a628e +DATA ·IEEEConst+3256(SB)/8,$0x000000006be557d6 + + /* x^52288 mod p(x), x^52224 mod p(x) */ +DATA ·IEEEConst+3264(SB)/8,$0x000000019e42ea92 +DATA ·IEEEConst+3272(SB)/8,$0x000000006a7806ea + + /* x^51264 mod p(x), x^51200 mod p(x) */ +DATA ·IEEEConst+3280(SB)/8,$0x000000012fa83ff2 +DATA ·IEEEConst+3288(SB)/8,$0x000000016155aa0c + + /* x^50240 mod p(x), x^50176 mod p(x) */ +DATA ·IEEEConst+3296(SB)/8,$0x000000011ca9cde0 +DATA ·IEEEConst+3304(SB)/8,$0x00000000908650ac + + /* x^49216 mod p(x), x^49152 mod p(x) */ +DATA ·IEEEConst+3312(SB)/8,$0x00000000c8e5cd74 +DATA ·IEEEConst+3320(SB)/8,$0x00000000aa5a8084 + + /* x^48192 mod p(x), x^48128 mod p(x) */ +DATA ·IEEEConst+3328(SB)/8,$0x0000000096c27f0c +DATA ·IEEEConst+3336(SB)/8,$0x0000000191bb500a + + /* x^47168 mod p(x), x^47104 mod p(x) */ +DATA ·IEEEConst+3344(SB)/8,$0x000000002baed926 +DATA ·IEEEConst+3352(SB)/8,$0x0000000064e9bed0 + + /* x^46144 mod p(x), x^46080 mod p(x) */ +DATA ·IEEEConst+3360(SB)/8,$0x000000017c8de8d2 +DATA ·IEEEConst+3368(SB)/8,$0x000000009444f302 + + /* x^45120 mod p(x), x^45056 mod p(x) */ +DATA ·IEEEConst+3376(SB)/8,$0x00000000d43d6068 +DATA ·IEEEConst+3384(SB)/8,$0x000000019db07d3c + + /* x^44096 mod p(x), x^44032 mod p(x) */ +DATA ·IEEEConst+3392(SB)/8,$0x00000000cb2c4b26 +DATA ·IEEEConst+3400(SB)/8,$0x00000001359e3e6e + + /* x^43072 mod p(x), x^43008 mod p(x) */ +DATA ·IEEEConst+3408(SB)/8,$0x0000000145b8da26 +DATA ·IEEEConst+3416(SB)/8,$0x00000001e4f10dd2 + + /* x^42048 mod p(x), x^41984 mod p(x) */ +DATA ·IEEEConst+3424(SB)/8,$0x000000018fff4b08 +DATA ·IEEEConst+3432(SB)/8,$0x0000000124f5735e + + /* x^41024 mod p(x), x^40960 mod p(x) */ +DATA ·IEEEConst+3440(SB)/8,$0x0000000150b58ed0 +DATA ·IEEEConst+3448(SB)/8,$0x0000000124760a4c + + /* x^40000 mod p(x), x^39936 mod p(x) */ +DATA ·IEEEConst+3456(SB)/8,$0x00000001549f39bc +DATA ·IEEEConst+3464(SB)/8,$0x000000000f1fc186 + + /* x^38976 mod p(x), x^38912 mod p(x) */ +DATA ·IEEEConst+3472(SB)/8,$0x00000000ef4d2f42 +DATA ·IEEEConst+3480(SB)/8,$0x00000000150e4cc4 + + /* x^37952 mod p(x), x^37888 mod p(x) */ +DATA ·IEEEConst+3488(SB)/8,$0x00000001b1468572 +DATA ·IEEEConst+3496(SB)/8,$0x000000002a6204e8 + + /* x^36928 mod p(x), x^36864 mod p(x) */ +DATA ·IEEEConst+3504(SB)/8,$0x000000013d7403b2 +DATA ·IEEEConst+3512(SB)/8,$0x00000000beb1d432 + + /* x^35904 mod p(x), x^35840 mod p(x) */ +DATA ·IEEEConst+3520(SB)/8,$0x00000001a4681842 +DATA ·IEEEConst+3528(SB)/8,$0x0000000135f3f1f0 + + /* x^34880 mod p(x), x^34816 mod p(x) */ +DATA ·IEEEConst+3536(SB)/8,$0x0000000167714492 +DATA ·IEEEConst+3544(SB)/8,$0x0000000074fe2232 + + /* x^33856 mod p(x), x^33792 mod p(x) */ +DATA ·IEEEConst+3552(SB)/8,$0x00000001e599099a +DATA ·IEEEConst+3560(SB)/8,$0x000000001ac6e2ba + + /* x^32832 mod p(x), x^32768 mod p(x) */ +DATA ·IEEEConst+3568(SB)/8,$0x00000000fe128194 +DATA ·IEEEConst+3576(SB)/8,$0x0000000013fca91e + + /* x^31808 mod p(x), x^31744 mod p(x) */ +DATA ·IEEEConst+3584(SB)/8,$0x0000000077e8b990 +DATA ·IEEEConst+3592(SB)/8,$0x0000000183f4931e + + /* x^30784 mod p(x), x^30720 mod p(x) */ +DATA ·IEEEConst+3600(SB)/8,$0x00000001a267f63a +DATA ·IEEEConst+3608(SB)/8,$0x00000000b6d9b4e4 + + /* x^29760 mod p(x), x^29696 mod p(x) */ +DATA ·IEEEConst+3616(SB)/8,$0x00000001945c245a +DATA ·IEEEConst+3624(SB)/8,$0x00000000b5188656 + + /* x^28736 mod p(x), x^28672 mod p(x) */ +DATA ·IEEEConst+3632(SB)/8,$0x0000000149002e76 +DATA ·IEEEConst+3640(SB)/8,$0x0000000027a81a84 + + /* x^27712 mod p(x), x^27648 mod p(x) */ +DATA ·IEEEConst+3648(SB)/8,$0x00000001bb8310a4 +DATA ·IEEEConst+3656(SB)/8,$0x0000000125699258 + + /* x^26688 mod p(x), x^26624 mod p(x) */ +DATA ·IEEEConst+3664(SB)/8,$0x000000019ec60bcc +DATA ·IEEEConst+3672(SB)/8,$0x00000001b23de796 + + /* x^25664 mod p(x), x^25600 mod p(x) */ +DATA ·IEEEConst+3680(SB)/8,$0x000000012d8590ae +DATA ·IEEEConst+3688(SB)/8,$0x00000000fe4365dc + + /* x^24640 mod p(x), x^24576 mod p(x) */ +DATA ·IEEEConst+3696(SB)/8,$0x0000000065b00684 +DATA ·IEEEConst+3704(SB)/8,$0x00000000c68f497a + + /* x^23616 mod p(x), x^23552 mod p(x) */ +DATA ·IEEEConst+3712(SB)/8,$0x000000015e5aeadc +DATA ·IEEEConst+3720(SB)/8,$0x00000000fbf521ee + + /* x^22592 mod p(x), x^22528 mod p(x) */ +DATA ·IEEEConst+3728(SB)/8,$0x00000000b77ff2b0 +DATA ·IEEEConst+3736(SB)/8,$0x000000015eac3378 + + /* x^21568 mod p(x), x^21504 mod p(x) */ +DATA ·IEEEConst+3744(SB)/8,$0x0000000188da2ff6 +DATA ·IEEEConst+3752(SB)/8,$0x0000000134914b90 + + /* x^20544 mod p(x), x^20480 mod p(x) */ +DATA ·IEEEConst+3760(SB)/8,$0x0000000063da929a +DATA ·IEEEConst+3768(SB)/8,$0x0000000016335cfe + + /* x^19520 mod p(x), x^19456 mod p(x) */ +DATA ·IEEEConst+3776(SB)/8,$0x00000001389caa80 +DATA ·IEEEConst+3784(SB)/8,$0x000000010372d10c + + /* x^18496 mod p(x), x^18432 mod p(x) */ +DATA ·IEEEConst+3792(SB)/8,$0x000000013db599d2 +DATA ·IEEEConst+3800(SB)/8,$0x000000015097b908 + + /* x^17472 mod p(x), x^17408 mod p(x) */ +DATA ·IEEEConst+3808(SB)/8,$0x0000000122505a86 +DATA ·IEEEConst+3816(SB)/8,$0x00000001227a7572 + + /* x^16448 mod p(x), x^16384 mod p(x) */ +DATA ·IEEEConst+3824(SB)/8,$0x000000016bd72746 +DATA ·IEEEConst+3832(SB)/8,$0x000000009a8f75c0 + + /* x^15424 mod p(x), x^15360 mod p(x) */ +DATA ·IEEEConst+3840(SB)/8,$0x00000001c3faf1d4 +DATA ·IEEEConst+3848(SB)/8,$0x00000000682c77a2 + + /* x^14400 mod p(x), x^14336 mod p(x) */ +DATA ·IEEEConst+3856(SB)/8,$0x00000001111c826c +DATA ·IEEEConst+3864(SB)/8,$0x00000000231f091c + + /* x^13376 mod p(x), x^13312 mod p(x) */ +DATA ·IEEEConst+3872(SB)/8,$0x00000000153e9fb2 +DATA ·IEEEConst+3880(SB)/8,$0x000000007d4439f2 + + /* x^12352 mod p(x), x^12288 mod p(x) */ +DATA ·IEEEConst+3888(SB)/8,$0x000000002b1f7b60 +DATA ·IEEEConst+3896(SB)/8,$0x000000017e221efc + + /* x^11328 mod p(x), x^11264 mod p(x) */ +DATA ·IEEEConst+3904(SB)/8,$0x00000000b1dba570 +DATA ·IEEEConst+3912(SB)/8,$0x0000000167457c38 + + /* x^10304 mod p(x), x^10240 mod p(x) */ +DATA ·IEEEConst+3920(SB)/8,$0x00000001f6397b76 +DATA ·IEEEConst+3928(SB)/8,$0x00000000bdf081c4 + + /* x^9280 mod p(x), x^9216 mod p(x) */ +DATA ·IEEEConst+3936(SB)/8,$0x0000000156335214 +DATA ·IEEEConst+3944(SB)/8,$0x000000016286d6b0 + + /* x^8256 mod p(x), x^8192 mod p(x) */ +DATA ·IEEEConst+3952(SB)/8,$0x00000001d70e3986 +DATA ·IEEEConst+3960(SB)/8,$0x00000000c84f001c + + /* x^7232 mod p(x), x^7168 mod p(x) */ +DATA ·IEEEConst+3968(SB)/8,$0x000000003701a774 +DATA ·IEEEConst+3976(SB)/8,$0x0000000064efe7c0 + + /* x^6208 mod p(x), x^6144 mod p(x) */ +DATA ·IEEEConst+3984(SB)/8,$0x00000000ac81ef72 +DATA ·IEEEConst+3992(SB)/8,$0x000000000ac2d904 + + /* x^5184 mod p(x), x^5120 mod p(x) */ +DATA ·IEEEConst+4000(SB)/8,$0x0000000133212464 +DATA ·IEEEConst+4008(SB)/8,$0x00000000fd226d14 + + /* x^4160 mod p(x), x^4096 mod p(x) */ +DATA ·IEEEConst+4016(SB)/8,$0x00000000e4e45610 +DATA ·IEEEConst+4024(SB)/8,$0x000000011cfd42e0 + + /* x^3136 mod p(x), x^3072 mod p(x) */ +DATA ·IEEEConst+4032(SB)/8,$0x000000000c1bd370 +DATA ·IEEEConst+4040(SB)/8,$0x000000016e5a5678 + + /* x^2112 mod p(x), x^2048 mod p(x) */ +DATA ·IEEEConst+4048(SB)/8,$0x00000001a7b9e7a6 +DATA ·IEEEConst+4056(SB)/8,$0x00000001d888fe22 + + /* x^1088 mod p(x), x^1024 mod p(x) */ +DATA ·IEEEConst+4064(SB)/8,$0x000000007d657a10 +DATA ·IEEEConst+4072(SB)/8,$0x00000001af77fcd4 + + /* x^2048 mod p(x), x^2016 mod p(x), x^1984 mod p(x), x^1952 mod p(x) */ +DATA ·IEEEConst+4080(SB)/8,$0x99168a18ec447f11 +DATA ·IEEEConst+4088(SB)/8,$0xed837b2613e8221e + + /* x^1920 mod p(x), x^1888 mod p(x), x^1856 mod p(x), x^1824 mod p(x) */ +DATA ·IEEEConst+4096(SB)/8,$0xe23e954e8fd2cd3c +DATA ·IEEEConst+4104(SB)/8,$0xc8acdd8147b9ce5a + + /* x^1792 mod p(x), x^1760 mod p(x), x^1728 mod p(x), x^1696 mod p(x) */ +DATA ·IEEEConst+4112(SB)/8,$0x92f8befe6b1d2b53 +DATA ·IEEEConst+4120(SB)/8,$0xd9ad6d87d4277e25 + + /* x^1664 mod p(x), x^1632 mod p(x), x^1600 mod p(x), x^1568 mod p(x) */ +DATA ·IEEEConst+4128(SB)/8,$0xf38a3556291ea462 +DATA ·IEEEConst+4136(SB)/8,$0xc10ec5e033fbca3b + + /* x^1536 mod p(x), x^1504 mod p(x), x^1472 mod p(x), x^1440 mod p(x) */ +DATA ·IEEEConst+4144(SB)/8,$0x974ac56262b6ca4b +DATA ·IEEEConst+4152(SB)/8,$0xc0b55b0e82e02e2f + + /* x^1408 mod p(x), x^1376 mod p(x), x^1344 mod p(x), x^1312 mod p(x) */ +DATA ·IEEEConst+4160(SB)/8,$0x855712b3784d2a56 +DATA ·IEEEConst+4168(SB)/8,$0x71aa1df0e172334d + + /* x^1280 mod p(x), x^1248 mod p(x), x^1216 mod p(x), x^1184 mod p(x) */ +DATA ·IEEEConst+4176(SB)/8,$0xa5abe9f80eaee722 +DATA ·IEEEConst+4184(SB)/8,$0xfee3053e3969324d + + /* x^1152 mod p(x), x^1120 mod p(x), x^1088 mod p(x), x^1056 mod p(x) */ +DATA ·IEEEConst+4192(SB)/8,$0x1fa0943ddb54814c +DATA ·IEEEConst+4200(SB)/8,$0xf44779b93eb2bd08 + + /* x^1024 mod p(x), x^992 mod p(x), x^960 mod p(x), x^928 mod p(x) */ +DATA ·IEEEConst+4208(SB)/8,$0xa53ff440d7bbfe6a +DATA ·IEEEConst+4216(SB)/8,$0xf5449b3f00cc3374 + + /* x^896 mod p(x), x^864 mod p(x), x^832 mod p(x), x^800 mod p(x) */ +DATA ·IEEEConst+4224(SB)/8,$0xebe7e3566325605c +DATA ·IEEEConst+4232(SB)/8,$0x6f8346e1d777606e + + /* x^768 mod p(x), x^736 mod p(x), x^704 mod p(x), x^672 mod p(x) */ +DATA ·IEEEConst+4240(SB)/8,$0xc65a272ce5b592b8 +DATA ·IEEEConst+4248(SB)/8,$0xe3ab4f2ac0b95347 + + /* x^640 mod p(x), x^608 mod p(x), x^576 mod p(x), x^544 mod p(x) */ +DATA ·IEEEConst+4256(SB)/8,$0x5705a9ca4721589f +DATA ·IEEEConst+4264(SB)/8,$0xaa2215ea329ecc11 + + /* x^512 mod p(x), x^480 mod p(x), x^448 mod p(x), x^416 mod p(x) */ +DATA ·IEEEConst+4272(SB)/8,$0xe3720acb88d14467 +DATA ·IEEEConst+4280(SB)/8,$0x1ed8f66ed95efd26 + + /* x^384 mod p(x), x^352 mod p(x), x^320 mod p(x), x^288 mod p(x) */ +DATA ·IEEEConst+4288(SB)/8,$0xba1aca0315141c31 +DATA ·IEEEConst+4296(SB)/8,$0x78ed02d5a700e96a + + /* x^256 mod p(x), x^224 mod p(x), x^192 mod p(x), x^160 mod p(x) */ +DATA ·IEEEConst+4304(SB)/8,$0xad2a31b3ed627dae +DATA ·IEEEConst+4312(SB)/8,$0xba8ccbe832b39da3 + + /* x^128 mod p(x), x^96 mod p(x), x^64 mod p(x), x^32 mod p(x) */ +DATA ·IEEEConst+4320(SB)/8,$0x6655004fa06a2517 +DATA ·IEEEConst+4328(SB)/8,$0xedb88320b1e6b092 + +GLOBL ·IEEEConst(SB),RODATA,$4336 + + /* Barrett constant m - (4^32)/n */ +DATA ·IEEEBarConst(SB)/8,$0x00000001f7011641 +DATA ·IEEEBarConst+8(SB)/8,$0x0000000000000000 +DATA ·IEEEBarConst+16(SB)/8,$0x00000001db710641 +DATA ·IEEEBarConst+24(SB)/8,$0x0000000000000000 +GLOBL ·IEEEBarConst(SB),RODATA,$32 + + /* Reduce 262144 kbits to 1024 bits */ + /* x^261184 mod p(x), x^261120 mod p(x) */ +DATA ·CastConst+0(SB)/8,$0x000000009c37c408 +DATA ·CastConst+8(SB)/8,$0x00000000b6ca9e20 + + /* x^260160 mod p(x), x^260096 mod p(x) */ +DATA ·CastConst+16(SB)/8,$0x00000001b51df26c +DATA ·CastConst+24(SB)/8,$0x00000000350249a8 + + /* x^259136 mod p(x), x^259072 mod p(x) */ +DATA ·CastConst+32(SB)/8,$0x000000000724b9d0 +DATA ·CastConst+40(SB)/8,$0x00000001862dac54 + + /* x^258112 mod p(x), x^258048 mod p(x) */ +DATA ·CastConst+48(SB)/8,$0x00000001c00532fe +DATA ·CastConst+56(SB)/8,$0x00000001d87fb48c + + /* x^257088 mod p(x), x^257024 mod p(x) */ +DATA ·CastConst+64(SB)/8,$0x00000000f05a9362 +DATA ·CastConst+72(SB)/8,$0x00000001f39b699e + + /* x^256064 mod p(x), x^256000 mod p(x) */ +DATA ·CastConst+80(SB)/8,$0x00000001e1007970 +DATA ·CastConst+88(SB)/8,$0x0000000101da11b4 + + /* x^255040 mod p(x), x^254976 mod p(x) */ +DATA ·CastConst+96(SB)/8,$0x00000000a57366ee +DATA ·CastConst+104(SB)/8,$0x00000001cab571e0 + + /* x^254016 mod p(x), x^253952 mod p(x) */ +DATA ·CastConst+112(SB)/8,$0x0000000192011284 +DATA ·CastConst+120(SB)/8,$0x00000000c7020cfe + + /* x^252992 mod p(x), x^252928 mod p(x) */ +DATA ·CastConst+128(SB)/8,$0x0000000162716d9a +DATA ·CastConst+136(SB)/8,$0x00000000cdaed1ae + + /* x^251968 mod p(x), x^251904 mod p(x) */ +DATA ·CastConst+144(SB)/8,$0x00000000cd97ecde +DATA ·CastConst+152(SB)/8,$0x00000001e804effc + + /* x^250944 mod p(x), x^250880 mod p(x) */ +DATA ·CastConst+160(SB)/8,$0x0000000058812bc0 +DATA ·CastConst+168(SB)/8,$0x0000000077c3ea3a + + /* x^249920 mod p(x), x^249856 mod p(x) */ +DATA ·CastConst+176(SB)/8,$0x0000000088b8c12e +DATA ·CastConst+184(SB)/8,$0x0000000068df31b4 + + /* x^248896 mod p(x), x^248832 mod p(x) */ +DATA ·CastConst+192(SB)/8,$0x00000001230b234c +DATA ·CastConst+200(SB)/8,$0x00000000b059b6c2 + + /* x^247872 mod p(x), x^247808 mod p(x) */ +DATA ·CastConst+208(SB)/8,$0x00000001120b416e +DATA ·CastConst+216(SB)/8,$0x0000000145fb8ed8 + + /* x^246848 mod p(x), x^246784 mod p(x) */ +DATA ·CastConst+224(SB)/8,$0x00000001974aecb0 +DATA ·CastConst+232(SB)/8,$0x00000000cbc09168 + + /* x^245824 mod p(x), x^245760 mod p(x) */ +DATA ·CastConst+240(SB)/8,$0x000000008ee3f226 +DATA ·CastConst+248(SB)/8,$0x000000005ceeedc2 + + /* x^244800 mod p(x), x^244736 mod p(x) */ +DATA ·CastConst+256(SB)/8,$0x00000001089aba9a +DATA ·CastConst+264(SB)/8,$0x0000000047d74e86 + + /* x^243776 mod p(x), x^243712 mod p(x) */ +DATA ·CastConst+272(SB)/8,$0x0000000065113872 +DATA ·CastConst+280(SB)/8,$0x00000001407e9e22 + + /* x^242752 mod p(x), x^242688 mod p(x) */ +DATA ·CastConst+288(SB)/8,$0x000000005c07ec10 +DATA ·CastConst+296(SB)/8,$0x00000001da967bda + + /* x^241728 mod p(x), x^241664 mod p(x) */ +DATA ·CastConst+304(SB)/8,$0x0000000187590924 +DATA ·CastConst+312(SB)/8,$0x000000006c898368 + + /* x^240704 mod p(x), x^240640 mod p(x) */ +DATA ·CastConst+320(SB)/8,$0x00000000e35da7c6 +DATA ·CastConst+328(SB)/8,$0x00000000f2d14c98 + + /* x^239680 mod p(x), x^239616 mod p(x) */ +DATA ·CastConst+336(SB)/8,$0x000000000415855a +DATA ·CastConst+344(SB)/8,$0x00000001993c6ad4 + + /* x^238656 mod p(x), x^238592 mod p(x) */ +DATA ·CastConst+352(SB)/8,$0x0000000073617758 +DATA ·CastConst+360(SB)/8,$0x000000014683d1ac + + /* x^237632 mod p(x), x^237568 mod p(x) */ +DATA ·CastConst+368(SB)/8,$0x0000000176021d28 +DATA ·CastConst+376(SB)/8,$0x00000001a7c93e6c + + /* x^236608 mod p(x), x^236544 mod p(x) */ +DATA ·CastConst+384(SB)/8,$0x00000001c358fd0a +DATA ·CastConst+392(SB)/8,$0x000000010211e90a + + /* x^235584 mod p(x), x^235520 mod p(x) */ +DATA ·CastConst+400(SB)/8,$0x00000001ff7a2c18 +DATA ·CastConst+408(SB)/8,$0x000000001119403e + + /* x^234560 mod p(x), x^234496 mod p(x) */ +DATA ·CastConst+416(SB)/8,$0x00000000f2d9f7e4 +DATA ·CastConst+424(SB)/8,$0x000000001c3261aa + + /* x^233536 mod p(x), x^233472 mod p(x) */ +DATA ·CastConst+432(SB)/8,$0x000000016cf1f9c8 +DATA ·CastConst+440(SB)/8,$0x000000014e37a634 + + /* x^232512 mod p(x), x^232448 mod p(x) */ +DATA ·CastConst+448(SB)/8,$0x000000010af9279a +DATA ·CastConst+456(SB)/8,$0x0000000073786c0c + + /* x^231488 mod p(x), x^231424 mod p(x) */ +DATA ·CastConst+464(SB)/8,$0x0000000004f101e8 +DATA ·CastConst+472(SB)/8,$0x000000011dc037f8 + + /* x^230464 mod p(x), x^230400 mod p(x) */ +DATA ·CastConst+480(SB)/8,$0x0000000070bcf184 +DATA ·CastConst+488(SB)/8,$0x0000000031433dfc + + /* x^229440 mod p(x), x^229376 mod p(x) */ +DATA ·CastConst+496(SB)/8,$0x000000000a8de642 +DATA ·CastConst+504(SB)/8,$0x000000009cde8348 + + /* x^228416 mod p(x), x^228352 mod p(x) */ +DATA ·CastConst+512(SB)/8,$0x0000000062ea130c +DATA ·CastConst+520(SB)/8,$0x0000000038d3c2a6 + + /* x^227392 mod p(x), x^227328 mod p(x) */ +DATA ·CastConst+528(SB)/8,$0x00000001eb31cbb2 +DATA ·CastConst+536(SB)/8,$0x000000011b25f260 + + /* x^226368 mod p(x), x^226304 mod p(x) */ +DATA ·CastConst+544(SB)/8,$0x0000000170783448 +DATA ·CastConst+552(SB)/8,$0x000000001629e6f0 + + /* x^225344 mod p(x), x^225280 mod p(x) */ +DATA ·CastConst+560(SB)/8,$0x00000001a684b4c6 +DATA ·CastConst+568(SB)/8,$0x0000000160838b4c + + /* x^224320 mod p(x), x^224256 mod p(x) */ +DATA ·CastConst+576(SB)/8,$0x00000000253ca5b4 +DATA ·CastConst+584(SB)/8,$0x000000007a44011c + + /* x^223296 mod p(x), x^223232 mod p(x) */ +DATA ·CastConst+592(SB)/8,$0x0000000057b4b1e2 +DATA ·CastConst+600(SB)/8,$0x00000000226f417a + + /* x^222272 mod p(x), x^222208 mod p(x) */ +DATA ·CastConst+608(SB)/8,$0x00000000b6bd084c +DATA ·CastConst+616(SB)/8,$0x0000000045eb2eb4 + + /* x^221248 mod p(x), x^221184 mod p(x) */ +DATA ·CastConst+624(SB)/8,$0x0000000123c2d592 +DATA ·CastConst+632(SB)/8,$0x000000014459d70c + + /* x^220224 mod p(x), x^220160 mod p(x) */ +DATA ·CastConst+640(SB)/8,$0x00000000159dafce +DATA ·CastConst+648(SB)/8,$0x00000001d406ed82 + + /* x^219200 mod p(x), x^219136 mod p(x) */ +DATA ·CastConst+656(SB)/8,$0x0000000127e1a64e +DATA ·CastConst+664(SB)/8,$0x0000000160c8e1a8 + + /* x^218176 mod p(x), x^218112 mod p(x) */ +DATA ·CastConst+672(SB)/8,$0x0000000056860754 +DATA ·CastConst+680(SB)/8,$0x0000000027ba8098 + + /* x^217152 mod p(x), x^217088 mod p(x) */ +DATA ·CastConst+688(SB)/8,$0x00000001e661aae8 +DATA ·CastConst+696(SB)/8,$0x000000006d92d018 + + /* x^216128 mod p(x), x^216064 mod p(x) */ +DATA ·CastConst+704(SB)/8,$0x00000000f82c6166 +DATA ·CastConst+712(SB)/8,$0x000000012ed7e3f2 + + /* x^215104 mod p(x), x^215040 mod p(x) */ +DATA ·CastConst+720(SB)/8,$0x00000000c4f9c7ae +DATA ·CastConst+728(SB)/8,$0x000000002dc87788 + + /* x^214080 mod p(x), x^214016 mod p(x) */ +DATA ·CastConst+736(SB)/8,$0x0000000074203d20 +DATA ·CastConst+744(SB)/8,$0x0000000018240bb8 + + /* x^213056 mod p(x), x^212992 mod p(x) */ +DATA ·CastConst+752(SB)/8,$0x0000000198173052 +DATA ·CastConst+760(SB)/8,$0x000000001ad38158 + + /* x^212032 mod p(x), x^211968 mod p(x) */ +DATA ·CastConst+768(SB)/8,$0x00000001ce8aba54 +DATA ·CastConst+776(SB)/8,$0x00000001396b78f2 + + /* x^211008 mod p(x), x^210944 mod p(x) */ +DATA ·CastConst+784(SB)/8,$0x00000001850d5d94 +DATA ·CastConst+792(SB)/8,$0x000000011a681334 + + /* x^209984 mod p(x), x^209920 mod p(x) */ +DATA ·CastConst+800(SB)/8,$0x00000001d609239c +DATA ·CastConst+808(SB)/8,$0x000000012104732e + + /* x^208960 mod p(x), x^208896 mod p(x) */ +DATA ·CastConst+816(SB)/8,$0x000000001595f048 +DATA ·CastConst+824(SB)/8,$0x00000000a140d90c + + /* x^207936 mod p(x), x^207872 mod p(x) */ +DATA ·CastConst+832(SB)/8,$0x0000000042ccee08 +DATA ·CastConst+840(SB)/8,$0x00000001b7215eda + + /* x^206912 mod p(x), x^206848 mod p(x) */ +DATA ·CastConst+848(SB)/8,$0x000000010a389d74 +DATA ·CastConst+856(SB)/8,$0x00000001aaf1df3c + + /* x^205888 mod p(x), x^205824 mod p(x) */ +DATA ·CastConst+864(SB)/8,$0x000000012a840da6 +DATA ·CastConst+872(SB)/8,$0x0000000029d15b8a + + /* x^204864 mod p(x), x^204800 mod p(x) */ +DATA ·CastConst+880(SB)/8,$0x000000001d181c0c +DATA ·CastConst+888(SB)/8,$0x00000000f1a96922 + + /* x^203840 mod p(x), x^203776 mod p(x) */ +DATA ·CastConst+896(SB)/8,$0x0000000068b7d1f6 +DATA ·CastConst+904(SB)/8,$0x00000001ac80d03c + + /* x^202816 mod p(x), x^202752 mod p(x) */ +DATA ·CastConst+912(SB)/8,$0x000000005b0f14fc +DATA ·CastConst+920(SB)/8,$0x000000000f11d56a + + /* x^201792 mod p(x), x^201728 mod p(x) */ +DATA ·CastConst+928(SB)/8,$0x0000000179e9e730 +DATA ·CastConst+936(SB)/8,$0x00000001f1c022a2 + + /* x^200768 mod p(x), x^200704 mod p(x) */ +DATA ·CastConst+944(SB)/8,$0x00000001ce1368d6 +DATA ·CastConst+952(SB)/8,$0x0000000173d00ae2 + + /* x^199744 mod p(x), x^199680 mod p(x) */ +DATA ·CastConst+960(SB)/8,$0x0000000112c3a84c +DATA ·CastConst+968(SB)/8,$0x00000001d4ffe4ac + + /* x^198720 mod p(x), x^198656 mod p(x) */ +DATA ·CastConst+976(SB)/8,$0x00000000de940fee +DATA ·CastConst+984(SB)/8,$0x000000016edc5ae4 + + /* x^197696 mod p(x), x^197632 mod p(x) */ +DATA ·CastConst+992(SB)/8,$0x00000000fe896b7e +DATA ·CastConst+1000(SB)/8,$0x00000001f1a02140 + + /* x^196672 mod p(x), x^196608 mod p(x) */ +DATA ·CastConst+1008(SB)/8,$0x00000001f797431c +DATA ·CastConst+1016(SB)/8,$0x00000000ca0b28a0 + + /* x^195648 mod p(x), x^195584 mod p(x) */ +DATA ·CastConst+1024(SB)/8,$0x0000000053e989ba +DATA ·CastConst+1032(SB)/8,$0x00000001928e30a2 + + /* x^194624 mod p(x), x^194560 mod p(x) */ +DATA ·CastConst+1040(SB)/8,$0x000000003920cd16 +DATA ·CastConst+1048(SB)/8,$0x0000000097b1b002 + + /* x^193600 mod p(x), x^193536 mod p(x) */ +DATA ·CastConst+1056(SB)/8,$0x00000001e6f579b8 +DATA ·CastConst+1064(SB)/8,$0x00000000b15bf906 + + /* x^192576 mod p(x), x^192512 mod p(x) */ +DATA ·CastConst+1072(SB)/8,$0x000000007493cb0a +DATA ·CastConst+1080(SB)/8,$0x00000000411c5d52 + + /* x^191552 mod p(x), x^191488 mod p(x) */ +DATA ·CastConst+1088(SB)/8,$0x00000001bdd376d8 +DATA ·CastConst+1096(SB)/8,$0x00000001c36f3300 + + /* x^190528 mod p(x), x^190464 mod p(x) */ +DATA ·CastConst+1104(SB)/8,$0x000000016badfee6 +DATA ·CastConst+1112(SB)/8,$0x00000001119227e0 + + /* x^189504 mod p(x), x^189440 mod p(x) */ +DATA ·CastConst+1120(SB)/8,$0x0000000071de5c58 +DATA ·CastConst+1128(SB)/8,$0x00000000114d4702 + + /* x^188480 mod p(x), x^188416 mod p(x) */ +DATA ·CastConst+1136(SB)/8,$0x00000000453f317c +DATA ·CastConst+1144(SB)/8,$0x00000000458b5b98 + + /* x^187456 mod p(x), x^187392 mod p(x) */ +DATA ·CastConst+1152(SB)/8,$0x0000000121675cce +DATA ·CastConst+1160(SB)/8,$0x000000012e31fb8e + + /* x^186432 mod p(x), x^186368 mod p(x) */ +DATA ·CastConst+1168(SB)/8,$0x00000001f409ee92 +DATA ·CastConst+1176(SB)/8,$0x000000005cf619d8 + + /* x^185408 mod p(x), x^185344 mod p(x) */ +DATA ·CastConst+1184(SB)/8,$0x00000000f36b9c88 +DATA ·CastConst+1192(SB)/8,$0x0000000063f4d8b2 + + /* x^184384 mod p(x), x^184320 mod p(x) */ +DATA ·CastConst+1200(SB)/8,$0x0000000036b398f4 +DATA ·CastConst+1208(SB)/8,$0x000000004138dc8a + + /* x^183360 mod p(x), x^183296 mod p(x) */ +DATA ·CastConst+1216(SB)/8,$0x00000001748f9adc +DATA ·CastConst+1224(SB)/8,$0x00000001d29ee8e0 + + /* x^182336 mod p(x), x^182272 mod p(x) */ +DATA ·CastConst+1232(SB)/8,$0x00000001be94ec00 +DATA ·CastConst+1240(SB)/8,$0x000000006a08ace8 + + /* x^181312 mod p(x), x^181248 mod p(x) */ +DATA ·CastConst+1248(SB)/8,$0x00000000b74370d6 +DATA ·CastConst+1256(SB)/8,$0x0000000127d42010 + + /* x^180288 mod p(x), x^180224 mod p(x) */ +DATA ·CastConst+1264(SB)/8,$0x00000001174d0b98 +DATA ·CastConst+1272(SB)/8,$0x0000000019d76b62 + + /* x^179264 mod p(x), x^179200 mod p(x) */ +DATA ·CastConst+1280(SB)/8,$0x00000000befc06a4 +DATA ·CastConst+1288(SB)/8,$0x00000001b1471f6e + + /* x^178240 mod p(x), x^178176 mod p(x) */ +DATA ·CastConst+1296(SB)/8,$0x00000001ae125288 +DATA ·CastConst+1304(SB)/8,$0x00000001f64c19cc + + /* x^177216 mod p(x), x^177152 mod p(x) */ +DATA ·CastConst+1312(SB)/8,$0x0000000095c19b34 +DATA ·CastConst+1320(SB)/8,$0x00000000003c0ea0 + + /* x^176192 mod p(x), x^176128 mod p(x) */ +DATA ·CastConst+1328(SB)/8,$0x00000001a78496f2 +DATA ·CastConst+1336(SB)/8,$0x000000014d73abf6 + + /* x^175168 mod p(x), x^175104 mod p(x) */ +DATA ·CastConst+1344(SB)/8,$0x00000001ac5390a0 +DATA ·CastConst+1352(SB)/8,$0x00000001620eb844 + + /* x^174144 mod p(x), x^174080 mod p(x) */ +DATA ·CastConst+1360(SB)/8,$0x000000002a80ed6e +DATA ·CastConst+1368(SB)/8,$0x0000000147655048 + + /* x^173120 mod p(x), x^173056 mod p(x) */ +DATA ·CastConst+1376(SB)/8,$0x00000001fa9b0128 +DATA ·CastConst+1384(SB)/8,$0x0000000067b5077e + + /* x^172096 mod p(x), x^172032 mod p(x) */ +DATA ·CastConst+1392(SB)/8,$0x00000001ea94929e +DATA ·CastConst+1400(SB)/8,$0x0000000010ffe206 + + /* x^171072 mod p(x), x^171008 mod p(x) */ +DATA ·CastConst+1408(SB)/8,$0x0000000125f4305c +DATA ·CastConst+1416(SB)/8,$0x000000000fee8f1e + + /* x^170048 mod p(x), x^169984 mod p(x) */ +DATA ·CastConst+1424(SB)/8,$0x00000001471e2002 +DATA ·CastConst+1432(SB)/8,$0x00000001da26fbae + + /* x^169024 mod p(x), x^168960 mod p(x) */ +DATA ·CastConst+1440(SB)/8,$0x0000000132d2253a +DATA ·CastConst+1448(SB)/8,$0x00000001b3a8bd88 + + /* x^168000 mod p(x), x^167936 mod p(x) */ +DATA ·CastConst+1456(SB)/8,$0x00000000f26b3592 +DATA ·CastConst+1464(SB)/8,$0x00000000e8f3898e + + /* x^166976 mod p(x), x^166912 mod p(x) */ +DATA ·CastConst+1472(SB)/8,$0x00000000bc8b67b0 +DATA ·CastConst+1480(SB)/8,$0x00000000b0d0d28c + + /* x^165952 mod p(x), x^165888 mod p(x) */ +DATA ·CastConst+1488(SB)/8,$0x000000013a826ef2 +DATA ·CastConst+1496(SB)/8,$0x0000000030f2a798 + + /* x^164928 mod p(x), x^164864 mod p(x) */ +DATA ·CastConst+1504(SB)/8,$0x0000000081482c84 +DATA ·CastConst+1512(SB)/8,$0x000000000fba1002 + + /* x^163904 mod p(x), x^163840 mod p(x) */ +DATA ·CastConst+1520(SB)/8,$0x00000000e77307c2 +DATA ·CastConst+1528(SB)/8,$0x00000000bdb9bd72 + + /* x^162880 mod p(x), x^162816 mod p(x) */ +DATA ·CastConst+1536(SB)/8,$0x00000000d4a07ec8 +DATA ·CastConst+1544(SB)/8,$0x0000000075d3bf5a + + /* x^161856 mod p(x), x^161792 mod p(x) */ +DATA ·CastConst+1552(SB)/8,$0x0000000017102100 +DATA ·CastConst+1560(SB)/8,$0x00000000ef1f98a0 + + /* x^160832 mod p(x), x^160768 mod p(x) */ +DATA ·CastConst+1568(SB)/8,$0x00000000db406486 +DATA ·CastConst+1576(SB)/8,$0x00000000689c7602 + + /* x^159808 mod p(x), x^159744 mod p(x) */ +DATA ·CastConst+1584(SB)/8,$0x0000000192db7f88 +DATA ·CastConst+1592(SB)/8,$0x000000016d5fa5fe + + /* x^158784 mod p(x), x^158720 mod p(x) */ +DATA ·CastConst+1600(SB)/8,$0x000000018bf67b1e +DATA ·CastConst+1608(SB)/8,$0x00000001d0d2b9ca + + /* x^157760 mod p(x), x^157696 mod p(x) */ +DATA ·CastConst+1616(SB)/8,$0x000000007c09163e +DATA ·CastConst+1624(SB)/8,$0x0000000041e7b470 + + /* x^156736 mod p(x), x^156672 mod p(x) */ +DATA ·CastConst+1632(SB)/8,$0x000000000adac060 +DATA ·CastConst+1640(SB)/8,$0x00000001cbb6495e + + /* x^155712 mod p(x), x^155648 mod p(x) */ +DATA ·CastConst+1648(SB)/8,$0x00000000bd8316ae +DATA ·CastConst+1656(SB)/8,$0x000000010052a0b0 + + /* x^154688 mod p(x), x^154624 mod p(x) */ +DATA ·CastConst+1664(SB)/8,$0x000000019f09ab54 +DATA ·CastConst+1672(SB)/8,$0x00000001d8effb5c + + /* x^153664 mod p(x), x^153600 mod p(x) */ +DATA ·CastConst+1680(SB)/8,$0x0000000125155542 +DATA ·CastConst+1688(SB)/8,$0x00000001d969853c + + /* x^152640 mod p(x), x^152576 mod p(x) */ +DATA ·CastConst+1696(SB)/8,$0x000000018fdb5882 +DATA ·CastConst+1704(SB)/8,$0x00000000523ccce2 + + /* x^151616 mod p(x), x^151552 mod p(x) */ +DATA ·CastConst+1712(SB)/8,$0x00000000e794b3f4 +DATA ·CastConst+1720(SB)/8,$0x000000001e2436bc + + /* x^150592 mod p(x), x^150528 mod p(x) */ +DATA ·CastConst+1728(SB)/8,$0x000000016f9bb022 +DATA ·CastConst+1736(SB)/8,$0x00000000ddd1c3a2 + + /* x^149568 mod p(x), x^149504 mod p(x) */ +DATA ·CastConst+1744(SB)/8,$0x00000000290c9978 +DATA ·CastConst+1752(SB)/8,$0x0000000019fcfe38 + + /* x^148544 mod p(x), x^148480 mod p(x) */ +DATA ·CastConst+1760(SB)/8,$0x0000000083c0f350 +DATA ·CastConst+1768(SB)/8,$0x00000001ce95db64 + + /* x^147520 mod p(x), x^147456 mod p(x) */ +DATA ·CastConst+1776(SB)/8,$0x0000000173ea6628 +DATA ·CastConst+1784(SB)/8,$0x00000000af582806 + + /* x^146496 mod p(x), x^146432 mod p(x) */ +DATA ·CastConst+1792(SB)/8,$0x00000001c8b4e00a +DATA ·CastConst+1800(SB)/8,$0x00000001006388f6 + + /* x^145472 mod p(x), x^145408 mod p(x) */ +DATA ·CastConst+1808(SB)/8,$0x00000000de95d6aa +DATA ·CastConst+1816(SB)/8,$0x0000000179eca00a + + /* x^144448 mod p(x), x^144384 mod p(x) */ +DATA ·CastConst+1824(SB)/8,$0x000000010b7f7248 +DATA ·CastConst+1832(SB)/8,$0x0000000122410a6a + + /* x^143424 mod p(x), x^143360 mod p(x) */ +DATA ·CastConst+1840(SB)/8,$0x00000001326e3a06 +DATA ·CastConst+1848(SB)/8,$0x000000004288e87c + + /* x^142400 mod p(x), x^142336 mod p(x) */ +DATA ·CastConst+1856(SB)/8,$0x00000000bb62c2e6 +DATA ·CastConst+1864(SB)/8,$0x000000016c5490da + + /* x^141376 mod p(x), x^141312 mod p(x) */ +DATA ·CastConst+1872(SB)/8,$0x0000000156a4b2c2 +DATA ·CastConst+1880(SB)/8,$0x00000000d1c71f6e + + /* x^140352 mod p(x), x^140288 mod p(x) */ +DATA ·CastConst+1888(SB)/8,$0x000000011dfe763a +DATA ·CastConst+1896(SB)/8,$0x00000001b4ce08a6 + + /* x^139328 mod p(x), x^139264 mod p(x) */ +DATA ·CastConst+1904(SB)/8,$0x000000007bcca8e2 +DATA ·CastConst+1912(SB)/8,$0x00000001466ba60c + + /* x^138304 mod p(x), x^138240 mod p(x) */ +DATA ·CastConst+1920(SB)/8,$0x0000000186118faa +DATA ·CastConst+1928(SB)/8,$0x00000001f6c488a4 + + /* x^137280 mod p(x), x^137216 mod p(x) */ +DATA ·CastConst+1936(SB)/8,$0x0000000111a65a88 +DATA ·CastConst+1944(SB)/8,$0x000000013bfb0682 + + /* x^136256 mod p(x), x^136192 mod p(x) */ +DATA ·CastConst+1952(SB)/8,$0x000000003565e1c4 +DATA ·CastConst+1960(SB)/8,$0x00000000690e9e54 + + /* x^135232 mod p(x), x^135168 mod p(x) */ +DATA ·CastConst+1968(SB)/8,$0x000000012ed02a82 +DATA ·CastConst+1976(SB)/8,$0x00000000281346b6 + + /* x^134208 mod p(x), x^134144 mod p(x) */ +DATA ·CastConst+1984(SB)/8,$0x00000000c486ecfc +DATA ·CastConst+1992(SB)/8,$0x0000000156464024 + + /* x^133184 mod p(x), x^133120 mod p(x) */ +DATA ·CastConst+2000(SB)/8,$0x0000000001b951b2 +DATA ·CastConst+2008(SB)/8,$0x000000016063a8dc + + /* x^132160 mod p(x), x^132096 mod p(x) */ +DATA ·CastConst+2016(SB)/8,$0x0000000048143916 +DATA ·CastConst+2024(SB)/8,$0x0000000116a66362 + + /* x^131136 mod p(x), x^131072 mod p(x) */ +DATA ·CastConst+2032(SB)/8,$0x00000001dc2ae124 +DATA ·CastConst+2040(SB)/8,$0x000000017e8aa4d2 + + /* x^130112 mod p(x), x^130048 mod p(x) */ +DATA ·CastConst+2048(SB)/8,$0x00000001416c58d6 +DATA ·CastConst+2056(SB)/8,$0x00000001728eb10c + + /* x^129088 mod p(x), x^129024 mod p(x) */ +DATA ·CastConst+2064(SB)/8,$0x00000000a479744a +DATA ·CastConst+2072(SB)/8,$0x00000001b08fd7fa + + /* x^128064 mod p(x), x^128000 mod p(x) */ +DATA ·CastConst+2080(SB)/8,$0x0000000096ca3a26 +DATA ·CastConst+2088(SB)/8,$0x00000001092a16e8 + + /* x^127040 mod p(x), x^126976 mod p(x) */ +DATA ·CastConst+2096(SB)/8,$0x00000000ff223d4e +DATA ·CastConst+2104(SB)/8,$0x00000000a505637c + + /* x^126016 mod p(x), x^125952 mod p(x) */ +DATA ·CastConst+2112(SB)/8,$0x000000010e84da42 +DATA ·CastConst+2120(SB)/8,$0x00000000d94869b2 + + /* x^124992 mod p(x), x^124928 mod p(x) */ +DATA ·CastConst+2128(SB)/8,$0x00000001b61ba3d0 +DATA ·CastConst+2136(SB)/8,$0x00000001c8b203ae + + /* x^123968 mod p(x), x^123904 mod p(x) */ +DATA ·CastConst+2144(SB)/8,$0x00000000680f2de8 +DATA ·CastConst+2152(SB)/8,$0x000000005704aea0 + + /* x^122944 mod p(x), x^122880 mod p(x) */ +DATA ·CastConst+2160(SB)/8,$0x000000008772a9a8 +DATA ·CastConst+2168(SB)/8,$0x000000012e295fa2 + + /* x^121920 mod p(x), x^121856 mod p(x) */ +DATA ·CastConst+2176(SB)/8,$0x0000000155f295bc +DATA ·CastConst+2184(SB)/8,$0x000000011d0908bc + + /* x^120896 mod p(x), x^120832 mod p(x) */ +DATA ·CastConst+2192(SB)/8,$0x00000000595f9282 +DATA ·CastConst+2200(SB)/8,$0x0000000193ed97ea + + /* x^119872 mod p(x), x^119808 mod p(x) */ +DATA ·CastConst+2208(SB)/8,$0x0000000164b1c25a +DATA ·CastConst+2216(SB)/8,$0x000000013a0f1c52 + + /* x^118848 mod p(x), x^118784 mod p(x) */ +DATA ·CastConst+2224(SB)/8,$0x00000000fbd67c50 +DATA ·CastConst+2232(SB)/8,$0x000000010c2c40c0 + + /* x^117824 mod p(x), x^117760 mod p(x) */ +DATA ·CastConst+2240(SB)/8,$0x0000000096076268 +DATA ·CastConst+2248(SB)/8,$0x00000000ff6fac3e + + /* x^116800 mod p(x), x^116736 mod p(x) */ +DATA ·CastConst+2256(SB)/8,$0x00000001d288e4cc +DATA ·CastConst+2264(SB)/8,$0x000000017b3609c0 + + /* x^115776 mod p(x), x^115712 mod p(x) */ +DATA ·CastConst+2272(SB)/8,$0x00000001eaac1bdc +DATA ·CastConst+2280(SB)/8,$0x0000000088c8c922 + + /* x^114752 mod p(x), x^114688 mod p(x) */ +DATA ·CastConst+2288(SB)/8,$0x00000001f1ea39e2 +DATA ·CastConst+2296(SB)/8,$0x00000001751baae6 + + /* x^113728 mod p(x), x^113664 mod p(x) */ +DATA ·CastConst+2304(SB)/8,$0x00000001eb6506fc +DATA ·CastConst+2312(SB)/8,$0x0000000107952972 + + /* x^112704 mod p(x), x^112640 mod p(x) */ +DATA ·CastConst+2320(SB)/8,$0x000000010f806ffe +DATA ·CastConst+2328(SB)/8,$0x0000000162b00abe + + /* x^111680 mod p(x), x^111616 mod p(x) */ +DATA ·CastConst+2336(SB)/8,$0x000000010408481e +DATA ·CastConst+2344(SB)/8,$0x000000000d7b404c + + /* x^110656 mod p(x), x^110592 mod p(x) */ +DATA ·CastConst+2352(SB)/8,$0x0000000188260534 +DATA ·CastConst+2360(SB)/8,$0x00000000763b13d4 + + /* x^109632 mod p(x), x^109568 mod p(x) */ +DATA ·CastConst+2368(SB)/8,$0x0000000058fc73e0 +DATA ·CastConst+2376(SB)/8,$0x00000000f6dc22d8 + + /* x^108608 mod p(x), x^108544 mod p(x) */ +DATA ·CastConst+2384(SB)/8,$0x00000000391c59b8 +DATA ·CastConst+2392(SB)/8,$0x000000007daae060 + + /* x^107584 mod p(x), x^107520 mod p(x) */ +DATA ·CastConst+2400(SB)/8,$0x000000018b638400 +DATA ·CastConst+2408(SB)/8,$0x000000013359ab7c + + /* x^106560 mod p(x), x^106496 mod p(x) */ +DATA ·CastConst+2416(SB)/8,$0x000000011738f5c4 +DATA ·CastConst+2424(SB)/8,$0x000000008add438a + + /* x^105536 mod p(x), x^105472 mod p(x) */ +DATA ·CastConst+2432(SB)/8,$0x000000008cf7c6da +DATA ·CastConst+2440(SB)/8,$0x00000001edbefdea + + /* x^104512 mod p(x), x^104448 mod p(x) */ +DATA ·CastConst+2448(SB)/8,$0x00000001ef97fb16 +DATA ·CastConst+2456(SB)/8,$0x000000004104e0f8 + + /* x^103488 mod p(x), x^103424 mod p(x) */ +DATA ·CastConst+2464(SB)/8,$0x0000000102130e20 +DATA ·CastConst+2472(SB)/8,$0x00000000b48a8222 + + /* x^102464 mod p(x), x^102400 mod p(x) */ +DATA ·CastConst+2480(SB)/8,$0x00000000db968898 +DATA ·CastConst+2488(SB)/8,$0x00000001bcb46844 + + /* x^101440 mod p(x), x^101376 mod p(x) */ +DATA ·CastConst+2496(SB)/8,$0x00000000b5047b5e +DATA ·CastConst+2504(SB)/8,$0x000000013293ce0a + + /* x^100416 mod p(x), x^100352 mod p(x) */ +DATA ·CastConst+2512(SB)/8,$0x000000010b90fdb2 +DATA ·CastConst+2520(SB)/8,$0x00000001710d0844 + + /* x^99392 mod p(x), x^99328 mod p(x) */ +DATA ·CastConst+2528(SB)/8,$0x000000004834a32e +DATA ·CastConst+2536(SB)/8,$0x0000000117907f6e + + /* x^98368 mod p(x), x^98304 mod p(x) */ +DATA ·CastConst+2544(SB)/8,$0x0000000059c8f2b0 +DATA ·CastConst+2552(SB)/8,$0x0000000087ddf93e + + /* x^97344 mod p(x), x^97280 mod p(x) */ +DATA ·CastConst+2560(SB)/8,$0x0000000122cec508 +DATA ·CastConst+2568(SB)/8,$0x000000005970e9b0 + + /* x^96320 mod p(x), x^96256 mod p(x) */ +DATA ·CastConst+2576(SB)/8,$0x000000000a330cda +DATA ·CastConst+2584(SB)/8,$0x0000000185b2b7d0 + + /* x^95296 mod p(x), x^95232 mod p(x) */ +DATA ·CastConst+2592(SB)/8,$0x000000014a47148c +DATA ·CastConst+2600(SB)/8,$0x00000001dcee0efc + + /* x^94272 mod p(x), x^94208 mod p(x) */ +DATA ·CastConst+2608(SB)/8,$0x0000000042c61cb8 +DATA ·CastConst+2616(SB)/8,$0x0000000030da2722 + + /* x^93248 mod p(x), x^93184 mod p(x) */ +DATA ·CastConst+2624(SB)/8,$0x0000000012fe6960 +DATA ·CastConst+2632(SB)/8,$0x000000012f925a18 + + /* x^92224 mod p(x), x^92160 mod p(x) */ +DATA ·CastConst+2640(SB)/8,$0x00000000dbda2c20 +DATA ·CastConst+2648(SB)/8,$0x00000000dd2e357c + + /* x^91200 mod p(x), x^91136 mod p(x) */ +DATA ·CastConst+2656(SB)/8,$0x000000011122410c +DATA ·CastConst+2664(SB)/8,$0x00000000071c80de + + /* x^90176 mod p(x), x^90112 mod p(x) */ +DATA ·CastConst+2672(SB)/8,$0x00000000977b2070 +DATA ·CastConst+2680(SB)/8,$0x000000011513140a + + /* x^89152 mod p(x), x^89088 mod p(x) */ +DATA ·CastConst+2688(SB)/8,$0x000000014050438e +DATA ·CastConst+2696(SB)/8,$0x00000001df876e8e + + /* x^88128 mod p(x), x^88064 mod p(x) */ +DATA ·CastConst+2704(SB)/8,$0x0000000147c840e8 +DATA ·CastConst+2712(SB)/8,$0x000000015f81d6ce + + /* x^87104 mod p(x), x^87040 mod p(x) */ +DATA ·CastConst+2720(SB)/8,$0x00000001cc7c88ce +DATA ·CastConst+2728(SB)/8,$0x000000019dd94dbe + + /* x^86080 mod p(x), x^86016 mod p(x) */ +DATA ·CastConst+2736(SB)/8,$0x00000001476b35a4 +DATA ·CastConst+2744(SB)/8,$0x00000001373d206e + + /* x^85056 mod p(x), x^84992 mod p(x) */ +DATA ·CastConst+2752(SB)/8,$0x000000013d52d508 +DATA ·CastConst+2760(SB)/8,$0x00000000668ccade + + /* x^84032 mod p(x), x^83968 mod p(x) */ +DATA ·CastConst+2768(SB)/8,$0x000000008e4be32e +DATA ·CastConst+2776(SB)/8,$0x00000001b192d268 + + /* x^83008 mod p(x), x^82944 mod p(x) */ +DATA ·CastConst+2784(SB)/8,$0x00000000024120fe +DATA ·CastConst+2792(SB)/8,$0x00000000e30f3a78 + + /* x^81984 mod p(x), x^81920 mod p(x) */ +DATA ·CastConst+2800(SB)/8,$0x00000000ddecddb4 +DATA ·CastConst+2808(SB)/8,$0x000000010ef1f7bc + + /* x^80960 mod p(x), x^80896 mod p(x) */ +DATA ·CastConst+2816(SB)/8,$0x00000000d4d403bc +DATA ·CastConst+2824(SB)/8,$0x00000001f5ac7380 + + /* x^79936 mod p(x), x^79872 mod p(x) */ +DATA ·CastConst+2832(SB)/8,$0x00000001734b89aa +DATA ·CastConst+2840(SB)/8,$0x000000011822ea70 + + /* x^78912 mod p(x), x^78848 mod p(x) */ +DATA ·CastConst+2848(SB)/8,$0x000000010e7a58d6 +DATA ·CastConst+2856(SB)/8,$0x00000000c3a33848 + + /* x^77888 mod p(x), x^77824 mod p(x) */ +DATA ·CastConst+2864(SB)/8,$0x00000001f9f04e9c +DATA ·CastConst+2872(SB)/8,$0x00000001bd151c24 + + /* x^76864 mod p(x), x^76800 mod p(x) */ +DATA ·CastConst+2880(SB)/8,$0x00000000b692225e +DATA ·CastConst+2888(SB)/8,$0x0000000056002d76 + + /* x^75840 mod p(x), x^75776 mod p(x) */ +DATA ·CastConst+2896(SB)/8,$0x000000019b8d3f3e +DATA ·CastConst+2904(SB)/8,$0x000000014657c4f4 + + /* x^74816 mod p(x), x^74752 mod p(x) */ +DATA ·CastConst+2912(SB)/8,$0x00000001a874f11e +DATA ·CastConst+2920(SB)/8,$0x0000000113742d7c + + /* x^73792 mod p(x), x^73728 mod p(x) */ +DATA ·CastConst+2928(SB)/8,$0x000000010d5a4254 +DATA ·CastConst+2936(SB)/8,$0x000000019c5920ba + + /* x^72768 mod p(x), x^72704 mod p(x) */ +DATA ·CastConst+2944(SB)/8,$0x00000000bbb2f5d6 +DATA ·CastConst+2952(SB)/8,$0x000000005216d2d6 + + /* x^71744 mod p(x), x^71680 mod p(x) */ +DATA ·CastConst+2960(SB)/8,$0x0000000179cc0e36 +DATA ·CastConst+2968(SB)/8,$0x0000000136f5ad8a + + /* x^70720 mod p(x), x^70656 mod p(x) */ +DATA ·CastConst+2976(SB)/8,$0x00000001dca1da4a +DATA ·CastConst+2984(SB)/8,$0x000000018b07beb6 + + /* x^69696 mod p(x), x^69632 mod p(x) */ +DATA ·CastConst+2992(SB)/8,$0x00000000feb1a192 +DATA ·CastConst+3000(SB)/8,$0x00000000db1e93b0 + + /* x^68672 mod p(x), x^68608 mod p(x) */ +DATA ·CastConst+3008(SB)/8,$0x00000000d1eeedd6 +DATA ·CastConst+3016(SB)/8,$0x000000000b96fa3a + + /* x^67648 mod p(x), x^67584 mod p(x) */ +DATA ·CastConst+3024(SB)/8,$0x000000008fad9bb4 +DATA ·CastConst+3032(SB)/8,$0x00000001d9968af0 + + /* x^66624 mod p(x), x^66560 mod p(x) */ +DATA ·CastConst+3040(SB)/8,$0x00000001884938e4 +DATA ·CastConst+3048(SB)/8,$0x000000000e4a77a2 + + /* x^65600 mod p(x), x^65536 mod p(x) */ +DATA ·CastConst+3056(SB)/8,$0x00000001bc2e9bc0 +DATA ·CastConst+3064(SB)/8,$0x00000000508c2ac8 + + /* x^64576 mod p(x), x^64512 mod p(x) */ +DATA ·CastConst+3072(SB)/8,$0x00000001f9658a68 +DATA ·CastConst+3080(SB)/8,$0x0000000021572a80 + + /* x^63552 mod p(x), x^63488 mod p(x) */ +DATA ·CastConst+3088(SB)/8,$0x000000001b9224fc +DATA ·CastConst+3096(SB)/8,$0x00000001b859daf2 + + /* x^62528 mod p(x), x^62464 mod p(x) */ +DATA ·CastConst+3104(SB)/8,$0x0000000055b2fb84 +DATA ·CastConst+3112(SB)/8,$0x000000016f788474 + + /* x^61504 mod p(x), x^61440 mod p(x) */ +DATA ·CastConst+3120(SB)/8,$0x000000018b090348 +DATA ·CastConst+3128(SB)/8,$0x00000001b438810e + + /* x^60480 mod p(x), x^60416 mod p(x) */ +DATA ·CastConst+3136(SB)/8,$0x000000011ccbd5ea +DATA ·CastConst+3144(SB)/8,$0x0000000095ddc6f2 + + /* x^59456 mod p(x), x^59392 mod p(x) */ +DATA ·CastConst+3152(SB)/8,$0x0000000007ae47f8 +DATA ·CastConst+3160(SB)/8,$0x00000001d977c20c + + /* x^58432 mod p(x), x^58368 mod p(x) */ +DATA ·CastConst+3168(SB)/8,$0x0000000172acbec0 +DATA ·CastConst+3176(SB)/8,$0x00000000ebedb99a + + /* x^57408 mod p(x), x^57344 mod p(x) */ +DATA ·CastConst+3184(SB)/8,$0x00000001c6e3ff20 +DATA ·CastConst+3192(SB)/8,$0x00000001df9e9e92 + + /* x^56384 mod p(x), x^56320 mod p(x) */ +DATA ·CastConst+3200(SB)/8,$0x00000000e1b38744 +DATA ·CastConst+3208(SB)/8,$0x00000001a4a3f952 + + /* x^55360 mod p(x), x^55296 mod p(x) */ +DATA ·CastConst+3216(SB)/8,$0x00000000791585b2 +DATA ·CastConst+3224(SB)/8,$0x00000000e2f51220 + + /* x^54336 mod p(x), x^54272 mod p(x) */ +DATA ·CastConst+3232(SB)/8,$0x00000000ac53b894 +DATA ·CastConst+3240(SB)/8,$0x000000004aa01f3e + + /* x^53312 mod p(x), x^53248 mod p(x) */ +DATA ·CastConst+3248(SB)/8,$0x00000001ed5f2cf4 +DATA ·CastConst+3256(SB)/8,$0x00000000b3e90a58 + + /* x^52288 mod p(x), x^52224 mod p(x) */ +DATA ·CastConst+3264(SB)/8,$0x00000001df48b2e0 +DATA ·CastConst+3272(SB)/8,$0x000000000c9ca2aa + + /* x^51264 mod p(x), x^51200 mod p(x) */ +DATA ·CastConst+3280(SB)/8,$0x00000000049c1c62 +DATA ·CastConst+3288(SB)/8,$0x0000000151682316 + + /* x^50240 mod p(x), x^50176 mod p(x) */ +DATA ·CastConst+3296(SB)/8,$0x000000017c460c12 +DATA ·CastConst+3304(SB)/8,$0x0000000036fce78c + + /* x^49216 mod p(x), x^49152 mod p(x) */ +DATA ·CastConst+3312(SB)/8,$0x000000015be4da7e +DATA ·CastConst+3320(SB)/8,$0x000000009037dc10 + + /* x^48192 mod p(x), x^48128 mod p(x) */ +DATA ·CastConst+3328(SB)/8,$0x000000010f38f668 +DATA ·CastConst+3336(SB)/8,$0x00000000d3298582 + + /* x^47168 mod p(x), x^47104 mod p(x) */ +DATA ·CastConst+3344(SB)/8,$0x0000000039f40a00 +DATA ·CastConst+3352(SB)/8,$0x00000001b42e8ad6 + + /* x^46144 mod p(x), x^46080 mod p(x) */ +DATA ·CastConst+3360(SB)/8,$0x00000000bd4c10c4 +DATA ·CastConst+3368(SB)/8,$0x00000000142a9838 + + /* x^45120 mod p(x), x^45056 mod p(x) */ +DATA ·CastConst+3376(SB)/8,$0x0000000042db1d98 +DATA ·CastConst+3384(SB)/8,$0x0000000109c7f190 + + /* x^44096 mod p(x), x^44032 mod p(x) */ +DATA ·CastConst+3392(SB)/8,$0x00000001c905bae6 +DATA ·CastConst+3400(SB)/8,$0x0000000056ff9310 + + /* x^43072 mod p(x), x^43008 mod p(x) */ +DATA ·CastConst+3408(SB)/8,$0x00000000069d40ea +DATA ·CastConst+3416(SB)/8,$0x00000001594513aa + + /* x^42048 mod p(x), x^41984 mod p(x) */ +DATA ·CastConst+3424(SB)/8,$0x000000008e4fbad0 +DATA ·CastConst+3432(SB)/8,$0x00000001e3b5b1e8 + + /* x^41024 mod p(x), x^40960 mod p(x) */ +DATA ·CastConst+3440(SB)/8,$0x0000000047bedd46 +DATA ·CastConst+3448(SB)/8,$0x000000011dd5fc08 + + /* x^40000 mod p(x), x^39936 mod p(x) */ +DATA ·CastConst+3456(SB)/8,$0x0000000026396bf8 +DATA ·CastConst+3464(SB)/8,$0x00000001675f0cc2 + + /* x^38976 mod p(x), x^38912 mod p(x) */ +DATA ·CastConst+3472(SB)/8,$0x00000000379beb92 +DATA ·CastConst+3480(SB)/8,$0x00000000d1c8dd44 + + /* x^37952 mod p(x), x^37888 mod p(x) */ +DATA ·CastConst+3488(SB)/8,$0x000000000abae54a +DATA ·CastConst+3496(SB)/8,$0x0000000115ebd3d8 + + /* x^36928 mod p(x), x^36864 mod p(x) */ +DATA ·CastConst+3504(SB)/8,$0x0000000007e6a128 +DATA ·CastConst+3512(SB)/8,$0x00000001ecbd0dac + + /* x^35904 mod p(x), x^35840 mod p(x) */ +DATA ·CastConst+3520(SB)/8,$0x000000000ade29d2 +DATA ·CastConst+3528(SB)/8,$0x00000000cdf67af2 + + /* x^34880 mod p(x), x^34816 mod p(x) */ +DATA ·CastConst+3536(SB)/8,$0x00000000f974c45c +DATA ·CastConst+3544(SB)/8,$0x000000004c01ff4c + + /* x^33856 mod p(x), x^33792 mod p(x) */ +DATA ·CastConst+3552(SB)/8,$0x00000000e77ac60a +DATA ·CastConst+3560(SB)/8,$0x00000000f2d8657e + + /* x^32832 mod p(x), x^32768 mod p(x) */ +DATA ·CastConst+3568(SB)/8,$0x0000000145895816 +DATA ·CastConst+3576(SB)/8,$0x000000006bae74c4 + + /* x^31808 mod p(x), x^31744 mod p(x) */ +DATA ·CastConst+3584(SB)/8,$0x0000000038e362be +DATA ·CastConst+3592(SB)/8,$0x0000000152af8aa0 + + /* x^30784 mod p(x), x^30720 mod p(x) */ +DATA ·CastConst+3600(SB)/8,$0x000000007f991a64 +DATA ·CastConst+3608(SB)/8,$0x0000000004663802 + + /* x^29760 mod p(x), x^29696 mod p(x) */ +DATA ·CastConst+3616(SB)/8,$0x00000000fa366d3a +DATA ·CastConst+3624(SB)/8,$0x00000001ab2f5afc + + /* x^28736 mod p(x), x^28672 mod p(x) */ +DATA ·CastConst+3632(SB)/8,$0x00000001a2bb34f0 +DATA ·CastConst+3640(SB)/8,$0x0000000074a4ebd4 + + /* x^27712 mod p(x), x^27648 mod p(x) */ +DATA ·CastConst+3648(SB)/8,$0x0000000028a9981e +DATA ·CastConst+3656(SB)/8,$0x00000001d7ab3a4c + + /* x^26688 mod p(x), x^26624 mod p(x) */ +DATA ·CastConst+3664(SB)/8,$0x00000001dbc672be +DATA ·CastConst+3672(SB)/8,$0x00000001a8da60c6 + + /* x^25664 mod p(x), x^25600 mod p(x) */ +DATA ·CastConst+3680(SB)/8,$0x00000000b04d77f6 +DATA ·CastConst+3688(SB)/8,$0x000000013cf63820 + + /* x^24640 mod p(x), x^24576 mod p(x) */ +DATA ·CastConst+3696(SB)/8,$0x0000000124400d96 +DATA ·CastConst+3704(SB)/8,$0x00000000bec12e1e + + /* x^23616 mod p(x), x^23552 mod p(x) */ +DATA ·CastConst+3712(SB)/8,$0x000000014ca4b414 +DATA ·CastConst+3720(SB)/8,$0x00000001c6368010 + + /* x^22592 mod p(x), x^22528 mod p(x) */ +DATA ·CastConst+3728(SB)/8,$0x000000012fe2c938 +DATA ·CastConst+3736(SB)/8,$0x00000001e6e78758 + + /* x^21568 mod p(x), x^21504 mod p(x) */ +DATA ·CastConst+3744(SB)/8,$0x00000001faed01e6 +DATA ·CastConst+3752(SB)/8,$0x000000008d7f2b3c + + /* x^20544 mod p(x), x^20480 mod p(x) */ +DATA ·CastConst+3760(SB)/8,$0x000000007e80ecfe +DATA ·CastConst+3768(SB)/8,$0x000000016b4a156e + + /* x^19520 mod p(x), x^19456 mod p(x) */ +DATA ·CastConst+3776(SB)/8,$0x0000000098daee94 +DATA ·CastConst+3784(SB)/8,$0x00000001c63cfeb6 + + /* x^18496 mod p(x), x^18432 mod p(x) */ +DATA ·CastConst+3792(SB)/8,$0x000000010a04edea +DATA ·CastConst+3800(SB)/8,$0x000000015f902670 + + /* x^17472 mod p(x), x^17408 mod p(x) */ +DATA ·CastConst+3808(SB)/8,$0x00000001c00b4524 +DATA ·CastConst+3816(SB)/8,$0x00000001cd5de11e + + /* x^16448 mod p(x), x^16384 mod p(x) */ +DATA ·CastConst+3824(SB)/8,$0x0000000170296550 +DATA ·CastConst+3832(SB)/8,$0x000000001acaec54 + + /* x^15424 mod p(x), x^15360 mod p(x) */ +DATA ·CastConst+3840(SB)/8,$0x0000000181afaa48 +DATA ·CastConst+3848(SB)/8,$0x000000002bd0ca78 + + /* x^14400 mod p(x), x^14336 mod p(x) */ +DATA ·CastConst+3856(SB)/8,$0x0000000185a31ffa +DATA ·CastConst+3864(SB)/8,$0x0000000032d63d5c + + /* x^13376 mod p(x), x^13312 mod p(x) */ +DATA ·CastConst+3872(SB)/8,$0x000000002469f608 +DATA ·CastConst+3880(SB)/8,$0x000000001c6d4e4c + + /* x^12352 mod p(x), x^12288 mod p(x) */ +DATA ·CastConst+3888(SB)/8,$0x000000006980102a +DATA ·CastConst+3896(SB)/8,$0x0000000106a60b92 + + /* x^11328 mod p(x), x^11264 mod p(x) */ +DATA ·CastConst+3904(SB)/8,$0x0000000111ea9ca8 +DATA ·CastConst+3912(SB)/8,$0x00000000d3855e12 + + /* x^10304 mod p(x), x^10240 mod p(x) */ +DATA ·CastConst+3920(SB)/8,$0x00000001bd1d29ce +DATA ·CastConst+3928(SB)/8,$0x00000000e3125636 + + /* x^9280 mod p(x), x^9216 mod p(x) */ +DATA ·CastConst+3936(SB)/8,$0x00000001b34b9580 +DATA ·CastConst+3944(SB)/8,$0x000000009e8f7ea4 + + /* x^8256 mod p(x), x^8192 mod p(x) */ +DATA ·CastConst+3952(SB)/8,$0x000000003076054e +DATA ·CastConst+3960(SB)/8,$0x00000001c82e562c + + /* x^7232 mod p(x), x^7168 mod p(x) */ +DATA ·CastConst+3968(SB)/8,$0x000000012a608ea4 +DATA ·CastConst+3976(SB)/8,$0x00000000ca9f09ce + + /* x^6208 mod p(x), x^6144 mod p(x) */ +DATA ·CastConst+3984(SB)/8,$0x00000000784d05fe +DATA ·CastConst+3992(SB)/8,$0x00000000c63764e6 + + /* x^5184 mod p(x), x^5120 mod p(x) */ +DATA ·CastConst+4000(SB)/8,$0x000000016ef0d82a +DATA ·CastConst+4008(SB)/8,$0x0000000168d2e49e + + /* x^4160 mod p(x), x^4096 mod p(x) */ +DATA ·CastConst+4016(SB)/8,$0x0000000075bda454 +DATA ·CastConst+4024(SB)/8,$0x00000000e986c148 + + /* x^3136 mod p(x), x^3072 mod p(x) */ +DATA ·CastConst+4032(SB)/8,$0x000000003dc0a1c4 +DATA ·CastConst+4040(SB)/8,$0x00000000cfb65894 + + /* x^2112 mod p(x), x^2048 mod p(x) */ +DATA ·CastConst+4048(SB)/8,$0x00000000e9a5d8be +DATA ·CastConst+4056(SB)/8,$0x0000000111cadee4 + + /* x^1088 mod p(x), x^1024 mod p(x) */ +DATA ·CastConst+4064(SB)/8,$0x00000001609bc4b4 +DATA ·CastConst+4072(SB)/8,$0x0000000171fb63ce + + /* x^2048 mod p(x), x^2016 mod p(x), x^1984 mod p(x), x^1952 mod p(x) */ +DATA ·CastConst+4080(SB)/8,$0x5cf015c388e56f72 +DATA ·CastConst+4088(SB)/8,$0x7fec2963e5bf8048 + + /* x^1920 mod p(x), x^1888 mod p(x), x^1856 mod p(x), x^1824 mod p(x) */ +DATA ·CastConst+4096(SB)/8,$0x963a18920246e2e6 +DATA ·CastConst+4104(SB)/8,$0x38e888d4844752a9 + + /* x^1792 mod p(x), x^1760 mod p(x), x^1728 mod p(x), x^1696 mod p(x) */ +DATA ·CastConst+4112(SB)/8,$0x419a441956993a31 +DATA ·CastConst+4120(SB)/8,$0x42316c00730206ad + + /* x^1664 mod p(x), x^1632 mod p(x), x^1600 mod p(x), x^1568 mod p(x) */ +DATA ·CastConst+4128(SB)/8,$0x924752ba2b830011 +DATA ·CastConst+4136(SB)/8,$0x543d5c543e65ddf9 + + /* x^1536 mod p(x), x^1504 mod p(x), x^1472 mod p(x), x^1440 mod p(x) */ +DATA ·CastConst+4144(SB)/8,$0x55bd7f9518e4a304 +DATA ·CastConst+4152(SB)/8,$0x78e87aaf56767c92 + + /* x^1408 mod p(x), x^1376 mod p(x), x^1344 mod p(x), x^1312 mod p(x) */ +DATA ·CastConst+4160(SB)/8,$0x6d76739fe0553f1e +DATA ·CastConst+4168(SB)/8,$0x8f68fcec1903da7f + + /* x^1280 mod p(x), x^1248 mod p(x), x^1216 mod p(x), x^1184 mod p(x) */ +DATA ·CastConst+4176(SB)/8,$0xc133722b1fe0b5c3 +DATA ·CastConst+4184(SB)/8,$0x3f4840246791d588 + + /* x^1152 mod p(x), x^1120 mod p(x), x^1088 mod p(x), x^1056 mod p(x) */ +DATA ·CastConst+4192(SB)/8,$0x64b67ee0e55ef1f3 +DATA ·CastConst+4200(SB)/8,$0x34c96751b04de25a + + /* x^1024 mod p(x), x^992 mod p(x), x^960 mod p(x), x^928 mod p(x) */ +DATA ·CastConst+4208(SB)/8,$0x069db049b8fdb1e7 +DATA ·CastConst+4216(SB)/8,$0x156c8e180b4a395b + + /* x^896 mod p(x), x^864 mod p(x), x^832 mod p(x), x^800 mod p(x) */ +DATA ·CastConst+4224(SB)/8,$0xa11bfaf3c9e90b9e +DATA ·CastConst+4232(SB)/8,$0xe0b99ccbe661f7be + + /* x^768 mod p(x), x^736 mod p(x), x^704 mod p(x), x^672 mod p(x) */ +DATA ·CastConst+4240(SB)/8,$0x817cdc5119b29a35 +DATA ·CastConst+4248(SB)/8,$0x041d37768cd75659 + + /* x^640 mod p(x), x^608 mod p(x), x^576 mod p(x), x^544 mod p(x) */ +DATA ·CastConst+4256(SB)/8,$0x1ce9d94b36c41f1c +DATA ·CastConst+4264(SB)/8,$0x3a0777818cfaa965 + + /* x^512 mod p(x), x^480 mod p(x), x^448 mod p(x), x^416 mod p(x) */ +DATA ·CastConst+4272(SB)/8,$0x4f256efcb82be955 +DATA ·CastConst+4280(SB)/8,$0x0e148e8252377a55 + + /* x^384 mod p(x), x^352 mod p(x), x^320 mod p(x), x^288 mod p(x) */ +DATA ·CastConst+4288(SB)/8,$0xec1631edb2dea967 +DATA ·CastConst+4296(SB)/8,$0x9c25531d19e65dde + + /* x^256 mod p(x), x^224 mod p(x), x^192 mod p(x), x^160 mod p(x) */ +DATA ·CastConst+4304(SB)/8,$0x5d27e147510ac59a +DATA ·CastConst+4312(SB)/8,$0x790606ff9957c0a6 + + /* x^128 mod p(x), x^96 mod p(x), x^64 mod p(x), x^32 mod p(x) */ +DATA ·CastConst+4320(SB)/8,$0xa66805eb18b8ea18 +DATA ·CastConst+4328(SB)/8,$0x82f63b786ea2d55c + +GLOBL ·CastConst(SB),RODATA,$4336 + + /* Barrett constant m - (4^32)/n */ +DATA ·CastBarConst(SB)/8,$0x00000000dea713f1 +DATA ·CastBarConst+8(SB)/8,$0x0000000000000000 +DATA ·CastBarConst+16(SB)/8,$0x0000000105ec76f1 +DATA ·CastBarConst+24(SB)/8,$0x0000000000000000 +GLOBL ·CastBarConst(SB),RODATA,$32 + + /* Reduce 262144 kbits to 1024 bits */ + /* x^261184 mod p(x), x^261120 mod p(x) */ +DATA ·KoopConst+0(SB)/8,$0x00000000d72535b2 +DATA ·KoopConst+8(SB)/8,$0x000000007fd74916 + + /* x^260160 mod p(x), x^260096 mod p(x) */ +DATA ·KoopConst+16(SB)/8,$0x0000000118a2a1b4 +DATA ·KoopConst+24(SB)/8,$0x000000010e944b56 + + /* x^259136 mod p(x), x^259072 mod p(x) */ +DATA ·KoopConst+32(SB)/8,$0x0000000147b5c49c +DATA ·KoopConst+40(SB)/8,$0x00000000bfe71c20 + + /* x^258112 mod p(x), x^258048 mod p(x) */ +DATA ·KoopConst+48(SB)/8,$0x00000001ca76a040 +DATA ·KoopConst+56(SB)/8,$0x0000000021324d9a + + /* x^257088 mod p(x), x^257024 mod p(x) */ +DATA ·KoopConst+64(SB)/8,$0x00000001e3152efc +DATA ·KoopConst+72(SB)/8,$0x00000000d20972ce + + /* x^256064 mod p(x), x^256000 mod p(x) */ +DATA ·KoopConst+80(SB)/8,$0x00000001b0349792 +DATA ·KoopConst+88(SB)/8,$0x000000003475ea06 + + /* x^255040 mod p(x), x^254976 mod p(x) */ +DATA ·KoopConst+96(SB)/8,$0x0000000120a60fe0 +DATA ·KoopConst+104(SB)/8,$0x00000001e40e36c4 + + /* x^254016 mod p(x), x^253952 mod p(x) */ +DATA ·KoopConst+112(SB)/8,$0x00000000b3c4b082 +DATA ·KoopConst+120(SB)/8,$0x00000000b2490102 + + /* x^252992 mod p(x), x^252928 mod p(x) */ +DATA ·KoopConst+128(SB)/8,$0x000000017fe9f3d2 +DATA ·KoopConst+136(SB)/8,$0x000000016b9e1332 + + /* x^251968 mod p(x), x^251904 mod p(x) */ +DATA ·KoopConst+144(SB)/8,$0x0000000145703cbe +DATA ·KoopConst+152(SB)/8,$0x00000001d6c378f4 + + /* x^250944 mod p(x), x^250880 mod p(x) */ +DATA ·KoopConst+160(SB)/8,$0x0000000107551c9c +DATA ·KoopConst+168(SB)/8,$0x0000000085796eac + + /* x^249920 mod p(x), x^249856 mod p(x) */ +DATA ·KoopConst+176(SB)/8,$0x000000003865a702 +DATA ·KoopConst+184(SB)/8,$0x000000019d2f3aaa + + /* x^248896 mod p(x), x^248832 mod p(x) */ +DATA ·KoopConst+192(SB)/8,$0x000000005504f9b8 +DATA ·KoopConst+200(SB)/8,$0x00000001554ddbd4 + + /* x^247872 mod p(x), x^247808 mod p(x) */ +DATA ·KoopConst+208(SB)/8,$0x00000000239bcdd4 +DATA ·KoopConst+216(SB)/8,$0x00000000a76376b0 + + /* x^246848 mod p(x), x^246784 mod p(x) */ +DATA ·KoopConst+224(SB)/8,$0x00000000caead774 +DATA ·KoopConst+232(SB)/8,$0x0000000139b7283c + + /* x^245824 mod p(x), x^245760 mod p(x) */ +DATA ·KoopConst+240(SB)/8,$0x0000000022a3fa16 +DATA ·KoopConst+248(SB)/8,$0x0000000111087030 + + /* x^244800 mod p(x), x^244736 mod p(x) */ +DATA ·KoopConst+256(SB)/8,$0x000000011f89160e +DATA ·KoopConst+264(SB)/8,$0x00000000ad786dc2 + + /* x^243776 mod p(x), x^243712 mod p(x) */ +DATA ·KoopConst+272(SB)/8,$0x00000001a976c248 +DATA ·KoopConst+280(SB)/8,$0x00000000b7a1d068 + + /* x^242752 mod p(x), x^242688 mod p(x) */ +DATA ·KoopConst+288(SB)/8,$0x00000000c20d09c8 +DATA ·KoopConst+296(SB)/8,$0x000000009c5c591c + + /* x^241728 mod p(x), x^241664 mod p(x) */ +DATA ·KoopConst+304(SB)/8,$0x000000016264fe38 +DATA ·KoopConst+312(SB)/8,$0x000000016482aa1a + + /* x^240704 mod p(x), x^240640 mod p(x) */ +DATA ·KoopConst+320(SB)/8,$0x00000001b57aee6a +DATA ·KoopConst+328(SB)/8,$0x000000009a409ba8 + + /* x^239680 mod p(x), x^239616 mod p(x) */ +DATA ·KoopConst+336(SB)/8,$0x00000000e8f1be0a +DATA ·KoopConst+344(SB)/8,$0x00000001ad8eaed8 + + /* x^238656 mod p(x), x^238592 mod p(x) */ +DATA ·KoopConst+352(SB)/8,$0x0000000053fcd0fc +DATA ·KoopConst+360(SB)/8,$0x000000017558b57a + + /* x^237632 mod p(x), x^237568 mod p(x) */ +DATA ·KoopConst+368(SB)/8,$0x000000012df9d496 +DATA ·KoopConst+376(SB)/8,$0x00000000cbb749c8 + + /* x^236608 mod p(x), x^236544 mod p(x) */ +DATA ·KoopConst+384(SB)/8,$0x000000004cb0db26 +DATA ·KoopConst+392(SB)/8,$0x000000008524fc5a + + /* x^235584 mod p(x), x^235520 mod p(x) */ +DATA ·KoopConst+400(SB)/8,$0x00000001150c4584 +DATA ·KoopConst+408(SB)/8,$0x0000000028ce6b76 + + /* x^234560 mod p(x), x^234496 mod p(x) */ +DATA ·KoopConst+416(SB)/8,$0x0000000104f52056 +DATA ·KoopConst+424(SB)/8,$0x00000000e0c48bdc + + /* x^233536 mod p(x), x^233472 mod p(x) */ +DATA ·KoopConst+432(SB)/8,$0x000000008ea11ac8 +DATA ·KoopConst+440(SB)/8,$0x000000003dd3bf9a + + /* x^232512 mod p(x), x^232448 mod p(x) */ +DATA ·KoopConst+448(SB)/8,$0x00000001cc0a3942 +DATA ·KoopConst+456(SB)/8,$0x00000000cb71066c + + /* x^231488 mod p(x), x^231424 mod p(x) */ +DATA ·KoopConst+464(SB)/8,$0x00000000d26231e6 +DATA ·KoopConst+472(SB)/8,$0x00000001d4ee1540 + + /* x^230464 mod p(x), x^230400 mod p(x) */ +DATA ·KoopConst+480(SB)/8,$0x00000000c70d5730 +DATA ·KoopConst+488(SB)/8,$0x00000001d82bed0a + + /* x^229440 mod p(x), x^229376 mod p(x) */ +DATA ·KoopConst+496(SB)/8,$0x00000000e215dfc4 +DATA ·KoopConst+504(SB)/8,$0x000000016e0c7d86 + + /* x^228416 mod p(x), x^228352 mod p(x) */ +DATA ·KoopConst+512(SB)/8,$0x000000013870d0dc +DATA ·KoopConst+520(SB)/8,$0x00000001437051b0 + + /* x^227392 mod p(x), x^227328 mod p(x) */ +DATA ·KoopConst+528(SB)/8,$0x0000000153e4cf3c +DATA ·KoopConst+536(SB)/8,$0x00000000f9a8d4be + + /* x^226368 mod p(x), x^226304 mod p(x) */ +DATA ·KoopConst+544(SB)/8,$0x0000000125f6fdf0 +DATA ·KoopConst+552(SB)/8,$0x000000016b09be1c + + /* x^225344 mod p(x), x^225280 mod p(x) */ +DATA ·KoopConst+560(SB)/8,$0x0000000157ba3a82 +DATA ·KoopConst+568(SB)/8,$0x0000000105f50ed6 + + /* x^224320 mod p(x), x^224256 mod p(x) */ +DATA ·KoopConst+576(SB)/8,$0x00000001cf711064 +DATA ·KoopConst+584(SB)/8,$0x00000001ca7fe3cc + + /* x^223296 mod p(x), x^223232 mod p(x) */ +DATA ·KoopConst+592(SB)/8,$0x00000001006353d2 +DATA ·KoopConst+600(SB)/8,$0x0000000192372e78 + + /* x^222272 mod p(x), x^222208 mod p(x) */ +DATA ·KoopConst+608(SB)/8,$0x000000010cd9faec +DATA ·KoopConst+616(SB)/8,$0x000000008a47af7e + + /* x^221248 mod p(x), x^221184 mod p(x) */ +DATA ·KoopConst+624(SB)/8,$0x000000012148b190 +DATA ·KoopConst+632(SB)/8,$0x00000000a67473e8 + + /* x^220224 mod p(x), x^220160 mod p(x) */ +DATA ·KoopConst+640(SB)/8,$0x00000000776473d6 +DATA ·KoopConst+648(SB)/8,$0x000000013689f2fa + + /* x^219200 mod p(x), x^219136 mod p(x) */ +DATA ·KoopConst+656(SB)/8,$0x00000001ce765bd6 +DATA ·KoopConst+664(SB)/8,$0x00000000e7231774 + + /* x^218176 mod p(x), x^218112 mod p(x) */ +DATA ·KoopConst+672(SB)/8,$0x00000000b29165e8 +DATA ·KoopConst+680(SB)/8,$0x0000000011b5ae68 + + /* x^217152 mod p(x), x^217088 mod p(x) */ +DATA ·KoopConst+688(SB)/8,$0x0000000084ff5a68 +DATA ·KoopConst+696(SB)/8,$0x000000004fd5c188 + + /* x^216128 mod p(x), x^216064 mod p(x) */ +DATA ·KoopConst+704(SB)/8,$0x00000001921e9076 +DATA ·KoopConst+712(SB)/8,$0x000000012148fa22 + + /* x^215104 mod p(x), x^215040 mod p(x) */ +DATA ·KoopConst+720(SB)/8,$0x000000009a753a3c +DATA ·KoopConst+728(SB)/8,$0x000000010cff4f3e + + /* x^214080 mod p(x), x^214016 mod p(x) */ +DATA ·KoopConst+736(SB)/8,$0x000000000251401e +DATA ·KoopConst+744(SB)/8,$0x00000001f9d991d4 + + /* x^213056 mod p(x), x^212992 mod p(x) */ +DATA ·KoopConst+752(SB)/8,$0x00000001f65541fa +DATA ·KoopConst+760(SB)/8,$0x00000001c31db214 + + /* x^212032 mod p(x), x^211968 mod p(x) */ +DATA ·KoopConst+768(SB)/8,$0x00000001d8c8117a +DATA ·KoopConst+776(SB)/8,$0x00000001849fba4a + + /* x^211008 mod p(x), x^210944 mod p(x) */ +DATA ·KoopConst+784(SB)/8,$0x000000014f7a2200 +DATA ·KoopConst+792(SB)/8,$0x00000001cb603184 + + /* x^209984 mod p(x), x^209920 mod p(x) */ +DATA ·KoopConst+800(SB)/8,$0x000000005154a9f4 +DATA ·KoopConst+808(SB)/8,$0x0000000132db7116 + + /* x^208960 mod p(x), x^208896 mod p(x) */ +DATA ·KoopConst+816(SB)/8,$0x00000001dfc69196 +DATA ·KoopConst+824(SB)/8,$0x0000000010694e22 + + /* x^207936 mod p(x), x^207872 mod p(x) */ +DATA ·KoopConst+832(SB)/8,$0x00000001c29f1aa0 +DATA ·KoopConst+840(SB)/8,$0x0000000103b7b478 + + /* x^206912 mod p(x), x^206848 mod p(x) */ +DATA ·KoopConst+848(SB)/8,$0x000000013785f232 +DATA ·KoopConst+856(SB)/8,$0x000000000ab44030 + + /* x^205888 mod p(x), x^205824 mod p(x) */ +DATA ·KoopConst+864(SB)/8,$0x000000010133536e +DATA ·KoopConst+872(SB)/8,$0x0000000131385b68 + + /* x^204864 mod p(x), x^204800 mod p(x) */ +DATA ·KoopConst+880(SB)/8,$0x00000001d45421dc +DATA ·KoopConst+888(SB)/8,$0x00000001761dab66 + + /* x^203840 mod p(x), x^203776 mod p(x) */ +DATA ·KoopConst+896(SB)/8,$0x000000000b59cc28 +DATA ·KoopConst+904(SB)/8,$0x000000012cf0a2a6 + + /* x^202816 mod p(x), x^202752 mod p(x) */ +DATA ·KoopConst+912(SB)/8,$0x00000001f2f74aba +DATA ·KoopConst+920(SB)/8,$0x00000001f4ce25a2 + + /* x^201792 mod p(x), x^201728 mod p(x) */ +DATA ·KoopConst+928(SB)/8,$0x00000000fb308e7e +DATA ·KoopConst+936(SB)/8,$0x000000014c2aae20 + + /* x^200768 mod p(x), x^200704 mod p(x) */ +DATA ·KoopConst+944(SB)/8,$0x0000000167583fa6 +DATA ·KoopConst+952(SB)/8,$0x00000001c162a55a + + /* x^199744 mod p(x), x^199680 mod p(x) */ +DATA ·KoopConst+960(SB)/8,$0x000000017ebb13e0 +DATA ·KoopConst+968(SB)/8,$0x0000000185681a40 + + /* x^198720 mod p(x), x^198656 mod p(x) */ +DATA ·KoopConst+976(SB)/8,$0x00000001ca653306 +DATA ·KoopConst+984(SB)/8,$0x00000001f2642b48 + + /* x^197696 mod p(x), x^197632 mod p(x) */ +DATA ·KoopConst+992(SB)/8,$0x0000000093bb6946 +DATA ·KoopConst+1000(SB)/8,$0x00000001d9cb5a78 + + /* x^196672 mod p(x), x^196608 mod p(x) */ +DATA ·KoopConst+1008(SB)/8,$0x00000000cbc1553e +DATA ·KoopConst+1016(SB)/8,$0x000000008059328c + + /* x^195648 mod p(x), x^195584 mod p(x) */ +DATA ·KoopConst+1024(SB)/8,$0x00000001f9a86fec +DATA ·KoopConst+1032(SB)/8,$0x000000009373c360 + + /* x^194624 mod p(x), x^194560 mod p(x) */ +DATA ·KoopConst+1040(SB)/8,$0x0000000005c52d8a +DATA ·KoopConst+1048(SB)/8,$0x00000001a14061d6 + + /* x^193600 mod p(x), x^193536 mod p(x) */ +DATA ·KoopConst+1056(SB)/8,$0x000000010d8dc668 +DATA ·KoopConst+1064(SB)/8,$0x00000000a9864d48 + + /* x^192576 mod p(x), x^192512 mod p(x) */ +DATA ·KoopConst+1072(SB)/8,$0x0000000158571310 +DATA ·KoopConst+1080(SB)/8,$0x000000011df8c040 + + /* x^191552 mod p(x), x^191488 mod p(x) */ +DATA ·KoopConst+1088(SB)/8,$0x0000000166102348 +DATA ·KoopConst+1096(SB)/8,$0x0000000023a3e6b6 + + /* x^190528 mod p(x), x^190464 mod p(x) */ +DATA ·KoopConst+1104(SB)/8,$0x0000000009513050 +DATA ·KoopConst+1112(SB)/8,$0x00000001207db28a + + /* x^189504 mod p(x), x^189440 mod p(x) */ +DATA ·KoopConst+1120(SB)/8,$0x00000000b0725c74 +DATA ·KoopConst+1128(SB)/8,$0x00000000f94bc632 + + /* x^188480 mod p(x), x^188416 mod p(x) */ +DATA ·KoopConst+1136(SB)/8,$0x000000002985c7e2 +DATA ·KoopConst+1144(SB)/8,$0x00000000ea32cbf6 + + /* x^187456 mod p(x), x^187392 mod p(x) */ +DATA ·KoopConst+1152(SB)/8,$0x00000000a7d4da9e +DATA ·KoopConst+1160(SB)/8,$0x0000000004eb981a + + /* x^186432 mod p(x), x^186368 mod p(x) */ +DATA ·KoopConst+1168(SB)/8,$0x000000000a3f8792 +DATA ·KoopConst+1176(SB)/8,$0x00000000ca8ce712 + + /* x^185408 mod p(x), x^185344 mod p(x) */ +DATA ·KoopConst+1184(SB)/8,$0x00000001ca2c1ce4 +DATA ·KoopConst+1192(SB)/8,$0x0000000065ba801c + + /* x^184384 mod p(x), x^184320 mod p(x) */ +DATA ·KoopConst+1200(SB)/8,$0x00000000e2900196 +DATA ·KoopConst+1208(SB)/8,$0x0000000194aade7a + + /* x^183360 mod p(x), x^183296 mod p(x) */ +DATA ·KoopConst+1216(SB)/8,$0x00000001fbadf0e4 +DATA ·KoopConst+1224(SB)/8,$0x00000001e7939fb2 + + /* x^182336 mod p(x), x^182272 mod p(x) */ +DATA ·KoopConst+1232(SB)/8,$0x00000000d5d96c40 +DATA ·KoopConst+1240(SB)/8,$0x0000000098e5fe22 + + /* x^181312 mod p(x), x^181248 mod p(x) */ +DATA ·KoopConst+1248(SB)/8,$0x000000015c11d3f2 +DATA ·KoopConst+1256(SB)/8,$0x000000016bba0324 + + /* x^180288 mod p(x), x^180224 mod p(x) */ +DATA ·KoopConst+1264(SB)/8,$0x0000000111fb2648 +DATA ·KoopConst+1272(SB)/8,$0x0000000104dce052 + + /* x^179264 mod p(x), x^179200 mod p(x) */ +DATA ·KoopConst+1280(SB)/8,$0x00000001d9f3a564 +DATA ·KoopConst+1288(SB)/8,$0x00000001af31a42e + + /* x^178240 mod p(x), x^178176 mod p(x) */ +DATA ·KoopConst+1296(SB)/8,$0x00000001b556cd1e +DATA ·KoopConst+1304(SB)/8,$0x00000001c56c57ba + + /* x^177216 mod p(x), x^177152 mod p(x) */ +DATA ·KoopConst+1312(SB)/8,$0x0000000101994d2c +DATA ·KoopConst+1320(SB)/8,$0x00000000f6bb1a2e + + /* x^176192 mod p(x), x^176128 mod p(x) */ +DATA ·KoopConst+1328(SB)/8,$0x00000001e8dbf09c +DATA ·KoopConst+1336(SB)/8,$0x00000001abdbf2b2 + + /* x^175168 mod p(x), x^175104 mod p(x) */ +DATA ·KoopConst+1344(SB)/8,$0x000000015580543a +DATA ·KoopConst+1352(SB)/8,$0x00000001a665a880 + + /* x^174144 mod p(x), x^174080 mod p(x) */ +DATA ·KoopConst+1360(SB)/8,$0x00000000c7074f24 +DATA ·KoopConst+1368(SB)/8,$0x00000000c102c700 + + /* x^173120 mod p(x), x^173056 mod p(x) */ +DATA ·KoopConst+1376(SB)/8,$0x00000000fa4112b0 +DATA ·KoopConst+1384(SB)/8,$0x00000000ee362a50 + + /* x^172096 mod p(x), x^172032 mod p(x) */ +DATA ·KoopConst+1392(SB)/8,$0x00000000e786c13e +DATA ·KoopConst+1400(SB)/8,$0x0000000045f29038 + + /* x^171072 mod p(x), x^171008 mod p(x) */ +DATA ·KoopConst+1408(SB)/8,$0x00000001e45e3694 +DATA ·KoopConst+1416(SB)/8,$0x0000000117b9ab5c + + /* x^170048 mod p(x), x^169984 mod p(x) */ +DATA ·KoopConst+1424(SB)/8,$0x000000005423dd8c +DATA ·KoopConst+1432(SB)/8,$0x00000001115dff5e + + /* x^169024 mod p(x), x^168960 mod p(x) */ +DATA ·KoopConst+1440(SB)/8,$0x00000001a1e67766 +DATA ·KoopConst+1448(SB)/8,$0x0000000117fad29c + + /* x^168000 mod p(x), x^167936 mod p(x) */ +DATA ·KoopConst+1456(SB)/8,$0x0000000041a3f508 +DATA ·KoopConst+1464(SB)/8,$0x000000017de134e6 + + /* x^166976 mod p(x), x^166912 mod p(x) */ +DATA ·KoopConst+1472(SB)/8,$0x000000003e792f7e +DATA ·KoopConst+1480(SB)/8,$0x00000000a2f5d19c + + /* x^165952 mod p(x), x^165888 mod p(x) */ +DATA ·KoopConst+1488(SB)/8,$0x00000000c8948aaa +DATA ·KoopConst+1496(SB)/8,$0x00000000dee13658 + + /* x^164928 mod p(x), x^164864 mod p(x) */ +DATA ·KoopConst+1504(SB)/8,$0x000000005d4ccb36 +DATA ·KoopConst+1512(SB)/8,$0x000000015355440c + + /* x^163904 mod p(x), x^163840 mod p(x) */ +DATA ·KoopConst+1520(SB)/8,$0x00000000e92a78a2 +DATA ·KoopConst+1528(SB)/8,$0x0000000197a21778 + + /* x^162880 mod p(x), x^162816 mod p(x) */ +DATA ·KoopConst+1536(SB)/8,$0x000000016ba67caa +DATA ·KoopConst+1544(SB)/8,$0x00000001a3835ec0 + + /* x^161856 mod p(x), x^161792 mod p(x) */ +DATA ·KoopConst+1552(SB)/8,$0x000000004838afc6 +DATA ·KoopConst+1560(SB)/8,$0x0000000011f20912 + + /* x^160832 mod p(x), x^160768 mod p(x) */ +DATA ·KoopConst+1568(SB)/8,$0x000000016644e308 +DATA ·KoopConst+1576(SB)/8,$0x00000001cce9d6cc + + /* x^159808 mod p(x), x^159744 mod p(x) */ +DATA ·KoopConst+1584(SB)/8,$0x0000000037c22f42 +DATA ·KoopConst+1592(SB)/8,$0x0000000084d1e71c + + /* x^158784 mod p(x), x^158720 mod p(x) */ +DATA ·KoopConst+1600(SB)/8,$0x00000001dedba6ca +DATA ·KoopConst+1608(SB)/8,$0x0000000197c2ad54 + + /* x^157760 mod p(x), x^157696 mod p(x) */ +DATA ·KoopConst+1616(SB)/8,$0x0000000146a43500 +DATA ·KoopConst+1624(SB)/8,$0x000000018609261e + + /* x^156736 mod p(x), x^156672 mod p(x) */ +DATA ·KoopConst+1632(SB)/8,$0x000000001cf762de +DATA ·KoopConst+1640(SB)/8,$0x00000000b4b4c224 + + /* x^155712 mod p(x), x^155648 mod p(x) */ +DATA ·KoopConst+1648(SB)/8,$0x0000000022ff7eda +DATA ·KoopConst+1656(SB)/8,$0x0000000080817496 + + /* x^154688 mod p(x), x^154624 mod p(x) */ +DATA ·KoopConst+1664(SB)/8,$0x00000001b6df625e +DATA ·KoopConst+1672(SB)/8,$0x00000001aefb473c + + /* x^153664 mod p(x), x^153600 mod p(x) */ +DATA ·KoopConst+1680(SB)/8,$0x00000001cc99ab58 +DATA ·KoopConst+1688(SB)/8,$0x000000013f1aa474 + + /* x^152640 mod p(x), x^152576 mod p(x) */ +DATA ·KoopConst+1696(SB)/8,$0x00000001c53f5ce2 +DATA ·KoopConst+1704(SB)/8,$0x000000010ca2c756 + + /* x^151616 mod p(x), x^151552 mod p(x) */ +DATA ·KoopConst+1712(SB)/8,$0x0000000082a9c60e +DATA ·KoopConst+1720(SB)/8,$0x000000002c63533a + + /* x^150592 mod p(x), x^150528 mod p(x) */ +DATA ·KoopConst+1728(SB)/8,$0x00000000ec78b570 +DATA ·KoopConst+1736(SB)/8,$0x00000001b7f2ad50 + + /* x^149568 mod p(x), x^149504 mod p(x) */ +DATA ·KoopConst+1744(SB)/8,$0x00000001d3fe1e8e +DATA ·KoopConst+1752(SB)/8,$0x00000000acdf4c20 + + /* x^148544 mod p(x), x^148480 mod p(x) */ +DATA ·KoopConst+1760(SB)/8,$0x000000007f9a7bde +DATA ·KoopConst+1768(SB)/8,$0x000000000bd29e8c + + /* x^147520 mod p(x), x^147456 mod p(x) */ +DATA ·KoopConst+1776(SB)/8,$0x00000000e606f518 +DATA ·KoopConst+1784(SB)/8,$0x00000001eef6992e + + /* x^146496 mod p(x), x^146432 mod p(x) */ +DATA ·KoopConst+1792(SB)/8,$0x000000008538cb96 +DATA ·KoopConst+1800(SB)/8,$0x00000000b01644e6 + + /* x^145472 mod p(x), x^145408 mod p(x) */ +DATA ·KoopConst+1808(SB)/8,$0x0000000131d030b2 +DATA ·KoopConst+1816(SB)/8,$0x0000000059c51acc + + /* x^144448 mod p(x), x^144384 mod p(x) */ +DATA ·KoopConst+1824(SB)/8,$0x00000000115a4d0e +DATA ·KoopConst+1832(SB)/8,$0x00000001a2849272 + + /* x^143424 mod p(x), x^143360 mod p(x) */ +DATA ·KoopConst+1840(SB)/8,$0x00000000e8a5356e +DATA ·KoopConst+1848(SB)/8,$0x00000001a4e0b610 + + /* x^142400 mod p(x), x^142336 mod p(x) */ +DATA ·KoopConst+1856(SB)/8,$0x0000000158d988be +DATA ·KoopConst+1864(SB)/8,$0x00000000084e81a6 + + /* x^141376 mod p(x), x^141312 mod p(x) */ +DATA ·KoopConst+1872(SB)/8,$0x00000001240db498 +DATA ·KoopConst+1880(SB)/8,$0x00000001b71f1fd8 + + /* x^140352 mod p(x), x^140288 mod p(x) */ +DATA ·KoopConst+1888(SB)/8,$0x000000009ce87826 +DATA ·KoopConst+1896(SB)/8,$0x000000017f7df380 + + /* x^139328 mod p(x), x^139264 mod p(x) */ +DATA ·KoopConst+1904(SB)/8,$0x0000000021944aae +DATA ·KoopConst+1912(SB)/8,$0x00000001f7f4e190 + + /* x^138304 mod p(x), x^138240 mod p(x) */ +DATA ·KoopConst+1920(SB)/8,$0x00000001cea3d67e +DATA ·KoopConst+1928(SB)/8,$0x0000000150220d86 + + /* x^137280 mod p(x), x^137216 mod p(x) */ +DATA ·KoopConst+1936(SB)/8,$0x000000004434e926 +DATA ·KoopConst+1944(SB)/8,$0x00000001db7d2b2e + + /* x^136256 mod p(x), x^136192 mod p(x) */ +DATA ·KoopConst+1952(SB)/8,$0x0000000011db8cbe +DATA ·KoopConst+1960(SB)/8,$0x00000000b6ba9668 + + /* x^135232 mod p(x), x^135168 mod p(x) */ +DATA ·KoopConst+1968(SB)/8,$0x00000001f6e0b8dc +DATA ·KoopConst+1976(SB)/8,$0x0000000103fdcecc + + /* x^134208 mod p(x), x^134144 mod p(x) */ +DATA ·KoopConst+1984(SB)/8,$0x00000001f163f4a0 +DATA ·KoopConst+1992(SB)/8,$0x0000000079816a22 + + /* x^133184 mod p(x), x^133120 mod p(x) */ +DATA ·KoopConst+2000(SB)/8,$0x000000007b6cc60e +DATA ·KoopConst+2008(SB)/8,$0x0000000173483482 + + /* x^132160 mod p(x), x^132096 mod p(x) */ +DATA ·KoopConst+2016(SB)/8,$0x000000000f26c82c +DATA ·KoopConst+2024(SB)/8,$0x00000000643ea4c0 + + /* x^131136 mod p(x), x^131072 mod p(x) */ +DATA ·KoopConst+2032(SB)/8,$0x00000000b0acad80 +DATA ·KoopConst+2040(SB)/8,$0x00000000a64752d2 + + /* x^130112 mod p(x), x^130048 mod p(x) */ +DATA ·KoopConst+2048(SB)/8,$0x000000013687e91c +DATA ·KoopConst+2056(SB)/8,$0x00000000ca98eb3a + + /* x^129088 mod p(x), x^129024 mod p(x) */ +DATA ·KoopConst+2064(SB)/8,$0x000000006bac3a96 +DATA ·KoopConst+2072(SB)/8,$0x00000001ca6ac8f8 + + /* x^128064 mod p(x), x^128000 mod p(x) */ +DATA ·KoopConst+2080(SB)/8,$0x00000001bf197d5c +DATA ·KoopConst+2088(SB)/8,$0x00000001c48e2e68 + + /* x^127040 mod p(x), x^126976 mod p(x) */ +DATA ·KoopConst+2096(SB)/8,$0x00000000256e84f2 +DATA ·KoopConst+2104(SB)/8,$0x0000000070086782 + + /* x^126016 mod p(x), x^125952 mod p(x) */ +DATA ·KoopConst+2112(SB)/8,$0x000000003eff0d16 +DATA ·KoopConst+2120(SB)/8,$0x00000000f763621c + + /* x^124992 mod p(x), x^124928 mod p(x) */ +DATA ·KoopConst+2128(SB)/8,$0x00000001748e9fd2 +DATA ·KoopConst+2136(SB)/8,$0x00000000ba58646a + + /* x^123968 mod p(x), x^123904 mod p(x) */ +DATA ·KoopConst+2144(SB)/8,$0x000000015bb85b42 +DATA ·KoopConst+2152(SB)/8,$0x0000000138e157d8 + + /* x^122944 mod p(x), x^122880 mod p(x) */ +DATA ·KoopConst+2160(SB)/8,$0x0000000164d1a980 +DATA ·KoopConst+2168(SB)/8,$0x00000001bf0a09dc + + /* x^121920 mod p(x), x^121856 mod p(x) */ +DATA ·KoopConst+2176(SB)/8,$0x000000001415c9f0 +DATA ·KoopConst+2184(SB)/8,$0x0000000098faf300 + + /* x^120896 mod p(x), x^120832 mod p(x) */ +DATA ·KoopConst+2192(SB)/8,$0x0000000195ae2f48 +DATA ·KoopConst+2200(SB)/8,$0x00000001f872f2c6 + + /* x^119872 mod p(x), x^119808 mod p(x) */ +DATA ·KoopConst+2208(SB)/8,$0x0000000059d1d81a +DATA ·KoopConst+2216(SB)/8,$0x00000000f92577be + + /* x^118848 mod p(x), x^118784 mod p(x) */ +DATA ·KoopConst+2224(SB)/8,$0x00000001bf80257a +DATA ·KoopConst+2232(SB)/8,$0x00000001a4d975f4 + + /* x^117824 mod p(x), x^117760 mod p(x) */ +DATA ·KoopConst+2240(SB)/8,$0x000000011e39bfce +DATA ·KoopConst+2248(SB)/8,$0x000000018b74eeca + + /* x^116800 mod p(x), x^116736 mod p(x) */ +DATA ·KoopConst+2256(SB)/8,$0x00000001287a0456 +DATA ·KoopConst+2264(SB)/8,$0x00000000e8980404 + + /* x^115776 mod p(x), x^115712 mod p(x) */ +DATA ·KoopConst+2272(SB)/8,$0x00000000a5eb589c +DATA ·KoopConst+2280(SB)/8,$0x0000000176ef2b74 + + /* x^114752 mod p(x), x^114688 mod p(x) */ +DATA ·KoopConst+2288(SB)/8,$0x000000017d71c452 +DATA ·KoopConst+2296(SB)/8,$0x0000000063c85caa + + /* x^113728 mod p(x), x^113664 mod p(x) */ +DATA ·KoopConst+2304(SB)/8,$0x00000000fa941f08 +DATA ·KoopConst+2312(SB)/8,$0x00000001708012cc + + /* x^112704 mod p(x), x^112640 mod p(x) */ +DATA ·KoopConst+2320(SB)/8,$0x0000000064ea030e +DATA ·KoopConst+2328(SB)/8,$0x00000000474d58f6 + + /* x^111680 mod p(x), x^111616 mod p(x) */ +DATA ·KoopConst+2336(SB)/8,$0x000000019b7cc7ba +DATA ·KoopConst+2344(SB)/8,$0x00000001c76085a6 + + /* x^110656 mod p(x), x^110592 mod p(x) */ +DATA ·KoopConst+2352(SB)/8,$0x00000000225cb7ba +DATA ·KoopConst+2360(SB)/8,$0x000000018fb0681a + + /* x^109632 mod p(x), x^109568 mod p(x) */ +DATA ·KoopConst+2368(SB)/8,$0x000000010ab3e1da +DATA ·KoopConst+2376(SB)/8,$0x00000001fcee1f16 + + /* x^108608 mod p(x), x^108544 mod p(x) */ +DATA ·KoopConst+2384(SB)/8,$0x00000001ce5cc33e +DATA ·KoopConst+2392(SB)/8,$0x00000000cfbffb7c + + /* x^107584 mod p(x), x^107520 mod p(x) */ +DATA ·KoopConst+2400(SB)/8,$0x000000005e980f6e +DATA ·KoopConst+2408(SB)/8,$0x000000017af8ee72 + + /* x^106560 mod p(x), x^106496 mod p(x) */ +DATA ·KoopConst+2416(SB)/8,$0x00000000d3bf3f46 +DATA ·KoopConst+2424(SB)/8,$0x000000001c2ad3e2 + + /* x^105536 mod p(x), x^105472 mod p(x) */ +DATA ·KoopConst+2432(SB)/8,$0x000000018d554ae0 +DATA ·KoopConst+2440(SB)/8,$0x00000000ee05450a + + /* x^104512 mod p(x), x^104448 mod p(x) */ +DATA ·KoopConst+2448(SB)/8,$0x000000018e276eb0 +DATA ·KoopConst+2456(SB)/8,$0x000000000f7d5bac + + /* x^103488 mod p(x), x^103424 mod p(x) */ +DATA ·KoopConst+2464(SB)/8,$0x000000001c0319ce +DATA ·KoopConst+2472(SB)/8,$0x00000001cb26e004 + + /* x^102464 mod p(x), x^102400 mod p(x) */ +DATA ·KoopConst+2480(SB)/8,$0x00000001ca0c75ec +DATA ·KoopConst+2488(SB)/8,$0x00000001553314e2 + + /* x^101440 mod p(x), x^101376 mod p(x) */ +DATA ·KoopConst+2496(SB)/8,$0x00000001fb075330 +DATA ·KoopConst+2504(SB)/8,$0x000000005729be2c + + /* x^100416 mod p(x), x^100352 mod p(x) */ +DATA ·KoopConst+2512(SB)/8,$0x00000000677920e4 +DATA ·KoopConst+2520(SB)/8,$0x0000000192c4479c + + /* x^99392 mod p(x), x^99328 mod p(x) */ +DATA ·KoopConst+2528(SB)/8,$0x00000000332247c8 +DATA ·KoopConst+2536(SB)/8,$0x0000000078d842b6 + + /* x^98368 mod p(x), x^98304 mod p(x) */ +DATA ·KoopConst+2544(SB)/8,$0x00000000ef84fc6c +DATA ·KoopConst+2552(SB)/8,$0x0000000145ffa282 + + /* x^97344 mod p(x), x^97280 mod p(x) */ +DATA ·KoopConst+2560(SB)/8,$0x0000000139ba7690 +DATA ·KoopConst+2568(SB)/8,$0x000000019d679bf4 + + /* x^96320 mod p(x), x^96256 mod p(x) */ +DATA ·KoopConst+2576(SB)/8,$0x00000000029ef444 +DATA ·KoopConst+2584(SB)/8,$0x000000019412f7a0 + + /* x^95296 mod p(x), x^95232 mod p(x) */ +DATA ·KoopConst+2592(SB)/8,$0x00000001d872048c +DATA ·KoopConst+2600(SB)/8,$0x00000000b28c5c96 + + /* x^94272 mod p(x), x^94208 mod p(x) */ +DATA ·KoopConst+2608(SB)/8,$0x000000016535d70a +DATA ·KoopConst+2616(SB)/8,$0x00000000554bfd44 + + /* x^93248 mod p(x), x^93184 mod p(x) */ +DATA ·KoopConst+2624(SB)/8,$0x00000000761dd222 +DATA ·KoopConst+2632(SB)/8,$0x00000000ce9cfa48 + + /* x^92224 mod p(x), x^92160 mod p(x) */ +DATA ·KoopConst+2640(SB)/8,$0x00000001509a3a44 +DATA ·KoopConst+2648(SB)/8,$0x00000000a4702ab2 + + /* x^91200 mod p(x), x^91136 mod p(x) */ +DATA ·KoopConst+2656(SB)/8,$0x000000007e7019f2 +DATA ·KoopConst+2664(SB)/8,$0x00000001c967fbee + + /* x^90176 mod p(x), x^90112 mod p(x) */ +DATA ·KoopConst+2672(SB)/8,$0x00000000fb4c56ea +DATA ·KoopConst+2680(SB)/8,$0x00000000fd514b3e + + /* x^89152 mod p(x), x^89088 mod p(x) */ +DATA ·KoopConst+2688(SB)/8,$0x000000012022e0ee +DATA ·KoopConst+2696(SB)/8,$0x00000001c0b6f95e + + /* x^88128 mod p(x), x^88064 mod p(x) */ +DATA ·KoopConst+2704(SB)/8,$0x0000000004bc6054 +DATA ·KoopConst+2712(SB)/8,$0x0000000180e103ce + + /* x^87104 mod p(x), x^87040 mod p(x) */ +DATA ·KoopConst+2720(SB)/8,$0x000000017a1a0030 +DATA ·KoopConst+2728(SB)/8,$0x00000001a1630916 + + /* x^86080 mod p(x), x^86016 mod p(x) */ +DATA ·KoopConst+2736(SB)/8,$0x00000001c021a864 +DATA ·KoopConst+2744(SB)/8,$0x000000009a727fb2 + + /* x^85056 mod p(x), x^84992 mod p(x) */ +DATA ·KoopConst+2752(SB)/8,$0x000000009c54421e +DATA ·KoopConst+2760(SB)/8,$0x00000000e83b081a + + /* x^84032 mod p(x), x^83968 mod p(x) */ +DATA ·KoopConst+2768(SB)/8,$0x00000001b4e33e6a +DATA ·KoopConst+2776(SB)/8,$0x000000006b1a1f44 + + /* x^83008 mod p(x), x^82944 mod p(x) */ +DATA ·KoopConst+2784(SB)/8,$0x000000015d615af0 +DATA ·KoopConst+2792(SB)/8,$0x00000000cf280394 + + /* x^81984 mod p(x), x^81920 mod p(x) */ +DATA ·KoopConst+2800(SB)/8,$0x00000001914a3ba8 +DATA ·KoopConst+2808(SB)/8,$0x00000001154b8a9a + + /* x^80960 mod p(x), x^80896 mod p(x) */ +DATA ·KoopConst+2816(SB)/8,$0x000000005f72ec44 +DATA ·KoopConst+2824(SB)/8,$0x0000000149ec63e2 + + /* x^79936 mod p(x), x^79872 mod p(x) */ +DATA ·KoopConst+2832(SB)/8,$0x00000000a33746a8 +DATA ·KoopConst+2840(SB)/8,$0x000000018ef902c4 + + /* x^78912 mod p(x), x^78848 mod p(x) */ +DATA ·KoopConst+2848(SB)/8,$0x00000001c91e90d4 +DATA ·KoopConst+2856(SB)/8,$0x0000000069addb88 + + /* x^77888 mod p(x), x^77824 mod p(x) */ +DATA ·KoopConst+2864(SB)/8,$0x00000001052eb05e +DATA ·KoopConst+2872(SB)/8,$0x00000000e90a29ae + + /* x^76864 mod p(x), x^76800 mod p(x) */ +DATA ·KoopConst+2880(SB)/8,$0x000000006a32f754 +DATA ·KoopConst+2888(SB)/8,$0x00000000c53641ae + + /* x^75840 mod p(x), x^75776 mod p(x) */ +DATA ·KoopConst+2896(SB)/8,$0x00000001ecbd6436 +DATA ·KoopConst+2904(SB)/8,$0x00000000a17c3796 + + /* x^74816 mod p(x), x^74752 mod p(x) */ +DATA ·KoopConst+2912(SB)/8,$0x000000000fd3f93a +DATA ·KoopConst+2920(SB)/8,$0x000000015307a62c + + /* x^73792 mod p(x), x^73728 mod p(x) */ +DATA ·KoopConst+2928(SB)/8,$0x00000001686a4c24 +DATA ·KoopConst+2936(SB)/8,$0x000000002f94bbda + + /* x^72768 mod p(x), x^72704 mod p(x) */ +DATA ·KoopConst+2944(SB)/8,$0x00000001e40afca0 +DATA ·KoopConst+2952(SB)/8,$0x0000000072c8b5e6 + + /* x^71744 mod p(x), x^71680 mod p(x) */ +DATA ·KoopConst+2960(SB)/8,$0x000000012779a2b8 +DATA ·KoopConst+2968(SB)/8,$0x00000000f09b7424 + + /* x^70720 mod p(x), x^70656 mod p(x) */ +DATA ·KoopConst+2976(SB)/8,$0x00000000dcdaeb9e +DATA ·KoopConst+2984(SB)/8,$0x00000001c57de3da + + /* x^69696 mod p(x), x^69632 mod p(x) */ +DATA ·KoopConst+2992(SB)/8,$0x00000001674f7a2a +DATA ·KoopConst+3000(SB)/8,$0x000000013922b30e + + /* x^68672 mod p(x), x^68608 mod p(x) */ +DATA ·KoopConst+3008(SB)/8,$0x00000000dcb9e846 +DATA ·KoopConst+3016(SB)/8,$0x000000008759a6c2 + + /* x^67648 mod p(x), x^67584 mod p(x) */ +DATA ·KoopConst+3024(SB)/8,$0x00000000ea9a6af6 +DATA ·KoopConst+3032(SB)/8,$0x00000000545ae424 + + /* x^66624 mod p(x), x^66560 mod p(x) */ +DATA ·KoopConst+3040(SB)/8,$0x000000006d1f7a74 +DATA ·KoopConst+3048(SB)/8,$0x00000001e0cbafd2 + + /* x^65600 mod p(x), x^65536 mod p(x) */ +DATA ·KoopConst+3056(SB)/8,$0x000000006add215e +DATA ·KoopConst+3064(SB)/8,$0x0000000018360c04 + + /* x^64576 mod p(x), x^64512 mod p(x) */ +DATA ·KoopConst+3072(SB)/8,$0x000000010a9ee4b0 +DATA ·KoopConst+3080(SB)/8,$0x00000000941dc432 + + /* x^63552 mod p(x), x^63488 mod p(x) */ +DATA ·KoopConst+3088(SB)/8,$0x00000000304c48d2 +DATA ·KoopConst+3096(SB)/8,$0x0000000004d3566e + + /* x^62528 mod p(x), x^62464 mod p(x) */ +DATA ·KoopConst+3104(SB)/8,$0x0000000163d0e672 +DATA ·KoopConst+3112(SB)/8,$0x0000000096aed14e + + /* x^61504 mod p(x), x^61440 mod p(x) */ +DATA ·KoopConst+3120(SB)/8,$0x0000000010049166 +DATA ·KoopConst+3128(SB)/8,$0x0000000087c13618 + + /* x^60480 mod p(x), x^60416 mod p(x) */ +DATA ·KoopConst+3136(SB)/8,$0x00000001d3913e34 +DATA ·KoopConst+3144(SB)/8,$0x00000001d52f7b0c + + /* x^59456 mod p(x), x^59392 mod p(x) */ +DATA ·KoopConst+3152(SB)/8,$0x00000001e392d54a +DATA ·KoopConst+3160(SB)/8,$0x000000000182058e + + /* x^58432 mod p(x), x^58368 mod p(x) */ +DATA ·KoopConst+3168(SB)/8,$0x0000000173f2704a +DATA ·KoopConst+3176(SB)/8,$0x00000001ed73aa02 + + /* x^57408 mod p(x), x^57344 mod p(x) */ +DATA ·KoopConst+3184(SB)/8,$0x000000019112b480 +DATA ·KoopConst+3192(SB)/8,$0x000000002721a82e + + /* x^56384 mod p(x), x^56320 mod p(x) */ +DATA ·KoopConst+3200(SB)/8,$0x0000000093d295d6 +DATA ·KoopConst+3208(SB)/8,$0x000000012ca83da2 + + /* x^55360 mod p(x), x^55296 mod p(x) */ +DATA ·KoopConst+3216(SB)/8,$0x0000000114e37f44 +DATA ·KoopConst+3224(SB)/8,$0x00000000da358698 + + /* x^54336 mod p(x), x^54272 mod p(x) */ +DATA ·KoopConst+3232(SB)/8,$0x00000000fcfebc86 +DATA ·KoopConst+3240(SB)/8,$0x0000000011fad322 + + /* x^53312 mod p(x), x^53248 mod p(x) */ +DATA ·KoopConst+3248(SB)/8,$0x00000000834c48d6 +DATA ·KoopConst+3256(SB)/8,$0x000000012b25025c + + /* x^52288 mod p(x), x^52224 mod p(x) */ +DATA ·KoopConst+3264(SB)/8,$0x000000017b909372 +DATA ·KoopConst+3272(SB)/8,$0x000000001290cd24 + + /* x^51264 mod p(x), x^51200 mod p(x) */ +DATA ·KoopConst+3280(SB)/8,$0x000000010156b9ac +DATA ·KoopConst+3288(SB)/8,$0x000000016edd0b06 + + /* x^50240 mod p(x), x^50176 mod p(x) */ +DATA ·KoopConst+3296(SB)/8,$0x0000000113a82fa8 +DATA ·KoopConst+3304(SB)/8,$0x00000000c08e222a + + /* x^49216 mod p(x), x^49152 mod p(x) */ +DATA ·KoopConst+3312(SB)/8,$0x0000000182dacb74 +DATA ·KoopConst+3320(SB)/8,$0x00000000cfb4d10e + + /* x^48192 mod p(x), x^48128 mod p(x) */ +DATA ·KoopConst+3328(SB)/8,$0x000000010210dc40 +DATA ·KoopConst+3336(SB)/8,$0x000000013e156ece + + /* x^47168 mod p(x), x^47104 mod p(x) */ +DATA ·KoopConst+3344(SB)/8,$0x000000008ab5ed20 +DATA ·KoopConst+3352(SB)/8,$0x00000000f12d89f8 + + /* x^46144 mod p(x), x^46080 mod p(x) */ +DATA ·KoopConst+3360(SB)/8,$0x00000000810386fa +DATA ·KoopConst+3368(SB)/8,$0x00000001fce3337c + + /* x^45120 mod p(x), x^45056 mod p(x) */ +DATA ·KoopConst+3376(SB)/8,$0x000000011dce2fe2 +DATA ·KoopConst+3384(SB)/8,$0x00000001c4bf3514 + + /* x^44096 mod p(x), x^44032 mod p(x) */ +DATA ·KoopConst+3392(SB)/8,$0x000000004bb0a390 +DATA ·KoopConst+3400(SB)/8,$0x00000001ae67c492 + + /* x^43072 mod p(x), x^43008 mod p(x) */ +DATA ·KoopConst+3408(SB)/8,$0x00000000028d486a +DATA ·KoopConst+3416(SB)/8,$0x00000000302af704 + + /* x^42048 mod p(x), x^41984 mod p(x) */ +DATA ·KoopConst+3424(SB)/8,$0x000000010e4d63fe +DATA ·KoopConst+3432(SB)/8,$0x00000001e375b250 + + /* x^41024 mod p(x), x^40960 mod p(x) */ +DATA ·KoopConst+3440(SB)/8,$0x000000014fd6f458 +DATA ·KoopConst+3448(SB)/8,$0x00000001678b58c0 + + /* x^40000 mod p(x), x^39936 mod p(x) */ +DATA ·KoopConst+3456(SB)/8,$0x00000000db7a83a2 +DATA ·KoopConst+3464(SB)/8,$0x0000000065103c1e + + /* x^38976 mod p(x), x^38912 mod p(x) */ +DATA ·KoopConst+3472(SB)/8,$0x000000016cf9fa3c +DATA ·KoopConst+3480(SB)/8,$0x000000000ccd28ca + + /* x^37952 mod p(x), x^37888 mod p(x) */ +DATA ·KoopConst+3488(SB)/8,$0x000000016bb33912 +DATA ·KoopConst+3496(SB)/8,$0x0000000059c177d4 + + /* x^36928 mod p(x), x^36864 mod p(x) */ +DATA ·KoopConst+3504(SB)/8,$0x0000000135bda8bc +DATA ·KoopConst+3512(SB)/8,$0x00000001d162f83a + + /* x^35904 mod p(x), x^35840 mod p(x) */ +DATA ·KoopConst+3520(SB)/8,$0x000000004e8c6b76 +DATA ·KoopConst+3528(SB)/8,$0x00000001efc0230c + + /* x^34880 mod p(x), x^34816 mod p(x) */ +DATA ·KoopConst+3536(SB)/8,$0x00000000e17cb750 +DATA ·KoopConst+3544(SB)/8,$0x00000001a2a2e2d2 + + /* x^33856 mod p(x), x^33792 mod p(x) */ +DATA ·KoopConst+3552(SB)/8,$0x000000010e8bb9cc +DATA ·KoopConst+3560(SB)/8,$0x00000001145c9dc2 + + /* x^32832 mod p(x), x^32768 mod p(x) */ +DATA ·KoopConst+3568(SB)/8,$0x00000001859d1cae +DATA ·KoopConst+3576(SB)/8,$0x00000000949e4a48 + + /* x^31808 mod p(x), x^31744 mod p(x) */ +DATA ·KoopConst+3584(SB)/8,$0x0000000167802bbe +DATA ·KoopConst+3592(SB)/8,$0x0000000128beecbc + + /* x^30784 mod p(x), x^30720 mod p(x) */ +DATA ·KoopConst+3600(SB)/8,$0x0000000086f5219c +DATA ·KoopConst+3608(SB)/8,$0x00000001ffc96ae4 + + /* x^29760 mod p(x), x^29696 mod p(x) */ +DATA ·KoopConst+3616(SB)/8,$0x00000001349a4faa +DATA ·KoopConst+3624(SB)/8,$0x00000001ba81e0aa + + /* x^28736 mod p(x), x^28672 mod p(x) */ +DATA ·KoopConst+3632(SB)/8,$0x000000007da3353e +DATA ·KoopConst+3640(SB)/8,$0x0000000104d7df14 + + /* x^27712 mod p(x), x^27648 mod p(x) */ +DATA ·KoopConst+3648(SB)/8,$0x00000000440fba4e +DATA ·KoopConst+3656(SB)/8,$0x00000001c2ff8518 + + /* x^26688 mod p(x), x^26624 mod p(x) */ +DATA ·KoopConst+3664(SB)/8,$0x00000000507aba70 +DATA ·KoopConst+3672(SB)/8,$0x00000000ba6d4708 + + /* x^25664 mod p(x), x^25600 mod p(x) */ +DATA ·KoopConst+3680(SB)/8,$0x0000000015b578b6 +DATA ·KoopConst+3688(SB)/8,$0x00000001d49d4bba + + /* x^24640 mod p(x), x^24576 mod p(x) */ +DATA ·KoopConst+3696(SB)/8,$0x0000000141633fb2 +DATA ·KoopConst+3704(SB)/8,$0x00000000d21247e6 + + /* x^23616 mod p(x), x^23552 mod p(x) */ +DATA ·KoopConst+3712(SB)/8,$0x0000000178712680 +DATA ·KoopConst+3720(SB)/8,$0x0000000063b4004a + + /* x^22592 mod p(x), x^22528 mod p(x) */ +DATA ·KoopConst+3728(SB)/8,$0x000000001404c194 +DATA ·KoopConst+3736(SB)/8,$0x0000000094f55d2c + + /* x^21568 mod p(x), x^21504 mod p(x) */ +DATA ·KoopConst+3744(SB)/8,$0x00000000469dbe46 +DATA ·KoopConst+3752(SB)/8,$0x00000001ca68fe74 + + /* x^20544 mod p(x), x^20480 mod p(x) */ +DATA ·KoopConst+3760(SB)/8,$0x00000000fb093fd8 +DATA ·KoopConst+3768(SB)/8,$0x00000001fd7d1b4c + + /* x^19520 mod p(x), x^19456 mod p(x) */ +DATA ·KoopConst+3776(SB)/8,$0x00000000767a2bfe +DATA ·KoopConst+3784(SB)/8,$0x0000000055982d0c + + /* x^18496 mod p(x), x^18432 mod p(x) */ +DATA ·KoopConst+3792(SB)/8,$0x00000001344e22bc +DATA ·KoopConst+3800(SB)/8,$0x00000000221553a6 + + /* x^17472 mod p(x), x^17408 mod p(x) */ +DATA ·KoopConst+3808(SB)/8,$0x0000000161cd9978 +DATA ·KoopConst+3816(SB)/8,$0x000000013d9a153a + + /* x^16448 mod p(x), x^16384 mod p(x) */ +DATA ·KoopConst+3824(SB)/8,$0x00000001d702e906 +DATA ·KoopConst+3832(SB)/8,$0x00000001cd108b3c + + /* x^15424 mod p(x), x^15360 mod p(x) */ +DATA ·KoopConst+3840(SB)/8,$0x00000001c7db9908 +DATA ·KoopConst+3848(SB)/8,$0x00000001d0af0f4a + + /* x^14400 mod p(x), x^14336 mod p(x) */ +DATA ·KoopConst+3856(SB)/8,$0x00000001665d025c +DATA ·KoopConst+3864(SB)/8,$0x00000001196cf0ec + + /* x^13376 mod p(x), x^13312 mod p(x) */ +DATA ·KoopConst+3872(SB)/8,$0x000000012df97c0e +DATA ·KoopConst+3880(SB)/8,$0x00000001c88c9704 + + /* x^12352 mod p(x), x^12288 mod p(x) */ +DATA ·KoopConst+3888(SB)/8,$0x000000006fed84da +DATA ·KoopConst+3896(SB)/8,$0x000000002013d300 + + /* x^11328 mod p(x), x^11264 mod p(x) */ +DATA ·KoopConst+3904(SB)/8,$0x00000000b094146e +DATA ·KoopConst+3912(SB)/8,$0x00000001c458501e + + /* x^10304 mod p(x), x^10240 mod p(x) */ +DATA ·KoopConst+3920(SB)/8,$0x00000001ceb518a6 +DATA ·KoopConst+3928(SB)/8,$0x000000003ce14802 + + /* x^9280 mod p(x), x^9216 mod p(x) */ +DATA ·KoopConst+3936(SB)/8,$0x000000011f16db0a +DATA ·KoopConst+3944(SB)/8,$0x00000000bb72bb98 + + /* x^8256 mod p(x), x^8192 mod p(x) */ +DATA ·KoopConst+3952(SB)/8,$0x00000001d4aa130e +DATA ·KoopConst+3960(SB)/8,$0x00000000fb9aeaba + + /* x^7232 mod p(x), x^7168 mod p(x) */ +DATA ·KoopConst+3968(SB)/8,$0x00000001991f01d2 +DATA ·KoopConst+3976(SB)/8,$0x000000000131f5e6 + + /* x^6208 mod p(x), x^6144 mod p(x) */ +DATA ·KoopConst+3984(SB)/8,$0x000000006bd58b4c +DATA ·KoopConst+3992(SB)/8,$0x0000000089d5799a + + /* x^5184 mod p(x), x^5120 mod p(x) */ +DATA ·KoopConst+4000(SB)/8,$0x000000007272c166 +DATA ·KoopConst+4008(SB)/8,$0x00000000474c43b0 + + /* x^4160 mod p(x), x^4096 mod p(x) */ +DATA ·KoopConst+4016(SB)/8,$0x000000013974e6f8 +DATA ·KoopConst+4024(SB)/8,$0x00000001db991f34 + + /* x^3136 mod p(x), x^3072 mod p(x) */ +DATA ·KoopConst+4032(SB)/8,$0x000000000bd6e03c +DATA ·KoopConst+4040(SB)/8,$0x000000004b1bfd00 + + /* x^2112 mod p(x), x^2048 mod p(x) */ +DATA ·KoopConst+4048(SB)/8,$0x000000005988c652 +DATA ·KoopConst+4056(SB)/8,$0x000000004036b796 + + /* x^1088 mod p(x), x^1024 mod p(x) */ +DATA ·KoopConst+4064(SB)/8,$0x00000000129ef036 +DATA ·KoopConst+4072(SB)/8,$0x000000000c5ec3d4 + + /* x^2048 mod p(x), x^2016 mod p(x), x^1984 mod p(x), x^1952 mod p(x) */ +DATA ·KoopConst+4080(SB)/8,$0xd6f94847201b5bcb +DATA ·KoopConst+4088(SB)/8,$0x1efc02e79571e892 + + /* x^1920 mod p(x), x^1888 mod p(x), x^1856 mod p(x), x^1824 mod p(x) */ +DATA ·KoopConst+4096(SB)/8,$0xce08adcc294c1393 +DATA ·KoopConst+4104(SB)/8,$0x0b269b5c5ab5f161 + + /* x^1792 mod p(x), x^1760 mod p(x), x^1728 mod p(x), x^1696 mod p(x) */ +DATA ·KoopConst+4112(SB)/8,$0x17315505e4201e72 +DATA ·KoopConst+4120(SB)/8,$0x2e841f4784acf3e9 + + /* x^1664 mod p(x), x^1632 mod p(x), x^1600 mod p(x), x^1568 mod p(x) */ +DATA ·KoopConst+4128(SB)/8,$0x37cfc3a67cc667e3 +DATA ·KoopConst+4136(SB)/8,$0x7020425856bc424b + + /* x^1536 mod p(x), x^1504 mod p(x), x^1472 mod p(x), x^1440 mod p(x) */ +DATA ·KoopConst+4144(SB)/8,$0x8e2fa3369218d2c3 +DATA ·KoopConst+4152(SB)/8,$0xdf81bf923f7c6ef1 + + /* x^1408 mod p(x), x^1376 mod p(x), x^1344 mod p(x), x^1312 mod p(x) */ +DATA ·KoopConst+4160(SB)/8,$0x5ce20d2d39ed1981 +DATA ·KoopConst+4168(SB)/8,$0x9d0898a0af5ddc43 + + /* x^1280 mod p(x), x^1248 mod p(x), x^1216 mod p(x), x^1184 mod p(x) */ +DATA ·KoopConst+4176(SB)/8,$0x6f7f4546ca081e03 +DATA ·KoopConst+4184(SB)/8,$0x4992836903fda047 + + /* x^1152 mod p(x), x^1120 mod p(x), x^1088 mod p(x), x^1056 mod p(x) */ +DATA ·KoopConst+4192(SB)/8,$0xfd4f413b9bf11d68 +DATA ·KoopConst+4200(SB)/8,$0xf4ddf452094f781b + + /* x^1024 mod p(x), x^992 mod p(x), x^960 mod p(x), x^928 mod p(x) */ +DATA ·KoopConst+4208(SB)/8,$0x11d84204062f61ea +DATA ·KoopConst+4216(SB)/8,$0x9487f1e51f3588cf + + /* x^896 mod p(x), x^864 mod p(x), x^832 mod p(x), x^800 mod p(x) */ +DATA ·KoopConst+4224(SB)/8,$0xfaedf111abf58a1f +DATA ·KoopConst+4232(SB)/8,$0x31da2c22b1384ec9 + + /* x^768 mod p(x), x^736 mod p(x), x^704 mod p(x), x^672 mod p(x) */ +DATA ·KoopConst+4240(SB)/8,$0x0246b541e8f81b22 +DATA ·KoopConst+4248(SB)/8,$0xc857ede58a42eb47 + + /* x^640 mod p(x), x^608 mod p(x), x^576 mod p(x), x^544 mod p(x) */ +DATA ·KoopConst+4256(SB)/8,$0xd4dbfa9b92b0372e +DATA ·KoopConst+4264(SB)/8,$0xe0354c0b2cd1c09a + + /* x^512 mod p(x), x^480 mod p(x), x^448 mod p(x), x^416 mod p(x) */ +DATA ·KoopConst+4272(SB)/8,$0x5f36c79cfc4417ec +DATA ·KoopConst+4280(SB)/8,$0x4b92cf8d54b8f25b + + /* x^384 mod p(x), x^352 mod p(x), x^320 mod p(x), x^288 mod p(x) */ +DATA ·KoopConst+4288(SB)/8,$0xdad234918345041e +DATA ·KoopConst+4296(SB)/8,$0x4e44c81828229301 + + /* x^256 mod p(x), x^224 mod p(x), x^192 mod p(x), x^160 mod p(x) */ +DATA ·KoopConst+4304(SB)/8,$0x56fd28cc8e02f1d0 +DATA ·KoopConst+4312(SB)/8,$0x3da5e43c8ee9ee84 + + /* x^128 mod p(x), x^96 mod p(x), x^64 mod p(x), x^32 mod p(x) */ +DATA ·KoopConst+4320(SB)/8,$0xa583017cdfcb9f08 +DATA ·KoopConst+4328(SB)/8,$0xeb31d82e0c62ab26 + +GLOBL ·KoopConst(SB),RODATA,$4336 + + /* Barrett constant m - (4^32)/n */ +DATA ·KoopBarConst(SB)/8,$0x0000000017d232cd +DATA ·KoopBarConst+8(SB)/8,$0x0000000000000000 +DATA ·KoopBarConst+16(SB)/8,$0x00000001d663b05d +DATA ·KoopBarConst+24(SB)/8,$0x0000000000000000 +GLOBL ·KoopBarConst(SB),RODATA,$32 diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/crc32_test.go b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_test.go new file mode 100644 index 0000000000000000000000000000000000000000..f084612f6f0ff1deeb1768633197960899135b67 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/crc32_test.go @@ -0,0 +1,342 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package crc32 + +import ( + "encoding" + "fmt" + "hash" + "io" + "math/rand" + "testing" +) + +// First test, so that it can be the one to initialize castagnoliTable. +func TestCastagnoliRace(t *testing.T) { + // The MakeTable(Castagnoli) lazily initializes castagnoliTable, + // which races with the switch on tab during Write to check + // whether tab == castagnoliTable. + ieee := NewIEEE() + go MakeTable(Castagnoli) + ieee.Write([]byte("hello")) +} + +type test struct { + ieee, castagnoli uint32 + in string + halfStateIEEE string // IEEE marshaled hash state after first half of in written, used by TestGoldenMarshal + halfStateCastagnoli string // Castagnoli marshaled hash state after first half of in written, used by TestGoldenMarshal +} + +var golden = []test{ + {0x0, 0x0, "", "crc\x01ʇ\x91M\x00\x00\x00\x00", "crc\x01wB\x84\x81\x00\x00\x00\x00"}, + {0xe8b7be43, 0xc1d04330, "a", "crc\x01ʇ\x91M\x00\x00\x00\x00", "crc\x01wB\x84\x81\x00\x00\x00\x00"}, + {0x9e83486d, 0xe2a22936, "ab", "crc\x01ʇ\x91M跾C", "crc\x01wB\x84\x81\xc1\xd0C0"}, + {0x352441c2, 0x364b3fb7, "abc", "crc\x01ʇ\x91M跾C", "crc\x01wB\x84\x81\xc1\xd0C0"}, + {0xed82cd11, 0x92c80a31, "abcd", "crc\x01ʇ\x91M\x9e\x83Hm", "crc\x01wB\x84\x81\xe2\xa2)6"}, + {0x8587d865, 0xc450d697, "abcde", "crc\x01ʇ\x91M\x9e\x83Hm", "crc\x01wB\x84\x81\xe2\xa2)6"}, + {0x4b8e39ef, 0x53bceff1, "abcdef", "crc\x01ʇ\x91M5$A\xc2", "crc\x01wB\x84\x816K?\xb7"}, + {0x312a6aa6, 0xe627f441, "abcdefg", "crc\x01ʇ\x91M5$A\xc2", "crc\x01wB\x84\x816K?\xb7"}, + {0xaeef2a50, 0xa9421b7, "abcdefgh", "crc\x01ʇ\x91M\xed\x82\xcd\x11", "crc\x01wB\x84\x81\x92\xc8\n1"}, + {0x8da988af, 0x2ddc99fc, "abcdefghi", "crc\x01ʇ\x91M\xed\x82\xcd\x11", "crc\x01wB\x84\x81\x92\xc8\n1"}, + {0x3981703a, 0xe6599437, "abcdefghij", "crc\x01ʇ\x91M\x85\x87\xd8e", "crc\x01wB\x84\x81\xc4P֗"}, + {0x6b9cdfe7, 0xb2cc01fe, "Discard medicine more than two years old.", "crc\x01ʇ\x91M\xfd\xe5\xc2J", "crc\x01wB\x84\x81S\"(\xe0"}, + {0xc90ef73f, 0xe28207f, "He who has a shady past knows that nice guys finish last.", "crc\x01ʇ\x91M\x01Nj+", "crc\x01wB\x84\x81'\xdaR\x15"}, + {0xb902341f, 0xbe93f964, "I wouldn't marry him with a ten foot pole.", "crc\x01ʇ\x91M\x9d\x13\xce\x10", "crc\x01wB\x84\x81\xc3\xed\xabG"}, + {0x42080e8, 0x9e3be0c3, "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave", "crc\x01ʇ\x91M-\xed\xf7\x94", "crc\x01wB\x84\x81\xce\xceb\x81"}, + {0x154c6d11, 0xf505ef04, "The days of the digital watch are numbered. -Tom Stoppard", "crc\x01ʇ\x91MOa\xa5\r", "crc\x01wB\x84\x81\xd3s\x9dP"}, + {0x4c418325, 0x85d3dc82, "Nepal premier won't resign.", "crc\x01ʇ\x91M\xa8S9\x85", "crc\x01wB\x84\x81{\x90\x8a\x14"}, + {0x33955150, 0xc5142380, "For every action there is an equal and opposite government program.", "crc\x01ʇ\x91Ma\xe9>\x86", "crc\x01wB\x84\x81\xaa@\xc4\x1c"}, + {0x26216a4b, 0x75eb77dd, "His money is twice tainted: 'taint yours and 'taint mine.", "crc\x01ʇ\x91M\\\x1an\x88", "crc\x01wB\x84\x81W\a8Z"}, + {0x1abbe45e, 0x91ebe9f7, "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977", "crc\x01ʇ\x91M\xb7\xf5\xf2\xca", "crc\x01wB\x84\x81\xc4o\x9d\x85"}, + {0xc89a94f7, 0xf0b1168e, "It's a tiny change to the code and not completely disgusting. - Bob Manchek", "crc\x01ʇ\x91M\x84g1\xe8", "crc\x01wB\x84\x81#\x98\f\xab"}, + {0xab3abe14, 0x572b74e2, "size: a.out: bad magic", "crc\x01ʇ\x91M\x8a\x0f\xad\b", "crc\x01wB\x84\x81\x80\xc9n\xd8"}, + {0xbab102b6, 0x8a58a6d5, "The major problem is with sendmail. -Mark Horton", "crc\x01ʇ\x91M\a\xf0\xb3\x15", "crc\x01wB\x84\x81liS\xcc"}, + {0x999149d7, 0x9c426c50, "Give me a rock, paper and scissors and I will move the world. CCFestoon", "crc\x01ʇ\x91M\x0fa\xbc.", "crc\x01wB\x84\x81\xdb͏C"}, + {0x6d52a33c, 0x735400a4, "If the enemy is within range, then so are you.", "crc\x01ʇ\x91My\x1b\x99\xf8", "crc\x01wB\x84\x81\xaaB\x037"}, + {0x90631e8d, 0xbec49c95, "It's well we cannot hear the screams/That we create in others' dreams.", "crc\x01ʇ\x91M\bqfY", "crc\x01wB\x84\x81\x16y\xa1\xd2"}, + {0x78309130, 0xa95a2079, "You remind me of a TV show, but that's all right: I watch it anyway.", "crc\x01ʇ\x91M\xbdO,\xc2", "crc\x01wB\x84\x81f&\xc5\xe4"}, + {0x7d0a377f, 0xde2e65c5, "C is as portable as Stonehedge!!", "crc\x01ʇ\x91M\xf7\xd6\x00\xd5", "crc\x01wB\x84\x81de\\\xf8"}, + {0x8c79fd79, 0x297a88ed, "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley", "crc\x01ʇ\x91Ml+\xb8\xa7", "crc\x01wB\x84\x81\xbf\xd6S\xdd"}, + {0xa20b7167, 0x66ed1d8b, "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule", "crc\x01ʇ\x91M= len(b) { + d = len(b) + } + ieee.Write(b[:d]) + ieee.Write(b[d:]) + return ieee.Sum32() + }) + } + + castagnoliTab := MakeTable(Castagnoli) + if castagnoliTab == nil { + t.Errorf("nil Castagnoli Table") + } + + testGoldenCastagnoli(t, func(b []byte) uint32 { + castagnoli := New(castagnoliTab) + castagnoli.Write(b) + return castagnoli.Sum32() + }) + + // Some implementations have special code to deal with misaligned + // data; test that as well. + for delta := 1; delta <= 7; delta++ { + testGoldenCastagnoli(t, func(b []byte) uint32 { + castagnoli := New(castagnoliTab) + d := delta + if d >= len(b) { + d = len(b) + } + castagnoli.Write(b[:d]) + castagnoli.Write(b[d:]) + return castagnoli.Sum32() + }) + } +} + +func BenchmarkCRC32(b *testing.B) { + b.Run("poly=IEEE", benchmarkAll(NewIEEE())) + b.Run("poly=Castagnoli", benchmarkAll(New(MakeTable(Castagnoli)))) + b.Run("poly=Koopman", benchmarkAll(New(MakeTable(Koopman)))) +} + +func benchmarkAll(h hash.Hash32) func(b *testing.B) { + return func(b *testing.B) { + for _, size := range []int{15, 40, 512, 1 << 10, 4 << 10, 32 << 10} { + name := fmt.Sprint(size) + if size >= 1024 { + name = fmt.Sprintf("%dkB", size/1024) + } + b.Run("size="+name, func(b *testing.B) { + for align := 0; align <= 1; align++ { + b.Run(fmt.Sprintf("align=%d", align), func(b *testing.B) { + benchmark(b, h, int64(size), int64(align)) + }) + } + }) + } + } +} + +func benchmark(b *testing.B, h hash.Hash32, n, alignment int64) { + b.SetBytes(n) + data := make([]byte, n+alignment) + data = data[alignment:] + for i := range data { + data[i] = byte(i) + } + in := make([]byte, 0, h.Size()) + + // Warm up + h.Reset() + h.Write(data) + h.Sum(in) + // Avoid further allocations + in = in[:0] + + b.ResetTimer() + for i := 0; i < b.N; i++ { + h.Reset() + h.Write(data) + h.Sum(in) + in = in[:0] + } +} diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/example_test.go b/platform/dbops/binaries/go/go/src/hash/crc32/example_test.go new file mode 100644 index 0000000000000000000000000000000000000000..621bf838309ed7cc2613a01097237cdf34463f5f --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/example_test.go @@ -0,0 +1,28 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package crc32_test + +import ( + "fmt" + "hash/crc32" +) + +func ExampleMakeTable() { + // In this package, the CRC polynomial is represented in reversed notation, + // or LSB-first representation. + // + // LSB-first representation is a hexadecimal number with n bits, in which the + // most significant bit represents the coefficient of x⁰ and the least significant + // bit represents the coefficient of xⁿ⁻¹ (the coefficient for xⁿ is implicit). + // + // For example, CRC32-Q, as defined by the following polynomial, + // x³²+ x³¹+ x²⁴+ x²²+ x¹⁶+ x¹⁴+ x⁸+ x⁷+ x⁵+ x³+ x¹+ x⁰ + // has the reversed notation 0b11010101100000101000001010000001, so the value + // that should be passed to MakeTable is 0xD5828281. + crc32q := crc32.MakeTable(0xD5828281) + fmt.Printf("%08x\n", crc32.Checksum([]byte("Hello world"), crc32q)) + // Output: + // 2964d064 +} diff --git a/platform/dbops/binaries/go/go/src/hash/crc32/gen_const_ppc64le.go b/platform/dbops/binaries/go/go/src/hash/crc32/gen_const_ppc64le.go new file mode 100644 index 0000000000000000000000000000000000000000..2f15a60b50e3bed04f131ac7d48ed1201d63ffcb --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc32/gen_const_ppc64le.go @@ -0,0 +1,150 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ignore + +// Generate the constant table associated with the poly used by the +// vpmsumd crc32 algorithm. +// +// go run gen_const_ppc64le.go +// +// generates crc32_table_ppc64le.s + +// The following is derived from code written by Anton Blanchard +// found at https://github.com/antonblanchard/crc32-vpmsum. +// The original is dual licensed under GPL and Apache 2. As the copyright holder +// for the work, IBM has contributed this new work under the golang license. + +// This code was written in Go based on the original C implementation. + +// This is a tool needed to generate the appropriate constants needed for +// the vpmsum algorithm. It is included to generate new constant tables if +// new polynomial values are included in the future. + +package main + +import ( + "bytes" + "fmt" + "os" +) + +var blocking = 32 * 1024 + +func reflect_bits(b uint64, nr uint) uint64 { + var ref uint64 + + for bit := uint64(0); bit < uint64(nr); bit++ { + if (b & uint64(1)) == 1 { + ref |= (1 << (uint64(nr-1) - bit)) + } + b = (b >> 1) + } + return ref +} + +func get_remainder(poly uint64, deg uint, n uint) uint64 { + + rem, _ := xnmodp(n, poly, deg) + return rem +} + +func get_quotient(poly uint64, bits, n uint) uint64 { + + _, div := xnmodp(n, poly, bits) + return div +} + +// xnmodp returns two values, p and div: +// p is the representation of the binary polynomial x**n mod (x ** deg + "poly") +// That is p is the binary representation of the modulus polynomial except for its highest-order term. +// div is the binary representation of the polynomial x**n / (x ** deg + "poly") +func xnmodp(n uint, poly uint64, deg uint) (uint64, uint64) { + + var mod, mask, high, div uint64 + + if n < deg { + div = 0 + return poly, div + } + mask = 1< deg { + high = (mod >> deg) & 1 + div = (div << 1) | high + mod <<= 1 + if high != 0 { + mod ^= poly + } + n-- + } + return mod & mask, div +} + +func main() { + w := new(bytes.Buffer) + + fmt.Fprintf(w, "// autogenerated: do not edit!\n") + fmt.Fprintf(w, "// generated from crc32/gen_const_ppc64le.go\n") + fmt.Fprintln(w) + fmt.Fprintf(w, "#include \"textflag.h\"\n") + + // These are the polynomials supported in vector now. + // If adding others, include the polynomial and a name + // to identify it. + + genCrc32ConstTable(w, 0xedb88320, "IEEE") + genCrc32ConstTable(w, 0x82f63b78, "Cast") + genCrc32ConstTable(w, 0xeb31d82e, "Koop") + b := w.Bytes() + + err := os.WriteFile("crc32_table_ppc64le.s", b, 0666) + if err != nil { + fmt.Printf("can't write output: %s\n", err) + } +} + +func genCrc32ConstTable(w *bytes.Buffer, poly uint32, polyid string) { + + ref_poly := reflect_bits(uint64(poly), 32) + fmt.Fprintf(w, "\n\t/* Reduce %d kbits to 1024 bits */\n", blocking*8) + j := 0 + for i := (blocking * 8) - 1024; i > 0; i -= 1024 { + a := reflect_bits(get_remainder(ref_poly, 32, uint(i)), 32) << 1 + b := reflect_bits(get_remainder(ref_poly, 32, uint(i+64)), 32) << 1 + + fmt.Fprintf(w, "\t/* x^%d mod p(x)%s, x^%d mod p(x)%s */\n", uint(i+64), "", uint(i), "") + fmt.Fprintf(w, "DATA ·%sConst+%d(SB)/8,$0x%016x\n", polyid, j*8, b) + fmt.Fprintf(w, "DATA ·%sConst+%d(SB)/8,$0x%016x\n", polyid, (j+1)*8, a) + + j += 2 + fmt.Fprintf(w, "\n") + } + + for i := (1024 * 2) - 128; i >= 0; i -= 128 { + a := reflect_bits(get_remainder(ref_poly, 32, uint(i+32)), 32) + b := reflect_bits(get_remainder(ref_poly, 32, uint(i+64)), 32) + c := reflect_bits(get_remainder(ref_poly, 32, uint(i+96)), 32) + d := reflect_bits(get_remainder(ref_poly, 32, uint(i+128)), 32) + + fmt.Fprintf(w, "\t/* x^%d mod p(x)%s, x^%d mod p(x)%s, x^%d mod p(x)%s, x^%d mod p(x)%s */\n", i+128, "", i+96, "", i+64, "", i+32, "") + fmt.Fprintf(w, "DATA ·%sConst+%d(SB)/8,$0x%08x%08x\n", polyid, j*8, c, d) + fmt.Fprintf(w, "DATA ·%sConst+%d(SB)/8,$0x%08x%08x\n", polyid, (j+1)*8, a, b) + + j += 2 + fmt.Fprintf(w, "\n") + } + + fmt.Fprintf(w, "GLOBL ·%sConst(SB),RODATA,$4336\n", polyid) + fmt.Fprintf(w, "\n /* Barrett constant m - (4^32)/n */\n") + fmt.Fprintf(w, "DATA ·%sBarConst(SB)/8,$0x%016x\n", polyid, reflect_bits(get_quotient(ref_poly, 32, 64), 33)) + fmt.Fprintf(w, "DATA ·%sBarConst+8(SB)/8,$0x0000000000000000\n", polyid) + fmt.Fprintf(w, "DATA ·%sBarConst+16(SB)/8,$0x%016x\n", polyid, reflect_bits((uint64(1)<<32)|ref_poly, 33)) // reflected? + fmt.Fprintf(w, "DATA ·%sBarConst+24(SB)/8,$0x0000000000000000\n", polyid) + fmt.Fprintf(w, "GLOBL ·%sBarConst(SB),RODATA,$32\n", polyid) +} diff --git a/platform/dbops/binaries/go/go/src/hash/crc64/crc64.go b/platform/dbops/binaries/go/go/src/hash/crc64/crc64.go new file mode 100644 index 0000000000000000000000000000000000000000..17ee8eb04e2b91b19eb27856a6731694f7790858 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc64/crc64.go @@ -0,0 +1,229 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package crc64 implements the 64-bit cyclic redundancy check, or CRC-64, +// checksum. See https://en.wikipedia.org/wiki/Cyclic_redundancy_check for +// information. +package crc64 + +import ( + "errors" + "hash" + "sync" +) + +// The size of a CRC-64 checksum in bytes. +const Size = 8 + +// Predefined polynomials. +const ( + // The ISO polynomial, defined in ISO 3309 and used in HDLC. + ISO = 0xD800000000000000 + + // The ECMA polynomial, defined in ECMA 182. + ECMA = 0xC96C5795D7870F42 +) + +// Table is a 256-word table representing the polynomial for efficient processing. +type Table [256]uint64 + +var ( + slicing8TablesBuildOnce sync.Once + slicing8TableISO *[8]Table + slicing8TableECMA *[8]Table +) + +func buildSlicing8TablesOnce() { + slicing8TablesBuildOnce.Do(buildSlicing8Tables) +} + +func buildSlicing8Tables() { + slicing8TableISO = makeSlicingBy8Table(makeTable(ISO)) + slicing8TableECMA = makeSlicingBy8Table(makeTable(ECMA)) +} + +// MakeTable returns a [Table] constructed from the specified polynomial. +// The contents of this [Table] must not be modified. +func MakeTable(poly uint64) *Table { + buildSlicing8TablesOnce() + switch poly { + case ISO: + return &slicing8TableISO[0] + case ECMA: + return &slicing8TableECMA[0] + default: + return makeTable(poly) + } +} + +func makeTable(poly uint64) *Table { + t := new(Table) + for i := 0; i < 256; i++ { + crc := uint64(i) + for j := 0; j < 8; j++ { + if crc&1 == 1 { + crc = (crc >> 1) ^ poly + } else { + crc >>= 1 + } + } + t[i] = crc + } + return t +} + +func makeSlicingBy8Table(t *Table) *[8]Table { + var helperTable [8]Table + helperTable[0] = *t + for i := 0; i < 256; i++ { + crc := t[i] + for j := 1; j < 8; j++ { + crc = t[crc&0xff] ^ (crc >> 8) + helperTable[j][i] = crc + } + } + return &helperTable +} + +// digest represents the partial evaluation of a checksum. +type digest struct { + crc uint64 + tab *Table +} + +// New creates a new hash.Hash64 computing the CRC-64 checksum using the +// polynomial represented by the [Table]. Its Sum method will lay the +// value out in big-endian byte order. The returned Hash64 also +// implements [encoding.BinaryMarshaler] and [encoding.BinaryUnmarshaler] to +// marshal and unmarshal the internal state of the hash. +func New(tab *Table) hash.Hash64 { return &digest{0, tab} } + +func (d *digest) Size() int { return Size } + +func (d *digest) BlockSize() int { return 1 } + +func (d *digest) Reset() { d.crc = 0 } + +const ( + magic = "crc\x02" + marshaledSize = len(magic) + 8 + 8 +) + +func (d *digest) MarshalBinary() ([]byte, error) { + b := make([]byte, 0, marshaledSize) + b = append(b, magic...) + b = appendUint64(b, tableSum(d.tab)) + b = appendUint64(b, d.crc) + return b, nil +} + +func (d *digest) UnmarshalBinary(b []byte) error { + if len(b) < len(magic) || string(b[:len(magic)]) != magic { + return errors.New("hash/crc64: invalid hash state identifier") + } + if len(b) != marshaledSize { + return errors.New("hash/crc64: invalid hash state size") + } + if tableSum(d.tab) != readUint64(b[4:]) { + return errors.New("hash/crc64: tables do not match") + } + d.crc = readUint64(b[12:]) + return nil +} + +// appendUint64 is semantically the same as [binary.BigEndian.AppendUint64] +// We copied this function because we can not import "encoding/binary" here. +func appendUint64(b []byte, x uint64) []byte { + return append(b, + byte(x>>56), + byte(x>>48), + byte(x>>40), + byte(x>>32), + byte(x>>24), + byte(x>>16), + byte(x>>8), + byte(x), + ) +} + +// readUint64 is semantically the same as [binary.BigEndian.Uint64] +// We copied this function because we can not import "encoding/binary" here. +func readUint64(b []byte) uint64 { + _ = b[7] + return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 | + uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56 +} + +func update(crc uint64, tab *Table, p []byte) uint64 { + buildSlicing8TablesOnce() + crc = ^crc + // Table comparison is somewhat expensive, so avoid it for small sizes + for len(p) >= 64 { + var helperTable *[8]Table + if *tab == slicing8TableECMA[0] { + helperTable = slicing8TableECMA + } else if *tab == slicing8TableISO[0] { + helperTable = slicing8TableISO + // For smaller sizes creating extended table takes too much time + } else if len(p) >= 2048 { + // According to the tests between various x86 and arm CPUs, 2k is a reasonable + // threshold for now. This may change in the future. + helperTable = makeSlicingBy8Table(tab) + } else { + break + } + // Update using slicing-by-8 + for len(p) > 8 { + crc ^= uint64(p[0]) | uint64(p[1])<<8 | uint64(p[2])<<16 | uint64(p[3])<<24 | + uint64(p[4])<<32 | uint64(p[5])<<40 | uint64(p[6])<<48 | uint64(p[7])<<56 + crc = helperTable[7][crc&0xff] ^ + helperTable[6][(crc>>8)&0xff] ^ + helperTable[5][(crc>>16)&0xff] ^ + helperTable[4][(crc>>24)&0xff] ^ + helperTable[3][(crc>>32)&0xff] ^ + helperTable[2][(crc>>40)&0xff] ^ + helperTable[1][(crc>>48)&0xff] ^ + helperTable[0][crc>>56] + p = p[8:] + } + } + // For reminders or small sizes + for _, v := range p { + crc = tab[byte(crc)^v] ^ (crc >> 8) + } + return ^crc +} + +// Update returns the result of adding the bytes in p to the crc. +func Update(crc uint64, tab *Table, p []byte) uint64 { + return update(crc, tab, p) +} + +func (d *digest) Write(p []byte) (n int, err error) { + d.crc = update(d.crc, d.tab, p) + return len(p), nil +} + +func (d *digest) Sum64() uint64 { return d.crc } + +func (d *digest) Sum(in []byte) []byte { + s := d.Sum64() + return append(in, byte(s>>56), byte(s>>48), byte(s>>40), byte(s>>32), byte(s>>24), byte(s>>16), byte(s>>8), byte(s)) +} + +// Checksum returns the CRC-64 checksum of data +// using the polynomial represented by the [Table]. +func Checksum(data []byte, tab *Table) uint64 { return update(0, tab, data) } + +// tableSum returns the ISO checksum of table t. +func tableSum(t *Table) uint64 { + var a [2048]byte + b := a[:0] + if t != nil { + for _, x := range t { + b = appendUint64(b, x) + } + } + return Checksum(b, MakeTable(ISO)) +} diff --git a/platform/dbops/binaries/go/go/src/hash/crc64/crc64_test.go b/platform/dbops/binaries/go/go/src/hash/crc64/crc64_test.go new file mode 100644 index 0000000000000000000000000000000000000000..9cf602c82f3eebb466ef8ea65eb2036369f61ffe --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/crc64/crc64_test.go @@ -0,0 +1,193 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package crc64 + +import ( + "encoding" + "io" + "testing" +) + +type test struct { + outISO uint64 + outECMA uint64 + in string + halfStateISO string // ISO marshaled hash state after first half of in written, used by TestGoldenMarshal + halfStateECMA string // ECMA marshaled hash state after first half of in written, used by TestGoldenMarshal +} + +var golden = []test{ + {0x0, 0x0, "", "crc\x02s\xba\x84\x84\xbb\xcd]\xef\x00\x00\x00\x00\x00\x00\x00\x00", "crc\x02`&\x9aR\xe1\xb7\xfee\x00\x00\x00\x00\x00\x00\x00\x00"}, + {0x3420000000000000, 0x330284772e652b05, "a", "crc\x02s\xba\x84\x84\xbb\xcd]\xef\x00\x00\x00\x00\x00\x00\x00\x00", "crc\x02`&\x9aR\xe1\xb7\xfee\x00\x00\x00\x00\x00\x00\x00\x00"}, + {0x36c4200000000000, 0xbc6573200e84b046, "ab", "crc\x02s\xba\x84\x84\xbb\xcd]\xef4 \x00\x00\x00\x00\x00\x00", "crc\x02`&\x9aR\xe1\xb7\xfee3\x02\x84w.e+\x05"}, + {0x3776c42000000000, 0x2cd8094a1a277627, "abc", "crc\x02s\xba\x84\x84\xbb\xcd]\xef4 \x00\x00\x00\x00\x00\x00", "crc\x02`&\x9aR\xe1\xb7\xfee3\x02\x84w.e+\x05"}, + {0x336776c420000000, 0x3c9d28596e5960ba, "abcd", "crc\x02s\xba\x84\x84\xbb\xcd]\xef6\xc4 \x00\x00\x00\x00\x00", "crc\x02`&\x9aR\xe1\xb7\xfee\xbces \x0e\x84\xb0F"}, + {0x32d36776c4200000, 0x40bdf58fb0895f2, "abcde", "crc\x02s\xba\x84\x84\xbb\xcd]\xef6\xc4 \x00\x00\x00\x00\x00", "crc\x02`&\x9aR\xe1\xb7\xfee\xbces \x0e\x84\xb0F"}, + {0x3002d36776c42000, 0xd08e9f8545a700f4, "abcdef", "crc\x02s\xba\x84\x84\xbb\xcd]\xef7v\xc4 \x00\x00\x00\x00", "crc\x02`&\x9aR\xe1\xb7\xfee,\xd8\tJ\x1a'v'"}, + {0x31b002d36776c420, 0xec20a3a8cc710e66, "abcdefg", "crc\x02s\xba\x84\x84\xbb\xcd]\xef7v\xc4 \x00\x00\x00\x00", "crc\x02`&\x9aR\xe1\xb7\xfee,\xd8\tJ\x1a'v'"}, + {0xe21b002d36776c4, 0x67b4f30a647a0c59, "abcdefgh", "crc\x02s\xba\x84\x84\xbb\xcd]\xef3gv\xc4 \x00\x00\x00", "crc\x02`&\x9aR\xe1\xb7\xfee<\x9d(YnY`\xba"}, + {0x8b6e21b002d36776, 0x9966f6c89d56ef8e, "abcdefghi", "crc\x02s\xba\x84\x84\xbb\xcd]\xef3gv\xc4 \x00\x00\x00", "crc\x02`&\x9aR\xe1\xb7\xfee<\x9d(YnY`\xba"}, + {0x7f5b6e21b002d367, 0x32093a2ecd5773f4, "abcdefghij", "crc\x02s\xba\x84\x84\xbb\xcd]\xef2\xd3gv\xc4 \x00\x00", "crc\x02`&\x9aR\xe1\xb7\xfee\x04\v\xdfX\xfb\b\x95\xf2"}, + {0x8ec0e7c835bf9cdf, 0x8a0825223ea6d221, "Discard medicine more than two years old.", "crc\x02s\xba\x84\x84\xbb\xcd]\xef\xc6\xc0\f\xac'\x11\x12\xd5", "crc\x02`&\x9aR\xe1\xb7\xfee\xfd%\xc0&\xa0R\xef\x95"}, + {0xc7db1759e2be5ab4, 0x8562c0ac2ab9a00d, "He who has a shady past knows that nice guys finish last.", "crc\x02s\xba\x84\x84\xbb\xcd]\xef\t\xcb\xd15X[r\t", "crc\x02`&\x9aR\xe1\xb7\xfee\a\x02\xe8|+\xc1\x06\xe3"}, + {0xfbf9d9603a6fa020, 0x3ee2a39c083f38b4, "I wouldn't marry him with a ten foot pole.", "crc\x02s\xba\x84\x84\xbb\xcd]\xef\x19\xc8d\xbe\x84\x14\x87_", "crc\x02`&\x9aR\xe1\xb7\xfee˷\xd3\xeeG\xdcE\x8c"}, + {0xeafc4211a6daa0ef, 0x1f603830353e518a, "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave", "crc\x02s\xba\x84\x84\xbb\xcd]\xef\xad\x1b*\xc0\xb1\xf3i(", "crc\x02`&\x9aR\xe1\xb7\xfee\xa7\x8a\xdb\xf6\xd2R\t\x96"}, + {0x3e05b21c7a4dc4da, 0x2fd681d7b2421fd, "The days of the digital watch are numbered. -Tom Stoppard", "crc\x02s\xba\x84\x84\xbb\xcd]\xefv78\x1ak\x02\x8f\xff", "crc\x02`&\x9aR\xe1\xb7\xfeeT\xcbl\x10\xfb\x87K*"}, + {0x5255866ad6ef28a6, 0x790ef2b16a745a41, "Nepal premier won't resign.", "crc\x02s\xba\x84\x84\xbb\xcd]\xef\xcbf\x11R\xbfh\xde\xc9", "crc\x02`&\x9aR\xe1\xb7\xfee6\x13ُ\x06_\xbd\x9a"}, + {0x8a79895be1e9c361, 0x3ef8f06daccdcddf, "For every action there is an equal and opposite government program.", "crc\x02s\xba\x84\x84\xbb\xcd]\xef\xf3pV\x01c_Wu", "crc\x02`&\x9aR\xe1\xb7\xfee\xe7\xc6\n\b\x12FL\xa0"}, + {0x8878963a649d4916, 0x49e41b2660b106d, "His money is twice tainted: 'taint yours and 'taint mine.", "crc\x02s\xba\x84\x84\xbb\xcd]\xefñ\xff\xf1\xe0/Δ", "crc\x02`&\x9aR\xe1\xb7\xfeeOL/\xb1\xec\xa2\x14\x87"}, + {0xa7b9d53ea87eb82f, 0x561cc0cfa235ac68, "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977", "crc\x02s\xba\x84\x84\xbb\xcd]\xefݸa\xe1\xb5\xf8\xb9W", "crc\x02`&\x9aR\xe1\xb7\xfee\x87)GQ\x03\xf4K\t"}, + {0xdb6805c0966a2f9c, 0xd4fe9ef082e69f59, "It's a tiny change to the code and not completely disgusting. - Bob Manchek", "crc\x02s\xba\x84\x84\xbb\xcd]\xefV\xba\x12\x91\x81\x1fNU", "crc\x02`&\x9aR\xe1\xb7\xfee\n\xb8\x81v?\xdeL\xcb"}, + {0xf3553c65dacdadd2, 0xe3b5e46cd8d63a4d, "size: a.out: bad magic", "crc\x02s\xba\x84\x84\xbb\xcd]\xefG\xad\xbc\xb2\xa8y\xc9\xdc", "crc\x02`&\x9aR\xe1\xb7\xfee\xcc\xce\xe5\xe6\x89p\x01\xb8"}, + {0x9d5e034087a676b9, 0x865aaf6b94f2a051, "The major problem is with sendmail. -Mark Horton", "crc\x02s\xba\x84\x84\xbb\xcd]\uf8acn\x8aT;&\xd5", "crc\x02`&\x9aR\xe1\xb7\xfeeFf\x9c\x1f\xc9x\xbfa"}, + {0xa6db2d7f8da96417, 0x7eca10d2f8136eb4, "Give me a rock, paper and scissors and I will move the world. CCFestoon", "crc\x02s\xba\x84\x84\xbb\xcd]\xef\xeb\x18\xbf\xf9}\x91\xe5|", "crc\x02`&\x9aR\xe1\xb7\xfeea\x9e\x05:\xce[\xe7\x19"}, + {0x325e00cd2fe819f9, 0xd7dd118c98e98727, "If the enemy is within range, then so are you.", "crc\x02s\xba\x84\x84\xbb\xcd]\xef^5k\xd0Aj_{", "crc\x02`&\x9aR\xe1\xb7\xfee\v#\x99\xa8r\x83YR"}, + {0x88c6600ce58ae4c6, 0x70fb33c119c29318, "It's well we cannot hear the screams/That we create in others' dreams.", "crc\x02s\xba\x84\x84\xbb\xcd]\xef|\xb5\x02\xdcw\x18/\x86", "crc\x02`&\x9aR\xe1\xb7\xfee]\x9d-\xed\x8c\xf9r9"}, + {0x28c4a3f3b769e078, 0x57c891e39a97d9b7, "You remind me of a TV show, but that's all right: I watch it anyway.", "crc\x02s\xba\x84\x84\xbb\xcd]\xef\x03\x8bd\x1c\xb0_\x16\x98", "crc\x02`&\x9aR\xe1\xb7\xfee\xafW\x98\xaa\"\xe7\xd7|"}, + {0xa698a34c9d9f1dca, 0xa1f46ba20ad06eb7, "C is as portable as Stonehedge!!", "crc\x02s\xba\x84\x84\xbb\xcd]\xef.P\xe1I\xc6pi\xdc", "crc\x02`&\x9aR\xe1\xb7\xfee֚\x06\x01(\xc0\x1e\x8b"}, + {0xf6c1e2a8c26c5cfc, 0x7ad25fafa1710407, "Even if I could be Shakespeare, I think I should still choose to be Faraday. - A. Huxley", "crc\x02s\xba\x84\x84\xbb\xcd]\xef\xf7\xa04\x8a\xf2o\xe0;", "crc\x02`&\x9aR\xe1\xb7\xfee<[\xd2%\x9em\x94\x04"}, + {0xd402559dfe9b70c, 0x73cef1666185c13f, "The fugacity of a constituent in a mixture of gases at a given temperature is proportional to its mole fraction. Lewis-Randall Rule", "crc\x02s\xba\x84\x84\xbb\xcd]\xef\u007f\xae\xb9\xbaX=\x19v", "crc\x02`&\x9aR\xe1\xb7\xfee\xb2˦Y\xc5\xd0G\x03"}, + {0xdb6efff26aa94946, 0xb41858f73c389602, "How can you write a big system without C++? -Paul Glick", "crc\x02s\xba\x84\x84\xbb\xcd]\xefa\xed$js\xb9\xa5A", "crc\x02`&\x9aR\xe1\xb7\xfeeZm\x96\x8a\xe2\xaf\x13p"}, + {0xe7fcf1006b503b61, 0x27db187fc15bbc72, "This is a test of the emergency broadcast system.", "crc\x02s\xba\x84\x84\xbb\xcd]\xef}\xee[q\x16\xcb\xe4\x8d", "crc\x02`&\x9aR\xe1\xb7\xfee\xb1\x93] \xeb\xa9am"}, +} + +func TestGolden(t *testing.T) { + tabISO := MakeTable(ISO) + tabECMA := MakeTable(ECMA) + for i := 0; i < len(golden); i++ { + g := golden[i] + c := New(tabISO) + io.WriteString(c, g.in) + s := c.Sum64() + if s != g.outISO { + t.Fatalf("ISO crc64(%s) = 0x%x want 0x%x", g.in, s, g.outISO) + } + c = New(tabECMA) + io.WriteString(c, g.in) + s = c.Sum64() + if s != g.outECMA { + t.Fatalf("ECMA crc64(%s) = 0x%x want 0x%x", g.in, s, g.outECMA) + } + } +} + +func TestGoldenMarshal(t *testing.T) { + t.Run("ISO", func(t *testing.T) { + table := MakeTable(ISO) + for _, g := range golden { + h := New(table) + h2 := New(table) + + io.WriteString(h, g.in[:len(g.in)/2]) + + state, err := h.(encoding.BinaryMarshaler).MarshalBinary() + if err != nil { + t.Errorf("could not marshal: %v", err) + continue + } + + if string(state) != g.halfStateISO { + t.Errorf("ISO crc64(%q) state = %q, want %q", g.in, state, g.halfStateISO) + continue + } + + if err := h2.(encoding.BinaryUnmarshaler).UnmarshalBinary(state); err != nil { + t.Errorf("could not unmarshal: %v", err) + continue + } + + io.WriteString(h, g.in[len(g.in)/2:]) + io.WriteString(h2, g.in[len(g.in)/2:]) + + if h.Sum64() != h2.Sum64() { + t.Errorf("ISO crc64(%s) = 0x%x != marshaled (0x%x)", g.in, h.Sum64(), h2.Sum64()) + } + } + }) + t.Run("ECMA", func(t *testing.T) { + table := MakeTable(ECMA) + for _, g := range golden { + h := New(table) + h2 := New(table) + + io.WriteString(h, g.in[:len(g.in)/2]) + + state, err := h.(encoding.BinaryMarshaler).MarshalBinary() + if err != nil { + t.Errorf("could not marshal: %v", err) + continue + } + + if string(state) != g.halfStateECMA { + t.Errorf("ECMA crc64(%q) state = %q, want %q", g.in, state, g.halfStateECMA) + continue + } + + if err := h2.(encoding.BinaryUnmarshaler).UnmarshalBinary(state); err != nil { + t.Errorf("could not unmarshal: %v", err) + continue + } + + io.WriteString(h, g.in[len(g.in)/2:]) + io.WriteString(h2, g.in[len(g.in)/2:]) + + if h.Sum64() != h2.Sum64() { + t.Errorf("ECMA crc64(%s) = 0x%x != marshaled (0x%x)", g.in, h.Sum64(), h2.Sum64()) + } + } + }) +} + +func TestMarshalTableMismatch(t *testing.T) { + h1 := New(MakeTable(ISO)) + h2 := New(MakeTable(ECMA)) + + state1, err := h1.(encoding.BinaryMarshaler).MarshalBinary() + if err != nil { + t.Errorf("could not marshal: %v", err) + } + + if err := h2.(encoding.BinaryUnmarshaler).UnmarshalBinary(state1); err == nil { + t.Errorf("no error when one was expected") + } +} + +func bench(b *testing.B, poly uint64, size int64) { + b.SetBytes(size) + data := make([]byte, size) + for i := range data { + data[i] = byte(i) + } + h := New(MakeTable(poly)) + in := make([]byte, 0, h.Size()) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + h.Reset() + h.Write(data) + h.Sum(in) + } +} + +func BenchmarkCrc64(b *testing.B) { + b.Run("ISO64KB", func(b *testing.B) { + bench(b, ISO, 64<<10) + }) + b.Run("ISO4KB", func(b *testing.B) { + bench(b, ISO, 4<<10) + }) + b.Run("ISO1KB", func(b *testing.B) { + bench(b, ISO, 1<<10) + }) + b.Run("ECMA64KB", func(b *testing.B) { + bench(b, ECMA, 64<<10) + }) + b.Run("Random64KB", func(b *testing.B) { + bench(b, 0x777, 64<<10) + }) + b.Run("Random16KB", func(b *testing.B) { + bench(b, 0x777, 16<<10) + }) +} diff --git a/platform/dbops/binaries/go/go/src/hash/fnv/fnv.go b/platform/dbops/binaries/go/go/src/hash/fnv/fnv.go new file mode 100644 index 0000000000000000000000000000000000000000..29439e2c1dcea1f8a19dae2e44e3e398709cd606 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/fnv/fnv.go @@ -0,0 +1,376 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package fnv implements FNV-1 and FNV-1a, non-cryptographic hash functions +// created by Glenn Fowler, Landon Curt Noll, and Phong Vo. +// See +// https://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function. +// +// All the hash.Hash implementations returned by this package also +// implement encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to +// marshal and unmarshal the internal state of the hash. +package fnv + +import ( + "errors" + "hash" + "math/bits" +) + +type ( + sum32 uint32 + sum32a uint32 + sum64 uint64 + sum64a uint64 + sum128 [2]uint64 + sum128a [2]uint64 +) + +const ( + offset32 = 2166136261 + offset64 = 14695981039346656037 + offset128Lower = 0x62b821756295c58d + offset128Higher = 0x6c62272e07bb0142 + prime32 = 16777619 + prime64 = 1099511628211 + prime128Lower = 0x13b + prime128Shift = 24 +) + +// New32 returns a new 32-bit FNV-1 [hash.Hash]. +// Its Sum method will lay the value out in big-endian byte order. +func New32() hash.Hash32 { + var s sum32 = offset32 + return &s +} + +// New32a returns a new 32-bit FNV-1a [hash.Hash]. +// Its Sum method will lay the value out in big-endian byte order. +func New32a() hash.Hash32 { + var s sum32a = offset32 + return &s +} + +// New64 returns a new 64-bit FNV-1 [hash.Hash]. +// Its Sum method will lay the value out in big-endian byte order. +func New64() hash.Hash64 { + var s sum64 = offset64 + return &s +} + +// New64a returns a new 64-bit FNV-1a [hash.Hash]. +// Its Sum method will lay the value out in big-endian byte order. +func New64a() hash.Hash64 { + var s sum64a = offset64 + return &s +} + +// New128 returns a new 128-bit FNV-1 [hash.Hash]. +// Its Sum method will lay the value out in big-endian byte order. +func New128() hash.Hash { + var s sum128 + s[0] = offset128Higher + s[1] = offset128Lower + return &s +} + +// New128a returns a new 128-bit FNV-1a [hash.Hash]. +// Its Sum method will lay the value out in big-endian byte order. +func New128a() hash.Hash { + var s sum128a + s[0] = offset128Higher + s[1] = offset128Lower + return &s +} + +func (s *sum32) Reset() { *s = offset32 } +func (s *sum32a) Reset() { *s = offset32 } +func (s *sum64) Reset() { *s = offset64 } +func (s *sum64a) Reset() { *s = offset64 } +func (s *sum128) Reset() { s[0] = offset128Higher; s[1] = offset128Lower } +func (s *sum128a) Reset() { s[0] = offset128Higher; s[1] = offset128Lower } + +func (s *sum32) Sum32() uint32 { return uint32(*s) } +func (s *sum32a) Sum32() uint32 { return uint32(*s) } +func (s *sum64) Sum64() uint64 { return uint64(*s) } +func (s *sum64a) Sum64() uint64 { return uint64(*s) } + +func (s *sum32) Write(data []byte) (int, error) { + hash := *s + for _, c := range data { + hash *= prime32 + hash ^= sum32(c) + } + *s = hash + return len(data), nil +} + +func (s *sum32a) Write(data []byte) (int, error) { + hash := *s + for _, c := range data { + hash ^= sum32a(c) + hash *= prime32 + } + *s = hash + return len(data), nil +} + +func (s *sum64) Write(data []byte) (int, error) { + hash := *s + for _, c := range data { + hash *= prime64 + hash ^= sum64(c) + } + *s = hash + return len(data), nil +} + +func (s *sum64a) Write(data []byte) (int, error) { + hash := *s + for _, c := range data { + hash ^= sum64a(c) + hash *= prime64 + } + *s = hash + return len(data), nil +} + +func (s *sum128) Write(data []byte) (int, error) { + for _, c := range data { + // Compute the multiplication + s0, s1 := bits.Mul64(prime128Lower, s[1]) + s0 += s[1]<>24), byte(v>>16), byte(v>>8), byte(v)) +} + +func (s *sum32a) Sum(in []byte) []byte { + v := uint32(*s) + return append(in, byte(v>>24), byte(v>>16), byte(v>>8), byte(v)) +} + +func (s *sum64) Sum(in []byte) []byte { + v := uint64(*s) + return append(in, byte(v>>56), byte(v>>48), byte(v>>40), byte(v>>32), byte(v>>24), byte(v>>16), byte(v>>8), byte(v)) +} + +func (s *sum64a) Sum(in []byte) []byte { + v := uint64(*s) + return append(in, byte(v>>56), byte(v>>48), byte(v>>40), byte(v>>32), byte(v>>24), byte(v>>16), byte(v>>8), byte(v)) +} + +func (s *sum128) Sum(in []byte) []byte { + return append(in, + byte(s[0]>>56), byte(s[0]>>48), byte(s[0]>>40), byte(s[0]>>32), byte(s[0]>>24), byte(s[0]>>16), byte(s[0]>>8), byte(s[0]), + byte(s[1]>>56), byte(s[1]>>48), byte(s[1]>>40), byte(s[1]>>32), byte(s[1]>>24), byte(s[1]>>16), byte(s[1]>>8), byte(s[1]), + ) +} + +func (s *sum128a) Sum(in []byte) []byte { + return append(in, + byte(s[0]>>56), byte(s[0]>>48), byte(s[0]>>40), byte(s[0]>>32), byte(s[0]>>24), byte(s[0]>>16), byte(s[0]>>8), byte(s[0]), + byte(s[1]>>56), byte(s[1]>>48), byte(s[1]>>40), byte(s[1]>>32), byte(s[1]>>24), byte(s[1]>>16), byte(s[1]>>8), byte(s[1]), + ) +} + +const ( + magic32 = "fnv\x01" + magic32a = "fnv\x02" + magic64 = "fnv\x03" + magic64a = "fnv\x04" + magic128 = "fnv\x05" + magic128a = "fnv\x06" + marshaledSize32 = len(magic32) + 4 + marshaledSize64 = len(magic64) + 8 + marshaledSize128 = len(magic128) + 8*2 +) + +func (s *sum32) MarshalBinary() ([]byte, error) { + b := make([]byte, 0, marshaledSize32) + b = append(b, magic32...) + b = appendUint32(b, uint32(*s)) + return b, nil +} + +func (s *sum32a) MarshalBinary() ([]byte, error) { + b := make([]byte, 0, marshaledSize32) + b = append(b, magic32a...) + b = appendUint32(b, uint32(*s)) + return b, nil +} + +func (s *sum64) MarshalBinary() ([]byte, error) { + b := make([]byte, 0, marshaledSize64) + b = append(b, magic64...) + b = appendUint64(b, uint64(*s)) + return b, nil +} + +func (s *sum64a) MarshalBinary() ([]byte, error) { + b := make([]byte, 0, marshaledSize64) + b = append(b, magic64a...) + b = appendUint64(b, uint64(*s)) + return b, nil +} + +func (s *sum128) MarshalBinary() ([]byte, error) { + b := make([]byte, 0, marshaledSize128) + b = append(b, magic128...) + b = appendUint64(b, s[0]) + b = appendUint64(b, s[1]) + return b, nil +} + +func (s *sum128a) MarshalBinary() ([]byte, error) { + b := make([]byte, 0, marshaledSize128) + b = append(b, magic128a...) + b = appendUint64(b, s[0]) + b = appendUint64(b, s[1]) + return b, nil +} + +func (s *sum32) UnmarshalBinary(b []byte) error { + if len(b) < len(magic32) || string(b[:len(magic32)]) != magic32 { + return errors.New("hash/fnv: invalid hash state identifier") + } + if len(b) != marshaledSize32 { + return errors.New("hash/fnv: invalid hash state size") + } + *s = sum32(readUint32(b[4:])) + return nil +} + +func (s *sum32a) UnmarshalBinary(b []byte) error { + if len(b) < len(magic32a) || string(b[:len(magic32a)]) != magic32a { + return errors.New("hash/fnv: invalid hash state identifier") + } + if len(b) != marshaledSize32 { + return errors.New("hash/fnv: invalid hash state size") + } + *s = sum32a(readUint32(b[4:])) + return nil +} + +func (s *sum64) UnmarshalBinary(b []byte) error { + if len(b) < len(magic64) || string(b[:len(magic64)]) != magic64 { + return errors.New("hash/fnv: invalid hash state identifier") + } + if len(b) != marshaledSize64 { + return errors.New("hash/fnv: invalid hash state size") + } + *s = sum64(readUint64(b[4:])) + return nil +} + +func (s *sum64a) UnmarshalBinary(b []byte) error { + if len(b) < len(magic64a) || string(b[:len(magic64a)]) != magic64a { + return errors.New("hash/fnv: invalid hash state identifier") + } + if len(b) != marshaledSize64 { + return errors.New("hash/fnv: invalid hash state size") + } + *s = sum64a(readUint64(b[4:])) + return nil +} + +func (s *sum128) UnmarshalBinary(b []byte) error { + if len(b) < len(magic128) || string(b[:len(magic128)]) != magic128 { + return errors.New("hash/fnv: invalid hash state identifier") + } + if len(b) != marshaledSize128 { + return errors.New("hash/fnv: invalid hash state size") + } + s[0] = readUint64(b[4:]) + s[1] = readUint64(b[12:]) + return nil +} + +func (s *sum128a) UnmarshalBinary(b []byte) error { + if len(b) < len(magic128a) || string(b[:len(magic128a)]) != magic128a { + return errors.New("hash/fnv: invalid hash state identifier") + } + if len(b) != marshaledSize128 { + return errors.New("hash/fnv: invalid hash state size") + } + s[0] = readUint64(b[4:]) + s[1] = readUint64(b[12:]) + return nil +} + +// readUint32 is semantically the same as [binary.BigEndian.Uint32] +// We copied this function because we can not import "encoding/binary" here. +func readUint32(b []byte) uint32 { + _ = b[3] + return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24 +} + +// appendUint32 is semantically the same as [binary.BigEndian.AppendUint32] +// We copied this function because we can not import "encoding/binary" here. +func appendUint32(b []byte, x uint32) []byte { + return append(b, + byte(x>>24), + byte(x>>16), + byte(x>>8), + byte(x), + ) +} + +// appendUint64 is semantically the same as [binary.BigEndian.AppendUint64] +// We copied this function because we can not import "encoding/binary" here. +func appendUint64(b []byte, x uint64) []byte { + return append(b, + byte(x>>56), + byte(x>>48), + byte(x>>40), + byte(x>>32), + byte(x>>24), + byte(x>>16), + byte(x>>8), + byte(x), + ) +} + +// readUint64 is semantically the same as [binary.BigEndian.Uint64] +// We copied this function because we can not import "encoding/binary" here. +func readUint64(b []byte) uint64 { + _ = b[7] + return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 | + uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56 +} diff --git a/platform/dbops/binaries/go/go/src/hash/fnv/fnv_test.go b/platform/dbops/binaries/go/go/src/hash/fnv/fnv_test.go new file mode 100644 index 0000000000000000000000000000000000000000..7b1f7a32eaac090c6900d04abf0385e4c20516d1 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/fnv/fnv_test.go @@ -0,0 +1,255 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package fnv + +import ( + "bytes" + "encoding" + "encoding/binary" + "hash" + "io" + "testing" +) + +type golden struct { + out []byte + in string + halfState string // marshaled hash state after first half of in written, used by TestGoldenMarshal +} + +var golden32 = []golden{ + {[]byte{0x81, 0x1c, 0x9d, 0xc5}, "", "fnv\x01\x81\x1c\x9d\xc5"}, + {[]byte{0x05, 0x0c, 0x5d, 0x7e}, "a", "fnv\x01\x81\x1c\x9d\xc5"}, + {[]byte{0x70, 0x77, 0x2d, 0x38}, "ab", "fnv\x01\x05\f]~"}, + {[]byte{0x43, 0x9c, 0x2f, 0x4b}, "abc", "fnv\x01\x05\f]~"}, +} + +var golden32a = []golden{ + {[]byte{0x81, 0x1c, 0x9d, 0xc5}, "", "fnv\x02\x81\x1c\x9d\xc5"}, + {[]byte{0xe4, 0x0c, 0x29, 0x2c}, "a", "fnv\x02\x81\x1c\x9d\xc5"}, + {[]byte{0x4d, 0x25, 0x05, 0xca}, "ab", "fnv\x02\xe4\f),"}, + {[]byte{0x1a, 0x47, 0xe9, 0x0b}, "abc", "fnv\x02\xe4\f),"}, +} + +var golden64 = []golden{ + {[]byte{0xcb, 0xf2, 0x9c, 0xe4, 0x84, 0x22, 0x23, 0x25}, "", "fnv\x03\xcb\xf2\x9c\xe4\x84\"#%"}, + {[]byte{0xaf, 0x63, 0xbd, 0x4c, 0x86, 0x01, 0xb7, 0xbe}, "a", "fnv\x03\xcb\xf2\x9c\xe4\x84\"#%"}, + {[]byte{0x08, 0x32, 0x67, 0x07, 0xb4, 0xeb, 0x37, 0xb8}, "ab", "fnv\x03\xafc\xbdL\x86\x01\xb7\xbe"}, + {[]byte{0xd8, 0xdc, 0xca, 0x18, 0x6b, 0xaf, 0xad, 0xcb}, "abc", "fnv\x03\xafc\xbdL\x86\x01\xb7\xbe"}, +} + +var golden64a = []golden{ + {[]byte{0xcb, 0xf2, 0x9c, 0xe4, 0x84, 0x22, 0x23, 0x25}, "", "fnv\x04\xcb\xf2\x9c\xe4\x84\"#%"}, + {[]byte{0xaf, 0x63, 0xdc, 0x4c, 0x86, 0x01, 0xec, 0x8c}, "a", "fnv\x04\xcb\xf2\x9c\xe4\x84\"#%"}, + {[]byte{0x08, 0x9c, 0x44, 0x07, 0xb5, 0x45, 0x98, 0x6a}, "ab", "fnv\x04\xafc\xdcL\x86\x01\xec\x8c"}, + {[]byte{0xe7, 0x1f, 0xa2, 0x19, 0x05, 0x41, 0x57, 0x4b}, "abc", "fnv\x04\xafc\xdcL\x86\x01\xec\x8c"}, +} + +var golden128 = []golden{ + {[]byte{0x6c, 0x62, 0x27, 0x2e, 0x07, 0xbb, 0x01, 0x42, 0x62, 0xb8, 0x21, 0x75, 0x62, 0x95, 0xc5, 0x8d}, "", "fnv\x05lb'.\a\xbb\x01Bb\xb8!ub\x95ō"}, + {[]byte{0xd2, 0x28, 0xcb, 0x69, 0x10, 0x1a, 0x8c, 0xaf, 0x78, 0x91, 0x2b, 0x70, 0x4e, 0x4a, 0x14, 0x1e}, "a", "fnv\x05lb'.\a\xbb\x01Bb\xb8!ub\x95ō"}, + {[]byte{0x8, 0x80, 0x94, 0x5a, 0xee, 0xab, 0x1b, 0xe9, 0x5a, 0xa0, 0x73, 0x30, 0x55, 0x26, 0xc0, 0x88}, "ab", "fnv\x05\xd2(\xcbi\x10\x1a\x8c\xafx\x91+pNJ\x14\x1e"}, + {[]byte{0xa6, 0x8b, 0xb2, 0xa4, 0x34, 0x8b, 0x58, 0x22, 0x83, 0x6d, 0xbc, 0x78, 0xc6, 0xae, 0xe7, 0x3b}, "abc", "fnv\x05\xd2(\xcbi\x10\x1a\x8c\xafx\x91+pNJ\x14\x1e"}, +} + +var golden128a = []golden{ + {[]byte{0x6c, 0x62, 0x27, 0x2e, 0x07, 0xbb, 0x01, 0x42, 0x62, 0xb8, 0x21, 0x75, 0x62, 0x95, 0xc5, 0x8d}, "", "fnv\x06lb'.\a\xbb\x01Bb\xb8!ub\x95ō"}, + {[]byte{0xd2, 0x28, 0xcb, 0x69, 0x6f, 0x1a, 0x8c, 0xaf, 0x78, 0x91, 0x2b, 0x70, 0x4e, 0x4a, 0x89, 0x64}, "a", "fnv\x06lb'.\a\xbb\x01Bb\xb8!ub\x95ō"}, + {[]byte{0x08, 0x80, 0x95, 0x44, 0xbb, 0xab, 0x1b, 0xe9, 0x5a, 0xa0, 0x73, 0x30, 0x55, 0xb6, 0x9a, 0x62}, "ab", "fnv\x06\xd2(\xcbio\x1a\x8c\xafx\x91+pNJ\x89d"}, + {[]byte{0xa6, 0x8d, 0x62, 0x2c, 0xec, 0x8b, 0x58, 0x22, 0x83, 0x6d, 0xbc, 0x79, 0x77, 0xaf, 0x7f, 0x3b}, "abc", "fnv\x06\xd2(\xcbio\x1a\x8c\xafx\x91+pNJ\x89d"}, +} + +func TestGolden32(t *testing.T) { + testGolden(t, New32(), golden32) +} + +func TestGolden32a(t *testing.T) { + testGolden(t, New32a(), golden32a) +} + +func TestGolden64(t *testing.T) { + testGolden(t, New64(), golden64) +} + +func TestGolden64a(t *testing.T) { + testGolden(t, New64a(), golden64a) +} + +func TestGolden128(t *testing.T) { + testGolden(t, New128(), golden128) +} + +func TestGolden128a(t *testing.T) { + testGolden(t, New128a(), golden128a) +} + +func testGolden(t *testing.T, hash hash.Hash, gold []golden) { + for _, g := range gold { + hash.Reset() + done, error := hash.Write([]byte(g.in)) + if error != nil { + t.Fatalf("write error: %s", error) + } + if done != len(g.in) { + t.Fatalf("wrote only %d out of %d bytes", done, len(g.in)) + } + if actual := hash.Sum(nil); !bytes.Equal(g.out, actual) { + t.Errorf("hash(%q) = 0x%x want 0x%x", g.in, actual, g.out) + } + } +} + +func TestGoldenMarshal(t *testing.T) { + tests := []struct { + name string + newHash func() hash.Hash + gold []golden + }{ + {"32", func() hash.Hash { return New32() }, golden32}, + {"32a", func() hash.Hash { return New32a() }, golden32a}, + {"64", func() hash.Hash { return New64() }, golden64}, + {"64a", func() hash.Hash { return New64a() }, golden64a}, + {"128", func() hash.Hash { return New128() }, golden128}, + {"128a", func() hash.Hash { return New128a() }, golden128a}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + for _, g := range tt.gold { + h := tt.newHash() + h2 := tt.newHash() + + io.WriteString(h, g.in[:len(g.in)/2]) + + state, err := h.(encoding.BinaryMarshaler).MarshalBinary() + if err != nil { + t.Errorf("could not marshal: %v", err) + continue + } + + if string(state) != g.halfState { + t.Errorf("checksum(%q) state = %q, want %q", g.in, state, g.halfState) + continue + } + + if err := h2.(encoding.BinaryUnmarshaler).UnmarshalBinary(state); err != nil { + t.Errorf("could not unmarshal: %v", err) + continue + } + + io.WriteString(h, g.in[len(g.in)/2:]) + io.WriteString(h2, g.in[len(g.in)/2:]) + + if actual, actual2 := h.Sum(nil), h2.Sum(nil); !bytes.Equal(actual, actual2) { + t.Errorf("hash(%q) = 0x%x != marshaled 0x%x", g.in, actual, actual2) + } + } + }) + } +} + +func TestIntegrity32(t *testing.T) { + testIntegrity(t, New32()) +} + +func TestIntegrity32a(t *testing.T) { + testIntegrity(t, New32a()) +} + +func TestIntegrity64(t *testing.T) { + testIntegrity(t, New64()) +} + +func TestIntegrity64a(t *testing.T) { + testIntegrity(t, New64a()) +} +func TestIntegrity128(t *testing.T) { + testIntegrity(t, New128()) +} + +func TestIntegrity128a(t *testing.T) { + testIntegrity(t, New128a()) +} + +func testIntegrity(t *testing.T, h hash.Hash) { + data := []byte{'1', '2', 3, 4, 5} + h.Write(data) + sum := h.Sum(nil) + + if size := h.Size(); size != len(sum) { + t.Fatalf("Size()=%d but len(Sum())=%d", size, len(sum)) + } + + if a := h.Sum(nil); !bytes.Equal(sum, a) { + t.Fatalf("first Sum()=0x%x, second Sum()=0x%x", sum, a) + } + + h.Reset() + h.Write(data) + if a := h.Sum(nil); !bytes.Equal(sum, a) { + t.Fatalf("Sum()=0x%x, but after Reset() Sum()=0x%x", sum, a) + } + + h.Reset() + h.Write(data[:2]) + h.Write(data[2:]) + if a := h.Sum(nil); !bytes.Equal(sum, a) { + t.Fatalf("Sum()=0x%x, but with partial writes, Sum()=0x%x", sum, a) + } + + switch h.Size() { + case 4: + sum32 := h.(hash.Hash32).Sum32() + if sum32 != binary.BigEndian.Uint32(sum) { + t.Fatalf("Sum()=0x%x, but Sum32()=0x%x", sum, sum32) + } + case 8: + sum64 := h.(hash.Hash64).Sum64() + if sum64 != binary.BigEndian.Uint64(sum) { + t.Fatalf("Sum()=0x%x, but Sum64()=0x%x", sum, sum64) + } + case 16: + // There's no Sum128 function, so we don't need to test anything here. + } +} + +func BenchmarkFnv32KB(b *testing.B) { + benchmarkKB(b, New32()) +} + +func BenchmarkFnv32aKB(b *testing.B) { + benchmarkKB(b, New32a()) +} + +func BenchmarkFnv64KB(b *testing.B) { + benchmarkKB(b, New64()) +} + +func BenchmarkFnv64aKB(b *testing.B) { + benchmarkKB(b, New64a()) +} + +func BenchmarkFnv128KB(b *testing.B) { + benchmarkKB(b, New128()) +} + +func BenchmarkFnv128aKB(b *testing.B) { + benchmarkKB(b, New128a()) +} + +func benchmarkKB(b *testing.B, h hash.Hash) { + b.SetBytes(1024) + data := make([]byte, 1024) + for i := range data { + data[i] = byte(i) + } + in := make([]byte, 0, h.Size()) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + h.Reset() + h.Write(data) + h.Sum(in) + } +} diff --git a/platform/dbops/binaries/go/go/src/hash/maphash/example_test.go b/platform/dbops/binaries/go/go/src/hash/maphash/example_test.go new file mode 100644 index 0000000000000000000000000000000000000000..78690fd65d9980249876d42fe807afdcd3f72303 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/maphash/example_test.go @@ -0,0 +1,37 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package maphash_test + +import ( + "fmt" + "hash/maphash" +) + +func Example() { + // The zero Hash value is valid and ready to use; setting an + // initial seed is not necessary. + var h maphash.Hash + + // Add a string to the hash, and print the current hash value. + h.WriteString("hello, ") + fmt.Printf("%#x\n", h.Sum64()) + + // Append additional data (in the form of a byte array). + h.Write([]byte{'w', 'o', 'r', 'l', 'd'}) + fmt.Printf("%#x\n", h.Sum64()) + + // Reset discards all data previously added to the Hash, without + // changing its seed. + h.Reset() + + // Use SetSeed to create a new Hash h2 which will behave + // identically to h. + var h2 maphash.Hash + h2.SetSeed(h.Seed()) + + h.WriteString("same") + h2.WriteString("same") + fmt.Printf("%#x == %#x\n", h.Sum64(), h2.Sum64()) +} diff --git a/platform/dbops/binaries/go/go/src/hash/maphash/maphash.go b/platform/dbops/binaries/go/go/src/hash/maphash/maphash.go new file mode 100644 index 0000000000000000000000000000000000000000..1e70a279f5f193514d5392a637b91d5126622283 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/maphash/maphash.go @@ -0,0 +1,277 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package maphash provides hash functions on byte sequences. +// These hash functions are intended to be used to implement hash tables or +// other data structures that need to map arbitrary strings or byte +// sequences to a uniform distribution on unsigned 64-bit integers. +// Each different instance of a hash table or data structure should use its own [Seed]. +// +// The hash functions are not cryptographically secure. +// (See crypto/sha256 and crypto/sha512 for cryptographic use.) +package maphash + +// A Seed is a random value that selects the specific hash function +// computed by a [Hash]. If two Hashes use the same Seeds, they +// will compute the same hash values for any given input. +// If two Hashes use different Seeds, they are very likely to compute +// distinct hash values for any given input. +// +// A Seed must be initialized by calling [MakeSeed]. +// The zero seed is uninitialized and not valid for use with [Hash]'s SetSeed method. +// +// Each Seed value is local to a single process and cannot be serialized +// or otherwise recreated in a different process. +type Seed struct { + s uint64 +} + +// Bytes returns the hash of b with the given seed. +// +// Bytes is equivalent to, but more convenient and efficient than: +// +// var h Hash +// h.SetSeed(seed) +// h.Write(b) +// return h.Sum64() +func Bytes(seed Seed, b []byte) uint64 { + state := seed.s + if state == 0 { + panic("maphash: use of uninitialized Seed") + } + + if len(b) > bufSize { + b = b[:len(b):len(b)] // merge len and cap calculations when reslicing + for len(b) > bufSize { + state = rthash(b[:bufSize], state) + b = b[bufSize:] + } + } + return rthash(b, state) +} + +// String returns the hash of s with the given seed. +// +// String is equivalent to, but more convenient and efficient than: +// +// var h Hash +// h.SetSeed(seed) +// h.WriteString(s) +// return h.Sum64() +func String(seed Seed, s string) uint64 { + state := seed.s + if state == 0 { + panic("maphash: use of uninitialized Seed") + } + for len(s) > bufSize { + state = rthashString(s[:bufSize], state) + s = s[bufSize:] + } + return rthashString(s, state) +} + +// A Hash computes a seeded hash of a byte sequence. +// +// The zero Hash is a valid Hash ready to use. +// A zero Hash chooses a random seed for itself during +// the first call to a Reset, Write, Seed, or Sum64 method. +// For control over the seed, use SetSeed. +// +// The computed hash values depend only on the initial seed and +// the sequence of bytes provided to the Hash object, not on the way +// in which the bytes are provided. For example, the three sequences +// +// h.Write([]byte{'f','o','o'}) +// h.WriteByte('f'); h.WriteByte('o'); h.WriteByte('o') +// h.WriteString("foo") +// +// all have the same effect. +// +// Hashes are intended to be collision-resistant, even for situations +// where an adversary controls the byte sequences being hashed. +// +// A Hash is not safe for concurrent use by multiple goroutines, but a Seed is. +// If multiple goroutines must compute the same seeded hash, +// each can declare its own Hash and call SetSeed with a common Seed. +type Hash struct { + _ [0]func() // not comparable + seed Seed // initial seed used for this hash + state Seed // current hash of all flushed bytes + buf [bufSize]byte // unflushed byte buffer + n int // number of unflushed bytes +} + +// bufSize is the size of the Hash write buffer. +// The buffer ensures that writes depend only on the sequence of bytes, +// not the sequence of WriteByte/Write/WriteString calls, +// by always calling rthash with a full buffer (except for the tail). +const bufSize = 128 + +// initSeed seeds the hash if necessary. +// initSeed is called lazily before any operation that actually uses h.seed/h.state. +// Note that this does not include Write/WriteByte/WriteString in the case +// where they only add to h.buf. (If they write too much, they call h.flush, +// which does call h.initSeed.) +func (h *Hash) initSeed() { + if h.seed.s == 0 { + seed := MakeSeed() + h.seed = seed + h.state = seed + } +} + +// WriteByte adds b to the sequence of bytes hashed by h. +// It never fails; the error result is for implementing [io.ByteWriter]. +func (h *Hash) WriteByte(b byte) error { + if h.n == len(h.buf) { + h.flush() + } + h.buf[h.n] = b + h.n++ + return nil +} + +// Write adds b to the sequence of bytes hashed by h. +// It always writes all of b and never fails; the count and error result are for implementing [io.Writer]. +func (h *Hash) Write(b []byte) (int, error) { + size := len(b) + // Deal with bytes left over in h.buf. + // h.n <= bufSize is always true. + // Checking it is ~free and it lets the compiler eliminate a bounds check. + if h.n > 0 && h.n <= bufSize { + k := copy(h.buf[h.n:], b) + h.n += k + if h.n < bufSize { + // Copied the entirety of b to h.buf. + return size, nil + } + b = b[k:] + h.flush() + // No need to set h.n = 0 here; it happens just before exit. + } + // Process as many full buffers as possible, without copying, and calling initSeed only once. + if len(b) > bufSize { + h.initSeed() + for len(b) > bufSize { + h.state.s = rthash(b[:bufSize], h.state.s) + b = b[bufSize:] + } + } + // Copy the tail. + copy(h.buf[:], b) + h.n = len(b) + return size, nil +} + +// WriteString adds the bytes of s to the sequence of bytes hashed by h. +// It always writes all of s and never fails; the count and error result are for implementing [io.StringWriter]. +func (h *Hash) WriteString(s string) (int, error) { + // WriteString mirrors Write. See Write for comments. + size := len(s) + if h.n > 0 && h.n <= bufSize { + k := copy(h.buf[h.n:], s) + h.n += k + if h.n < bufSize { + return size, nil + } + s = s[k:] + h.flush() + } + if len(s) > bufSize { + h.initSeed() + for len(s) > bufSize { + h.state.s = rthashString(s[:bufSize], h.state.s) + s = s[bufSize:] + } + } + copy(h.buf[:], s) + h.n = len(s) + return size, nil +} + +// Seed returns h's seed value. +func (h *Hash) Seed() Seed { + h.initSeed() + return h.seed +} + +// SetSeed sets h to use seed, which must have been returned by [MakeSeed] +// or by another [Hash.Seed] method. +// Two [Hash] objects with the same seed behave identically. +// Two [Hash] objects with different seeds will very likely behave differently. +// Any bytes added to h before this call will be discarded. +func (h *Hash) SetSeed(seed Seed) { + if seed.s == 0 { + panic("maphash: use of uninitialized Seed") + } + h.seed = seed + h.state = seed + h.n = 0 +} + +// Reset discards all bytes added to h. +// (The seed remains the same.) +func (h *Hash) Reset() { + h.initSeed() + h.state = h.seed + h.n = 0 +} + +// precondition: buffer is full. +func (h *Hash) flush() { + if h.n != len(h.buf) { + panic("maphash: flush of partially full buffer") + } + h.initSeed() + h.state.s = rthash(h.buf[:h.n], h.state.s) + h.n = 0 +} + +// Sum64 returns h's current 64-bit value, which depends on +// h's seed and the sequence of bytes added to h since the +// last call to [Hash.Reset] or [Hash.SetSeed]. +// +// All bits of the Sum64 result are close to uniformly and +// independently distributed, so it can be safely reduced +// by using bit masking, shifting, or modular arithmetic. +func (h *Hash) Sum64() uint64 { + h.initSeed() + return rthash(h.buf[:h.n], h.state.s) +} + +// MakeSeed returns a new random seed. +func MakeSeed() Seed { + var s uint64 + for { + s = randUint64() + // We use seed 0 to indicate an uninitialized seed/hash, + // so keep trying until we get a non-zero seed. + if s != 0 { + break + } + } + return Seed{s: s} +} + +// Sum appends the hash's current 64-bit value to b. +// It exists for implementing [hash.Hash]. +// For direct calls, it is more efficient to use [Hash.Sum64]. +func (h *Hash) Sum(b []byte) []byte { + x := h.Sum64() + return append(b, + byte(x>>0), + byte(x>>8), + byte(x>>16), + byte(x>>24), + byte(x>>32), + byte(x>>40), + byte(x>>48), + byte(x>>56)) +} + +// Size returns h's hash value size, 8 bytes. +func (h *Hash) Size() int { return 8 } + +// BlockSize returns h's block size. +func (h *Hash) BlockSize() int { return len(h.buf) } diff --git a/platform/dbops/binaries/go/go/src/hash/maphash/maphash_purego.go b/platform/dbops/binaries/go/go/src/hash/maphash/maphash_purego.go new file mode 100644 index 0000000000000000000000000000000000000000..d49a44ae646674f12f946803a896482c03ee7097 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/maphash/maphash_purego.go @@ -0,0 +1,104 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build purego + +package maphash + +import ( + "crypto/rand" + "math/bits" +) + +func rthash(buf []byte, seed uint64) uint64 { + if len(buf) == 0 { + return seed + } + return wyhash(buf, seed, uint64(len(buf))) +} + +func rthashString(s string, state uint64) uint64 { + return rthash([]byte(s), state) +} + +func randUint64() uint64 { + buf := make([]byte, 8) + _, _ = rand.Read(buf) + return leUint64(buf) +} + +// This is a port of wyhash implementation in runtime/hash64.go, +// without using unsafe for purego. + +const ( + m1 = 0xa0761d6478bd642f + m2 = 0xe7037ed1a0b428db + m3 = 0x8ebc6af09c88c6e3 + m4 = 0x589965cc75374cc3 + m5 = 0x1d8e4e27c47d124f +) + +func wyhash(key []byte, seed, len uint64) uint64 { + p := key + i := len + var a, b uint64 + seed ^= m1 + + if i > 16 { + if i > 48 { + seed1 := seed + seed2 := seed + for ; i > 48; i -= 48 { + seed = mix(r8(p)^m2, r8(p[8:])^seed) + seed1 = mix(r8(p[16:])^m3, r8(p[24:])^seed1) + seed2 = mix(r8(p[32:])^m4, r8(p[40:])^seed2) + p = p[48:] + } + seed ^= seed1 ^ seed2 + } + for ; i > 16; i -= 16 { + seed = mix(r8(p)^m2, r8(p[8:])^seed) + p = p[16:] + } + } + switch { + case i == 0: + return seed + case i < 4: + a = r3(p, i) + default: + n := (i >> 3) << 2 + a = r4(p)<<32 | r4(p[n:]) + b = r4(p[i-4:])<<32 | r4(p[i-4-n:]) + } + return mix(m5^len, mix(a^m2, b^seed)) +} + +func r3(p []byte, k uint64) uint64 { + return (uint64(p[0]) << 16) | (uint64(p[k>>1]) << 8) | uint64(p[k-1]) +} + +func r4(p []byte) uint64 { + return uint64(leUint32(p)) +} + +func r8(p []byte) uint64 { + return leUint64(p) +} + +func mix(a, b uint64) uint64 { + hi, lo := bits.Mul64(a, b) + return hi ^ lo +} + +func leUint32(b []byte) uint32 { + _ = b[3] // bounds check hint to compiler; see golang.org/issue/14808 + return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24 +} + +func leUint64(b []byte) uint64 { + _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808 + return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | + uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56 +} diff --git a/platform/dbops/binaries/go/go/src/hash/maphash/maphash_runtime.go b/platform/dbops/binaries/go/go/src/hash/maphash/maphash_runtime.go new file mode 100644 index 0000000000000000000000000000000000000000..b831df2cf4a9c4fdc4389f6d1e67c94358733df8 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/maphash/maphash_runtime.go @@ -0,0 +1,43 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !purego + +package maphash + +import ( + "unsafe" +) + +//go:linkname runtime_rand runtime.rand +func runtime_rand() uint64 + +//go:linkname runtime_memhash runtime.memhash +//go:noescape +func runtime_memhash(p unsafe.Pointer, seed, s uintptr) uintptr + +func rthash(buf []byte, seed uint64) uint64 { + if len(buf) == 0 { + return seed + } + len := len(buf) + // The runtime hasher only works on uintptr. For 64-bit + // architectures, we use the hasher directly. Otherwise, + // we use two parallel hashers on the lower and upper 32 bits. + if unsafe.Sizeof(uintptr(0)) == 8 { + return uint64(runtime_memhash(unsafe.Pointer(&buf[0]), uintptr(seed), uintptr(len))) + } + lo := runtime_memhash(unsafe.Pointer(&buf[0]), uintptr(seed), uintptr(len)) + hi := runtime_memhash(unsafe.Pointer(&buf[0]), uintptr(seed>>32), uintptr(len)) + return uint64(hi)<<32 | uint64(lo) +} + +func rthashString(s string, state uint64) uint64 { + buf := unsafe.Slice(unsafe.StringData(s), len(s)) + return rthash(buf, state) +} + +func randUint64() uint64 { + return runtime_rand() +} diff --git a/platform/dbops/binaries/go/go/src/hash/maphash/maphash_test.go b/platform/dbops/binaries/go/go/src/hash/maphash/maphash_test.go new file mode 100644 index 0000000000000000000000000000000000000000..ed70f0ce51c52f30f975a76f8b2593adffb7d357 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/maphash/maphash_test.go @@ -0,0 +1,255 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package maphash + +import ( + "bytes" + "fmt" + "hash" + "testing" +) + +func TestUnseededHash(t *testing.T) { + m := map[uint64]struct{}{} + for i := 0; i < 1000; i++ { + h := new(Hash) + m[h.Sum64()] = struct{}{} + } + if len(m) < 900 { + t.Errorf("empty hash not sufficiently random: got %d, want 1000", len(m)) + } +} + +func TestSeededHash(t *testing.T) { + s := MakeSeed() + m := map[uint64]struct{}{} + for i := 0; i < 1000; i++ { + h := new(Hash) + h.SetSeed(s) + m[h.Sum64()] = struct{}{} + } + if len(m) != 1 { + t.Errorf("seeded hash is random: got %d, want 1", len(m)) + } +} + +func TestHashGrouping(t *testing.T) { + b := bytes.Repeat([]byte("foo"), 100) + hh := make([]*Hash, 7) + for i := range hh { + hh[i] = new(Hash) + } + for _, h := range hh[1:] { + h.SetSeed(hh[0].Seed()) + } + hh[0].Write(b) + hh[1].WriteString(string(b)) + + writeByte := func(h *Hash, b byte) { + err := h.WriteByte(b) + if err != nil { + t.Fatalf("WriteByte: %v", err) + } + } + writeSingleByte := func(h *Hash, b byte) { + _, err := h.Write([]byte{b}) + if err != nil { + t.Fatalf("Write single byte: %v", err) + } + } + writeStringSingleByte := func(h *Hash, b byte) { + _, err := h.WriteString(string([]byte{b})) + if err != nil { + t.Fatalf("WriteString single byte: %v", err) + } + } + + for i, x := range b { + writeByte(hh[2], x) + writeSingleByte(hh[3], x) + if i == 0 { + writeByte(hh[4], x) + } else { + writeSingleByte(hh[4], x) + } + writeStringSingleByte(hh[5], x) + if i == 0 { + writeByte(hh[6], x) + } else { + writeStringSingleByte(hh[6], x) + } + } + + sum := hh[0].Sum64() + for i, h := range hh { + if sum != h.Sum64() { + t.Errorf("hash %d not identical to a single Write", i) + } + } + + if sum1 := Bytes(hh[0].Seed(), b); sum1 != hh[0].Sum64() { + t.Errorf("hash using Bytes not identical to a single Write") + } + + if sum1 := String(hh[0].Seed(), string(b)); sum1 != hh[0].Sum64() { + t.Errorf("hash using String not identical to a single Write") + } +} + +func TestHashBytesVsString(t *testing.T) { + s := "foo" + b := []byte(s) + h1 := new(Hash) + h2 := new(Hash) + h2.SetSeed(h1.Seed()) + n1, err1 := h1.WriteString(s) + if n1 != len(s) || err1 != nil { + t.Fatalf("WriteString(s) = %d, %v, want %d, nil", n1, err1, len(s)) + } + n2, err2 := h2.Write(b) + if n2 != len(b) || err2 != nil { + t.Fatalf("Write(b) = %d, %v, want %d, nil", n2, err2, len(b)) + } + if h1.Sum64() != h2.Sum64() { + t.Errorf("hash of string and bytes not identical") + } +} + +func TestHashHighBytes(t *testing.T) { + // See issue 34925. + const N = 10 + m := map[uint64]struct{}{} + for i := 0; i < N; i++ { + h := new(Hash) + h.WriteString("foo") + m[h.Sum64()>>32] = struct{}{} + } + if len(m) < N/2 { + t.Errorf("from %d seeds, wanted at least %d different hashes; got %d", N, N/2, len(m)) + } +} + +func TestRepeat(t *testing.T) { + h1 := new(Hash) + h1.WriteString("testing") + sum1 := h1.Sum64() + + h1.Reset() + h1.WriteString("testing") + sum2 := h1.Sum64() + + if sum1 != sum2 { + t.Errorf("different sum after resetting: %#x != %#x", sum1, sum2) + } + + h2 := new(Hash) + h2.SetSeed(h1.Seed()) + h2.WriteString("testing") + sum3 := h2.Sum64() + + if sum1 != sum3 { + t.Errorf("different sum on the same seed: %#x != %#x", sum1, sum3) + } +} + +func TestSeedFromSum64(t *testing.T) { + h1 := new(Hash) + h1.WriteString("foo") + x := h1.Sum64() // seed generated here + h2 := new(Hash) + h2.SetSeed(h1.Seed()) + h2.WriteString("foo") + y := h2.Sum64() + if x != y { + t.Errorf("hashes don't match: want %x, got %x", x, y) + } +} + +func TestSeedFromSeed(t *testing.T) { + h1 := new(Hash) + h1.WriteString("foo") + _ = h1.Seed() // seed generated here + x := h1.Sum64() + h2 := new(Hash) + h2.SetSeed(h1.Seed()) + h2.WriteString("foo") + y := h2.Sum64() + if x != y { + t.Errorf("hashes don't match: want %x, got %x", x, y) + } +} + +func TestSeedFromFlush(t *testing.T) { + b := make([]byte, 65) + h1 := new(Hash) + h1.Write(b) // seed generated here + x := h1.Sum64() + h2 := new(Hash) + h2.SetSeed(h1.Seed()) + h2.Write(b) + y := h2.Sum64() + if x != y { + t.Errorf("hashes don't match: want %x, got %x", x, y) + } +} + +func TestSeedFromReset(t *testing.T) { + h1 := new(Hash) + h1.WriteString("foo") + h1.Reset() // seed generated here + h1.WriteString("foo") + x := h1.Sum64() + h2 := new(Hash) + h2.SetSeed(h1.Seed()) + h2.WriteString("foo") + y := h2.Sum64() + if x != y { + t.Errorf("hashes don't match: want %x, got %x", x, y) + } +} + +// Make sure a Hash implements the hash.Hash and hash.Hash64 interfaces. +var _ hash.Hash = &Hash{} +var _ hash.Hash64 = &Hash{} + +func benchmarkSize(b *testing.B, size int) { + h := &Hash{} + buf := make([]byte, size) + s := string(buf) + + b.Run("Write", func(b *testing.B) { + b.SetBytes(int64(size)) + for i := 0; i < b.N; i++ { + h.Reset() + h.Write(buf) + h.Sum64() + } + }) + + b.Run("Bytes", func(b *testing.B) { + b.SetBytes(int64(size)) + seed := h.Seed() + for i := 0; i < b.N; i++ { + Bytes(seed, buf) + } + }) + + b.Run("String", func(b *testing.B) { + b.SetBytes(int64(size)) + seed := h.Seed() + for i := 0; i < b.N; i++ { + String(seed, s) + } + }) +} + +func BenchmarkHash(b *testing.B) { + sizes := []int{4, 8, 16, 32, 64, 256, 320, 1024, 4096, 16384} + for _, size := range sizes { + b.Run(fmt.Sprint("n=", size), func(b *testing.B) { + benchmarkSize(b, size) + }) + } +} diff --git a/platform/dbops/binaries/go/go/src/hash/maphash/smhasher_test.go b/platform/dbops/binaries/go/go/src/hash/maphash/smhasher_test.go new file mode 100644 index 0000000000000000000000000000000000000000..085036bd7b3d65fd11db48453b6ad0016de8bcf3 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/hash/maphash/smhasher_test.go @@ -0,0 +1,474 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !race + +package maphash + +import ( + "fmt" + "math" + "math/rand" + "runtime" + "strings" + "testing" + "unsafe" +) + +// Smhasher is a torture test for hash functions. +// https://code.google.com/p/smhasher/ +// This code is a port of some of the Smhasher tests to Go. + +// Note: due to the long running time of these tests, they are +// currently disabled in -race mode. + +var fixedSeed = MakeSeed() + +// Sanity checks. +// hash should not depend on values outside key. +// hash should not depend on alignment. +func TestSmhasherSanity(t *testing.T) { + r := rand.New(rand.NewSource(1234)) + const REP = 10 + const KEYMAX = 128 + const PAD = 16 + const OFFMAX = 16 + for k := 0; k < REP; k++ { + for n := 0; n < KEYMAX; n++ { + for i := 0; i < OFFMAX; i++ { + var b [KEYMAX + OFFMAX + 2*PAD]byte + var c [KEYMAX + OFFMAX + 2*PAD]byte + randBytes(r, b[:]) + randBytes(r, c[:]) + copy(c[PAD+i:PAD+i+n], b[PAD:PAD+n]) + if bytesHash(b[PAD:PAD+n]) != bytesHash(c[PAD+i:PAD+i+n]) { + t.Errorf("hash depends on bytes outside key") + } + } + } + } +} + +func bytesHash(b []byte) uint64 { + var h Hash + h.SetSeed(fixedSeed) + h.Write(b) + return h.Sum64() +} +func stringHash(s string) uint64 { + var h Hash + h.SetSeed(fixedSeed) + h.WriteString(s) + return h.Sum64() +} + +const hashSize = 64 + +func randBytes(r *rand.Rand, b []byte) { + r.Read(b) // can't fail +} + +// A hashSet measures the frequency of hash collisions. +type hashSet struct { + m map[uint64]struct{} // set of hashes added + n int // number of hashes added +} + +func newHashSet() *hashSet { + return &hashSet{make(map[uint64]struct{}), 0} +} +func (s *hashSet) add(h uint64) { + s.m[h] = struct{}{} + s.n++ +} +func (s *hashSet) addS(x string) { + s.add(stringHash(x)) +} +func (s *hashSet) addB(x []byte) { + s.add(bytesHash(x)) +} +func (s *hashSet) addS_seed(x string, seed Seed) { + var h Hash + h.SetSeed(seed) + h.WriteString(x) + s.add(h.Sum64()) +} +func (s *hashSet) check(t *testing.T) { + const SLOP = 10.0 + collisions := s.n - len(s.m) + pairs := int64(s.n) * int64(s.n-1) / 2 + expected := float64(pairs) / math.Pow(2.0, float64(hashSize)) + stddev := math.Sqrt(expected) + if float64(collisions) > expected+SLOP*(3*stddev+1) { + t.Errorf("unexpected number of collisions: got=%d mean=%f stddev=%f", collisions, expected, stddev) + } +} + +// a string plus adding zeros must make distinct hashes +func TestSmhasherAppendedZeros(t *testing.T) { + s := "hello" + strings.Repeat("\x00", 256) + h := newHashSet() + for i := 0; i <= len(s); i++ { + h.addS(s[:i]) + } + h.check(t) +} + +// All 0-3 byte strings have distinct hashes. +func TestSmhasherSmallKeys(t *testing.T) { + h := newHashSet() + var b [3]byte + for i := 0; i < 256; i++ { + b[0] = byte(i) + h.addB(b[:1]) + for j := 0; j < 256; j++ { + b[1] = byte(j) + h.addB(b[:2]) + if !testing.Short() { + for k := 0; k < 256; k++ { + b[2] = byte(k) + h.addB(b[:3]) + } + } + } + } + h.check(t) +} + +// Different length strings of all zeros have distinct hashes. +func TestSmhasherZeros(t *testing.T) { + N := 256 * 1024 + if testing.Short() { + N = 1024 + } + h := newHashSet() + b := make([]byte, N) + for i := 0; i <= N; i++ { + h.addB(b[:i]) + } + h.check(t) +} + +// Strings with up to two nonzero bytes all have distinct hashes. +func TestSmhasherTwoNonzero(t *testing.T) { + if runtime.GOARCH == "wasm" { + t.Skip("Too slow on wasm") + } + if testing.Short() { + t.Skip("Skipping in short mode") + } + h := newHashSet() + for n := 2; n <= 16; n++ { + twoNonZero(h, n) + } + h.check(t) +} +func twoNonZero(h *hashSet, n int) { + b := make([]byte, n) + + // all zero + h.addB(b) + + // one non-zero byte + for i := 0; i < n; i++ { + for x := 1; x < 256; x++ { + b[i] = byte(x) + h.addB(b) + b[i] = 0 + } + } + + // two non-zero bytes + for i := 0; i < n; i++ { + for x := 1; x < 256; x++ { + b[i] = byte(x) + for j := i + 1; j < n; j++ { + for y := 1; y < 256; y++ { + b[j] = byte(y) + h.addB(b) + b[j] = 0 + } + } + b[i] = 0 + } + } +} + +// Test strings with repeats, like "abcdabcdabcdabcd..." +func TestSmhasherCyclic(t *testing.T) { + if testing.Short() { + t.Skip("Skipping in short mode") + } + r := rand.New(rand.NewSource(1234)) + const REPEAT = 8 + const N = 1000000 + for n := 4; n <= 12; n++ { + h := newHashSet() + b := make([]byte, REPEAT*n) + for i := 0; i < N; i++ { + b[0] = byte(i * 79 % 97) + b[1] = byte(i * 43 % 137) + b[2] = byte(i * 151 % 197) + b[3] = byte(i * 199 % 251) + randBytes(r, b[4:n]) + for j := n; j < n*REPEAT; j++ { + b[j] = b[j-n] + } + h.addB(b) + } + h.check(t) + } +} + +// Test strings with only a few bits set +func TestSmhasherSparse(t *testing.T) { + if runtime.GOARCH == "wasm" { + t.Skip("Too slow on wasm") + } + if testing.Short() { + t.Skip("Skipping in short mode") + } + sparse(t, 32, 6) + sparse(t, 40, 6) + sparse(t, 48, 5) + sparse(t, 56, 5) + sparse(t, 64, 5) + sparse(t, 96, 4) + sparse(t, 256, 3) + sparse(t, 2048, 2) +} +func sparse(t *testing.T, n int, k int) { + b := make([]byte, n/8) + h := newHashSet() + setbits(h, b, 0, k) + h.check(t) +} + +// set up to k bits at index i and greater +func setbits(h *hashSet, b []byte, i int, k int) { + h.addB(b) + if k == 0 { + return + } + for j := i; j < len(b)*8; j++ { + b[j/8] |= byte(1 << uint(j&7)) + setbits(h, b, j+1, k-1) + b[j/8] &= byte(^(1 << uint(j&7))) + } +} + +// Test all possible combinations of n blocks from the set s. +// "permutation" is a bad name here, but it is what Smhasher uses. +func TestSmhasherPermutation(t *testing.T) { + if runtime.GOARCH == "wasm" { + t.Skip("Too slow on wasm") + } + if testing.Short() { + t.Skip("Skipping in short mode") + } + permutation(t, []uint32{0, 1, 2, 3, 4, 5, 6, 7}, 8) + permutation(t, []uint32{0, 1 << 29, 2 << 29, 3 << 29, 4 << 29, 5 << 29, 6 << 29, 7 << 29}, 8) + permutation(t, []uint32{0, 1}, 20) + permutation(t, []uint32{0, 1 << 31}, 20) + permutation(t, []uint32{0, 1, 2, 3, 4, 5, 6, 7, 1 << 29, 2 << 29, 3 << 29, 4 << 29, 5 << 29, 6 << 29, 7 << 29}, 6) +} +func permutation(t *testing.T, s []uint32, n int) { + b := make([]byte, n*4) + h := newHashSet() + genPerm(h, b, s, 0) + h.check(t) +} +func genPerm(h *hashSet, b []byte, s []uint32, n int) { + h.addB(b[:n]) + if n == len(b) { + return + } + for _, v := range s { + b[n] = byte(v) + b[n+1] = byte(v >> 8) + b[n+2] = byte(v >> 16) + b[n+3] = byte(v >> 24) + genPerm(h, b, s, n+4) + } +} + +type key interface { + clear() // set bits all to 0 + random(r *rand.Rand) // set key to something random + bits() int // how many bits key has + flipBit(i int) // flip bit i of the key + hash() uint64 // hash the key + name() string // for error reporting +} + +type bytesKey struct { + b []byte +} + +func (k *bytesKey) clear() { + for i := range k.b { + k.b[i] = 0 + } +} +func (k *bytesKey) random(r *rand.Rand) { + randBytes(r, k.b) +} +func (k *bytesKey) bits() int { + return len(k.b) * 8 +} +func (k *bytesKey) flipBit(i int) { + k.b[i>>3] ^= byte(1 << uint(i&7)) +} +func (k *bytesKey) hash() uint64 { + return bytesHash(k.b) +} +func (k *bytesKey) name() string { + return fmt.Sprintf("bytes%d", len(k.b)) +} + +// Flipping a single bit of a key should flip each output bit with 50% probability. +func TestSmhasherAvalanche(t *testing.T) { + if runtime.GOARCH == "wasm" { + t.Skip("Too slow on wasm") + } + if testing.Short() { + t.Skip("Skipping in short mode") + } + avalancheTest1(t, &bytesKey{make([]byte, 2)}) + avalancheTest1(t, &bytesKey{make([]byte, 4)}) + avalancheTest1(t, &bytesKey{make([]byte, 8)}) + avalancheTest1(t, &bytesKey{make([]byte, 16)}) + avalancheTest1(t, &bytesKey{make([]byte, 32)}) + avalancheTest1(t, &bytesKey{make([]byte, 200)}) +} +func avalancheTest1(t *testing.T, k key) { + const REP = 100000 + r := rand.New(rand.NewSource(1234)) + n := k.bits() + + // grid[i][j] is a count of whether flipping + // input bit i affects output bit j. + grid := make([][hashSize]int, n) + + for z := 0; z < REP; z++ { + // pick a random key, hash it + k.random(r) + h := k.hash() + + // flip each bit, hash & compare the results + for i := 0; i < n; i++ { + k.flipBit(i) + d := h ^ k.hash() + k.flipBit(i) + + // record the effects of that bit flip + g := &grid[i] + for j := 0; j < hashSize; j++ { + g[j] += int(d & 1) + d >>= 1 + } + } + } + + // Each entry in the grid should be about REP/2. + // More precisely, we did N = k.bits() * hashSize experiments where + // each is the sum of REP coin flips. We want to find bounds on the + // sum of coin flips such that a truly random experiment would have + // all sums inside those bounds with 99% probability. + N := n * hashSize + var c float64 + // find c such that Prob(mean-c*stddev < x < mean+c*stddev)^N > .9999 + for c = 0.0; math.Pow(math.Erf(c/math.Sqrt(2)), float64(N)) < .9999; c += .1 { + } + c *= 11.0 // allowed slack: 40% to 60% - we don't need to be perfectly random + mean := .5 * REP + stddev := .5 * math.Sqrt(REP) + low := int(mean - c*stddev) + high := int(mean + c*stddev) + for i := 0; i < n; i++ { + for j := 0; j < hashSize; j++ { + x := grid[i][j] + if x < low || x > high { + t.Errorf("bad bias for %s bit %d -> bit %d: %d/%d\n", k.name(), i, j, x, REP) + } + } + } +} + +// All bit rotations of a set of distinct keys +func TestSmhasherWindowed(t *testing.T) { + windowed(t, &bytesKey{make([]byte, 128)}) +} +func windowed(t *testing.T, k key) { + if runtime.GOARCH == "wasm" { + t.Skip("Too slow on wasm") + } + if testing.Short() { + t.Skip("Skipping in short mode") + } + const BITS = 16 + + for r := 0; r < k.bits(); r++ { + h := newHashSet() + for i := 0; i < 1<>uint(j)&1 != 0 { + k.flipBit((j + r) % k.bits()) + } + } + h.add(k.hash()) + } + h.check(t) + } +} + +// All keys of the form prefix + [A-Za-z0-9]*N + suffix. +func TestSmhasherText(t *testing.T) { + if testing.Short() { + t.Skip("Skipping in short mode") + } + text(t, "Foo", "Bar") + text(t, "FooBar", "") + text(t, "", "FooBar") +} +func text(t *testing.T, prefix, suffix string) { + const N = 4 + const S = "ABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrst0123456789" + const L = len(S) + b := make([]byte, len(prefix)+N+len(suffix)) + copy(b, prefix) + copy(b[len(prefix)+N:], suffix) + h := newHashSet() + c := b[len(prefix):] + for i := 0; i < L; i++ { + c[0] = S[i] + for j := 0; j < L; j++ { + c[1] = S[j] + for k := 0; k < L; k++ { + c[2] = S[k] + for x := 0; x < L; x++ { + c[3] = S[x] + h.addB(b) + } + } + } + } + h.check(t) +} + +// Make sure different seed values generate different hashes. +func TestSmhasherSeed(t *testing.T) { + if unsafe.Sizeof(uintptr(0)) == 4 { + t.Skip("32-bit platforms don't have ideal seed-input distributions (see issue 33988)") + } + h := newHashSet() + const N = 100000 + s := "hello" + for i := 0; i < N; i++ { + h.addS_seed(s, Seed{s: uint64(i + 1)}) + h.addS_seed(s, Seed{s: uint64(i+1) << 32}) // make sure high bits are used + } + h.check(t) +} diff --git a/platform/dbops/binaries/go/go/src/html/template/attr.go b/platform/dbops/binaries/go/go/src/html/template/attr.go new file mode 100644 index 0000000000000000000000000000000000000000..6c52211fede1d096f955a6bae656297bd5db8694 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/html/template/attr.go @@ -0,0 +1,175 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package template + +import ( + "strings" +) + +// attrTypeMap[n] describes the value of the given attribute. +// If an attribute affects (or can mask) the encoding or interpretation of +// other content, or affects the contents, idempotency, or credentials of a +// network message, then the value in this map is contentTypeUnsafe. +// This map is derived from HTML5, specifically +// https://www.w3.org/TR/html5/Overview.html#attributes-1 +// as well as "%URI"-typed attributes from +// https://www.w3.org/TR/html4/index/attributes.html +var attrTypeMap = map[string]contentType{ + "accept": contentTypePlain, + "accept-charset": contentTypeUnsafe, + "action": contentTypeURL, + "alt": contentTypePlain, + "archive": contentTypeURL, + "async": contentTypeUnsafe, + "autocomplete": contentTypePlain, + "autofocus": contentTypePlain, + "autoplay": contentTypePlain, + "background": contentTypeURL, + "border": contentTypePlain, + "checked": contentTypePlain, + "cite": contentTypeURL, + "challenge": contentTypeUnsafe, + "charset": contentTypeUnsafe, + "class": contentTypePlain, + "classid": contentTypeURL, + "codebase": contentTypeURL, + "cols": contentTypePlain, + "colspan": contentTypePlain, + "content": contentTypeUnsafe, + "contenteditable": contentTypePlain, + "contextmenu": contentTypePlain, + "controls": contentTypePlain, + "coords": contentTypePlain, + "crossorigin": contentTypeUnsafe, + "data": contentTypeURL, + "datetime": contentTypePlain, + "default": contentTypePlain, + "defer": contentTypeUnsafe, + "dir": contentTypePlain, + "dirname": contentTypePlain, + "disabled": contentTypePlain, + "draggable": contentTypePlain, + "dropzone": contentTypePlain, + "enctype": contentTypeUnsafe, + "for": contentTypePlain, + "form": contentTypeUnsafe, + "formaction": contentTypeURL, + "formenctype": contentTypeUnsafe, + "formmethod": contentTypeUnsafe, + "formnovalidate": contentTypeUnsafe, + "formtarget": contentTypePlain, + "headers": contentTypePlain, + "height": contentTypePlain, + "hidden": contentTypePlain, + "high": contentTypePlain, + "href": contentTypeURL, + "hreflang": contentTypePlain, + "http-equiv": contentTypeUnsafe, + "icon": contentTypeURL, + "id": contentTypePlain, + "ismap": contentTypePlain, + "keytype": contentTypeUnsafe, + "kind": contentTypePlain, + "label": contentTypePlain, + "lang": contentTypePlain, + "language": contentTypeUnsafe, + "list": contentTypePlain, + "longdesc": contentTypeURL, + "loop": contentTypePlain, + "low": contentTypePlain, + "manifest": contentTypeURL, + "max": contentTypePlain, + "maxlength": contentTypePlain, + "media": contentTypePlain, + "mediagroup": contentTypePlain, + "method": contentTypeUnsafe, + "min": contentTypePlain, + "multiple": contentTypePlain, + "name": contentTypePlain, + "novalidate": contentTypeUnsafe, + // Skip handler names from + // https://www.w3.org/TR/html5/webappapis.html#event-handlers-on-elements,-document-objects,-and-window-objects + // since we have special handling in attrType. + "open": contentTypePlain, + "optimum": contentTypePlain, + "pattern": contentTypeUnsafe, + "placeholder": contentTypePlain, + "poster": contentTypeURL, + "profile": contentTypeURL, + "preload": contentTypePlain, + "pubdate": contentTypePlain, + "radiogroup": contentTypePlain, + "readonly": contentTypePlain, + "rel": contentTypeUnsafe, + "required": contentTypePlain, + "reversed": contentTypePlain, + "rows": contentTypePlain, + "rowspan": contentTypePlain, + "sandbox": contentTypeUnsafe, + "spellcheck": contentTypePlain, + "scope": contentTypePlain, + "scoped": contentTypePlain, + "seamless": contentTypePlain, + "selected": contentTypePlain, + "shape": contentTypePlain, + "size": contentTypePlain, + "sizes": contentTypePlain, + "span": contentTypePlain, + "src": contentTypeURL, + "srcdoc": contentTypeHTML, + "srclang": contentTypePlain, + "srcset": contentTypeSrcset, + "start": contentTypePlain, + "step": contentTypePlain, + "style": contentTypeCSS, + "tabindex": contentTypePlain, + "target": contentTypePlain, + "title": contentTypePlain, + "type": contentTypeUnsafe, + "usemap": contentTypeURL, + "value": contentTypeUnsafe, + "width": contentTypePlain, + "wrap": contentTypePlain, + "xmlns": contentTypeURL, +} + +// attrType returns a conservative (upper-bound on authority) guess at the +// type of the lowercase named attribute. +func attrType(name string) contentType { + if strings.HasPrefix(name, "data-") { + // Strip data- so that custom attribute heuristics below are + // widely applied. + // Treat data-action as URL below. + name = name[5:] + } else if prefix, short, ok := strings.Cut(name, ":"); ok { + if prefix == "xmlns" { + return contentTypeURL + } + // Treat svg:href and xlink:href as href below. + name = short + } + if t, ok := attrTypeMap[name]; ok { + return t + } + // Treat partial event handler names as script. + if strings.HasPrefix(name, "on") { + return contentTypeJS + } + + // Heuristics to prevent "javascript:..." injection in custom + // data attributes and custom attributes like g:tweetUrl. + // https://www.w3.org/TR/html5/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes + // "Custom data attributes are intended to store custom data + // private to the page or application, for which there are no + // more appropriate attributes or elements." + // Developers seem to store URL content in data URLs that start + // or end with "URI" or "URL". + if strings.Contains(name, "src") || + strings.Contains(name, "uri") || + strings.Contains(name, "url") { + return contentTypeURL + } + return contentTypePlain +} diff --git a/platform/dbops/binaries/go/go/src/html/template/attr_string.go b/platform/dbops/binaries/go/go/src/html/template/attr_string.go new file mode 100644 index 0000000000000000000000000000000000000000..51c3f262084c04592e18c6c563070c706eac9ba2 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/html/template/attr_string.go @@ -0,0 +1,28 @@ +// Code generated by "stringer -type attr"; DO NOT EDIT. + +package template + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[attrNone-0] + _ = x[attrScript-1] + _ = x[attrScriptType-2] + _ = x[attrStyle-3] + _ = x[attrURL-4] + _ = x[attrSrcset-5] +} + +const _attr_name = "attrNoneattrScriptattrScriptTypeattrStyleattrURLattrSrcset" + +var _attr_index = [...]uint8{0, 8, 18, 32, 41, 48, 58} + +func (i attr) String() string { + if i >= attr(len(_attr_index)-1) { + return "attr(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _attr_name[_attr_index[i]:_attr_index[i+1]] +} diff --git a/platform/dbops/binaries/go/go/src/html/template/clone_test.go b/platform/dbops/binaries/go/go/src/html/template/clone_test.go new file mode 100644 index 0000000000000000000000000000000000000000..e4f6f78835414b618e70a9bcfebad2341a53476a --- /dev/null +++ b/platform/dbops/binaries/go/go/src/html/template/clone_test.go @@ -0,0 +1,278 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package template + +import ( + "errors" + "fmt" + "io" + "strings" + "sync" + "testing" + "text/template/parse" +) + +func TestAddParseTreeHTML(t *testing.T) { + root := Must(New("root").Parse(`{{define "a"}} {{.}} {{template "b"}} {{.}} ">{{end}}`)) + tree, err := parse.Parse("t", `{{define "b"}}0") + if err != nil { + t.Fatal(err) + } + if got, want := b.String(), ` 1>0 `; got != want { + t.Errorf("got %q want %q", got, want) + } +} + +func TestClone(t *testing.T) { + // The {{.}} will be executed with data "*/" in different contexts. + // In the t0 template, it will be in a text context. + // In the t1 template, it will be in a URL context. + // In the t2 template, it will be in a JavaScript context. + // In the t3 template, it will be in a CSS context. + const tmpl = `{{define "a"}}{{template "lhs"}}{{.}}{{template "rhs"}}{{end}}` + b := new(strings.Builder) + + // Create an incomplete template t0. + t0 := Must(New("t0").Parse(tmpl)) + + // Clone t0 as t1. + t1 := Must(t0.Clone()) + Must(t1.Parse(`{{define "lhs"}} {{end}}`)) + + // Execute t1. + b.Reset() + if err := t1.ExecuteTemplate(b, "a", "*/"); err != nil { + t.Fatal(err) + } + if got, want := b.String(), ` `; got != want { + t.Errorf("t1: got %q want %q", got, want) + } + + // Clone t0 as t2. + t2 := Must(t0.Clone()) + Must(t2.Parse(`{{define "lhs"}}

{{end}}`)) + + // Execute t2. + b.Reset() + if err := t2.ExecuteTemplate(b, "a", "*/"); err != nil { + t.Fatal(err) + } + if got, want := b.String(), `

`; got != want { + t.Errorf("t2: got %q want %q", got, want) + } + + // Clone t0 as t3, but do not execute t3 yet. + t3 := Must(t0.Clone()) + Must(t3.Parse(`{{define "lhs"}} {{end}}`)) + + // Complete t0. + Must(t0.Parse(`{{define "lhs"}} ( {{end}}`)) + Must(t0.Parse(`{{define "rhs"}} ) {{end}}`)) + + // Clone t0 as t4. Redefining the "lhs" template should not fail. + t4 := Must(t0.Clone()) + if _, err := t4.Parse(`{{define "lhs"}} OK {{end}}`); err != nil { + t.Errorf(`redefine "lhs": got err %v want nil`, err) + } + // Cloning t1 should fail as it has been executed. + if _, err := t1.Clone(); err == nil { + t.Error("cloning t1: got nil err want non-nil") + } + // Redefining the "lhs" template in t1 should fail as it has been executed. + if _, err := t1.Parse(`{{define "lhs"}} OK {{end}}`); err == nil { + t.Error(`redefine "lhs": got nil err want non-nil`) + } + + // Execute t0. + b.Reset() + if err := t0.ExecuteTemplate(b, "a", "*/"); err != nil { + t.Fatal(err) + } + if got, want := b.String(), ` ( <i>*/ ) `; got != want { + t.Errorf("t0: got %q want %q", got, want) + } + + // Clone t0. This should fail, as t0 has already executed. + if _, err := t0.Clone(); err == nil { + t.Error(`t0.Clone(): got nil err want non-nil`) + } + + // Similarly, cloning sub-templates should fail. + if _, err := t0.Lookup("a").Clone(); err == nil { + t.Error(`t0.Lookup("a").Clone(): got nil err want non-nil`) + } + if _, err := t0.Lookup("lhs").Clone(); err == nil { + t.Error(`t0.Lookup("lhs").Clone(): got nil err want non-nil`) + } + + // Execute t3. + b.Reset() + if err := t3.ExecuteTemplate(b, "a", "*/"); err != nil { + t.Fatal(err) + } + if got, want := b.String(), ` `; got != want { + t.Errorf("t3: got %q want %q", got, want) + } +} + +func TestTemplates(t *testing.T) { + names := []string{"t0", "a", "lhs", "rhs"} + // Some template definitions borrowed from TestClone. + const tmpl = ` + {{define "a"}}{{template "lhs"}}{{.}}{{template "rhs"}}{{end}} + {{define "lhs"}} {{end}}` + t0 := Must(New("t0").Parse(tmpl)) + templates := t0.Templates() + if len(templates) != len(names) { + t.Errorf("expected %d templates; got %d", len(names), len(templates)) + } + for _, name := range names { + found := false + for _, tmpl := range templates { + if name == tmpl.text.Name() { + found = true + break + } + } + if !found { + t.Error("could not find template", name) + } + } +} + +// This used to crash; https://golang.org/issue/3281 +func TestCloneCrash(t *testing.T) { + t1 := New("all") + Must(t1.New("t1").Parse(`{{define "foo"}}foo{{end}}`)) + t1.Clone() +} + +// Ensure that this guarantee from the docs is upheld: +// "Further calls to Parse in the copy will add templates +// to the copy but not to the original." +func TestCloneThenParse(t *testing.T) { + t0 := Must(New("t0").Parse(`{{define "a"}}{{template "embedded"}}{{end}}`)) + t1 := Must(t0.Clone()) + Must(t1.Parse(`{{define "embedded"}}t1{{end}}`)) + if len(t0.Templates())+1 != len(t1.Templates()) { + t.Error("adding a template to a clone added it to the original") + } + // double check that the embedded template isn't available in the original + err := t0.ExecuteTemplate(io.Discard, "a", nil) + if err == nil { + t.Error("expected 'no such template' error") + } +} + +// https://golang.org/issue/5980 +func TestFuncMapWorksAfterClone(t *testing.T) { + funcs := FuncMap{"customFunc": func() (string, error) { + return "", errors.New("issue5980") + }} + + // get the expected error output (no clone) + uncloned := Must(New("").Funcs(funcs).Parse("{{customFunc}}")) + wantErr := uncloned.Execute(io.Discard, nil) + + // toClone must be the same as uncloned. It has to be recreated from scratch, + // since cloning cannot occur after execution. + toClone := Must(New("").Funcs(funcs).Parse("{{customFunc}}")) + cloned := Must(toClone.Clone()) + gotErr := cloned.Execute(io.Discard, nil) + + if wantErr.Error() != gotErr.Error() { + t.Errorf("clone error message mismatch want %q got %q", wantErr, gotErr) + } +} + +// https://golang.org/issue/16101 +func TestTemplateCloneExecuteRace(t *testing.T) { + const ( + input = `{{block "a" .}}a{{end}}{{block "b" .}}b{{end}}` + overlay = `{{define "b"}}A{{end}}` + ) + outer := Must(New("outer").Parse(input)) + tmpl := Must(Must(outer.Clone()).Parse(overlay)) + + var wg sync.WaitGroup + for i := 0; i < 10; i++ { + wg.Add(1) + go func() { + defer wg.Done() + for i := 0; i < 100; i++ { + if err := tmpl.Execute(io.Discard, "data"); err != nil { + panic(err) + } + } + }() + } + wg.Wait() +} + +func TestTemplateCloneLookup(t *testing.T) { + // Template.escape makes an assumption that the template associated + // with t.Name() is t. Check that this holds. + tmpl := Must(New("x").Parse("a")) + tmpl = Must(tmpl.Clone()) + if tmpl.Lookup(tmpl.Name()) != tmpl { + t.Error("after Clone, tmpl.Lookup(tmpl.Name()) != tmpl") + } +} + +func TestCloneGrowth(t *testing.T) { + tmpl := Must(New("root").Parse(`{{block "B". }}Arg{{end}}`)) + tmpl = Must(tmpl.Clone()) + Must(tmpl.Parse(`{{define "B"}}Text{{end}}`)) + for i := 0; i < 10; i++ { + tmpl.Execute(io.Discard, nil) + } + if len(tmpl.DefinedTemplates()) > 200 { + t.Fatalf("too many templates: %v", len(tmpl.DefinedTemplates())) + } +} + +// https://golang.org/issue/17735 +func TestCloneRedefinedName(t *testing.T) { + const base = ` +{{ define "a" -}}{{ template "b" . -}}{{ end -}} +{{ define "b" }}{{ end -}} +` + const page = `{{ template "a" . }}` + + t1 := Must(New("a").Parse(base)) + + for i := 0; i < 2; i++ { + t2 := Must(t1.Clone()) + t2 = Must(t2.New(fmt.Sprintf("%d", i)).Parse(page)) + err := t2.Execute(io.Discard, nil) + if err != nil { + t.Fatal(err) + } + } +} + +// Issue 24791. +func TestClonePipe(t *testing.T) { + a := Must(New("a").Parse(`{{define "a"}}{{range $v := .A}}{{$v}}{{end}}{{end}}`)) + data := struct{ A []string }{A: []string{"hi"}} + b := Must(a.Clone()) + var buf strings.Builder + if err := b.Execute(&buf, &data); err != nil { + t.Fatal(err) + } + if got, want := buf.String(), "hi"; got != want { + t.Errorf("got %q want %q", got, want) + } +} diff --git a/platform/dbops/binaries/go/go/src/html/template/content.go b/platform/dbops/binaries/go/go/src/html/template/content.go new file mode 100644 index 0000000000000000000000000000000000000000..6a9eb4e3cb7ca9be67b90a4e820679a0c55ce9e2 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/html/template/content.go @@ -0,0 +1,185 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package template + +import ( + "fmt" + "reflect" +) + +// Strings of content from a trusted source. +type ( + // CSS encapsulates known safe content that matches any of: + // 1. The CSS3 stylesheet production, such as `p { color: purple }`. + // 2. The CSS3 rule production, such as `a[href=~"https:"].foo#bar`. + // 3. CSS3 declaration productions, such as `color: red; margin: 2px`. + // 4. The CSS3 value production, such as `rgba(0, 0, 255, 127)`. + // See https://www.w3.org/TR/css3-syntax/#parsing and + // https://web.archive.org/web/20090211114933/http://w3.org/TR/css3-syntax#style + // + // Use of this type presents a security risk: + // the encapsulated content should come from a trusted source, + // as it will be included verbatim in the template output. + CSS string + + // HTML encapsulates a known safe HTML document fragment. + // It should not be used for HTML from a third-party, or HTML with + // unclosed tags or comments. The outputs of a sound HTML sanitizer + // and a template escaped by this package are fine for use with HTML. + // + // Use of this type presents a security risk: + // the encapsulated content should come from a trusted source, + // as it will be included verbatim in the template output. + HTML string + + // HTMLAttr encapsulates an HTML attribute from a trusted source, + // for example, ` dir="ltr"`. + // + // Use of this type presents a security risk: + // the encapsulated content should come from a trusted source, + // as it will be included verbatim in the template output. + HTMLAttr string + + // JS encapsulates a known safe EcmaScript5 Expression, for example, + // `(x + y * z())`. + // Template authors are responsible for ensuring that typed expressions + // do not break the intended precedence and that there is no + // statement/expression ambiguity as when passing an expression like + // "{ foo: bar() }\n['foo']()", which is both a valid Expression and a + // valid Program with a very different meaning. + // + // Use of this type presents a security risk: + // the encapsulated content should come from a trusted source, + // as it will be included verbatim in the template output. + // + // Using JS to include valid but untrusted JSON is not safe. + // A safe alternative is to parse the JSON with json.Unmarshal and then + // pass the resultant object into the template, where it will be + // converted to sanitized JSON when presented in a JavaScript context. + JS string + + // JSStr encapsulates a sequence of characters meant to be embedded + // between quotes in a JavaScript expression. + // The string must match a series of StringCharacters: + // StringCharacter :: SourceCharacter but not `\` or LineTerminator + // | EscapeSequence + // Note that LineContinuations are not allowed. + // JSStr("foo\\nbar") is fine, but JSStr("foo\\\nbar") is not. + // + // Use of this type presents a security risk: + // the encapsulated content should come from a trusted source, + // as it will be included verbatim in the template output. + JSStr string + + // URL encapsulates a known safe URL or URL substring (see RFC 3986). + // A URL like `javascript:checkThatFormNotEditedBeforeLeavingPage()` + // from a trusted source should go in the page, but by default dynamic + // `javascript:` URLs are filtered out since they are a frequently + // exploited injection vector. + // + // Use of this type presents a security risk: + // the encapsulated content should come from a trusted source, + // as it will be included verbatim in the template output. + URL string + + // Srcset encapsulates a known safe srcset attribute + // (see https://w3c.github.io/html/semantics-embedded-content.html#element-attrdef-img-srcset). + // + // Use of this type presents a security risk: + // the encapsulated content should come from a trusted source, + // as it will be included verbatim in the template output. + Srcset string +) + +type contentType uint8 + +const ( + contentTypePlain contentType = iota + contentTypeCSS + contentTypeHTML + contentTypeHTMLAttr + contentTypeJS + contentTypeJSStr + contentTypeURL + contentTypeSrcset + // contentTypeUnsafe is used in attr.go for values that affect how + // embedded content and network messages are formed, vetted, + // or interpreted; or which credentials network messages carry. + contentTypeUnsafe +) + +// indirect returns the value, after dereferencing as many times +// as necessary to reach the base type (or nil). +func indirect(a any) any { + if a == nil { + return nil + } + if t := reflect.TypeOf(a); t.Kind() != reflect.Pointer { + // Avoid creating a reflect.Value if it's not a pointer. + return a + } + v := reflect.ValueOf(a) + for v.Kind() == reflect.Pointer && !v.IsNil() { + v = v.Elem() + } + return v.Interface() +} + +var ( + errorType = reflect.TypeFor[error]() + fmtStringerType = reflect.TypeFor[fmt.Stringer]() +) + +// indirectToStringerOrError returns the value, after dereferencing as many times +// as necessary to reach the base type (or nil) or an implementation of fmt.Stringer +// or error. +func indirectToStringerOrError(a any) any { + if a == nil { + return nil + } + v := reflect.ValueOf(a) + for !v.Type().Implements(fmtStringerType) && !v.Type().Implements(errorType) && v.Kind() == reflect.Pointer && !v.IsNil() { + v = v.Elem() + } + return v.Interface() +} + +// stringify converts its arguments to a string and the type of the content. +// All pointers are dereferenced, as in the text/template package. +func stringify(args ...any) (string, contentType) { + if len(args) == 1 { + switch s := indirect(args[0]).(type) { + case string: + return s, contentTypePlain + case CSS: + return string(s), contentTypeCSS + case HTML: + return string(s), contentTypeHTML + case HTMLAttr: + return string(s), contentTypeHTMLAttr + case JS: + return string(s), contentTypeJS + case JSStr: + return string(s), contentTypeJSStr + case URL: + return string(s), contentTypeURL + case Srcset: + return string(s), contentTypeSrcset + } + } + i := 0 + for _, arg := range args { + // We skip untyped nil arguments for backward compatibility. + // Without this they would be output as , escaped. + // See issue 25875. + if arg == nil { + continue + } + + args[i] = indirectToStringerOrError(arg) + i++ + } + return fmt.Sprint(args[:i]...), contentTypePlain +} diff --git a/platform/dbops/binaries/go/go/src/html/template/content_test.go b/platform/dbops/binaries/go/go/src/html/template/content_test.go new file mode 100644 index 0000000000000000000000000000000000000000..d1d8d2d211c22974d0b00655144e9a50ebae0e38 --- /dev/null +++ b/platform/dbops/binaries/go/go/src/html/template/content_test.go @@ -0,0 +1,458 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package template + +import ( + "bytes" + "fmt" + "strings" + "testing" +) + +func TestTypedContent(t *testing.T) { + data := []any{ + ` "foo%" O'Reilly &bar;`, + CSS(`a[href =~ "//example.com"]#foo`), + HTML(`Hello, World &tc!`), + HTMLAttr(` dir="ltr"`), + JS(`c && alert("Hello, World!");`), + JSStr(`Hello, World & O'Reilly\u0021`), + URL(`greeting=H%69,&addressee=(World)`), + Srcset(`greeting=H%69,&addressee=(World) 2x, https://golang.org/favicon.ico 500.5w`), + URL(`,foo/,`), + } + + // For each content sensitive escaper, see how it does on + // each of the typed strings above. + tests := []struct { + // A template containing a single {{.}}. + input string + want []string + }{ + { + ``, + []string{ + `ZgotmplZ`, + // Allowed but not escaped. + `a[href =~ "//example.com"]#foo`, + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + }, + }, + { + `
`, + []string{ + `ZgotmplZ`, + // Allowed and HTML escaped. + `a[href =~ "//example.com"]#foo`, + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + }, + }, + { + `{{.}}`, + []string{ + `<b> "foo%" O'Reilly &bar;`, + `a[href =~ "//example.com"]#foo`, + // Not escaped. + `Hello, World &tc!`, + ` dir="ltr"`, + `c && alert("Hello, World!");`, + `Hello, World & O'Reilly\u0021`, + `greeting=H%69,&addressee=(World)`, + `greeting=H%69,&addressee=(World) 2x, https://golang.org/favicon.ico 500.5w`, + `,foo/,`, + }, + }, + { + ``, + []string{ + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + // Allowed and HTML escaped. + ` dir="ltr"`, + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + `ZgotmplZ`, + }, + }, + { + ``, + []string{ + `<b> "foo%" O'Reilly &bar;`, + `a[href =~ "//example.com"]#foo`, + // Tags stripped, spaces escaped, entity not re-escaped. + `Hello, World &tc!`, + ` dir="ltr"`, + `c && alert("Hello, World!");`, + `Hello, World & O'Reilly\u0021`, + `greeting=H%69,&addressee=(World)`, + `greeting=H%69,&addressee=(World) 2x, https://golang.org/favicon.ico 500.5w`, + `,foo/,`, + }, + }, + { + ``, + []string{ + `<b> "foo%" O'Reilly &bar;`, + `a[href =~ "//example.com"]#foo`, + // Tags stripped, entity not re-escaped. + `Hello, World &tc!`, + ` dir="ltr"`, + `c && alert("Hello, World!");`, + `Hello, World & O'Reilly\u0021`, + `greeting=H%69,&addressee=(World)`, + `greeting=H%69,&addressee=(World) 2x, https://golang.org/favicon.ico 500.5w`, + `,foo/,`, + }, + }, + { + ``, + []string{ + `<b> "foo%" O'Reilly &bar;`, + `a[href =~ "//example.com"]#foo`, + // Angle brackets escaped to prevent injection of close tags, entity not re-escaped. + `Hello, <b>World</b> &tc!`, + ` dir="ltr"`, + `c && alert("Hello, World!");`, + `Hello, World & O'Reilly\u0021`, + `greeting=H%69,&addressee=(World)`, + `greeting=H%69,&addressee=(World) 2x, https://golang.org/favicon.ico 500.5w`, + `,foo/,`, + }, + }, + { + ``, + []string{ + `"\u003cb\u003e \"foo%\" O'Reilly \u0026bar;"`, + `"a[href =~ \"//example.com\"]#foo"`, + `"Hello, \u003cb\u003eWorld\u003c/b\u003e \u0026amp;tc!"`, + `" dir=\"ltr\""`, + // Not escaped. + `c && alert("Hello, World!");`, + // Escape sequence not over-escaped. + `"Hello, World & O'Reilly\u0021"`, + `"greeting=H%69,\u0026addressee=(World)"`, + `"greeting=H%69,\u0026addressee=(World) 2x, https://golang.org/favicon.ico 500.5w"`, + `",foo/,"`, + }, + }, + { + `