Skip to content

Fix implicit BTreeMap clones on Attributes::into_iter - #2518

Open
john-h-kastner-aws wants to merge 3 commits into
mainfrom
fix-implicit-btreemap-clones
Open

Fix implicit BTreeMap clones on Attributes::into_iter#2518
john-h-kastner-aws wants to merge 3 commits into
mainfrom
fix-implicit-btreemap-clones

Conversation

@john-h-kastner-aws

@john-h-kastner-aws john-h-kastner-aws commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Description of changes

The IntoIter implementation for Attributes, was self.attrs.as_ref().clone().into_iter() where self.attrs is an Arc<BTreeMap<_, _>>, so the whole map (not the Arc) was cloned on every into_iter call.

Since the type wraps an Arc, it can't meaningfully implement IntoIter other than by cloning the iter elements (which would be better than the current implementations), but It's preferable to have callers explicitly call iter().cloned() if they need owned elements, so I've removed the IntoIter implementation entirely.

Multiple call sites in policy validation should benefit from this.

Issue #, if available

Checklist for requesting a review

The change in this PR is (choose one, and delete the other options):

  • A breaking change requiring a major version bump to cedar-policy (e.g., changes to the signature of an existing API).
  • A backwards-compatible change requiring a minor version bump to cedar-policy (e.g., addition of a new API).
  • A bug fix or other functionality change requiring a patch to cedar-policy.
  • A change "invisible" to users (e.g., documentation, changes to "internal" crates like cedar-policy-core, cedar-validator, etc.)
  • A change (breaking or otherwise) that only impacts unreleased or experimental code.

I confirm that this PR (choose one, and delete the other options):

  • Updates the "Unreleased" section of the CHANGELOG with a description of my change (required for major/minor version bumps).
  • Does not update the CHANGELOG because my change does not significantly impact released code.

I confirm that cedar-spec (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar formal model or DRT infrastructure.
  • Requires updates, and I have made / will make these updates myself. (Please include in your description a timeline or link to the relevant PR in cedar-spec, and how you have tested that your updates are correct.)
  • Requires updates, but I do not plan to make them in the near future. (Make sure that your changes are hidden behind a feature flag to mark them as experimental.)
  • I'm not sure how my change impacts cedar-spec. (Post your PR anyways, and we'll discuss in the comments.)

I confirm that docs.cedarpolicy.com (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar language specification.
  • Requires updates, and I have made / will make these updates myself. (Please include in your description a timeline or link to the relevant PR in cedar-docs. PRs should be targeted at a staging-X.Y branch, not main.)
  • I'm not sure how my change impacts the documentation. (Post your PR anyways, and we'll discuss in the comments.)

Signed-off-by: jkastner <jkastner@amazon.com>
Signed-off-by: jkastner <jkastner@amazon.com>
@github-actions

Copy link
Copy Markdown

Coverage Report

Head Commit: 82cd2a842cc4952fb89ca685dffe90b1ed5e0a6e

Base Commit: 261b20363388c8715097ab98f246401e5e157d2f

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 88.00%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-language-server/src/policy/types/cedar.rs 🟢 1/1 100.00%
cedar-policy-core/src/validator/schema.rs 🟢 20/24 83.33% 834-837
cedar-policy-core/src/validator/schema/namespace_def.rs 🟢 6/6 100.00%
cedar-policy-core/src/validator/typecheck.rs 🟢 2/2 100.00%
cedar-policy-core/src/validator/types.rs 🟢 11/13 84.62% 425, 1145
cedar-policy-symcc/src/symcc/env.rs 🟢 4/4 100.00%

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 88.36%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-language-server 🟢 4716/5102 92.43% 92.55%
cedar-policy 🟢 4844/5950 81.41% 81.41%
cedar-policy-cli 🟡 1294/1669 77.53% 77.53%
cedar-policy-core 🟢 24648/27809 88.63% 88.65%
cedar-policy-formatter 🟢 914/1088 84.01% 84.01%
cedar-policy-symcc 🟢 6921/7401 93.51% 93.51%
cedar-wasm 🔴 0/28 0.00% 0.00%

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.

3 participants