summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-11-29 14:16:05 -0800
committerGitHub <noreply@github.com>2022-11-29 14:16:05 -0800
commitaf7f40063dfed1c651d33b93956c7623a7d2c050 (patch)
treefd2225cffda6a9a887051bd00c5ccaba9ec6b5ea
parentd85c7b809d02e6dc0844aab07e66a6bac2462017 (diff)
Complete removal of DifferentialBottom type. (#2537)
Co-authored-by: Yong He <yhe@nvidia.com>
-rw-r--r--source/slang/core.meta.slang22
-rw-r--r--source/slang/slang-ast-builder.cpp10
-rw-r--r--source/slang/slang-ast-builder.h3
-rw-r--r--source/slang/slang-ast-type.cpp21
-rw-r--r--source/slang/slang-ast-type.h14
-rw-r--r--source/slang/slang-check-decl.cpp122
-rw-r--r--source/slang/slang-ir-inst-defs.h1
-rw-r--r--source/slang/slang-ir-insts.h1
-rw-r--r--source/slang/slang-ir.cpp17
-rw-r--r--source/slang/slang-ir.h2
10 files changed, 42 insertions, 171 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang
index 8cfa85983..73a004720 100644
--- a/source/slang/core.meta.slang
+++ b/source/slang/core.meta.slang
@@ -132,28 +132,6 @@ interface IDifferentiable
static Differential dmul(This, Differential);
};
-__magic_type(DifferentialBottomType)
-__intrinsic_type($(kIROp_DifferentialBottomType))
-struct __DifferentialBottom : IDifferentiable
-{
- typedef __DifferentialBottom Differential;
-
- __intrinsic_op($(kIROp_DifferentialBottomValue))
- static __DifferentialBottom dzero();
-
- [__unsafeForceInlineEarly]
- static __DifferentialBottom dadd(Differential a, Differential b)
- {
- return dzero();
- }
-
- [__unsafeForceInlineEarly]
- static __DifferentialBottom dmul(This a, Differential b)
- {
- return dzero();
- }
-}
-
/// A type that can represent non-integers
[sealed]
[builtin]
diff --git a/source/slang/slang-ast-builder.cpp b/source/slang/slang-ast-builder.cpp
index 819fe7d25..d8fec88ce 100644
--- a/source/slang/slang-ast-builder.cpp
+++ b/source/slang/slang-ast-builder.cpp
@@ -141,16 +141,6 @@ Type* SharedASTBuilder::getNoneType()
return m_noneType;
}
-Type* SharedASTBuilder::getDifferentialBottomType()
-{
- if (!m_diffBottomType)
- {
- auto diffBottomTypeDecl = findMagicDecl("DifferentialBottomType");
- m_diffBottomType = DeclRefType::create(m_astBuilder, makeDeclRef<Decl>(diffBottomTypeDecl));
- }
- return m_diffBottomType;
-}
-
SharedASTBuilder::~SharedASTBuilder()
{
// Release built in types..
diff --git a/source/slang/slang-ast-builder.h b/source/slang/slang-ast-builder.h
index 6c0e1af36..f011feae8 100644
--- a/source/slang/slang-ast-builder.h
+++ b/source/slang/slang-ast-builder.h
@@ -36,8 +36,6 @@ public:
Type* getNullPtrType();
/// Get the NullPtr type
Type* getNoneType();
- /// Get the DifferentialBottom type.
- Type* getDifferentialBottomType();
const ReflectClassInfo* findClassInfo(Name* name);
SyntaxClass<NodeBase> findSyntaxClass(Name* name);
@@ -306,7 +304,6 @@ public:
Type* getOverloadedType() { return m_sharedASTBuilder->m_overloadedType; }
Type* getErrorType() { return m_sharedASTBuilder->m_errorType; }
Type* getBottomType() { return m_sharedASTBuilder->m_bottomType; }
- Type* getDifferentialBottomType() { return m_sharedASTBuilder->getDifferentialBottomType(); }
Type* getStringType() { return m_sharedASTBuilder->getStringType(); }
Type* getNullPtrType() { return m_sharedASTBuilder->getNullPtrType(); }
Type* getNoneType() { return m_sharedASTBuilder->getNoneType(); }
diff --git a/source/slang/slang-ast-type.cpp b/source/slang/slang-ast-type.cpp
index 3fcc762ec..3801b99b0 100644
--- a/source/slang/slang-ast-type.cpp
+++ b/source/slang/slang-ast-type.cpp
@@ -169,27 +169,6 @@ Val* BottomType::_substituteImplOverride(
HashCode BottomType::_getHashCodeOverride() { return HashCode(size_t(this)); }
-// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DifferentialBottomType !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-void DifferentialBottomType::_toTextOverride(StringBuilder& out) { out << toSlice("diff_bottom"); }
-
-bool DifferentialBottomType::_equalsImplOverride(Type* type)
-{
- if (auto bottomType = as<DifferentialBottomType>(type))
- return true;
- return false;
-}
-
-Type* DifferentialBottomType::_createCanonicalTypeOverride() { return this; }
-
-Val* DifferentialBottomType::_substituteImplOverride(
- ASTBuilder* /* astBuilder */, SubstitutionSet /*subst*/, int* /*ioDiff*/)
-{
- return this;
-}
-
-HashCode DifferentialBottomType::_getHashCodeOverride() { return HashCode(size_t(this)); }
-
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DeclRefType !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void DeclRefType::_toTextOverride(StringBuilder& out)
diff --git a/source/slang/slang-ast-type.h b/source/slang/slang-ast-type.h
index 8953f0b10..f19b71b56 100644
--- a/source/slang/slang-ast-type.h
+++ b/source/slang/slang-ast-type.h
@@ -86,20 +86,6 @@ protected:
{}
};
-// The bottom/empty type as a result of Differentiating a Differential.
-class DifferentialBottomType : public DeclRefType
-{
- SLANG_AST_CLASS(DifferentialBottomType)
-
- // Overrides should be public so base classes can access
- void _toTextOverride(StringBuilder& out);
- Type* _createCanonicalTypeOverride();
- bool _equalsImplOverride(Type* type);
- HashCode _getHashCodeOverride();
- Val* _substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet subst, int* ioDiff);
-};
-
-
// Base class for types that can be used in arithmetic expressions
class ArithmeticExpressionType : public DeclRefType
{
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index 4d2839b8d..5e6c6eedf 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -259,8 +259,6 @@ namespace Slang
void visitParamDecl(ParamDecl* paramDecl);
- void _maybeRegisterDifferentialBottomTypeConformance(SemanticsContext& context);
-
void checkDerivativeOfAttribute(FunctionDeclBase* funcDecl);
void checkDerivativeAttribute(FunctionDeclBase* funcDecl, ForwardDerivativeAttribute* attr);
@@ -3317,73 +3315,52 @@ namespace Slang
auto seqStmt = synth.pushSeqStmtScope();
blockStmt->body = seqStmt;
- if (synFunc->returnType.type->equals(m_astBuilder->getDifferentialBottomType()))
- {
- // Trivial case, the `Differential` type is `DifferentialBottom`.
- // We will just return `DifferentialBottom.dzero()`.
- auto resultExpr = m_astBuilder->create<InvokeExpr>();
- auto dzeroMember = m_astBuilder->create<StaticMemberExpr>();
- auto base = m_astBuilder->create<SharedTypeExpr>();
- auto typetype = m_astBuilder->create<TypeType>();
- typetype->type = m_astBuilder->getDifferentialBottomType();
- base->type.type = typetype;
- dzeroMember->baseExpression = base;
- dzeroMember->name = getName("dzero");
- resultExpr->functionExpr = dzeroMember;
- auto synReturn = m_astBuilder->create<ReturnStmt>();
- synReturn->expression = resultExpr;
- seqStmt->stmts.add(synReturn);
- }
- else
- {
- // The general case.
- // Create a variable for return value.
- synth.pushVarScope();
- auto varStmt = synth.emitVarDeclStmt(synFunc->returnType.type, getName("result"));
- auto resultVarExpr = synth.emitVarExpr(varStmt, synFunc->returnType.type);
+ // Create a variable for return value.
+ synth.pushVarScope();
+ auto varStmt = synth.emitVarDeclStmt(synFunc->returnType.type, getName("result"));
+ auto resultVarExpr = synth.emitVarExpr(varStmt, synFunc->returnType.type);
- for (auto member : context->parentDecl->members)
- {
- auto derivativeAttr = member->findModifier<DerivativeMemberAttribute>();
- if (!derivativeAttr)
- continue;
- auto varMember = as<VarDeclBase>(member);
- if (!varMember)
- continue;
- ensureDecl(varMember, DeclCheckState::ReadyForReference);
- auto memberType = varMember->getType();
- auto diffMemberType = tryGetDifferentialType(m_astBuilder, memberType);
- if (!diffMemberType)
- continue;
-
- // Construct reference exprs to the member's corresponding fields in each parameter.
- List<Expr*> paramFields;
- int paramIndex = 0;
- for (auto arg : synArgs)
- {
- auto memberExpr = m_astBuilder->create<MemberExpr>();
- memberExpr->baseExpression = arg;
- // TODO: we should probably fetch the name from `[DerivativeMember]` if `arg` is
- // Differential type.
- memberExpr->name = varMember->getName();
- paramFields.add(memberExpr);
- paramIndex++;
- }
+ for (auto member : context->parentDecl->members)
+ {
+ auto derivativeAttr = member->findModifier<DerivativeMemberAttribute>();
+ if (!derivativeAttr)
+ continue;
+ auto varMember = as<VarDeclBase>(member);
+ if (!varMember)
+ continue;
+ ensureDecl(varMember, DeclCheckState::ReadyForReference);
+ auto memberType = varMember->getType();
+ auto diffMemberType = tryGetDifferentialType(m_astBuilder, memberType);
+ if (!diffMemberType)
+ continue;
- // Invoke the method for the field and assign the value to resultVar.
- // TODO: we should probably fetch the name from `[DerivativeMember]` if `resultVarExpr`
- // is Differential type.
- auto leftVal = synth.emitMemberExpr(resultVarExpr, varMember->getName());
- if (!_synthesizeMemberAssignMemberHelper(synth, requirementDeclRef.getName(), memberType, leftVal, _Move(paramFields)))
- return false;
- }
+ // Construct reference exprs to the member's corresponding fields in each parameter.
+ List<Expr*> paramFields;
+ int paramIndex = 0;
+ for (auto arg : synArgs)
+ {
+ auto memberExpr = m_astBuilder->create<MemberExpr>();
+ memberExpr->baseExpression = arg;
+ // TODO: we should probably fetch the name from `[DerivativeMember]` if `arg` is
+ // Differential type.
+ memberExpr->name = varMember->getName();
+ paramFields.add(memberExpr);
+ paramIndex++;
+ }
+
+ // Invoke the method for the field and assign the value to resultVar.
+ // TODO: we should probably fetch the name from `[DerivativeMember]` if `resultVarExpr`
+ // is Differential type.
+ auto leftVal = synth.emitMemberExpr(resultVarExpr, varMember->getName());
+ if (!_synthesizeMemberAssignMemberHelper(synth, requirementDeclRef.getName(), memberType, leftVal, _Move(paramFields)))
+ return false;
+ }
- // TODO: synthesize assignments for inherited members here.
+ // TODO: synthesize assignments for inherited members here.
- auto synReturn = m_astBuilder->create<ReturnStmt>();
- synReturn->expression = resultVarExpr;
- seqStmt->stmts.add(synReturn);
- }
+ auto synReturn = m_astBuilder->create<ReturnStmt>();
+ synReturn->expression = resultVarExpr;
+ seqStmt->stmts.add(synReturn);
context->parentDecl->members.add(synFunc);
context->parentDecl->invalidateMemberDictionary();
@@ -4633,21 +4610,6 @@ namespace Slang
getSink()->diagnose(decl, Slang::Diagnostics::assocTypeInInterfaceOnly);
}
- void SemanticsDeclBodyVisitor::_maybeRegisterDifferentialBottomTypeConformance(SemanticsContext& context)
- {
- auto parentDifferentiableAttr = context.getParentDifferentiableAttribute();
- if (parentDifferentiableAttr)
- {
- auto diffBottomType = m_astBuilder->getDifferentialBottomType();
- auto idifferentiable = DeclRef<InterfaceDecl>(m_astBuilder->getDifferentiableInterface(), nullptr);
- auto witness = as<SubtypeWitness>(tryGetInterfaceConformanceWitness(diffBottomType, idifferentiable));
- SLANG_ASSERT(witness);
- parentDifferentiableAttr->m_mapTypeToIDifferentiableWitness.Add(
- as<DeclRefType>(diffBottomType)->declRef,
- witness);
- }
- }
-
void SemanticsDeclBodyVisitor::checkDerivativeOfAttribute(FunctionDeclBase* funcDecl)
{
auto attr = funcDecl->findModifier<ForwardDerivativeOfAttribute>();
diff --git a/source/slang/slang-ir-inst-defs.h b/source/slang/slang-ir-inst-defs.h
index 9233972ad..3ca9f1d41 100644
--- a/source/slang/slang-ir-inst-defs.h
+++ b/source/slang/slang-ir-inst-defs.h
@@ -60,7 +60,6 @@ INST(Nop, nop, 0, 0)
INST(OptionalType, Optional, 1, 0)
INST(DifferentialPairType, DiffPair, 1, 0)
- INST(DifferentialBottomType, DiffBottomType, 0, 0)
/* BindExistentialsTypeBase */
diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h
index 250088f96..7cf8b3032 100644
--- a/source/slang/slang-ir-insts.h
+++ b/source/slang/slang-ir-insts.h
@@ -2439,7 +2439,6 @@ public:
IRAnyValueType* getAnyValueType(IRIntegerValue size);
IRAnyValueType* getAnyValueType(IRInst* size);
IRDynamicType* getDynamicType();
- IRDifferentialBottomType* getDifferentialBottomType();
IRTupleType* getTupleType(UInt count, IRType* const* types);
IRTupleType* getTupleType(List<IRType*> const& types)
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index c12872320..ecfcab7f5 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -2214,17 +2214,6 @@ namespace Slang
return _findOrEmitConstant(keyInst);
}
- IRInst* IRBuilder::getDifferentialBottom()
- {
- IRType* type = getDifferentialBottomType();
- IRConstant keyInst;
- memset(&keyInst, 0, sizeof(keyInst));
- keyInst.m_op = kIROp_DifferentialBottomValue;
- keyInst.typeUse.usedValue = type;
- keyInst.value.intVal = 0;
- return (IRInst*)_findOrEmitConstant(keyInst);
- }
-
IRStringLit* IRBuilder::getStringValue(const UnownedStringSlice& inSlice)
{
IRConstant keyInst;
@@ -2607,12 +2596,6 @@ namespace Slang
IRDynamicType* IRBuilder::getDynamicType() { return (IRDynamicType*)getType(kIROp_DynamicType); }
- IRDifferentialBottomType* IRBuilder::getDifferentialBottomType()
- {
- return (IRDifferentialBottomType*)getType(kIROp_DifferentialBottomType);
- }
-
-
IRAssociatedType* IRBuilder::getAssociatedType(ArrayView<IRInterfaceType*> constraintTypes)
{
return (IRAssociatedType*)getType(kIROp_AssociatedType,
diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h
index ab3f010b0..0909615af 100644
--- a/source/slang/slang-ir.h
+++ b/source/slang/slang-ir.h
@@ -864,8 +864,6 @@ SIMPLE_IR_TYPE(NativeStringType, StringTypeBase)
SIMPLE_IR_TYPE(DynamicType, Type)
-SIMPLE_IR_TYPE(DifferentialBottomType, Type)
-
// True if types are equal
// Note compares nominal types by name alone
bool isTypeEqual(IRType* a, IRType* b);