Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(670)

Issue 7395056: code review 7395056: cmd/gc: emit explicit type information for local variables (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 3 months ago by rsc
Modified:
12 years, 3 months ago
Reviewers:
DMorsing
CC:
ken2, golang-dev
Visibility:
Public.

Description

cmd/gc: emit explicit type information for local variables The type information is (and for years has been) included as an extra field in the address chunk of an instruction. Unfortunately, suppose there is a string at a+24(FP) and we have an instruction reading its length. It will say: MOVQ x+32(FP), AX and the type of *that* argument is int (not slice), because it is the length being read. This confuses the picture seen by debuggers and now, worse, by the garbage collector. Instead of attaching the type information to all uses, emit an explicit list of TYPE instructions with the information. The TYPE instructions are no-ops whose only role is to provide an address to attach type information to. For example, this function: func f(x, y, z int) (a, b string) { return } now compiles into: --- prog list "f" --- 0000 (/Users/rsc/x.go:3) TEXT f+0(SB),$0-56 0001 (/Users/rsc/x.go:3) LOCALS , 0002 (/Users/rsc/x.go:3) TYPE x+0(FP){int},$8 0003 (/Users/rsc/x.go:3) TYPE y+8(FP){int},$8 0004 (/Users/rsc/x.go:3) TYPE z+16(FP){int},$8 0005 (/Users/rsc/x.go:3) TYPE a+24(FP){string},$16 0006 (/Users/rsc/x.go:3) TYPE b+40(FP){string},$16 0007 (/Users/rsc/x.go:3) MOVQ $0,b+40(FP) 0008 (/Users/rsc/x.go:3) MOVQ $0,b+48(FP) 0009 (/Users/rsc/x.go:3) MOVQ $0,a+24(FP) 0010 (/Users/rsc/x.go:3) MOVQ $0,a+32(FP) 0011 (/Users/rsc/x.go:4) RET , The { } show the formerly hidden type information. The { } syntax is used when printing from within the gc compiler. It is not accepted by the assemblers. The same type information is now included on global variables: 0055 (/Users/rsc/x.go:15) GLOBL slice+0(SB){[]string},$24(AL*0) This more accurate type information fixes a bug in the garbage collector's precise heap collection. The linker only cares about globals right now, but having the local information should make things a little nicer for Carl in the future. Fixes issue 4907.

Patch Set 1 #

Patch Set 2 : diff -r ba6a123a1ea3 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r ba6a123a1ea3 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 08dc15884e88 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+132 lines, -41 lines) Patch
M src/cmd/5g/ggen.c View 1 2 2 chunks +13 lines, -1 line 0 comments Download
M src/cmd/5g/gsubr.c View 1 2 1 chunk +3 lines, -2 lines 0 comments Download
M src/cmd/5g/list.c View 1 2 1 chunk +4 lines, -1 line 0 comments Download
M src/cmd/5g/peep.c View 1 2 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/5g/reg.c View 1 2 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/5l/5.out.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/5l/obj.c View 1 1 chunk +4 lines, -0 lines 0 comments Download
M src/cmd/5l/span.c View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/6g/ggen.c View 1 2 2 chunks +13 lines, -2 lines 0 comments Download
M src/cmd/6g/gsubr.c View 1 2 2 chunks +4 lines, -5 lines 0 comments Download
M src/cmd/6g/list.c View 1 1 chunk +4 lines, -1 line 0 comments Download
M src/cmd/6g/peep.c View 1 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/6g/reg.c View 1 2 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/6l/6.out.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/6l/obj.c View 1 1 chunk +4 lines, -0 lines 0 comments Download
M src/cmd/6l/optab.c View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/8g/ggen.c View 1 2 2 chunks +13 lines, -1 line 0 comments Download
M src/cmd/8g/gsubr.c View 1 2 2 chunks +3 lines, -3 lines 0 comments Download
M src/cmd/8g/list.c View 1 2 1 chunk +4 lines, -1 line 0 comments Download
M src/cmd/8g/peep.c View 1 2 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/8g/reg.c View 1 2 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/8l/8.out.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/8l/obj.c View 1 1 chunk +4 lines, -0 lines 0 comments Download
M src/cmd/8l/optab.c View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/gc/closure.c View 1 2 chunks +2 lines, -5 lines 0 comments Download
M src/cmd/gc/dcl.c View 1 4 chunks +9 lines, -4 lines 0 comments Download
M src/cmd/gc/fmt.c View 1 1 chunk +7 lines, -4 lines 0 comments Download
M src/cmd/gc/go.h View 1 2 2 chunks +1 line, -2 lines 0 comments Download
M src/cmd/gc/obj.c View 1 2 1 chunk +1 line, -1 line 0 comments Download
M src/cmd/gc/pgen.c View 1 2 chunks +17 lines, -3 lines 0 comments Download
M src/cmd/gc/subr.c View 1 2 1 chunk +2 lines, -4 lines 0 comments Download
M src/cmd/gc/typecheck.c View 1 2 1 chunk +0 lines, -1 line 0 comments Download
M src/cmd/gc/walk.c View 1 1 chunk +2 lines, -0 lines 0 comments Download

Messages

Total messages: 3
rsc
Hello ken2 (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
12 years, 3 months ago (2013-02-25 17:13:46 UTC) #1
rsc
*** Submitted as https://code.google.com/p/go/source/detail?r=21524f026a58 *** cmd/gc: emit explicit type information for local variables The type ...
12 years, 3 months ago (2013-02-25 17:13:52 UTC) #2
DMorsing
12 years, 3 months ago (2013-02-25 17:58:38 UTC) #3
On Mon, Feb 25, 2013 at 6:13 PM,  <rsc@golang.org> wrote:
> *** Submitted as
> https://code.google.com/p/go/source/detail?r=21524f026a58 ***

This change doesn't handle closure variables well.

var y int
var foo = func(){
	y = 10
}

turns into

--- prog list "funcĀ·001" ---
0021 (test.go:9) TEXT    funcĀ·001+0(SB),$0-0
0022 (test.go:9) LOCALS  ,$0
0023 (test.go:9) TYPE    &y+-1000000000(SP){*int},$8
0024 (test.go:9) MOVQ    8(DX),BX
0025 (test.go:10) MOVQ    $10,(BX)
0026 (test.go:9) RET     ,
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b