8000 Fix make macro by pablf · Pull Request #9147 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix make macro #9147

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

Closed
wants to merge 1 commit into from
Closed

Fix make macro #9147

wants to merge 1 commit into from

Conversation

pablf
Copy link
Member
@pablf pablf commented Aug 27, 2024

Graph implementation using a List instead of a Map so that possible differences in how scala registers as keys the types are not a problem. I think this should be somewhat faster and could potentially use more memory if there is a lot of redundancy.

@kyri-petrou, @RobVermazeren, @strokyl, I don't know if this fixes #9145 because I can't reproduce the issue. The tests for zio and zio-test were passing and I haven't been able to reproduce the issue locally with non-zio repositories. If someone of you could either open a repository with a working example of the issue so I can check what's happening or try this version locally, that would be really helpful!

Respect to the @butcherless issue, your error can only appear once the layer construction has been correct, so it isn't entirely related. I have added a fix for that. I don't know if it's the more appropriate as the layer construction is a bit more complex than before and can't be printed in such a nice way.

< 8000 div class="pr-review-reactions ">
Comment on lines +18 to +19
private def get(k: Key, m: List[Key]): Int =
m.count(key => areEquals(key, k))
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should add an exists method as well here just to avoid traversing the whole list in L84 below?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes and also create another custom method because we only need to differentiate between 0, 1 and >1 appearances in the other cases

m.count(key => areEquals(key, k))

private def areEquals(k1: Key, k2: Key): Boolean =
keyEquals(k1, k2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this needs to be keyEquals(k1, k2) || keyEquals(k2, k1)?

Copy link
Member Author

Choose a reason for hiding this comment

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

It shouldn't be needed but the order is important, maybe that was an issue if you tried this version also

Copy link
Member

Choose a reason for hiding this comment

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

Should probably have a test here to catch the "wrong" implementation.

@kyri-petrou
Copy link
Contributor

After making this change and publishing locally, it seems the test compilation errors are gone, but now I'm getting a different compilation error in Scala 3 with a very large provide in production code:

Exception occurred while executing macro expansion.
scala.MatchError: scala.quoted.runtime.impl.ExprImpl@17d09f29 (of class scala.quoted.runtime.impl.ExprImpl)
	at zio.internal.macros.LayerMacroUtils$.composeV$1(LayerMacroUtils.scala:78)
	at zio.internal.macros.LayerMacroUtils$.buildFinalTree$1$$anonfun$2$$anonfun$2(LayerMacroUtils.scala:87)
	at zio.internal.macros.LayerTree.fold(LayerTree.scala:20)
	at zio.internal.macros.LayerTree.fold(LayerTree.scala:20)
	at zio.internal.macros.LayerMacroUtils$.buildFinalTree$1$$anonfun$2(LayerMacroUtils.scala:87)
	at scala.quoted.runtime.impl.QuotesImpl$reflect$ValDef$.let(QuotesImpl.scala:352)
	at scala.quoted.runtime.impl.QuotesImpl$reflect$ValDef$.let(QuotesImpl.scala:348)
	at zio.internal.macros.LayerMacroUtils$.buildFinalTree$1(LayerMacroUtils.scala:87)
	at zio.internal.macros.LayerMacroUtils$.$anonfun$4(LayerMacroUtils.scala:100)
	at zio.internal.macros.LayerBuilder.build(LayerBuilder.scala:102)
	at zio.internal.macros.LayerMacroUtils$.constructLayer$$anonfun$1$$anonfun$1(LayerMacroUtils.scala:110)
	at zio.internal.macros.LayerMacroUtils$.constructLayer$$anonfun$1(LayerMacroUtils.scala:110)
	at zio.internal.macros.LayerMacroUtils$.constructLayer$$anonfun$adapted$1(LayerMacroUtils.scala:110)
	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:111)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1568)
	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
	at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock$$anonfun$1$$anonfun$1(tpd.scala:1245)
	at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1227)
	at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1240)
	at dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1245)
	at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1548)
	at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:136)
	at dotty.tools.dotc.quoted.PickledQuotes$.spliceTerms(PickledQuotes.scala:153)
	at dotty.tools.dotc.quoted.PickledQuotes$.unpickleTerm(PickledQuotes.scala:89)
	at scala.quoted.runtime.impl.QuotesImpl.unpickleExprV2(QuotesImpl.scala:3259)
	at zio.internal.macros.LayerMacroUtils$.constructLayer(LayerMacroUtils.scala:110)
	at zio.internal.macros.LayerMacros$.constructLayer(LayerMacros.scala:19)
	at zio.internal.macros.LayerMacros$.provideImpl(LayerMacros.scala:25)

@pablf pablf marked this pull request as draft August 28, 2024 22:38
@pablf pablf changed the title fix make macro Fix make macro Aug 28, 2024
@jdegoes
Copy link
Member
jdegoes commented Nov 8, 2024

@pablf Would like to get this in. Can you re-open when conflicts are merged and it's no longer a draft?? 🙏

@jdegoes jdegoes closed this Nov 8, 2024
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.

Release 2.1.8 introduces exception in macro expansion.
3 participants
0