Skip to content

Commit 8e97053

Browse files
committed
cmd/compile: revert user-visible changes related to aliases
Reason: Decision to back out current alias implementation. Leaving import/export related code in place for now. For #16339. TBR=mdempsky Change-Id: Ib0897cab2c1c3dc8a541f2efb9893271b0b0efe2 Reviewed-on: https://go-review.googlesource.com/32757 Reviewed-by: Robert Griesemer <[email protected]>
1 parent dd1e7b3 commit 8e97053

File tree

7 files changed

+1
-410
lines changed

7 files changed

+1
-410
lines changed

src/cmd/compile/internal/gc/noder.go

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ func (p *noder) decls(decls []syntax.Decl) (l []*Node) {
6161
case *syntax.ImportDecl:
6262
p.importDecl(decl)
6363

64-
case *syntax.AliasDecl:
65-
p.aliasDecl(decl)
66-
6764
case *syntax.VarDecl:
6865
l = append(l, p.varDecl(decl)...)
6966

@@ -150,100 +147,6 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) {
150147
my.Block = 1 // at top level
151148
}
152149

153-
func (p *noder) aliasDecl(decl *syntax.AliasDecl) {
154-
// Because alias declarations must refer to imported entities
155-
// which are already set up, we can do all checks right here.
156-
// We won't know anything about entities that have not been
157-
// declared yet, but since they cannot have been imported, we
158-
// know there's an error and we don't care about the details.
159-
160-
// The original entity must be denoted by a qualified identifier.
161-
// (The parser doesn't make this restriction to be more error-
162-
// tolerant.)
163-
qident, ok := decl.Orig.(*syntax.SelectorExpr)
164-
if !ok {
165-
// TODO(gri) This prints a dot-imported object with qualification
166-
// (confusing error). Fix this.
167-
yyerror("invalid alias: %v is not a package-qualified identifier", p.expr(decl.Orig))
168-
return
169-
}
170-
171-
pkg := p.expr(qident.X)
172-
if pkg.Op != OPACK {
173-
yyerror("invalid alias: %v is not a package", pkg)
174-
return
175-
}
176-
pkg.Used = true
177-
178-
// Resolve original entity
179-
orig := oldname(restrictlookup(qident.Sel.Value, pkg.Name.Pkg))
180-
if orig.Sym.Flags&SymAlias != 0 {
181-
Fatalf("original %v marked as alias", orig.Sym)
182-
}
183-
184-
// An alias declaration must not refer to package unsafe.
185-
if orig.Sym.Pkg == unsafepkg {
186-
yyerror("invalid alias: %v refers to package unsafe (%v)", decl.Name.Value, orig)
187-
return
188-
}
189-
190-
// The aliased entity must be from a matching constant, type, variable,
191-
// or function declaration, respectively.
192-
var what string
193-
switch decl.Tok {
194-
case syntax.Const:
195-
if orig.Op != OLITERAL {
196-
what = "constant"
197-
}
198-
case syntax.Type:
199-
if orig.Op != OTYPE {
200-
what = "type"
201-
}
202-
case syntax.Var:
203-
if orig.Op != ONAME || orig.Class != PEXTERN {
204-
what = "variable"
205-
}
206-
case syntax.Func:
207-
if orig.Op != ONAME || orig.Class != PFUNC {
208-
what = "function"
209-
}
210-
default:
211-
Fatalf("unexpected token: %s", decl.Tok)
212-
}
213-
if what != "" {
214-
yyerror("invalid alias: %v is not a %s", orig, what)
215-
return
216-
}
217-
218-
// handle special cases
219-
switch decl.Name.Value {
220-
case "_":
221-
return // don't declare blank aliases
222-
case "init":
223-
yyerror("cannot declare init - must be non-alias function declaration")
224-
return
225-
}
226-
227-
// declare alias
228-
// (this is similar to handling dot imports)
229-
asym := p.name(decl.Name)
230-
if asym.Def != nil {
231-
redeclare(asym, "in alias declaration")
232-
return
233-
}
234-
asym.Flags |= SymAlias
235-
asym.Def = orig
236-
asym.Block = block
237-
asym.Lastlineno = lineno
238-
239-
if exportname(asym.Name) {
240-
// TODO(gri) newname(asym) is only needed to satisfy exportsym
241-
// (and indirectly, exportlist). We should be able to just
242-
// collect the Syms, eventually.
243-
exportsym(newname(asym))
244-
}
245-
}
246-
247150
func (p *noder) varDecl(decl *syntax.VarDecl) []*Node {
248151
names := p.declNames(decl.NameList)
249152

src/go/internal/gcimporter/testdata/exports.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77

88
package exports
99

10-
import (
11-
"go/ast"
12-
"go/build"
13-
"math"
14-
)
10+
import "go/ast"
1511

1612
// Issue 3682: Correctly read dotted identifiers from export data.
1713
const init1 = 0
@@ -29,10 +25,6 @@ const (
2925
C7 = `bar\n`
3026
)
3127

32-
const (
33-
C8 => math.Pi
34-
)
35-
3628
type (
3729
T1 int
3830
T2 [10]int
@@ -81,29 +73,16 @@ type (
8173
T28 func(T28) T28
8274
)
8375

84-
type (
85-
T29 => ast.File
86-
T30 => build.Context
87-
)
88-
8976
var (
9077
V0 int
9178
V1 = -991.0
9279
V2 float32 = 1.2
9380
)
9481

95-
var (
96-
V3 => build.Default
97-
)
98-
9982
func F1() {}
10083
func F2(x int) {}
10184
func F3() int { return 0 }
10285
func F4() float32 { return 0 }
10386
func F5(a, b, c int, u, v, w struct{ x, y T1 }, more ...interface{}) (p, q, r chan<- T10)
10487

10588
func (p *T1) M1()
106-
107-
func F6 => math.Sin
108-
func F7 => ast.IsExported
109-
func F8 => build.Import

test/alias2.go

Lines changed: 0 additions & 103 deletions
This file was deleted.

test/alias3.dir/a.go

Lines changed: 0 additions & 54 deletions
This file was deleted.

test/alias3.dir/b.go

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)