@@ -990,7 +990,7 @@ class irgen::ConformanceInfo {
990
990
CanType conformingType) const = 0;
991
991
};
992
992
993
- static std::pair< llvm::Value *, llvm::Value *>
993
+ static llvm::Value *
994
994
emitConditionalConformancesBuffer (IRGenFunction &IGF, CanType conformingType,
995
995
const ProtocolConformance *conformance) {
996
996
// Pointers to the witness tables, in the right order, which will be included
@@ -1034,13 +1034,9 @@ emitConditionalConformancesBuffer(IRGenFunction &IGF, CanType conformingType,
1034
1034
return /* finished?*/ false ;
1035
1035
});
1036
1036
1037
- // No conditional requirements means no need for a buffer, and size == 0 means
1038
- // no reading of the pointer.
1039
- // FIXME(cond. conf. assert): once the dynamic assertion is removed from the
1040
- // instantiation function, we can have size as undef too.
1037
+ // No conditional requirements means no need for a buffer.
1041
1038
if (tables.empty ()) {
1042
- return {llvm::UndefValue::get (IGF.IGM .WitnessTablePtrPtrTy ),
1043
- llvm::ConstantInt::get (IGF.IGM .SizeTy , 0 )};
1039
+ return llvm::UndefValue::get (IGF.IGM .WitnessTablePtrPtrTy );
1044
1040
}
1045
1041
1046
1042
auto buffer = IGF.createAlloca (
@@ -1055,8 +1051,7 @@ emitConditionalConformancesBuffer(IRGenFunction &IGF, CanType conformingType,
1055
1051
IGF.Builder .CreateStore (tables[idx], slot);
1056
1052
}
1057
1053
1058
- auto count = llvm::ConstantInt::get (IGF.IGM .SizeTy , tables.size ());
1059
- return {buffer.getAddress (), count};
1054
+ return buffer.getAddress ();
1060
1055
}
1061
1056
1062
1057
static llvm::Value *emitWitnessTableAccessorCall (
@@ -1074,12 +1069,11 @@ static llvm::Value *emitWitnessTableAccessorCall(
1074
1069
*srcMetadataCache = IGF.emitTypeMetadataRef (conformingType);
1075
1070
}
1076
1071
1077
- llvm::Value *conditionalTables, *numConditionalTables;
1078
- std::tie (conditionalTables, numConditionalTables) =
1072
+ auto conditionalTables =
1079
1073
emitConditionalConformancesBuffer (IGF, conformingType, conformance);
1080
1074
1081
- call = IGF.Builder .CreateCall (
1082
- accessor, {*srcMetadataCache, conditionalTables, numConditionalTables });
1075
+ call = IGF.Builder .CreateCall (accessor,
1076
+ {*srcMetadataCache, conditionalTables});
1083
1077
1084
1078
} else {
1085
1079
call = IGF.Builder .CreateCall (accessor, {});
@@ -1762,17 +1756,16 @@ void WitnessTableBuilder::buildAccessFunction(llvm::Constant *wtable) {
1762
1756
1763
1757
Explosion params = IGF.collectParameters ();
1764
1758
llvm::Value *metadata;
1765
- llvm::Value *conditionalReqtWtables;
1766
- llvm::Value *numConditionalReqtWtables;
1759
+ llvm::Value *instantiationArgs;
1767
1760
1768
1761
if (Conformance.witnessTableAccessorRequiresArguments ()) {
1769
1762
metadata = params.claimNext ();
1770
- conditionalReqtWtables = params.claimNext ();
1771
- numConditionalReqtWtables = params.claimNext ();
1763
+ auto conditionalReqtWtables = params.claimNext ();
1764
+ instantiationArgs =
1765
+ IGF.Builder .CreateBitCast (conditionalReqtWtables, IGF.IGM .Int8PtrPtrTy );
1772
1766
} else {
1773
1767
metadata = llvm::ConstantPointerNull::get (IGF.IGM .TypeMetadataPtrTy );
1774
- conditionalReqtWtables = nullptr ;
1775
- numConditionalReqtWtables = llvm::ConstantInt::get (IGF.IGM .SizeTy , 0 );
1768
+ instantiationArgs = llvm::ConstantPointerNull::get (IGF.IGM .Int8PtrPtrTy );
1776
1769
}
1777
1770
1778
1771
// Okay, we need a cache. Build the cache structure.
@@ -1803,7 +1796,6 @@ void WitnessTableBuilder::buildAccessFunction(llvm::Constant *wtable) {
1803
1796
1804
1797
// We need an instantiation function if the base conformance
1805
1798
// is non-dependent.
1806
- // TODO: the conformance might be conditional.
1807
1799
llvm::Constant *instantiationFn;
1808
1800
if (SpecializedBaseConformances.empty () &&
1809
1801
ConditionalRequirementPrivateDataIndices.empty ()) {
@@ -1845,31 +1837,9 @@ void WitnessTableBuilder::buildAccessFunction(llvm::Constant *wtable) {
1845
1837
cacheData.finishAndSetAsInitializer (cache);
1846
1838
cache->setConstant (true );
1847
1839
1848
- // Create the slice structure for the conditional conformances, which is
1849
- // passed as the last argument to the instantiation function.
1850
- // FIXME(cond. conf. assert): Elide this local/replace it with `undef` once
1851
- // the size assertion in the instantiation function is gone.
1852
- auto conditionalSlice =
1853
- IGF.createAlloca (IGF.IGM .WitnessTableSliceTy ,
1854
- IGF.IGM .getPointerAlignment (), " conditional.tables" );
1855
-
1856
- // Only store a pointer if it will be read. If not (i.e. size == 0/this
1857
- // conformance is unconditional), we can leave it as undef.
1858
- if (conditionalReqtWtables) {
1859
- auto tableSlot = IGF.Builder .CreateStructGEP (conditionalSlice, 0 , Size (0 ));
1860
- IGF.Builder .CreateStore (conditionalReqtWtables, tableSlot);
1861
- }
1862
-
1863
- auto sizeSlot = IGF.Builder .CreateStructGEP (conditionalSlice, 1 ,
1864
- Size (IGF.IGM .getPointerSize ()));
1865
- IGF.Builder .CreateStore (numConditionalReqtWtables, sizeSlot);
1840
+ auto call = IGF.Builder .CreateCall (IGM.getGetGenericWitnessTableFn (),
1841
+ {cache, metadata, instantiationArgs});
1866
1842
1867
- auto instantiationArgs =
1868
- IGF.Builder .CreateBitCast (conditionalSlice, IGM.Int8PtrPtrTy );
1869
-
1870
- auto call =
1871
- IGF.Builder .CreateCall (IGM.getGetGenericWitnessTableFn (),
1872
- {cache, metadata, instantiationArgs.getAddress ()});
1873
1843
call->setDoesNotThrow ();
1874
1844
1875
1845
IGF.Builder .CreateRet (call);
@@ -1889,39 +1859,11 @@ llvm::Constant *WitnessTableBuilder::buildInstantiationFunction() {
1889
1859
Explosion params = IGF.collectParameters ();
1890
1860
Address wtable (params.claimNext (), PointerAlignment);
1891
1861
llvm::Value *metadata = params.claimNext ();
1892
- Address instantiationArgs (params.claimNext (), PointerAlignment);
1893
-
1894
- // The details of any conditional conformances are in the last argument, as a
1895
- // pointer/size pair.
1896
- auto conditionalTablesSlice = IGF.Builder .CreateElementBitCast (
1897
- instantiationArgs, IGF.IGM .WitnessTableSliceTy );
1898
-
1899
- auto conditionalTablesPtr =
1900
- IGF.Builder .CreateStructGEP (conditionalTablesSlice, 0 , Size (0 ));
1901
- Address conditionalTables (IGF.Builder .CreateLoad (conditionalTablesPtr),
1902
- PointerAlignment);
1903
-
1904
- auto numConditionalTablesPtr =
1905
- IGF.Builder .CreateStructGEP (conditionalTablesSlice, 1 , Size (PointerSize));
1906
- auto numConditionalTables = IGF.Builder .CreateLoad (numConditionalTablesPtr);
1907
-
1908
- // Assert that the number of witness tables passed in is the number required
1909
- // for the conditional conformances of this witness table.
1910
-
1911
- // FIXME(cond. conf. assert): remove this once we're confident in conditional
1912
- // conformances and especially dynamic casting. (Look for the other
1913
- // 'cond. conf. assert' FIXMEs too.)
1914
- auto failBB = IGF.createBasicBlock (" bad_witness_table_count" );
1915
- auto contBB = IGF.createBasicBlock (" cont" );
1916
-
1917
- auto cmp = IGF.Builder .CreateICmpEQ (
1918
- numConditionalTables,
1919
- llvm::ConstantInt::get (IGM.SizeTy ,
1920
- ConditionalRequirementPrivateDataIndices.size ()));
1921
- IGF.Builder .CreateCondBr (cmp, contBB, failBB);
1922
-
1923
- // All good: now we can actually fill in the witness table.
1924
- IGF.Builder .emitBlock (contBB);
1862
+ llvm::Value *instantiationArgs = params.claimNext ();
1863
+ Address conditionalTables (
1864
+ IGF.Builder .CreateBitCast (instantiationArgs,
1865
+ IGF.IGM .WitnessTablePtrPtrTy ),
1866
+ PointerAlignment);
1925
1867
1926
1868
// / Run through the conditional conformance witness tables, pulling them out
1927
1869
// / of the slice and putting them into the private data of the witness table.
@@ -1966,10 +1908,6 @@ llvm::Constant *WitnessTableBuilder::buildInstantiationFunction() {
1966
1908
1967
1909
IGF.Builder .CreateRetVoid ();
1968
1910
1969
- // The counts didn't match; abort.
1970
- IGF.Builder .emitBlock (failBB);
1971
- IGF.emitTrap (/* EmitUnreachable=*/ true );
1972
-
1973
1911
return fn;
1974
1912
}
1975
1913
0 commit comments