IRGen: Fix ArchetypeMethodInst for static funcs.

The argument to archetype_method can be a metatype, so allow that. While we're here, implement lowering for AssociatedMetatypeInst, and fix initial bringup of SIL-IRGen so that polymorphic arguments get emitted into the entry point BB instead of a random other BB.

Swift SVN r4741
This commit is contained in:
Joe Groff
2013-04-15 22:21:45 +00:00
parent 16ecdcbe09
commit c217d69779
4 changed files with 46 additions and 33 deletions

View File

@@ -3661,9 +3661,27 @@ static CallEmission prepareProtocolMethodCall(IRGenFunction &IGF, FuncDecl *fn,
return emission;
}
static void getWitnessMethodValue(IRGenFunction &IGF,
FuncDecl *fn,
ProtocolDecl *fnProto,
llvm::Value *wtable,
llvm::Value *metadata,
Explosion &out) {
// Find the actual witness.
auto &fnProtoInfo = IGF.IGM.getProtocolInfo(fnProto);
auto index = fnProtoInfo.getWitnessEntry(fn).getFunctionIndex();
llvm::Value *witness = loadOpaqueWitness(IGF, wtable, index);
// Cast the witness pointer to i8*.
witness = IGF.Builder.CreateBitCast(witness, IGF.IGM.Int8PtrTy);
// Build the value.
out.addUnmanaged(witness);
out.addUnmanaged(metadata);
}
void
irgen::getArchetypeMethodValue(IRGenFunction &IGF,
Address thisObject,
CanType baseTy,
SILConstant member,
CanType substResultType,
@@ -3689,20 +3707,11 @@ irgen::getArchetypeMethodValue(IRGenFunction &IGF,
llvm::Value *origin = archetypeTI.getWitnessTable(IGF, path.getOriginIndex());
llvm::Value *wtable = path.apply(IGF, origin);
// Find the actual witness.
auto &fnProtoInfo = IGF.IGM.getProtocolInfo(fnProto);
auto index = fnProtoInfo.getWitnessEntry(fn).getFunctionIndex();
llvm::Value *witness = loadOpaqueWitness(IGF, wtable, index);
// Acquire the archetype metadata.
llvm::Value *metadata = archetypeTI.getMetadataRef(IGF);
// Cast the witness pointer to i8*.
witness = IGF.Builder.CreateBitCast(witness, IGF.IGM.Int8PtrTy);
// Build the value.
out.addUnmanaged(witness);
out.addUnmanaged(metadata);
getWitnessMethodValue(IGF, fn, fnProto, wtable, metadata, out);
}
/// Extract the method pointer and metadata from a protocol witness table
@@ -3735,17 +3744,8 @@ irgen::getProtocolMethodValue(IRGenFunction &IGF,
auto existLayout = baseTI.getLayout();
llvm::Value *metadata = existLayout.loadMetadataRef(IGF, existAddr);
// Find the actual witness.
auto &fnProtoInfo = IGF.IGM.getProtocolInfo(fnProto);
auto index = fnProtoInfo.getWitnessEntry(fn).getFunctionIndex();
llvm::Value *witness = loadOpaqueWitness(IGF, wtable, index);
// Cast the witness pointer to i8*.
witness = IGF.Builder.CreateBitCast(witness, IGF.IGM.Int8PtrTy);
// Build the value.
out.addUnmanaged(witness);
out.addUnmanaged(metadata);
getWitnessMethodValue(IGF, fn, fnProto, wtable, metadata, out);
}
/// Emit an existential member reference as a callee.