From 0ca75fe002f346f6ab9b77f40c0576d2905560f1 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 24 Jun 2020 13:16:11 -0700 Subject: Dynamic dispatch for generic interface requirements. -Lower interfaces into actual `IRInterfaceType` insts. -Lower `DeclRef` into `IRAssociatedType` -Generate proper IRType for generic functions. -Add a test case exercising dynamic dispatching a generic static function through an associated type. -Bug fixes for the test case. --- source/slang/slang-emit-c-like.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'source/slang/slang-emit-c-like.cpp') diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 3438fd3f4..2605723c7 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -236,9 +236,9 @@ List CLikeSourceEmitter::getSortedWitnessTableEntries(IRWi // Get a sorted list of entries using RequirementKeys defined in `interfaceType`. for (UInt i = 0; i < interfaceType->getOperandCount(); i++) { - auto reqKey = cast(interfaceType->getOperand(i)); + auto reqEntry = cast(interfaceType->getOperand(i)); IRWitnessTableEntry* entry = nullptr; - if (witnessTableEntryDictionary.TryGetValue(reqKey, entry)) + if (witnessTableEntryDictionary.TryGetValue(reqEntry->getRequirementKey(), entry)) { sortedWitnessTableEntries.add(entry); } @@ -1962,6 +1962,10 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO are hashed with 'getStringHash' */ break; + case kIROp_undefined: + m_writer->emit(getName(inst)); + break; + case kIROp_IntLit: case kIROp_FloatLit: case kIROp_BoolLit: @@ -3554,6 +3558,11 @@ void CLikeSourceEmitter::emitGlobalInst(IRInst* inst) are hashed with 'getStringHash' */ break; + case kIROp_InterfaceRequirementEntry: + // Don't emit anything for interface requirement at global level. + // They are handled in `emitInterface`. + break; + case kIROp_Func: emitFunc((IRFunc*) inst); break; @@ -3610,6 +3619,10 @@ void CLikeSourceEmitter::ensureInstOperandsRec(ComputeEmitActionsContext* ctx, I ensureInstOperand(ctx, inst->getFullType()); UInt operandCount = inst->operandCount; + auto requiredLevel = EmitAction::Definition; + if (inst->op == kIROp_InterfaceType) + requiredLevel = EmitAction::ForwardDeclaration; + for(UInt ii = 0; ii < operandCount; ++ii) { // TODO: there are some special cases we can add here, @@ -3620,8 +3633,8 @@ void CLikeSourceEmitter::ensureInstOperandsRec(ComputeEmitActionsContext* ctx, I // only need the type they point to to be forward-declared. // Similarly, a `call` instruction only needs the callee // to be forward-declared, etc. - - ensureInstOperand(ctx, inst->getOperand(ii)); + + ensureInstOperand(ctx, inst->getOperand(ii), requiredLevel); } for(auto child : inst->getDecorationsAndChildren()) -- cgit v1.2.3