Skip to content

cmd/compile: constant string -> []byte and []byte -> string conversions aren't constant folded #26498

Open
@FMNSSun

Description

@FMNSSun

What did you see?

Conversions like

string([]byte{...})
[]byte("...")

are not constant folded.

What did you expect?

Conversions of const literals should probably be constant folded because it significantly slows down
things like

for .... {
  p.Write([]byte(":=")
}

This is related to #26264 but the scope of that issues should probably be the difference between Write, WriteByte, WriteString as some conversions not being constant folded is an issue on a different level that has little to do with the performance of these functions per se.

I can't quite tell whether []rune(...) is also not constant folded because I'm not sure what type.[]int32 actually does but for []byte(...) and string(...) there are calls to runtime.stringtoslicebyte(SB) and runtime.slicebytetostring(SB).

What version of Go are you using (go version)?

1.10.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Triage Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions