Skip to content

[CSSolver] Refactor selectBestBindingDisjunction #18785

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 1 commit into from
Aug 18, 2018

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Aug 17, 2018

Add an assert which verifies that all of the disjunction
choices has the same type variable on the left-hand side.

Based on that fact, refactor selectBestBindingDisjunction
to only check first choice to find suitable "bind" disjunctions
to favor.

@xedin xedin requested a review from rudkx August 17, 2018 09:13
@xedin
Copy link
Contributor Author

xedin commented Aug 17, 2018

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Aug 17, 2018

@swift-ci please test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - acb94b22abbf7ba811366ec674f4ed8395020453

@xedin
Copy link
Contributor Author

xedin commented Aug 17, 2018

<unknown>:0: error: unsupported option '-sanitize=thread' for target 'i386-apple-ios7.0'

@xedin
Copy link
Contributor Author

xedin commented Aug 17, 2018

Looks like it's going to be resolved by #18797

Type commonType;
assert(llvm::all_of(constraints, [&](const Constraint *choice) -> bool {
auto currentType = choice->getFirstType()->lookThroughAllOptionalTypes();
assert(currentType);
Copy link
Contributor

Choose a reason for hiding this comment

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

This assert doesn't seem all that useful since we would crash in lookThroughAllOptionalTypes() if getFirstType() returned false and lookThroughAllOptionalTypes() never returns nullptr (and it would break code all over if that changed).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, right, just went overly paranoid... :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed assert and made it so we skip disjunctions formed by restrictions/fixes, this way we don't have to lookThroughAllOptionalTypes


return commonType->isEqual(currentType);
}));
(void)commonType;
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't need this as the declaration is under #ifndef.

@xedin xedin force-pushed the select-best-disjunction-improvements branch from acb94b2 to 838f87f Compare August 17, 2018 19:34
@xedin
Copy link
Contributor Author

xedin commented Aug 17, 2018

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - acb94b22abbf7ba811366ec674f4ed8395020453

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - acb94b22abbf7ba811366ec674f4ed8395020453

// Only do this for simple type variable bindings, not for
// bindings like: ($T1) -> $T2 bind String -> Int
if (auto *typeVar = getAsTypeVar(choice->getFirstType()))
bindingDisjunctions.push_back({disjunction, typeVar});
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned in the other review thread we should be able to just immediately gather the constraints for the type variable and do the test below rather than collecting all the disjunctions and then going back through them and gathering constraints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sure, I can do that too! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just didn't want to change the shape too much...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, new changes are in!

@xedin xedin force-pushed the select-best-disjunction-improvements branch from 838f87f to 96b7bc8 Compare August 17, 2018 22:46
@xedin
Copy link
Contributor Author

xedin commented Aug 17, 2018

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 838f87f900222af11dcf13f93104bb8711f3a4b0

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 838f87f900222af11dcf13f93104bb8711f3a4b0

->getRValueType()
->getAs<TypeVariableType>();
assert(tv);
bindingDisjunctions.push_back(disjunction);
Copy link
Contributor

Choose a reason for hiding this comment

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

This no longer needs to be a vector. You should just be able to keep track of the fact that you saw some binding disjunction and return it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugh, right...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed! This is now net-negative locs :)

Add an assert which verifies that all of the disjunction
choices has the same type variable on the left-hand side.

Based on that fact, refactor `selectBestBindingDisjunction`
to only check first choice to find suitable "bind" disjunctions
to favor.
@xedin xedin force-pushed the select-best-disjunction-improvements branch from 96b7bc8 to e81ce93 Compare August 18, 2018 00:47
@xedin
Copy link
Contributor Author

xedin commented Aug 18, 2018

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 96b7bc8f630dffb94952c6751dfd873e381e68c2

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 96b7bc8f630dffb94952c6751dfd873e381e68c2

Copy link
Contributor

@rudkx rudkx left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for cleaning this up!

@xedin
Copy link
Contributor Author

xedin commented Aug 18, 2018

@swift-ci please test source compatibility

@xedin xedin merged commit 007375b into swiftlang:master Aug 18, 2018
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.

3 participants