Skip to content
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

Unused field policies, Merging transformations, Recursive Patchers #614

Merged
merged 79 commits into from
Jan 23, 2025

Conversation

MateuszKubuszok
Copy link
Member

@MateuszKubuszok MateuszKubuszok commented Oct 3, 2024

This PR will implement the long awaited:

  1. transformations from more than 1 value - Support for mapping multiple case classes #115
  2. setting policy for unused fields/unmatched subtypes - Policy for checking which fields were used for transformation #248
  3. using the 2 above to reimplement Patchers - Rewrite Patchers as a special case of multiple case classes mapping #538
  4. enhance Patchers:
    1. make them recursive - Nested patchers don't work with subset of fields #119
    2. allow using implicit Patcher in nested fields - Support nested patchers that look for implicits #133
    3. allow using custom logic for setting fields - Support custom patching logic #134
    4. allow ignoring some fields in Patch - Allow to ignore specific field in patchers #161, Patching from another instance of the same case class #57

No ETA at the moment.

Plan

  1. kick-off policies
  2. kick off fallbacks
  3. implement product to product merge
  4. impliment Optional values merge
  5. reimplement Patchers special case as special case of merging transformtion
  6. add support to corresponding merges and Patchers rules at once
  7. more detailed tests and docs last

Progress

  • unused field policy/unmatched subtype policy - Policy for checking which fields were used for transformation #248

    • unused fields
      • add flags
      • add DSL
      • parse new flags
      • use new flags
      • test new flags
      • add withFieldUnused to suppress errors per field with policy enabled
      • test suppressing
      • mkdocs
      • scaladocs + mkdocs links
    • unmatched subtypes
      • add flags
      • add DSL
      • parse new flags
      • use new flags
      • test new flags
      • add withSubtypeUnmatched to suppress errors per subtype with policy enabled
      • test suppressing
      • mkdocs
      • scaladocs + mkdocs links
  • merging transformations - Support for mapping multiple case classes #115

    • add Fallback to TransformerOverrides
    • add withFallback DSL method
    • add withFallbackFrom DSL method
    • add val fallbacks: List[(Path, ExistentialExpr)] to TransformationContext
    • parse TransformerOverrides.Fallback type in TransformerConfiguration
    • add ability to update fallbacks list next to src: Expr[From] in recursion
    • new mkdocs section
    • ProductToProduct
      • lazily, obtain extractors for each fallback
      • find first extractor matching to pass value down in field resolution
      • convert current type's fallbacks list into a fallback list for the handled field
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • OptionToOption/ToOption/UnwrapOption
      • add a flag to decide how option should be handled: source only, orElse chain
      • filter out non-Option fallbacks for recursion, leave others
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • IterableToIterable/MapToMap
      • add a flag to decide how collections should be treated: source only, append
      • filter-out collection-fallbacks for recursion, leave other
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • EitherToEither
      • Either orElse (with 2.12 workaround)
      • add a flag to decide how option should be handled: source only, orElse chain
      • filter out non-Either fallbacks for recursion, leave others
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • SealedToSealed
      • sealed to sealed - pass fallbacks unchanged
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • AnyVal rules
      • unwrap fallbacks
      • tests
      • mkdocs
      • scaladocs + mkdocs links
  • recursive Patchers - Rewrite Patchers as a special case of multiple case classes mapping #538, Nested patchers don't work with subset of fields #119, Support nested patchers that look for implicits #133

    • translate PatchingContext -> TransformationContext
    • override rules (add implicit Patcher rule!)
    • delegate patching to merging transformations
    • new section in mkdocs
    • providing custom patching values - Support custom patching logic #134
      • withFieldConst+withFieldComputed
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • ignoring patcher fields - Allow to ignore specific field in patchers #161, Patching from another instance of the same case class #57
      • withFieldIgnored
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • scoped flags
      • withPatchedValueFlag
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • Products
      • new rule
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • Options
      • new rule
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • collections
      • new rule
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • Eithers
      • new rule
      • tests
      • mkdocs
      • scaladocs + mkdocs links
    • AnyVals
      • mkdocs
      • scaladocs + mkdocs links
  • other docs

    • update all @since TODO
    • make sure all new DSL types have scaladoc
    • update landing page with merged and patchers
    • update feature list
    • update macro settings section
    • update Ducktape section - allMatching can we replaced with merge transformers in many cases
    • update under the hood

