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

[CSSolver/SILGen] Fix solver to support function conversion with collection subtyping #13138

Merged
merged 1 commit into from
Dec 4, 2017

Conversation

xedin
Copy link
Member

@xedin xedin commented Nov 29, 2017

Fix collection subtyping relation in function argument position
by emiting special re-abstraction thunk with collection upcast.

Resolves: rdar://problem/35702810

@xedin
Copy link
Member Author

xedin commented Nov 29, 2017

@DougGregor please take a look, I most likely did it wrong but at least it works now :)

@@ -0,0 +1,21 @@
// RUN: %target-swift-frontend -emit-sil -verify %s | %FileCheck %s
Copy link
Member

Choose a reason for hiding this comment

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

Please put this test case in test/SILGen/function_conversions.swift together with the others, and add executable test to test/Interpreter/FunctionConversion.swift.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Will do!

@@ -490,6 +490,27 @@ ManagedValue Transform::transform(ManagedValue v,
}
}

if (outputSubstType->getStructOrBoundGenericStruct() &&
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment here to match the other comments in this function

@@ -2090,8 +2090,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
}

// Special implicit nominal conversions.
if (!type1->is<LValueType>() &&
Copy link
Member

Choose a reason for hiding this comment

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

Making these Subtype rather than Conversion is likely to have other consequences

Copy link
Member Author

Choose a reason for hiding this comment

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

I've talked to @DougGregor offline about this, upcasts were intended for everything >= Subtype which is one right before Conversion :)

@slavapestov
Copy link
Member

This is a language change, does it need an evolution proposal?

@xedin xedin changed the title [CSSolver/SILGen] Fix solver to support function conversion with collection subtyping [WIP] [CSSolver/SILGen] Fix solver to support function conversion with collection subtyping Nov 29, 2017
@xedin
Copy link
Member Author

xedin commented Nov 29, 2017

@slavapestov it's a bug, upcasts should have been supported to constraints starting from Subtype instead of starting from Conversion which is one position down from it...

@xedin
Copy link
Member Author

xedin commented Nov 30, 2017

@swift-ci please smoke test

@@ -490,6 +490,28 @@ ManagedValue Transform::transform(ManagedValue v,
}
}

// - upcasts for structs
Copy link
Member

Choose a reason for hiding this comment

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

"for collections" to be more precise

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah absolutely, sorry I was fixed on "generic struct" for some reason while writing that comment...

@xedin
Copy link
Member Author

xedin commented Nov 30, 2017

@swift-ci please test

@xedin
Copy link
Member Author

xedin commented Nov 30, 2017

@swift-ci please test source compatibility

@apple apple deleted a comment from swift-ci Nov 30, 2017
@apple apple deleted a comment from swift-ci Nov 30, 2017
@xedin
Copy link
Member Author

xedin commented Nov 30, 2017

@swift-ci please test source compatibility

@xedin
Copy link
Member Author

xedin commented Nov 30, 2017

@DougGregor @slavapestov are you ok if I merge it as is (i've fixed the comment)?

@@ -490,6 +490,28 @@ ManagedValue Transform::transform(ManagedValue v,
}
}

// - upcasts for collections
Copy link
Member

Choose a reason for hiding this comment

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

It looks like you should check that the input and output struct decls are the same. Otherwise, [T] to AnyHashable conversion will fail, since we check for that further down. Can you add a test?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, will do!

…ection subtyping

Fix collection subtyping relation in function argument position
by emiting special re-abstraction thunk with collection upcast.

Resolves: rdar://problem/35702810
@xedin
Copy link
Member Author

xedin commented Dec 1, 2017

@slavapestov Does this look better? I've updated both Interpreter and SILGen tests.

@xedin
Copy link
Member Author

xedin commented Dec 3, 2017

@swift-ci please test

@apple apple deleted a comment from swift-ci Dec 3, 2017
@apple apple deleted a comment from swift-ci Dec 3, 2017
@xedin
Copy link
Member Author

xedin commented Dec 3, 2017

@swift-ci please test source compatibility

@xedin xedin changed the title [WIP] [CSSolver/SILGen] Fix solver to support function conversion with collection subtyping [CSSolver/SILGen] Fix solver to support function conversion with collection subtyping Dec 4, 2017
@xedin xedin merged commit 6ca3d3f into apple:master Dec 4, 2017
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.

None yet

2 participants