"redeclared in this block" error on tip

3,894 views
Skip to first unread message

Tamás Gulácsi

unread,
Oct 31, 2012, 9:36:38 AM10/31/12
to golan...@googlegroups.com
tgulacsi@nell:~/projects/aostor/srv_aostor$ rm -rf ~/projects/go/pkg && (cd .. && go fmt && go build) && go fmt && go build
# _/home/tgulacsi/projects/aostor/srv_aostor
./server.go:36: config.ok redeclared in this block
    previous declaration at ./server.go:36

tgulacsi@nell:~/projects/aostor/srv_aostor$ head -n 50 server.go
// Copyright 2012 Tamás Gulácsi, UNO-SOFT Computing Ltd.
// This file is part of aostor.

// Aostor is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Aostor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Aostor.  If not, see <http://www.gnu.org/licenses/>.

// Append-Only Storage HTTP server
package main

import _ "net/http/pprof" // pprof

import (
    "bufio"
    "encoding/base64"
    "flag"
    "fmt"
    "io"
    "log"
    "net/http"
    "os"
    "os/signal"
    "runtime"
    "strings"
    "syscall"
    "time"
    "unosoft.hu/aostor"
)

var logger = log.New(os.Stderr, "server ", log.LstdFlags|log.Lshortfile)
var MaxRequestMemory = 20 * int64(1<<20)