Excluded from this PR

Can be implemented later (if anyone would need it):

  • merging product with exactly 1 sealed fallback (and 0 or more other product fallbacks)
  • patching sealed with sealed
  • porting every single flag/override from total transformers to patchers (java beans, method accessors, name comparisons, etc)

Copy link

codecov bot commented Jan 5, 2025

Codecov Report

Attention: Patch coverage is 82.39437% with 250 lines in your changes missing coverage. Please review.

Project coverage is 85.46%. Comparing base (1368dba) to head (aa9098c).
Report is 79 commits behind head on master.

Files with missing lines Patch % Lines
...letime/derivation/transformer/Configurations.scala 82.01% 34 Missing ⚠️
...ey/internal/compiletime/ChimneyTypesPlatform.scala 75.00% 27 Missing ⚠️
...ey/internal/compiletime/ChimneyTypesPlatform.scala 70.45% 26 Missing ⚠️
...atchCollectionWithOptionCollectionRuleModule.scala 15.00% 17 Missing ⚠️
.../rules/PatchEitherWithOptionEitherRuleModule.scala 15.00% 17 Missing ⚠️
...rnal/compiletime/dsl/PatcherDefinitionMacros.scala 0.00% 15 Missing ⚠️
...etime/dsl/PartialTransformerDefinitionMacros.scala 0.00% 12 Missing ⚠️
.../compiletime/dsl/TransformerDefinitionMacros.scala 0.00% 12 Missing ⚠️
...rnal/compiletime/dsl/PatcherDefinitionMacros.scala 0.00% 9 Missing ⚠️
...er/rules/TransformProductToProductRuleModule.scala 93.66% 9 Missing ⚠️
... and 23 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #614      +/-   ##
==========================================
- Coverage   86.38%   85.46%   -0.92%     
==========================================
  Files         160      181      +21     
  Lines        6873     8105    +1232     
  Branches      577      770     +193     
==========================================
+ Hits         5937     6927     +990     
- Misses        936     1178     +242     

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

@MateuszKubuszok MateuszKubuszok force-pushed the merging-transformations branch from d2f1c6d to 0d8b516 Compare January 7, 2025 13:03
@MateuszKubuszok MateuszKubuszok changed the title WIP: Merging transformations WIP: Unused field policies, Merging transformations Jan 13, 2025
@MateuszKubuszok MateuszKubuszok changed the title WIP: Unused field policies, Merging transformations WIP: Unused field policies, Merging transformations, Recursive Patchers Jan 14, 2025
@MateuszKubuszok MateuszKubuszok force-pushed the merging-transformations branch from 3b2e151 to fb092d6 Compare January 15, 2025 17:32
@MateuszKubuszok MateuszKubuszok force-pushed the merging-transformations branch 4 times, most recently from 7d289fc to ac74c93 Compare January 21, 2025 09:53
@MateuszKubuszok MateuszKubuszok changed the title WIP: Unused field policies, Merging transformations, Recursive Patchers Unused field policies, Merging transformations, Recursive Patchers Jan 22, 2025
@MateuszKubuszok MateuszKubuszok marked this pull request as ready for review January 22, 2025 11:57
@MateuszKubuszok MateuszKubuszok force-pushed the merging-transformations branch from f10847e to 7725b67 Compare January 23, 2025 10:31
@MateuszKubuszok MateuszKubuszok merged commit 508dabb into master Jan 23, 2025
22 of 24 checks passed
@MateuszKubuszok MateuszKubuszok deleted the merging-transformations branch January 23, 2025 12:09
@michaelbilow
Copy link

Awesome! Thank you @MateuszKubuszok

@nsutcliffe
Copy link

Amazing! Thank you so much @MateuszKubuszok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment