Skip to content

[SR-12033] [Sema] Do not allow inferring defaultable closure () -> $T for autoclosure arguments result #35503

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 2 commits into from
Feb 10, 2021

Conversation

LucianoPAlmeida
Copy link
Contributor

Prevent defaultable closure binding to be added if its connected to an auto closure argument.
Sorry it took some time, but have been between other things and actually giving a thought if this would be the correct
approach and about source compatibility in this case.

Resolves SR-12033.

@LucianoPAlmeida LucianoPAlmeida requested a review from xedin January 20, 2021 01:25
Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

Looks much better, just need to figure out how to avoid adding new flags to the binding set (since they can't be maintained in incremental mode I'm working on).

@LucianoPAlmeida
Copy link
Contributor Author

Looks much better, just need to figure out how to avoid adding new flags to the binding set (since they can't be maintained in incremental mode I'm working on).

Great, I made some changes and now to track the exact DefaultConstraints that are "disallowed" instead of using a flag.
I've been following the recently PRs related to bindings(normally trying to learn something) but the understanding I have for what "incremental mode" is very little. So let me know if that should be sufficient or if I should try another approach =]

@xedin
Copy link
Contributor

xedin commented Jan 24, 2021

I'm working on making it right now. The idea is that determineBestBindings can avoid having to gather constraints and re-compute bindings all the time since that's just wasted work if constraints didn't change, instead bindings could be tracked in constraint graph as constraints are introduced and removed.

@LucianoPAlmeida
Copy link
Contributor Author

I'm working on making it right now. The idea is that determineBestBindings can avoid having to gather constraints and re-compute bindings all the time since that's just wasted work if constraints didn't change, instead bindings could be tracked in constraint graph as constraints are introduced and removed.

Awesome, it seems that it will give a good speed up on inference 🎉
So for this PR, should we wait on those changes to land to avoid any issues?

@xedin
Copy link
Contributor

xedin commented Jan 25, 2021

No really, it shouldn't collide with that work if everything is done in a stateless manner.

@LucianoPAlmeida
Copy link
Contributor Author

No really, it shouldn't collide with that work if everything is done in a stateless manner.

Right! I modify the approach to a way where we don't have a state on the binding set.
So let me know what you think :)

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

This is still state although passed in. Need to figure out how to do that without any form of state. Alternative solution might be to add that constraint to the binding set (since it doesn't affect the score) and remove it during finalization.

@LucianoPAlmeida
Copy link
Contributor Author

This is still state although passed in. Need to figure out how to do that without any form of state. Alternative solution might be to add that constraint to the binding set (since it doesn't affect the score) and remove it during finalization.

Ah ok, I see thanks :)
My understanding of state was never left anything on the binding set object. That is why I thought this will be fine to hold just while running the set of constraints, sorry for that.

@xedin
Copy link
Contributor

xedin commented Jan 26, 2021

No worries, I should have been more precise :)

@LucianoPAlmeida
Copy link
Contributor Author

