Skip to content

refactor(value): migrate Value::Set to Set storage abstraction - #778

Draft
Anand Krishnamoorthi (anakrish) wants to merge 1 commit into
microsoft:mainfrom
anakrish:set-abstraction-migration
Draft

refactor(value): migrate Value::Set to Set storage abstraction#778
Anand Krishnamoorthi (anakrish) wants to merge 1 commit into
microsoft:mainfrom
anakrish:set-abstraction-migration

Conversation

@anakrish

Copy link
Copy Markdown
Collaborator

Switch Value::Set from Rc<BTreeSet> to Rc, wiring the previously-merged Set wrapper struct (#740) into the enum and updating all call sites across interpreter, RVM, builtins, serialization, and languages. Mirrors the merged Object migration (#736).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR completes the Value::Set storage migration by switching the enum payload from Rc<BTreeSet<Value>> to Rc<value::Set>, wiring in the Set abstraction introduced earlier and updating call sites across RVM, builtins, serialization, language compilers, and tests. This follows the same “opaque storage wrapper” pattern as the prior Value::ObjectObject migration, reducing direct dependence on the concrete collection type.

Changes:

  • Replace Value::Set(Rc<BTreeSet<Value>>) with Value::Set(Rc<Set>), update From<BTreeSet<Value>> for Value, and adjust as_set / as_set_mut to return &Set / &mut Set.
  • Update RVM set iteration to mirror object iteration by using an opaque resumable SetCursor over a shared Rc<Set> (removing the prior current_item / first_iteration snapshot scheme).
  • Migrate set construction and set algebra call sites (union/intersection/difference) to use the Set API and Value::from(...) conversions.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/rvm/compiler.rs Updates expected literal set construction to use Value::from(BTreeSet<_>) instead of manually constructing Value::Set(Rc<...>).
src/value/set/mod.rs Adjusts Set::iter to return the stable wrapper iterator type and updates Set::into_value to produce Rc<Set>-backed Value::Set.
src/value/mod.rs Switches Value::Set payload type to Rc<Set> and updates conversions/accessors accordingly.
src/rvm/vm/loops.rs Refactors set loop iteration to use SetCursor and Set::next, removing manual resume snapshotting.
src/rvm/vm/dispatch.rs Updates set literal construction to use Value::from(BTreeSet) conversion.
src/rvm/vm/context.rs Updates IterationState::Set to store Rc<Set> and SetCursor, aligning semantics with object iteration.
src/rvm/vm/comprehension.rs Updates comprehension-driven set iteration to use SetCursor and removes now-unneeded snapshot/resume logic.
src/rvm/vm/arithmetic.rs Switches set subtraction to use Set::difference returning a Set, then Value::from(Set).
src/rvm/program/serialization/value.rs Switches binary set serialization to accept &Set and iterates via iter_sorted() for canonical ordering.
src/rvm/program/metadata.rs Updates metadata set construction to use Value::from_set(...) helper (now producing Rc<Set> internally).
src/languages/rego/compiler/expressions/collection_literals.rs Updates constant set evaluation/hoisting to construct sets via Value::from_set(...).
src/languages/azure_rbac/builtins/lists.rs Updates helper signature to accept &Set and uses Set::contains.
src/languages/azure_policy/compiler/metadata.rs Updates set-valued annotations to use Value::from_set(...).
src/builtins/utils.rs Updates ensure_set to return Rc<Set> instead of Rc<BTreeSet<Value>>.
src/builtins/sets.rs Migrates set builtins to Set operations (union/intersection/difference) returning Set and wrapping via Value::from(Set).

@anakrish
Anand Krishnamoorthi (anakrish) force-pushed the set-abstraction-migration branch 2 times, most recently from 0fc87fb to ef809a8 Compare August 4, 2026 20:51
Switch Value::Set from Rc<BTreeSet<Value>> to Rc<Set>, wiring the
previously-merged Set wrapper struct (microsoft#740) into the enum and updating
all call sites across interpreter, RVM, builtins, serialization, and
languages. Mirrors the merged Object migration (microsoft#736).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: fc92437e-8820-49a4-ba5f-ec82a79f1221
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