-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Open
Labels
LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal
Milestone
Description
Proposal Details
Use of reflect.Value.Method or reflect.Value.MethodByName disables dead code elimination in the linker as it cannot know needs to kept around vs what can be dropped.
text/template
and by extension html/template
are perhaps the main paths through which these methods become reachable in programs written in Go.
This leads to issues like:
- x/net/trace: dependency on html/template inhibits dead code elimination #62024: x/net/trace: dependency on html/template inhibits dead code elimination
- Allow linker to perform deadcode elimination for program using Cobra spf13/cobra#1956 cobra using text/template disable DCE
I assert that many using of text/template only need to operate on static data (precomputed struct fields, maps, slices).
A new method for template execution that skips attempting to resolve arguments to methods could work for a majority of users while still enabling DCE.
package template
// ExecuteLite executes the named template like [Template.ExecuteTemplate]
// except that arguments are not resolved to methods. For example:
//
// {{ .Foo }}
//
// Would resolve to a struct field named "Foo", or a map with the key "Foo",
// but not a method named "Foo".
//
// Exclusive use of [Template.ExecuteLite] in rendering templates allows the compiler
// to perform dead code elimination.
func (t *Template) ExecuteLite(w io.Writer, name string, data any) error
ikonst, tmthrgd, doggedOwl, egonelbre, paulcacheux and 4 moremzattahri and fumin
Metadata
Metadata
Assignees
Labels
LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal
Type
Projects
Status
Incoming