@@ -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, {});
@@ -1763,17 +1757,15 @@ void WitnessTableBuilder::buildAccessFunction(llvm::Constant *wtable) {
1763
1757
1764
1758
Explosion params = IGF.collectParameters ();
1765
1759
llvm::Value *metadata;
1766
- llvm::Value *conditionalReqtWtables;
1767
- llvm::Value *numConditionalReqtWtables;
1760
+ llvm::Value *instantiationArgs;
1768
1761
1769
1762
if (Conformance.witnessTableAccessorRequiresArguments ()) {
1770
1763
metadata = params.claimNext ();
1771
- conditionalReqtWtables = params.claimNext ();
1772
- numConditionalReqtWtables = params.claimNext ();
1764
+ instantiationArgs = params.claimNext ();
1773
1765
} else {
1774
1766
metadata = llvm::ConstantPointerNull::get (IGF.IGM .TypeMetadataPtrTy );
1775
- conditionalReqtWtables = nullptr ;
1776
- numConditionalReqtWtables = llvm::ConstantInt ::get (IGF.IGM .SizeTy , 0 );
1767
+ instantiationArgs =
1768
+ llvm::ConstantPointerNull ::get (IGF.IGM .WitnessTablePtrPtrTy );
1777
1769
}
1778
1770
1779
1771
// Okay, we need a cache. Build the cache structure.
@@ -1804,7 +1796,6 @@ void WitnessTableBuilder::buildAccessFunction(llvm::Constant *wtable) {
1804
1796
1805
1797
// We need an instantiation function if the base conformance
1806
1798
// is non-dependent.
1807
- // TODO: the conformance might be conditional.
1808
1799
llvm::Constant *instantiationFn;
1809
1800
if (SpecializedBaseConformances.empty () &&
1810
1801
ConditionalRequirementPrivateDataIndices.empty ()) {
@@ -1846,31 +1837,9 @@ void WitnessTableBuilder::buildAccessFunction(llvm::Constant *wtable) {
1846
1837
cacheData.finishAndSetAsInitializer (cache);
1847
1838
cache->setConstant (true );
1848
1839
1849
- // Create the slice structure for the conditional conformances, which is
1850
- // passed as the last argument to the instantiation function.
1851
- // FIXME(cond. conf. assert): Elide this local/replace it with `undef` once
1852
- // the size assertion in the instantiation function is gone.
1853
- auto conditionalSlice =
1854
- IGF.createAlloca (IGF.IGM .WitnessTableSliceTy ,
1855
- IGF.IGM .getPointerAlignment (), " conditional.tables" );
1856
-
1857
- // Only store a pointer if it will be read. If not (i.e. size == 0/this
1858
- // conformance is unconditional), we can leave it as undef.
1859
- if (conditionalReqtWtables) {
1860
- auto tableSlot = IGF.Builder .CreateStructGEP (conditionalSlice, 0 , Size (0 ));
1861
- IGF.Builder .CreateStore (conditionalReqtWtables, tableSlot);
1862
- }
1863
-
1864
- auto sizeSlot = IGF.Builder .CreateStructGEP (conditionalSlice, 1 ,
1865
- Size (IGF.IGM .getPointerSize ()));
1866
- IGF.Builder .CreateStore (numConditionalReqtWtables, sizeSlot);
1840
+ auto call = IGF.Builder .CreateCall (IGM.getGetGenericWitnessTableFn (),
1841
+ {cache, metadata, instantiationArgs});
1867
1842
1868
- auto instantiationArgs =
1869
- IGF.Builder .CreateBitCast (conditionalSlice, IGM.Int8PtrPtrTy );
1870
-
1871
- auto call =
1872
- IGF.Builder .CreateCall (IGM.getGetGenericWitnessTableFn (),
1873
- {cache, metadata, instantiationArgs.getAddress ()});
1874
1843
call->setDoesNotThrow ();
1875
1844
1876
1845
IGF.Builder .CreateRet (call);
@@ -1890,39 +1859,11 @@ llvm::Constant *WitnessTableBuilder::buildInstantiationFunction() {
1890
1859
Explosion params = IGF.collectParameters ();
1891
1860
Address wtable (params.claimNext (), PointerAlignment);
1892
1861
llvm::Value *metadata = params.claimNext ();
1893
- Address instantiationArgs (params.claimNext (), PointerAlignment);
1894
-
1895
- // The details of any conditional conformances are in the last argument, as a
1896
- // pointer/size pair.
1897
- auto conditionalTablesSlice = IGF.Builder .CreateElementBitCast (
1898
- instantiationArgs, IGF.IGM .WitnessTableSliceTy );
1899
-
1900
- auto conditionalTablesPtr =
1901
- IGF.Builder .CreateStructGEP (conditionalTablesSlice, 0 , Size (0 ));
1902
- Address conditionalTables (IGF.Builder .CreateLoad (conditionalTablesPtr),
1903
- PointerAlignment);
1904
-
1905
- auto numConditionalTablesPtr =
1906
- IGF.Builder .CreateStructGEP (conditionalTablesSlice, 1 , Size (PointerSize));
1907
- auto numConditionalTables = IGF.Builder .CreateLoad (numConditionalTablesPtr);
1908
-
1909
- // Assert that the number of witness tables passed in is the number required
1910
- // for the conditional conformances of this witness table.
1911
-
1912
- // FIXME(cond. conf. assert): remove this once we're confident in conditional
1913
- // conformances and especially dynamic casting. (Look for the other
1914
- // 'cond. conf. assert' FIXMEs too.)
1915
- auto failBB = IGF.createBasicBlock (" bad_witness_table_count" );
1916
- auto contBB = IGF.createBasicBlock (" cont" );
1917
-
1918
- auto cmp = IGF.Builder .CreateICmpEQ (
1919
- numConditionalTables,
1920
- llvm::ConstantInt::get (IGM.SizeTy ,
1921
- ConditionalRequirementPrivateDataIndices.size ()));
1922
- IGF.Builder .CreateCondBr (cmp, contBB, failBB);
1923
-
1924
- // All good: now we can actually fill in the witness table.
1925
- IGF.Builder .emitBlock (contBB);
1862
+ llvm::Value *instantiationArgs = params.claimNext ();
1863
+ Address conditionalTables (
1864
+ IGF.Builder .CreateBitCast (instantiationArgs,
1865
+ IGF.IGM .WitnessTablePtrPtrTy ),
1866
+ PointerAlignment);
1926
1867
1927
1868
// / Run through the conditional conformance witness tables, pulling them out
1928
1869
// / of the slice and putting them into the private data of the witness table.
@@ -1967,10 +1908,6 @@ llvm::Constant *WitnessTableBuilder::buildInstantiationFunction() {
1967
1908
1968
1909
IGF.Builder .CreateRetVoid ();
1969
1910
1970
- // The counts didn't match; abort.
1971
- IGF.Builder .emitBlock (failBB);
1972
- IGF.emitTrap (/* EmitUnreachable=*/ true );
1973
-
1974
1911
return fn;
1975
1912
}
1976
1913
0 commit comments