Skip to content

runtime: reflect Value.Seq/Seq2#1442

Merged
xushiwei merged 4 commits intogoplus:mainfrom
visualfc:reflect_iter
Dec 9, 2025
Merged

runtime: reflect Value.Seq/Seq2#1442
xushiwei merged 4 commits intogoplus:mainfrom
visualfc:reflect_iter

Conversation

@visualfc
Copy link
Member

@visualfc visualfc commented Dec 6, 2025

  • runtime: support reflect.Value.Seq/Seq2
  • ssa/abi: fix structure name public if it is a closure
  • _demo/go: add text/template demo

@gemini-code-assist
Copy link

Summary of Changes

Hello @visualfc, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces new Seq and Seq2 methods to the reflect.Value type, providing a standardized way to obtain single-value and key-value iterators, respectively, for a wide range of Go types. These additions leverage the iter package to integrate Go's iteration proposals with the reflection system, allowing for dynamic traversal of data structures. The changes are part of an ongoing effort, with a known ABI type error still requiring resolution.

Highlights

  • New Iteration Methods: Introduced Seq() and Seq2() methods to reflect.Value, enabling reflection-based iteration over various Go data structures using the new iter package.
  • Supported Types for Iteration: The Seq() method supports iteration over numeric types, pointers to arrays, arrays, slices, strings (indices), maps (keys), channels (received values), and specific function signatures. The Seq2() method supports iteration over pointers to arrays (index, element), arrays, slices (index, element), strings (index, rune), maps (key, value), and specific function signatures.
  • New Internal Package: A new file iter.go has been added to the internal runtime/internal/lib/reflect package, containing the implementation for these new reflection iteration capabilities.
  • Work In Progress: This pull request is marked as a Work In Progress ([WIP]) and has a known 'abi type error' that needs to be addressed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces Value.Seq and Value.Seq2 to support ranging over reflect.Values. The implementation covers various kinds like integers, arrays, slices, strings, maps, channels, and functions. I've found a critical bug in the handling of pointers to arrays in both Seq and Seq2 that would cause a panic on subsequent uses of an iterator. I've suggested a refactoring that fixes this bug and also reduces code duplication. Additionally, I've pointed out an unclear comment that could be improved for better maintainability.

@xgopilot
Copy link
Contributor

xgopilot bot commented Dec 6, 2025

Code Review Summary

Solid implementation of Go 1.23 iterator support for reflect.Value. The code structure is clean and follows reflect package patterns well.

Critical Issues:

  • Nil pointer checks missing (lines 73, 137) - could cause panics
  • Resource exhaustion risk with large integers - no iteration limits
  • Documentation doesn't specify what's yielded per type (indices vs elements)

Other Notable:

  • Inconsistent Kind() vs kind() usage (line 135)
  • Heavy allocation overhead in loops (ValueOf per iteration)

Overall well-written, but security and documentation gaps need attention before merge.

@codecov
Copy link

codecov bot commented Dec 6, 2025

Codecov Report

❌ Patch coverage is 10.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.54%. Comparing base (7135b63) to head (f911fa5).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
ssa/abi/abi.go 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1442      +/-   ##
==========================================
- Coverage   90.65%   90.54%   -0.12%     
==========================================
  Files          43       43              
  Lines       11419    11423       +4     
==========================================
- Hits        10352    10343       -9     
- Misses        904      917      +13     
  Partials      163      163              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@visualfc visualfc changed the title [WIP] runtime: reflect Value.Seq/Seq2 runtime: reflect Value.Seq/Seq2 Dec 8, 2025
@xushiwei xushiwei merged commit 21ec089 into goplus:main Dec 9, 2025
40 of 42 checks passed
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