Skip to content

Various AST transform improvements#1892

Merged
anderseknert merged 1 commit intoopen-policy-agent:mainfrom
anderseknert:transform-fixes
Feb 25, 2026
Merged

Various AST transform improvements#1892
anderseknert merged 1 commit intoopen-policy-agent:mainfrom
anderseknert:transform-fixes

Conversation

@anderseknert
Copy link
Copy Markdown
Member

Reduce allocations, fix some TODOs, and so on. Not much to see, just me doing anything but work on what I'm supposed to work on.

@srenatus srenatus changed the title Various AST transform improvemens Various AST transform improvements Feb 25, 2026

for i, comment := range mod.Comments {
encoded := base64.StdEncoding.EncodeToString(comment.Text)
encoded := "IE1FVEFEQVRB" // " METADATA"
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.

😄

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hah! Like 500+ of them in Regal alone :P

value := ast.NewObjectWithCapacity(1 +
min(1, len(mod.Imports)) +
min(1, len(mod.Rules)) +
min(1, len(mod.Comments)),
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.

I see what you did there... OK... Perhaps this would warrant a small (to-be-inlined) helper?

func selector[T ~[]](s T) int { // 1 or 0
  return min(1, len(T))
}

(untested)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm already well over my time budget, but noted for the next round 👍

Reduce allocations, fix some TODOs, and so on. Not much to see,
just me doing anything but work on what I'm supposed to work on.

Signed-off-by: Anders Eknert <anders.eknert@apple.com>
@anderseknert anderseknert enabled auto-merge (squash) February 25, 2026 09:28
@anderseknert anderseknert merged commit eca4e23 into open-policy-agent:main Feb 25, 2026
8 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