Skip to content

[sil-capture-promotion] Properly handle generic SILBoxTypes #8420

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
Mar 30, 2017

Conversation

swiftix
Copy link
Contributor

@swiftix swiftix commented Mar 30, 2017

  • Use SILFunction::getTypeLowering, because it knows how to handle generic contexts properly
  • Map interface types into context
  • Fix a use-after-release runtime bug, uncovered by recent Erik's changes.

Fixes rdar://31309883.

@swiftix
Copy link
Contributor Author

swiftix commented Mar 30, 2017

@swift-ci please test

@swiftix
Copy link
Contributor Author

swiftix commented Mar 30, 2017

@slavapestov Does this fix make sense?

{
Lowering::GenericContextScope GenericScope(
F->getModule().Types, paramBoxTy->getLayout()->getGenericSignature());
auto &paramTL = F->getModule().Types.getTypeLowering(paramBoxedTy);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we not have a getTypeLowering() method on SILFunction itself?

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure the context is needed? The box should know how to lower itself without you pushing it's generic signature. @jckarter

Copy link
Contributor Author

@swiftix swiftix Mar 30, 2017

Choose a reason for hiding this comment

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

The box knows how to lower itself, yes. But it returns a lowered SILType.
And we need this TypeLowering paramTL , because the code that follows uses it in conditional statements like:

      if (paramTL.isFormallyPassedIndirectly()) {
        convention = ParameterConvention::Indirect_In;
      } else if (paramTL.isTrivial()) {
        convention = ParameterConvention::Direct_Unowned;
      } else {
        convention = ParameterConvention::Direct_Owned;

That's why a used an explicit generic context to get the TypeLowering, as this is what was used before. I was not sure how to call isFormallyPassedIndirectly directly on SILType, because it asks for a GenericSignature and ResilienceExpansion.

@slavapestov
Copy link
Contributor

@jckarter I'm not qualified to review this -- can you take a quick look?

@slavapestov
Copy link
Contributor

@swiftix Is there no test case and you noticed this by inspection, or...?

@swiftix
Copy link
Contributor Author

swiftix commented Mar 30, 2017

@slavapestov No, it is a crasher on an external project.

@swiftix swiftix force-pushed the fix-rdar-31309883 branch from 8486648 to 7ce5860 Compare March 30, 2017 01:30
@swiftix
Copy link
Contributor Author

swiftix commented Mar 30, 2017

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 848664836685da06083099917fd5f7febe46d9f5
Test requested by - @swiftix

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 848664836685da06083099917fd5f7febe46d9f5
Test requested by - @swiftix

@swiftix swiftix changed the title [sil-capture-propagation] Properly handle generic SILBoxTypes [sil-capture-promotion] Properly handle generic SILBoxTypes Mar 30, 2017
{
Lowering::GenericContextScope GenericScope(
F->getModule().Types, paramBoxTy->getLayout()->getGenericSignature());
auto &paramTL = F->getTypeLowering(paramBoxedTy);
Copy link
Contributor

Choose a reason for hiding this comment

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

paramBoxTy->getFieldType ought to give you a type in the surrounding generic context. You shouldn't need to push the box layout's generic signature as a context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jckarter I think I found the actual issue. The current code in the master uses:

 auto &paramTL = F->getModule().Types.getTypeLowering(paramBoxedTy);

whereas the right thing to do would be:

 auto &paramTL = F->getTypeLowering(paramBoxedTy);

SILFunction:: getTypeLowering actually pushes the right generic context, etc.

I'll try to come up with a reduced test-case.

@slavapestov
Copy link
Contributor

@swiftix This is why a reduced test case would be great -- then we can look at it and figure out what the correct behavior should be. At this stage I don't think either one of us is comfortable with this change.

@swiftix swiftix force-pushed the fix-rdar-31309883 branch from 7ce5860 to 1ec6a8e Compare March 30, 2017 07:00
@swiftix
Copy link
Contributor Author

swiftix commented Mar 30, 2017

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 7ce58601b3f67b5e819a8e8db0692844121f8a74
Test requested by - @swiftix

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 7ce58601b3f67b5e819a8e8db0692844121f8a74
Test requested by - @swiftix

@swiftix
Copy link
Contributor Author

swiftix commented Mar 30, 2017

@jckarter @slavapestov Added a test case and simplified the code. Does it look OK now?


// CHECK-LABEL: sil @_T023generic_promotable_box2Tf2nni_n : $@convention(thin) <T> (@in R<T>, @in Builtin.Int32, @owned E<(R<T>) -> Builtin.Int32>) -> ()
// CHECK: bb0(%0 : $*R<T>, %1 : $*Builtin.Int32, %2 : $E<(R<T>) -> Builtin.Int32>):
// CHECK-NOT: project_box
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a CHECK: line that ensures the promoted stack slot has type $*E<(R<T>)->Int> would be a good idea. LGTM otherwise.

- Use SILFunction::getTypeLowering, because it knows how to handle generic contexts properly
- Map interface types into context
- Fix a use-after-release runtime bug, uncovered by recent Erik's changes.

Fixes rdar://31309883.
@swiftix swiftix force-pushed the fix-rdar-31309883 branch from 1ec6a8e to 7887eb3 Compare March 30, 2017 21:10
@swiftix
Copy link
Contributor Author

swiftix commented Mar 30, 2017

@swift-ci please test and merge

1 similar comment
@swiftix
Copy link
Contributor Author

swiftix commented Mar 30, 2017

@swift-ci please test and merge

@gottesmm gottesmm merged commit 585c527 into swiftlang:master Mar 30, 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.

5 participants