func main() {
    defer aostor.FlushLog()
    configfile := flag.String("c", aostor.ConfigFile, "config file")
    hostport := flag.String("http", "",
        "host:port, default="+aostor.DefaultHostport)
    flag.Parse()
    conf, err := aostor.ReadConf(*configfile, "")
    if err != nil {
        logger.Fatalf("cannot read configuration %s: %s", *configfile, err)


I've bisected since 8e87cb8dca7d (actual tip is 93dc7f0e302b)
The first bad revision is:
changeset:   14713:bb4ee132b967
user:        Luuk van Dijk <lvd at golang dot org>
date:        Mon Oct 29 13:55:27 2012 +0100
summary:     cmd/gc: inlining functions with local variables


1. Is this really an errror in gc, or PEBKAC?
2. will it be fixed?

Thanks,
GThomas

Jan Mercl

unread,
Oct 31, 2012, 9:56:11 AM10/31/12
to Tamás Gulácsi, golang-nuts
On Wed, Oct 31, 2012 at 2:36 PM, Tamás Gulácsi <tgula...@gmail.com> wrote:

What is your $GOPATH? I see no `/src/` anywhere in the source path?
"go build" doesn't work like that - or what am I missing?

Longer version:

`$ rm -rf ~/projects/go/pkg` seems to indicate $GOPATH is ~/projects/go

but

the `server.go` (the trouble maker) is in
`~/projects/aostor/srv_aostor` (per the `$ head -n 50 server.go`)
which AFAIK cannot be a valid path for the "go build" command. == It
doesn't have the form $GOPATH/src/whatever - the `/src/` is missing,
but that is obligatory. (???)

Also I wonder what the "go build" is invoked twice in the shown
command line - that also look very strange to me. Why is it there?

-j

Gulácsi Tamás

unread,
Oct 31, 2012, 10:04:20 AM10/31/12
to Jan Mercl, golang-nuts
GOPATH=/home/tgulacsi/projects/go
GOROOT=/usr/local/go

server.go is in package main, in subdirectory of aostor, which is
linked as unosoft.hu/aostor under src:

tgulacsi@nell:~/projects/aostor$ l $GOPATH/src/*
/home/tgulacsi/projects/go/src/code.google.com:
total 0
drwxr-xr-x 1 tgulacsi gthomas 504 Oct 24 09:58 p

/home/tgulacsi/projects/go/src/github.com:
total 0
drwxr-xr-x 1 tgulacsi gthomas 168 Aug 31 15:12 cihub
drwxr-xr-x 1 tgulacsi gthomas 168 Aug 31 15:12 kless
drwxr-xr-x 1 tgulacsi gthomas 168 Sep 19 15:00 kylelemons
drwxr-xr-x 1 tgulacsi gthomas 168 Oct 24 09:57 str1ngs
drwxr-xr-x 1 tgulacsi gthomas 336 Oct 19 13:51 tgulacsi

/home/tgulacsi/projects/go/src/unosoft.hu:
total 0
lrwxrwxrwx 1 tgulacsi gthomas 15 Aug 31 15:19 aostor -> ../../../aostor


Should I use another setup, or edit things directly under $GOPATH/src/... ?
I've tried that, but with the same result - and for older versions of
tip, it worked flawlessly.

(The other thing, is that with the current tip, my test program
induces several "runtime: invalid memory address" printouts, but
without anything panicing) - older versions work as expected).
GThomas

2012/10/31 Jan Mercl <0xj...@gmail.com>:

Rémy Oudompheng

unread,
Oct 31, 2012, 4:17:59 PM10/31/12
to Tamás Gulácsi, golan...@googlegroups.com
On 2012/10/31 Tamás Gulácsi <tgula...@gmail.com> wrote:
> I've bisected since 8e87cb8dca7d (actual tip is 93dc7f0e302b)
> The first bad revision is:
> changeset: 14713:bb4ee132b967
> user: Luuk van Dijk <lvd at golang dot org>
> date: Mon Oct 29 13:55:27 2012 +0100
> summary: cmd/gc: inlining functions with local variables
>
>
> 1. Is this really an errror in gc, or PEBKAC?

If it used to compile, it is an error (either the previous behaviour
or the current behaviour is wrong).

> 2. will it be fixed?

Please provide a minimal example (main file + minimal package import
that triggers the error) and open an issue. The issue can't be fixed
if you don't provide what is failing.

Rémy.

Rémy Oudompheng

unread,
Oct 31, 2012, 5:51:04 PM10/31/12
to Tamás Gulácsi, golan...@googlegroups.com
There are inded quite several bugs with the current tree. It does not
even build anymore with gcflags -lll.

Rémy.

Gulácsi Tamás

unread,
Oct 31, 2012, 5:55:03 PM10/31/12
to Rémy Oudompheng, golan...@googlegroups.com
A minimal example:

gthomas@waterhouse:~/projects/go/src/example.com/goerr/main$ cat main.go
package main

import (
"github.com/tgulacsi/aostor"
)

func main() {
aostor.ReadConf("", "config.ini")
}

gthomas@waterhouse:~/projects/go/src/example.com/goerr/main$ go build
# example.com/goerr/main
./main.go:4: config.ok redeclared in this block
previous declaration at ./main.go:4


From the "config.ok" string, I'd search somewhere config reading - it
uses github.com/kless/goconfig/config , but if I import only that lib,
it doesn't produce the error.
Where/how should I start searching?

GThomas


2012/10/31 Rémy Oudompheng <remyoud...@gmail.com>:

Rémy Oudompheng

unread,
Oct 31, 2012, 6:02:17 PM10/31/12
to Gulácsi Tamás, golan...@googlegroups.com
On 2012/10/31 Gulácsi Tamás <tgula...@gmail.com> wrote:
> A minimal example:
>
> gthomas@waterhouse:~/projects/go/src/example.com/goerr/main$ cat main.go
> package main
>
> import (
> "github.com/tgulacsi/aostor"
> )
>
> func main() {
> aostor.ReadConf("", "config.ini")
> }

It doesn't work:

package github.com/tgulacsi/aostor
imports code.google.com/p/go-uuid/uuid
imports github.com/cihub/seelog
imports github.com/kless/goconfig/config
imports github.com/tgulacsi/go-cdb
imports unosoft.hu/aostor/compressor: unrecognized import path
"unosoft.hu/aostor/compressor"

> gthomas@waterhouse:~/projects/go/src/example.com/goerr/main$ go build
> # example.com/goerr/main
> ./main.go:4: config.ok redeclared in this block
> previous declaration at ./main.go:4
>
>
> From the "config.ok" string, I'd search somewhere config reading - it
> uses github.com/kless/goconfig/config , but if I import only that lib,
> it doesn't produce the error.
> Where/how should I start searching?

If you want to help fixing, you need to look at the inlining code in
the compiler. For example, it is failing on a variable shadowing
problem:

at exp/types/types.go:230

func Deref(typ Type) Type {
if typ, ok := typ.(*Pointer); ok {
return typ.Base
}
return typ
}

The inliner converts:
typ, ok := typ.(*Pointer)
to:
var typ *Pointer
var ok bool
typ, ok = typ.(*Pointer)

which is wrong due to shadowing. The internal representation still
works but the exported data in packages is broken due to that. Your
issue may be related to this pattern or may be another bug.

Rémy.

Gulácsi Tamás

unread,
Oct 31, 2012, 6:38:54 PM10/31/12
to Rémy Oudompheng, golan...@googlegroups.com
cd /tmp && mkdir -p goerr/cfg && cd goerr/cfg && cat >main.go <<EOF
package main
import "github.com/tgulacsi/aostor"
func main() {
aostor.ReadConf("", "config.ini")
}
EOF
export GOPATH=/tmp/goerr
go get


results in
# _/tmp/goerr/cfg
./main.go:2: config.ok redeclared in this block
previous declaration at ./main.go:2


I've tried to chase shadow(ing)s in config.go, and found some, but didn't help.
Thanks for your time and helping hand!

GThomas

Rémy Oudompheng

unread,
Nov 1, 2012, 4:12:49 AM11/1/12
to Gulácsi Tamás, golan...@googlegroups.com
On 2012/10/31 Gulácsi Tamás <tgula...@gmail.com> wrote:
> cd /tmp && mkdir -p goerr/cfg && cd goerr/cfg && cat >main.go <<EOF
> package main
> import "github.com/tgulacsi/aostor"
> func main() {
> aostor.ReadConf("", "config.ini")
> }
> EOF
> export GOPATH=/tmp/goerr
> go get

It works because you fixed the imports. It was broken when you told us
to try, A minimal example is not only about minimizing your main
program file, but also about minimizing all the external packages you
are using.

Here is a minimal example:

$ cat p1.go
package p1

type O map[string]map[string]string

func (opts O) RemoveOption(sect, opt string) bool {
if _, ok := opts[sect]; !ok {
return false
}
_, ok := opts[sect][opt]
delete(opts[sect], opt)
return ok
}

$ cat p2.go
package p2

import "./p1"

func NewO() p1.O { return nil }

$ cat main.go
package main

import "./p2"

func main() {
p2.NewO().RemoveOption("hello", "world")
}

$ go tool 8g -I. p1.go
$ go tool 8g -I. p2.go
$ go tool 8g -I. main.go
main.go:3: p1.ok redeclared in this block
previous declaration at main.go:3
go tool 8g: exit status 1

Rémy.

Gulácsi Tamás

unread,
Nov 1, 2012, 2:01:11 PM11/1/12
to Rémy Oudompheng, golan...@googlegroups.com
Thank you Rémy!

Since I know nothing about the nature of the error, just a happy user
of Go, I was delighted that my error are reproducible after all, even
with that bloated import :)

You're absolutely right that a minimal example is minimal, in every aspect.


So, after all this error is not PEBKAC, but an adverse effect of a new
feature (inlining functions with local variables).
Hope this will be resolved, till that I'm stuck (but ok) with 7df8438a2c41.

GThomas


2012/11/1 Rémy Oudompheng <remyoud...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages