]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: load builtin export data only once
authorMatthew Dempsky <mdempsky@google.com>
Tue, 1 Dec 2015 20:02:42 +0000 (12:02 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 19 Feb 2016 19:56:32 +0000 (19:56 +0000)
Previously, the builtin runtime export data was reparsed before every
Go source file, and the unsafe export data was reparsed for every
import of package unsafe.  Now, we parse both of them just once ahead
of time.

This does mean package unsafe's export data will be loaded even when
compiling packages that don't import it, but it's tiny anyway.

Change-Id: Ic6931bc58f6d62f664348bfa932f92d4ccacc3ef
Reviewed-on: https://go-review.googlesource.com/19626
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/lex.go
src/cmd/compile/internal/gc/parser.go

index a2a8be161002d888caca1712c7c63d0f816cffa4..8161cad568dd5e2cee10ae39f2c6369088726aa1 100644 (file)
@@ -311,6 +311,8 @@ func Main() {
        lexlineno = 1
        const BOM = 0xFEFF
 
+       loadsys()
+
        for _, infile = range flag.Args() {
                if trace && Debug['x'] != 0 {
                        fmt.Printf("--- %s ---\n", infile)
@@ -656,6 +658,30 @@ func findpkg(name string) (file string, ok bool) {
        return "", false
 }
 
+// loadsys loads the definitions for the low-level runtime and unsafe functions,
+// so that the compiler can generate calls to them,
+// but does not make the names "runtime" or "unsafe" visible as packages.
+func loadsys() {
+       if Debug['A'] != 0 {
+               return
+       }
+
+       block = 1
+       iota_ = -1000000
+
+       importpkg = Runtimepkg
+       cannedimports("runtime.Builtin", runtimeimport)
+       thenewparser.import_package()
+       thenewparser.import_there()
+
+       importpkg = unsafepkg
+       cannedimports("unsafe.o", unsafeimport)
+       thenewparser.import_package()
+       thenewparser.import_there()
+
+       importpkg = nil
+}
+
 func fakeimport() {
        importpkg = mkpkg("fake")
        cannedimports("fake.o", "$$\n")
@@ -706,8 +732,8 @@ func importfile(f *Val, line int) {
                        errorexit()
                }
 
-               importpkg = mkpkg(f.U.(string))
-               cannedimports("unsafe.o", unsafeimport)
+               importpkg = unsafepkg
+               cannedimports("unsafe.o", "package unsafe\n\n$$\n\n")
                imported_unsafe = true
                return
        }
index dc6ae72d5fc418a12844222c849c40d961289cb8..7e521d1f7d95b95f3ce02d354d20cb67bfe2b8d3 100644 (file)
@@ -51,33 +51,10 @@ func pop_parser() {
 // parse_file sets up a new parser and parses a single Go source file.
 func parse_file() {
        thenewparser = parser{}
-       thenewparser.loadsys()
        thenewparser.next()
        thenewparser.file()
 }
 
-// loadsys loads the definitions for the low-level runtime functions,
-// so that the compiler can generate calls to them,
-// but does not make the name "runtime" visible as a package.
-func (p *parser) loadsys() {
-       if trace && Debug['x'] != 0 {
-               defer p.trace("loadsys")()
-       }
-
-       importpkg = Runtimepkg
-
-       if Debug['A'] != 0 {
-               cannedimports("runtime.Builtin", "package runtime safe\n\n$$\n\n")
-       } else {
-               cannedimports("runtime.Builtin", runtimeimport)
-       }
-
-       p.import_package()
-       p.import_there()
-
-       importpkg = nil
-}
-
 type parser struct {
        tok    int32     // next token (one-token look-ahead)
        op     Op        // valid if tok == LASOP