Skip to content

Commit 14bc6a9

Browse files
removing unneeded changes from cache 4
1 parent 2ec947a commit 14bc6a9

File tree

3 files changed

+19
-98
lines changed

3 files changed

+19
-98
lines changed

compiler/declNames.go

Lines changed: 14 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
package compiler
22

33
import (
4-
"fmt"
5-
"go/token"
64
"go/types"
7-
"path/filepath"
8-
"strings"
95

106
"github.com/gopherjs/gopherjs/compiler/internal/symbol"
117
"github.com/gopherjs/gopherjs/compiler/internal/typeparams"
128
)
139

14-
const (
15-
varDeclNotUniqueFullName = `var:blank`
16-
funcVarDeclNotUniqueFullName = `funcVar:init`
17-
mainFuncDeclNotUniqueFullName = `init:main`
18-
funcDeclNotUniqueFullName = `func:init`
19-
typeDeclNestedPrefix = `type:nested:`
20-
)
21-
2210
// importDeclFullName returns a unique name for an import declaration.
2311
// This import name may be duplicated in different packages if they both
2412
// import the same package, they are only unique per package.
@@ -28,65 +16,36 @@ func importDeclFullName(importedPkg *types.Package) string {
2816

2917
// varDeclFullName returns a name for a package-level variable declaration.
3018
// This var name only references the first named variable in an assignment.
31-
//
32-
// If no variables are named, this will attempt to create a unique name
33-
// using the integer value of the first valid position of the blank variables.
34-
// Otherwise the name is not unique (i.e. varDeclNotUniqueFullName).
35-
func varDeclFullName(init *types.Initializer, fSet *token.FileSet) string {
19+
// If no variables are named, the name is `var:blank` and not unique.
20+
func varDeclFullName(init *types.Initializer) string {
3621
for _, lhs := range init.Lhs {
3722
if lhs.Name() != `_` {
3823
return `var:` + symbol.New(lhs).String()
3924
}
4025
}
41-
42-
for _, lhs := range init.Lhs {
43-
if pos := lhs.Pos(); pos.IsValid() {
44-
return `var:blank` + declFullNameDiscriminator(pos, fSet)
45-
}
46-
}
47-
48-
return varDeclNotUniqueFullName
26+
return `var:blank`
4927
}
5028

5129
// funcVarDeclFullName returns a name for a package-level variable
5230
// that is used for a function (without a receiver) declaration.
53-
// If the function is generic, this declaration name is for the list
54-
// of instantiations of the function.
55-
//
5631
// The name is unique unless the function is an `init` function.
57-
// If the name is for an `init` function, the position of the function
58-
// is used to create a unique name if it is valid,
59-
// otherwise the name is not unique (i.e. funcVarDeclNotUniqueFullName).
60-
func funcVarDeclFullName(o *types.Func, fSet *token.FileSet) string {
61-
name := `funcVar:` + symbol.New(o).String()
62-
if o.Name() == `init` {
63-
name += declFullNameDiscriminator(o.Pos(), fSet)
64-
}
65-
// In the case of an `init` function with an invalid position,
66-
// the name is not unique and will be equal to funcVarDeclNotUnqueName.
67-
return name
32+
// If the function is generic, this declaration name is also for the list
33+
// of instantiations of the function.
34+
func funcVarDeclFullName(o *types.Func) string {
35+
return `funcVar:` + symbol.New(o).String()
6836
}
6937

7038
// mainFuncDeclFullName returns the name for the declaration used to invoke the
7139
// main function of the program. There should only be one decl with this name.
72-
// This will always return mainFuncDeclNotUniqueFullName.
7340
func mainFuncDeclFullName() string {
74-
return mainFuncDeclNotUniqueFullName
41+
return `init:main`
7542
}
7643

7744
// funcDeclFullName returns a name for a package-level function
7845
// declaration for the given instance of a function.
79-
// The name is unique unless the function is an `init` function
80-
// then it tries to use the position of the function to create a unique name.
81-
// Otherwise the name is not unique (i.e. funcDeclNotUniqueFullName).
82-
func funcDeclFullName(inst typeparams.Instance, fSet *token.FileSet) string {
83-
name := `func:` + inst.String()
84-
if inst.IsTrivial() && inst.Object.Name() == `init` {
85-
name += declFullNameDiscriminator(inst.Object.Pos(), fSet)
86-
}
87-
// In the case of an `init` function with an invalid position,
88-
// the name is not unique and will be equal to funcDeclNotUniqueFullName.
89-
return name
46+
// The name is unique unless the function is an `init` function.
47+
func funcDeclFullName(inst typeparams.Instance) string {
48+
return `func:` + inst.String()
9049
}
9150

9251
// typeVarDeclFullName returns a unique name for a package-level variable
@@ -98,17 +57,10 @@ func typeVarDeclFullName(o *types.TypeName) string {
9857
}
9958

10059
// typeDeclFullName returns a unique name for a package-level type declaration
101-
// for the given instance of a type. Names are only unique per package
60+
// for the given instance of a type. Names are only unique per scope package
10261
// unless the type is a nested type then the name is only unique per the
103-
// function or method it is declared in. In that case, the position of the
104-
// declaration is used to try to create a unique name.
105-
// If the position is invalid, the nested name may be unique or not,
106-
// we cannot guarantee uniqueness in that case.
107-
func typeDeclFullName(inst typeparams.Instance, fSet *token.FileSet) string {
108-
if typeparams.FindNestingFunc(inst.Object) != nil {
109-
return typeDeclNestedPrefix + inst.String() +
110-
declFullNameDiscriminator(inst.Object.Pos(), fSet)
111-
}
62+
// function or method it is declared in.
63+
func typeDeclFullName(inst typeparams.Instance) string {
11264
return `type:` + inst.String()
11365
}
11466

@@ -118,31 +70,3 @@ func typeDeclFullName(inst typeparams.Instance, fSet *token.FileSet) string {
11870
func anonTypeDeclFullName(o types.Object) string {
11971
return `anonType:` + symbol.New(o).String()
12072
}
121-
122-
// declFullNameDiscriminator returns a string representing the position of a
123-
// declaration that is used to differentiate declarations with the same name.
124-
// Since the package path will already be part of the full name, only the file,
125-
// line, and column are used.
126-
// If position is invalid, an empty string is returned.
127-
func declFullNameDiscriminator(pos token.Pos, fSet *token.FileSet) string {
128-
if !pos.IsValid() {
129-
return ``
130-
}
131-
p := fSet.Position(pos)
132-
fileName := filepath.Base(filepath.ToSlash(p.Filename))
133-
return fmt.Sprintf("@%s:%d:%d", fileName, p.Line, p.Column)
134-
}
135-
136-
// isUniqueDeclFullName reports whether the given declaration full name is unique.
137-
// A unique declaration name can be safely cached and reused.
138-
func isUniqueDeclFullName(name string) bool {
139-
switch name {
140-
case ``, varDeclNotUniqueFullName, funcVarDeclNotUniqueFullName,
141-
mainFuncDeclNotUniqueFullName, funcDeclNotUniqueFullName:
142-
return false // not unique since it equals one of the known non-unique names
143-
}
144-
145-
// If the name is for a nested type declaration without a position discriminator,
146-
// then it is not unique, otherwise it should be unique.
147-
return !strings.HasPrefix(name, typeDeclNestedPrefix) || strings.Contains(name, `@`)
148-
}

compiler/decls.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func (fc *funcContext) varDecls(vars []*types.Var) []*Decl {
253253
// newVarDecl creates a new Decl describing a variable, given an explicit
254254
// initializer.
255255
func (fc *funcContext) newVarDecl(init *types.Initializer) *Decl {
256-
fullName := varDeclFullName(init, fc.pkgCtx.fileSet)
256+
fullName := varDeclFullName(init)
257257
d := &Decl{
258258
FullName: fullName,
259259
}
@@ -361,7 +361,7 @@ func (fc *funcContext) funcDecls(functions []*funcGroup) ([]*Decl, error) {
361361
}
362362

363363
func (fc *funcContext) newFuncVarDecl(fun *ast.FuncDecl, o *types.Func, instances []typeparams.Instance) *Decl {
364-
fullName := funcVarDeclFullName(o, fc.pkgCtx.fileSet)
364+
fullName := funcVarDeclFullName(o)
365365
objName := fc.objectName(o)
366366
generic := len(instances) > 1 || !instances[0].IsTrivial()
367367

@@ -396,7 +396,7 @@ func (fc *funcContext) newCallMainFuncDecl(mainFunc *types.Func) *Decl {
396396

397397
// newFuncDecl returns a Decl that defines a package-level function or a method.
398398
func (fc *funcContext) newFuncDecl(fun *ast.FuncDecl, inst typeparams.Instance) *Decl {
399-
fullName := funcDeclFullName(inst, fc.pkgCtx.fileSet)
399+
fullName := funcDeclFullName(inst)
400400
o := fc.pkgCtx.Defs[fun.Name].(*types.Func)
401401
d := &Decl{
402402
FullName: fullName,
@@ -555,7 +555,7 @@ func (fc *funcContext) newNamedTypeVarDecl(obj *types.TypeName) *Decl {
555555
// newNamedTypeInstDecl returns a Decl that represents an instantiation of a
556556
// named Go type.
557557
func (fc *funcContext) newNamedTypeInstDecl(inst typeparams.Instance) (*Decl, error) {
558-
fullName := typeDeclFullName(inst, fc.pkgCtx.fileSet)
558+
fullName := typeDeclFullName(inst)
559559
originType := inst.Object.Type().(*types.Named)
560560

561561
fc.typeResolver = typeparams.NewResolver(fc.pkgCtx.typesCtx, inst)

compiler/sources/serializer.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ func (s *Sources) Read(decode func(any) error) error {
7070
for _, f := range s.Files {
7171
unpackFile(f, s.FileSet)
7272
}
73-
if err := decode(&s.JSFiles); err != nil {
74-
return err
75-
}
76-
return nil
73+
return decode(&s.JSFiles)
7774
}
7875

7976
// prepareFile is run when serializing a source to remove fields that can be

0 commit comments

Comments
 (0)