@@ -37,50 +37,48 @@ type Decl struct {
3737 // implementation.
3838 LinkingName symbol.Name
3939 // A list of package-level JavaScript variable names this symbol needs to declare.
40- Vars []string
40+ Vars []string `json:",omitempty"`
4141 // A JS expression by which the object represented by this decl may be
4242 // referenced within the package context. Empty if the decl represents no such
4343 // object.
44- RefExpr string
44+ RefExpr string `json:",omitempty"`
4545 // NamedRecvType is method named recv declare.
46- NamedRecvType string
46+ NamedRecvType string `json:",omitempty"`
4747 // JavaScript code that declares a local variable for an imported package.
48- ImportCode []byte
48+ ImportCode []byte `json:",omitempty"`
4949 // JavaScript code that declares basic information about a named type symbol.
5050 // It configures basic information about the type and its identity.
51- TypeDeclCode []byte
51+ TypeDeclCode []byte `json:",omitempty"`
5252 // JavaScript code that assigns exposed named types to the package.
53- ExportTypeCode []byte
53+ ExportTypeCode []byte `json:",omitempty"`
5454 // JavaScript code that declares basic information about an anonymous type.
5555 // It configures basic information about the type.
5656 // This is added to the finish setup phase to have access to all packages.
57- AnonTypeDeclCode []byte
57+ AnonTypeDeclCode []byte `json:",omitempty"`
5858 // JavaScript code that declares basic information about a function or
5959 // method symbol. This contains the function's or method's compiled body.
6060 // This is added to the finish setup phase to have access to all packages.
61- FuncDeclCode []byte
61+ FuncDeclCode []byte `json:",omitempty"`
6262 // JavaScript code that assigns exposed functions to the package.
6363 // This is added to the finish setup phase to have access to all packages.
64- ExportFuncCode []byte
64+ ExportFuncCode []byte `json:",omitempty"`
6565 // JavaScript code that initializes reflection metadata about a type's method list.
6666 // This is added to the finish setup phase to have access to all packages.
67- MethodListCode []byte
67+ MethodListCode []byte `json:",omitempty"`
6868 // JavaScript code that initializes the rest of reflection metadata about a type
6969 // (e.g. struct fields, array type sizes, element types, etc.).
7070 // This is added to the finish setup phase to have access to all packages.
71- TypeInitCode []byte
71+ TypeInitCode []byte `json:",omitempty"`
7272 // JavaScript code that needs to be executed during the package init phase to
7373 // set the symbol up (e.g. initialize package-level variable value).
74- InitCode []byte
74+ InitCode []byte `json:",omitempty"`
7575 // DCEInfo stores the information for dead-code elimination.
7676 DCEInfo dce.Info
7777 // Set to true if a function performs a blocking operation (I/O or
7878 // synchronization). The compiler will have to generate function code such
7979 // that it can be resumed after a blocking operation completes without
8080 // blocking the main thread in the meantime.
8181 Blocking bool
82- // ForGeneric inidicates this decl is for a generic function or type.
83- ForGeneric bool
8482}
8583
8684// minify returns a copy of Decl with unnecessary whitespace removed from the
@@ -185,10 +183,9 @@ func (fc *funcContext) importDecls() (importedPaths []string, importDecls []*Dec
185183
186184// newImportDecl registers the imported package and returns a Decl instance for it.
187185func (fc * funcContext ) newImportDecl (importedPkg * types.Package ) * Decl {
188- fullName := importDeclFullName (importedPkg )
189186 pkgVar := fc .importedPkgVar (importedPkg )
190187 d := & Decl {
191- FullName : fullName ,
188+ FullName : importDeclFullName ( importedPkg ) ,
192189 Vars : []string {pkgVar },
193190 ImportCode : []byte (fmt .Sprintf ("\t %s = $packages[\" %s\" ];\n " , pkgVar , importedPkg .Path ())),
194191 InitCode : fc .CatchOutput (1 , func () { fc .translateStmt (fc .importInitializer (importedPkg .Path ()), nil ) }),
@@ -253,9 +250,8 @@ func (fc *funcContext) varDecls(vars []*types.Var) []*Decl {
253250// newVarDecl creates a new Decl describing a variable, given an explicit
254251// initializer.
255252func (fc * funcContext ) newVarDecl (init * types.Initializer ) * Decl {
256- fullName := varDeclFullName (init )
257253 d := & Decl {
258- FullName : fullName ,
254+ FullName : varDeclFullName ( init ) ,
259255 }
260256 assignLHS := []ast.Expr {}
261257 for _ , o := range init .Lhs {
@@ -371,9 +367,8 @@ func (fc *funcContext) newFuncVarDecl(fun *ast.FuncDecl, o *types.Func, instance
371367 }
372368
373369 varDecl := & Decl {
374- FullName : fullName ,
375- Vars : []string {varName },
376- ForGeneric : generic ,
370+ FullName : fullName ,
371+ Vars : []string {varName },
377372 }
378373 varDecl .Dce ().SetName (o , nil , nil )
379374
@@ -386,23 +381,20 @@ func (fc *funcContext) newFuncVarDecl(fun *ast.FuncDecl, o *types.Func, instance
386381}
387382
388383func (fc * funcContext ) newCallMainFuncDecl (mainFunc * types.Func ) * Decl {
389- fullName := mainFuncDeclFullName ()
390384 d := & Decl {
391- FullName : fullName ,
385+ FullName : mainFuncDeclFullName () ,
392386 InitCode : fc .CatchOutput (1 , func () { fc .translateStmt (fc .callMainFunc (mainFunc ), nil ) }),
393387 }
394388 return d
395389}
396390
397391// newFuncDecl returns a Decl that defines a package-level function or a method.
398392func (fc * funcContext ) newFuncDecl (fun * ast.FuncDecl , inst typeparams.Instance ) * Decl {
399- fullName := funcDeclFullName (inst )
400393 o := fc .pkgCtx .Defs [fun .Name ].(* types.Func )
401394 d := & Decl {
402- FullName : fullName ,
395+ FullName : funcDeclFullName ( inst ) ,
403396 Blocking : fc .pkgCtx .IsBlocking (inst ),
404397 LinkingName : symbol .New (o ),
405- ForGeneric : ! inst .IsTrivial (),
406398 }
407399 d .Dce ().SetName (o , inst .TNest , inst .TArgs )
408400
@@ -531,17 +523,15 @@ func (fc *funcContext) namedTypeDecls(typeNames typesutil.TypeNames) ([]*Decl, e
531523// of the type, keyed by the type argument combination. Otherwise it contains
532524// the type definition directly.
533525func (fc * funcContext ) newNamedTypeVarDecl (obj * types.TypeName ) * Decl {
534- fullName := typeVarDeclFullName (obj )
535526 name := fc .objectName (obj )
536527 generic := fc .pkgCtx .instanceSet .Pkg (obj .Pkg ()).ObjHasInstances (obj )
537528 varName := name
538529 if generic {
539530 varName += ` = []`
540531 }
541532 varDecl := & Decl {
542- FullName : fullName ,
543- Vars : []string {varName },
544- ForGeneric : generic ,
533+ FullName : typeVarDeclFullName (obj ),
534+ Vars : []string {varName },
545535 }
546536 varDecl .Dce ().SetName (obj , nil , nil )
547537 if isPkgLevel (obj ) {
@@ -555,7 +545,6 @@ func (fc *funcContext) newNamedTypeVarDecl(obj *types.TypeName) *Decl {
555545// newNamedTypeInstDecl returns a Decl that represents an instantiation of a
556546// named Go type.
557547func (fc * funcContext ) newNamedTypeInstDecl (inst typeparams.Instance ) (* Decl , error ) {
558- fullName := typeDeclFullName (inst )
559548 originType := inst .Object .Type ().(* types.Named )
560549
561550 fc .typeResolver = typeparams .NewResolver (fc .pkgCtx .typesCtx , inst )
@@ -575,8 +564,7 @@ func (fc *funcContext) newNamedTypeInstDecl(inst typeparams.Instance) (*Decl, er
575564
576565 underlying := instanceType .Underlying ()
577566 d := & Decl {
578- FullName : fullName ,
579- ForGeneric : ! inst .IsTrivial (),
567+ FullName : typeDeclFullName (inst ),
580568 }
581569 d .Dce ().SetName (inst .Object , inst .TNest , inst .TArgs )
582570 fc .pkgCtx .CollectDCEDeps (d , func () {
@@ -700,9 +688,8 @@ func (fc *funcContext) anonTypeDecls(anonTypes []*types.TypeName) []*Decl {
700688 }
701689 decls := []* Decl {}
702690 for _ , t := range anonTypes {
703- fullName := anonTypeDeclFullName (t )
704691 d := & Decl {
705- FullName : fullName ,
692+ FullName : anonTypeDeclFullName ( t ) ,
706693 Vars : []string {t .Name ()},
707694 }
708695 d .Dce ().SetName (t , nil , nil )
0 commit comments