diff options
| author | Yong He <yonghe@outlook.com> | 2020-06-25 14:01:33 -0700 |
|---|---|---|
| committer | Yong He <yonghe@outlook.com> | 2020-06-25 14:01:33 -0700 |
| commit | 509e36b62de7578843abc2547921beadff7a3ce0 (patch) | |
| tree | a74096fa8a71a69f5645fc7ad4b94b0bf8860ac1 | |
| parent | a1fed5e49bc1c8452752d13d401ee0bbbc5c71c4 (diff) | |
Remove interfaceType operand from lookup_witness_method inst
| -rw-r--r-- | source/slang/slang-emit-cpp.cpp | 4 | ||||
| -rw-r--r-- | source/slang/slang-ir-inst-defs.h | 2 | ||||
| -rw-r--r-- | source/slang/slang-ir-insts.h | 7 | ||||
| -rw-r--r-- | source/slang/slang-ir-lower-generics.cpp | 3 | ||||
| -rw-r--r-- | source/slang/slang-ir.cpp | 17 | ||||
| -rw-r--r-- | source/slang/slang-ir.h | 4 | ||||
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 19 |
7 files changed, 27 insertions, 29 deletions
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp index a449a2c56..f895b1119 100644 --- a/source/slang/slang-emit-cpp.cpp +++ b/source/slang/slang-emit-cpp.cpp @@ -1790,9 +1790,9 @@ void CPPSourceEmitter::_maybeEmitWitnessTableTypeDefinition( } m_writer->emit(");\n"); } - else if (auto constraintInterfaceType = as<IRInterfaceType>(entry->getRequirementVal())) + else if (auto witnessTableType = as<IRWitnessTableType>(entry->getRequirementVal())) { - emitType(constraintInterfaceType); + emitType((IRType*)witnessTableType->getConformanceType()); m_writer->emit("* "); m_writer->emit(getName(entry->getRequirementKey())); m_writer->emit(";\n"); diff --git a/source/slang/slang-ir-inst-defs.h b/source/slang/slang-ir-inst-defs.h index c4fd6edf8..94c29371a 100644 --- a/source/slang/slang-ir-inst-defs.h +++ b/source/slang/slang-ir-inst-defs.h @@ -173,7 +173,7 @@ INST(AssociatedType, associated_type, 0, 0) INST(TypeType, type_t, 0, 0) // An `IRWitnessTable` has type `WitnessTableType`. -INST(WitnessTableType, witness_table_t, 0, 0) +INST(WitnessTableType, witness_table_t, 1, 0) INST_RANGE(Type, VoidType, WitnessTableType) diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h index 5d467085e..fcefa8b26 100644 --- a/source/slang/slang-ir-insts.h +++ b/source/slang/slang-ir-insts.h @@ -408,11 +408,9 @@ struct IRLookupWitnessMethod : IRInst { IRUse witnessTable; IRUse requirementKey; - IRUse interfaceType; IRInst* getWitnessTable() { return witnessTable.get(); } IRInst* getRequirementKey() { return requirementKey.get(); } - IRInst* getInterfaceType() { return interfaceType.get(); } IR_LEAF_ISA(lookup_interface_method) }; @@ -1680,8 +1678,7 @@ struct IRBuilder IRInst* emitLookupInterfaceMethodInst( IRType* type, IRInst* witnessTableVal, - IRInst* interfaceMethodVal, - IRType* interfaceType); + IRInst* interfaceMethodVal); IRInst* emitCallInst( IRType* type, @@ -1806,7 +1803,7 @@ struct IRBuilder IRType* valueType); IRGlobalParam* createGlobalParam( IRType* valueType); - + /// Creates an IRWitnessTable value. /// @param baseType: The comformant-to type of this witness. IRWitnessTable* createWitnessTable(IRType* baseType); diff --git a/source/slang/slang-ir-lower-generics.cpp b/source/slang/slang-ir-lower-generics.cpp index 4b1b267f9..c374f45fa 100644 --- a/source/slang/slang-ir-lower-generics.cpp +++ b/source/slang/slang-ir-lower-generics.cpp @@ -224,7 +224,8 @@ namespace Slang // The callee is a result of witness table lookup, we will only // translate the call. IRInst* callee = nullptr; - auto interfaceType = maybeLowerInterfaceType(cast<IRInterfaceType>(interfaceLookup->getInterfaceType())); + auto witnessTableType = cast<IRWitnessTableType>(interfaceLookup->getWitnessTable()->getFullType()); + auto interfaceType = maybeLowerInterfaceType(cast<IRInterfaceType>(witnessTableType->getConformanceType())); for (UInt i = 0; i < interfaceType->getOperandCount(); i++) { auto entry = cast<IRInterfaceRequirementEntry>(interfaceType->getOperand(i)); diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 07cb957db..8cf7ab171 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -1408,10 +1408,7 @@ namespace Slang inst->op = op; - if (type) - { - inst->typeUse.init(inst, type); - } + inst->typeUse.init(inst, type); maybeSetSourceLoc(builder, inst); @@ -1423,6 +1420,10 @@ namespace Slang { operand->init(inst, fixedArgs[aa]); } + else + { + operand->init(inst, nullptr); + } operand++; } @@ -2518,16 +2519,14 @@ namespace Slang IRInst* IRBuilder::emitLookupInterfaceMethodInst( IRType* type, IRInst* witnessTableVal, - IRInst* interfaceMethodVal, - IRType* interfaceType) + IRInst* interfaceMethodVal) { - IRInst* args[3] = { witnessTableVal , interfaceMethodVal, interfaceType }; auto inst = createInst<IRLookupWitnessMethod>( this, kIROp_lookup_interface_method, type, - 3, - args); + witnessTableVal, + interfaceMethodVal); addInst(inst); return inst; diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h index 6447deddb..54658980d 100644 --- a/source/slang/slang-ir.h +++ b/source/slang/slang-ir.h @@ -1226,6 +1226,10 @@ struct IRTypeType : IRType struct IRWitnessTableType : IRType { + IRInst* getConformanceType() + { + return getOperand(0); + } IR_LEAF_ISA(WitnessTableType); }; diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 96d4b121f..5bd983cab 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -1049,7 +1049,7 @@ struct ValLoweringVisitor : ValVisitor<ValLoweringVisitor, LoweredValInfo, Lower { return emitDeclRef(context, val->declRef, context->irBuilder->getWitnessTableType( - lowerType(context, DeclRefType::create(context->astBuilder, val->declRef)))); + lowerType(context, val->sup))); } LoweredValInfo visitTransitiveSubtypeWitness( @@ -1071,10 +1071,9 @@ struct ValLoweringVisitor : ValVisitor<ValLoweringVisitor, LoweredValInfo, Lower // to reflect the right constraints. return LoweredValInfo::simple(getBuilder()->emitLookupInterfaceMethodInst( - nullptr, + getBuilder()->getWitnessTableType(lowerType(context, val->sup)), baseWitnessTable, - requirementKey, - lowerType(context, val->subToMid->sup))); + requirementKey)); } LoweredValInfo visitTaggedUnionSubtypeWitness( @@ -1255,8 +1254,7 @@ struct ValLoweringVisitor : ValVisitor<ValLoweringVisitor, LoweredValInfo, Lower auto caseFunc = subBuilder->emitLookupInterfaceMethodInst( caseFuncType, caseWitnessTable, - irReqKey, - irWitnessTableBaseType); + irReqKey); // We are going to emit a `call` to the satisfying value // for the case type, so we will collect the arguments for that call. @@ -5311,7 +5309,7 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> auto constraintKey = getInterfaceRequirementKey(constraintDecl); requirementEntries.add( subBuilder->createInterfaceRequirementEntry(constraintKey, - lowerType(context, constraintDecl->getSup().type))); + getBuilder()->getWitnessTableType(lowerType(context, constraintDecl->getSup().type)))); } } } @@ -6578,9 +6576,9 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> for (UInt i = 0; i < irInterfaceType->getOperandCount(); i++) { auto operand = cast<IRInterfaceRequirementEntry>(irInterfaceType->getOperand(i)); - if (operand->getOperand(0) == key) + if (operand->getRequirementKey() == key) { - operand->setOperand(1, irFuncType); + operand->setRequirementVal(irFuncType); return; } } @@ -6874,8 +6872,7 @@ LoweredValInfo emitDeclRef( auto irSatisfyingVal = context->irBuilder->emitLookupInterfaceMethodInst( type, irWitnessTable, - irRequirementKey, - lowerType(context, thisTypeSubst->witness->sup)); + irRequirementKey); return LoweredValInfo::simple(irSatisfyingVal); } else |
