Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: return LITERAL on INDEXMAP when map and key are LITERALs #35763

Closed
Segflow opened this issue Nov 21, 2019 · 2 comments
Closed

cmd/compile: return LITERAL on INDEXMAP when map and key are LITERALs #35763

Segflow opened this issue Nov 21, 2019 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@Segflow
Copy link
Contributor

Segflow commented Nov 21, 2019

Given

package main
const (
	key = "literalKey"
)
func main() {
	v := map[string]string{
		"literalKey": "v1",
		"anotherkey": "v2",
	}[key]
	_ = v
}

When compiled, the compiler will add the different map initialisations methods and assign the different values, then call mapaccess1.

I believe this should not be the case when the map is an OMAPLIT and the key is a LITERAL defined in the map.

The compiler at compile-time can detect this and change the INDEXMAP operation to LITERAL.

The above code should be similar to this one:

package main
const (
	key = "literalKey"
)
func main() {
	v := "v1"
	_ = v
}

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

$ go version
go version go1.13.4 darwin/amd64
@gopherbot
Copy link

Change https://golang.org/cl/208323 mentions this issue: cmd/compile: return LITERAL on INDEXMAP when map and key are LITERALs

@randall77 randall77 added this to the Go1.15 milestone Nov 22, 2019
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 26, 2019
@mdempsky
Copy link
Member

This is a duplicate of #10848.

@golang golang locked and limited conversation to collaborators Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants