I've been working on some reflect additions such as FuncOf(). I've been
issue to deadcode() in ld which is blowing away typelinks to interface
method types not directly referenced by the code.
Heres a quick example to show why this is problematic:
type I int
func (I) X(in int) int {
return in
}
func main() {
intT := TypeOf(0)
ft := FuncOf([]Type{intT}, []Type{intT}, false))
}
Here I've constructed a function type using FuncOf(). The 'func(int) int'
type of X was never referenced by the code and hence deleted by the
deadcode detector.
However, the type lives on in the main.I.X method type. When FuncOf fails
to find it in the typelinks it creates a new type that is not equal to
main.I.X, causing havoc in the runtime.
By commenting out a few lines, I was able to keep my typelinks, though I am
now a bit over my head. I would like to ask someone in the know what the
implications of my reckless commenting are.
// keep each beginning with 'typelink.' if the symbol it points at is
being kept.
for(s = ctxt->allsym; s != S; s = s->allsym) {
//if(strncmp(s->name, "go.typelink.", 12) == 0)
//s->reachable = s->nr==1 && s->r[0].sym->reachable;
s->reachable = 1;
}
In particular, what is s->nr? I'm guessing r[0].sym->reachable is the
typelink for main.I, which is the unused type that gets deleted? Is this
roughly correct?
Playing around,
for(s = ctxt->allsym; s != S; s = s->allsym) {
if(strncmp(s->name, "go.typelink.", 12) == 0)
s->reachable = 1;
}
results in unreachable symbol errors, e.g.
type.[]*go/ast.InterfaceType: unreachable sym in relocation:
type.[]*go/ast.InterfaceType type..gc.[]*go/ast.InterfaceType
Thank you.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.