Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[go1.21] Updated reflect, reflectlite, and abi#1417

Merged
grantnelson-wf merged 1 commit intogopherjs:go1.21from
Workiva:reflectUpdates
Mar 2, 2026
Merged

[go1.21] Updated reflect, reflectlite, and abi#1417
grantnelson-wf merged 1 commit intogopherjs:go1.21from
Workiva:reflectUpdates

Conversation

@grantnelson-wf
Copy link
Collaborator

There was a large refactor in reflect and reflectlite that moved a lot of the duplicate code out to abi. For example, they consolidated the reflect.name and reflectlite.name object into abi.Name. I updated the native overrides to adjust for these changes. I also removed anything in reflectlite that was no longer needed.

The main issues I ran into was that I didn't remember or wasn't aware of the kindType casts. I added comments into the code to help devs with future updates. With many of the type methods moving to abi, there was a new type of object created, extensions on kind types, e.g. type structType { abi.StructType }, that needed another way to cast. The code now would cast between *rtype, *abi.Type, *abi.StructType, and reflect.structType. I added a function into reflect to handle this complication. toKindTypeExt will perform the additional types of casting that couldn't be handled with kindType. kindType is still being used for reflectlite, abi, and most of the reflect casts.

I tried to minimize the diffs for this PR but with things moving around, it was difficult. Most of the stuff in abi is very similar to what was in reflect and reflectlite except with exported identifier names. However, there were some notable changes:

  • abi.Name, formerly reflect.name, used to use a *byte to lookup name information in a map. NameOff uses an index to lookup a name in a slice of names. To keep from using a global map or slice, I changed abi.Name to store the name information directly and NameOff to store a pointer to that Name.
    This does mean we'll need to update TestLinknameReflectName since it was linking to reflect.name using a *byte, but since we have to do that anyway for the move to abi.Name, it has to be updated anyway. I left that test update for a later PR.
  • TypeOff and TextOff had similar updates to Name and I followed the same pattern as I used for Name.
  • reflect.Value.Clear is new to go1.21 so I implemented it as well.

If #1416 is in merged into go1.21, then the reflect, reflectlite, and abi packages should pass when tests are run on them. However, since go1.21 is an integration branch, it may be difficult to test and CI will continue to fail.

Related to #1415

Copy link
Member

@nevkontakte nevkontakte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will be 100% honest and admit that I can't fully wrap my mind around these changes, and so I will put my trust into tests for validating correctness.

It does look reasonable to me from readability/maintainability perspective. The overlap between reflect and reflectlite has been bugging me and moving some commonalities out into internal/abi is nice.

@grantnelson-wf grantnelson-wf merged commit 0bee75b into gopherjs:go1.21 Mar 2, 2026
1 of 10 checks passed
@grantnelson-wf grantnelson-wf deleted the reflectUpdates branch March 2, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants