Skip to content

Normalise optics when constructing VarName; remove extra constructors #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 6, 2025

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Jul 5, 2025

Closes #122.

I also added a changelog, because I've actually found it super helpful for DynamicPPL/Turing. I'm going to copy paste from it to describe this PR:

  • Removed the constructors VarName(vn, optic) (this wasn't deprecated, but is IMO quite dangerous as it silently discards the existing optic in vn), and VarName(vn, ::Tuple) (which was deprecated).
  • In the inner constructor of a VarName, its optic is now normalised to ensure that the associativity of ComposedFunction is always the same, and that compositions with identity are removed. This helps to prevent subtle bugs where VarNames with semantically equal optics are not considered equal.

Also changed all usage of ComposedOptic to ComposedFunction (it's the same thing: https://github.com/JuliaObjects/Accessors.jl/blob/18e9ddbc727ed4e48a3c19ffa00a02f7f407cdb5/src/optics.jl#L129).

Copy link

codecov bot commented Jul 5, 2025

Codecov Report

Attention: Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.

Project coverage is 83.56%. Comparing base (a39791b) to head (7bc83d8).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/varname.jl 96.87% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #123      +/-   ##
==========================================
+ Coverage   82.43%   83.56%   +1.12%     
==========================================
  Files           2        2              
  Lines         296      292       -4     
==========================================
  Hits          244      244              
+ Misses         52       48       -4     

☔ 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.

@coveralls
Copy link

coveralls commented Jul 5, 2025

Pull Request Test Coverage Report for Build 16098270412

Details

  • 29 of 32 (90.63%) changed or added relevant lines in 1 file are covered.
  • 16 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+1.1%) to 83.562%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/varname.jl 29 32 90.63%
Files with Coverage Reduction New Missed Lines %
src/varname.jl 16 78.09%
Totals Coverage Status
Change from base Build 16091588928: 1.1%
Covered Lines: 244
Relevant Lines: 292

💛 - Coveralls

@penelopeysm penelopeysm changed the title Normalise optics when constructing VarName Normalise optics when constructing VarName; remove extra constructors Jul 5, 2025
Copy link
Contributor

github-actions bot commented Jul 5, 2025

AbstractPPL.jl documentation for PR #123 is available at:
https://TuringLang.github.io/AbstractPPL.jl/previews/PR123/

@penelopeysm penelopeysm requested a review from sunxd3 July 5, 2025 20:01
Copy link
Member

@sunxd3 sunxd3 left a comment

Choose a reason for hiding this comment

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

lgtm

maybe add a comment somewhere saying that ComposedOptics is just a alias of ComposedFunctions? (I opted for ComposedOptics when migrating to Accessors because I thought it's simpler to understand in context of the migration. But I support use ComposedFunction now.)

@penelopeysm
Copy link
Member Author

(I opted for ComposedOptics when migrating to Accessors because I thought it's simpler to understand in context of the migration. But I support use ComposedFunction now.)

That makes sense. I guess it's really Julia that had me confused 😄 , since Accessors writes const ComposedOptic = ComposedFunction whenever you dump something it prints as ComposedFunction.

julia> using Accessors

julia> @o _.a.b
(@o _.a.b)

julia> dump(ans)
(@o _.a.b) (function of type ComposedFunction{PropertyLens{:b}, PropertyLens{:a}})
  outer: PropertyLens{:b} (@o _.b)
  inner: PropertyLens{:a} (@o _.a)

I'll add a note!

@penelopeysm penelopeysm merged commit 7be9556 into main Jul 6, 2025
11 checks passed
@penelopeysm penelopeysm deleted the py/composed-assoc branch July 6, 2025 10:58
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.

nasty edge cases with prefix and unprefix
3 participants