Alternative solution might be to add that constraint to the binding set (since it doesn't affect the score) and remove it during finalization.

Right, looking into it!

@LucianoPAlmeida
Copy link
Contributor Author

Alternative solution might be to add that constraint to the binding set (since it doesn't affect the score) and remove it during finalization.

Hey @xedin :)
When you say "removing during finalization", do you mean remove the defaults from the set on finalize? Or actually removing the Bindings from default that are expected to be on the set at this point?

I'm trying to figure out why given:

$T3 arg conv $T2 [apply argument -> comparing call argument #0 to parameter #0 -> @autoclosure result];
$T3 closure can default to () -> $T4

If I try wait for finalization $T2 still gets bound to defaulted ($T2 potentially_incomplete involves_type_vars bindings={} defaults={() -> $T4}), even removing defaults for $T3 adjacents as well from inferredBindings (which is just $T2) .

@xedin
Copy link
Contributor

xedin commented Jan 29, 2021

Yes, my suggesting what dealing with it during finalize. The behavior you see is related to transitive inference, $T2 has access to bindings of $T3 and it know that it could be bound to any supertype of $T3 due to arg conversion constraint so it infers defaults from $T3.

@LucianoPAlmeida
Copy link
Contributor Author

The behavior you see is related to transitive inference, $T2 has access to bindings of $T3 and it know that it could be bound to any supertype of $T3 due to arg conversion constraint so it infers defaults from $T3.

Ah that makes sense, thanks :)

@LucianoPAlmeida LucianoPAlmeida requested a review from xedin January 30, 2021 18:10
@LucianoPAlmeida LucianoPAlmeida force-pushed the SR-12033-autoclosure branch 2 times, most recently from 6a1a511 to 053db31 Compare January 31, 2021 23:04
@LucianoPAlmeida LucianoPAlmeida force-pushed the SR-12033-autoclosure branch 3 times, most recently from 6b89be0 to b5b687a Compare February 5, 2021 03:10
@LucianoPAlmeida LucianoPAlmeida requested a review from xedin February 5, 2021 03:14
@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please smoke test

@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please test source compatibility

1 similar comment
@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please test source compatibility

@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please smoke test MacOS platform

@LucianoPAlmeida
Copy link
Contributor Author

Compat suit seems to be broken on building spm

09:41:37 fatal error
09:41:37 : module map file '/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/build/compat_macos/swiftpm-macosx-x86_64/apple/Intermediates.noindex/GeneratedModuleMaps/macosx/CCryptoBoringSSL.modulemap' not found

@LucianoPAlmeida
Copy link
Contributor Author

I'm still looking but suspect it could be something related to recent changes on apple/swift-crypto#71

@LucianoPAlmeida
Copy link
Contributor Author

swiftlang/swift-package-manager#3238
@swift-ci Please test source compatibility

@LucianoPAlmeida
Copy link
Contributor Author

Ping @compnerd @yim-lee
To check if compat issue is indeed related to that PR? :)

@yim-lee
Copy link
Contributor

yim-lee commented Feb 6, 2021

We haven't merged swiftlang/swift-package-manager#3238 yet but could be related to swiftlang/swift-package-manager#3202. Investigating.

@compnerd
Copy link
Member

compnerd commented Feb 6, 2021

I think that @yim-lee is correct about swiftlang/swift-package-manager#3202 raising this issue - but I'm not sure I understand how it is causing the issue as of yet. It seems to be looking for a generated modulemap, which is not needed as swift-crypto provides a pre-generated one. I wonder if there is some cached content.

@LucianoPAlmeida
Copy link
Contributor Author

Thanks for looking @yim-lee @compnerd =]

Seems like the clean suit didn't trigger

@yim-lee
Copy link
Contributor

yim-lee commented Feb 6, 2021

@LucianoPAlmeida We will need @shahmishal's help with #35503 (comment). Sorry for the trouble!

@LucianoPAlmeida
Copy link
Contributor Author

@LucianoPAlmeida We will need @shahmishal's help with #35503 (comment). Sorry for the trouble!

No worries! Thank you for looking :))

@LucianoPAlmeida
Copy link
Contributor Author

@swift-ci Please test source compatibility

@LucianoPAlmeida
Copy link
Contributor Author

Seems like there is a FAIL is source compatibility suit https://ci.swift.org/job/swift-PR-source-compat-suite-debug/3508//artifact/swift-source-compat-suite/FAIL_Dollar-Dollar.xcodeproj_4.0_BuildXcodeProjectScheme_Dollar_generic-platform-macOS.log, I'm still not sure how those changes could cause this issue... it seems unrelated but I can't say for sure ...

@shahmishal
Copy link
Member

This is the same failure on the main branch, it's not related to your change.

@LucianoPAlmeida
Copy link
Contributor Author

This is the same failure on the main branch, it's not related to your change.

Ah great, thank you @shahmishal :)

@LucianoPAlmeida
Copy link
Contributor Author

So @xedin anything else on this one?

@xedin xedin merged commit daa4fff into swiftlang:main Feb 10, 2021
@xedin
Copy link
Contributor

xedin commented Feb 10, 2021

Nope, this is great :)

@LucianoPAlmeida
Copy link
Contributor Author

Haha I ping you at the same time 🤣 😆
Thank you! :)

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.

5 participants