-
Notifications
You must be signed in to change notification settings - Fork 10.5k
IRGen: Ensure collocation of relative pointers in resilient witness tables #15793
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
aschwaighofer
merged 1 commit into
swiftlang:master
from
aschwaighofer:irgen_relative_pointers_in_resilient_witness_table
Apr 6, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1832,10 +1832,6 @@ static llvm::Constant *emitResilientWitnessTable(IRGenModule &IGM, | |
SILFunction *Func = entry.getMethodWitness().Witness; | ||
llvm::Constant *witness; | ||
if (Func) { | ||
// Force the thunk to be emitted in the current translation unit | ||
// when in multi-threaded mode. | ||
IGM.IRGen.forceLocalEmitOfLazyFunction(Func); | ||
|
||
witness = IGM.getAddrOfSILFunction(Func, NotForDefinition); | ||
} else { | ||
// The method is removed by dead method elimination. | ||
|
@@ -2046,6 +2042,21 @@ llvm::Constant *WitnessTableBuilder::buildInstantiationFunction() { | |
return fn; | ||
} | ||
|
||
void IRGenModule::ensureRelativeSymbolCollocation(SILWitnessTable &wt) { | ||
// Only resilient conformances use relative pointers for witness methods. | ||
if (wt.isDeclaration() || isAvailableExternally(wt.getLinkage()) || | ||
!isResilientConformance(wt.getConformance())) | ||
return; | ||
|
||
for (auto &entry : wt.getEntries()) { | ||
if (entry.getKind() != SILWitnessTable::Method) | ||
continue; | ||
auto *witness = entry.getMethodWitness().Witness; | ||
if (witness) | ||
IRGen.forceLocalEmitOfLazyFunction(witness); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using IRGen.forceLocalEmitOfLazyFunction here. |
||
} | ||
} | ||
|
||
/// Do a memoized witness-table layout for a protocol. | ||
const ProtocolInfo &IRGenModule::getProtocolInfo(ProtocolDecl *protocol) { | ||
return Types.getProtocolInfo(protocol); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public func test() { | ||
inlineThis(Character("1")) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-swift-frontend -module-name test -num-threads 1 -O -c -g %S/Inputs/resilient-witness-2.swift %s -o %t/resilient-witness-2.o -o %t/resilient-witness.o | ||
// RUN: %target-swift-frontend -module-name test -num-threads 1 -O -emit-ir -g %S/Inputs/resilient-witness-2.swift %s -o %t/resilient-witness-2.ll -o %t/resilient-witness.ll | ||
// RUN: %FileCheck %s < %t/resilient-witness.ll | ||
|
||
// We used to crash on this test case during code generation because the | ||
// resilient witness table and the witness of the equatable conformance was | ||
// emitted into different files. Because the witness is expressed as a relative | ||
// pointer this was problematic. | ||
|
||
class Context { | ||
enum SomeEnum: Int { | ||
case One = 1 | ||
case MinusOne = -1 | ||
|
||
init?(_ delimiter: Character) { | ||
switch delimiter { | ||
case "1": | ||
self = .One | ||
case "-": | ||
self = .MinusOne | ||
default: | ||
return nil | ||
} | ||
} | ||
} | ||
private struct SomeEnumStruct { | ||
var e: SomeEnum? | ||
} | ||
|
||
private var arr: [SomeEnumStruct?] = [] | ||
} | ||
|
||
public func inlineThis(_ char: Character) { | ||
if Context.SomeEnum(char) == .MinusOne { | ||
print("foobar") | ||
} | ||
} | ||
|
||
// The witness table and witness definition need to be in the same file. | ||
|
||
// CHECK: @"$S4test7ContextC8SomeEnumOs9EquatableAAWr" = {{.*}}sub {{.*}} @"$S4test7ContextC8SomeEnumOs9EquatableAAsAFP2eeoiySbx_xtFZTW" {{.*}} @"$S4test7ContextC8SomeEnumOs9EquatableAAWr" | ||
|
||
// CHECK: define{{.*}}@"$S4test7ContextC8SomeEnumOs9EquatableAAsAFP2eeoiySbx_xtFZTW"({{.*}}){{.*}} { | ||
// CHECK-NEXT: entry: |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was the only usage of forceLocalEmitOfLazyFunction so you can remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now use it in ensureRelativeSymbolCollocation.