summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ast-support-types.h2
-rw-r--r--source/slang/slang-check-impl.h2
-rwxr-xr-xsource/slang/slang-compiler.h45
-rw-r--r--source/slang/slang-preprocessor.cpp5
-rw-r--r--source/slang/slang-preprocessor.h2
-rw-r--r--source/slang/slang-serialize-type-info.h70
-rw-r--r--source/slang/slang.cpp25
7 files changed, 121 insertions, 30 deletions
diff --git a/source/slang/slang-ast-support-types.h b/source/slang/slang-ast-support-types.h
index 61580ca9e..4c92810d9 100644
--- a/source/slang/slang-ast-support-types.h
+++ b/source/slang/slang-ast-support-types.h
@@ -1424,7 +1424,7 @@ namespace Slang
Val* m_val = nullptr;
};
- typedef Dictionary<Decl*, RequirementWitness> RequirementDictionary;
+ typedef OrderedDictionary<Decl*, RequirementWitness> RequirementDictionary;
struct WitnessTable : SerialRefObject
{
diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h
index af1173051..821f785f5 100644
--- a/source/slang/slang-check-impl.h
+++ b/source/slang/slang-check-impl.h
@@ -274,7 +274,7 @@ namespace Slang
};
/// Mapping from types to subtype witnesses for conformance to IDifferentiable.
- Dictionary<DeclRefTypeKey, SubtypeWitness*> m_mapTypeToIDifferentiableWitness;
+ OrderedDictionary<DeclRefTypeKey, SubtypeWitness*> m_mapTypeToIDifferentiableWitness;
/// List of external dictionaries (from imported modules)
List<DeclRef<DifferentiableTypeDictionary>> m_importedDictionaries;
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index bd7cd4a18..eb6d6c1a5 100755
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -298,7 +298,7 @@ namespace Slang
SlangInt entryPointIndex,
SlangInt targetIndex,
slang::Digest* outHash) SLANG_OVERRIDE;
- SLANG_NO_THROW void SLANG_MCALL computeASTBasedHash(slang::Digest* outHash) SLANG_OVERRIDE;
+ SLANG_NO_THROW void SLANG_MCALL computeContentsBasedHash(slang::Digest* outHash) SLANG_OVERRIDE;
/// Get the linkage (aka "session" in the public API) for this component type.
Linkage* getLinkage() { return m_linkage; }
@@ -313,10 +313,10 @@ namespace Slang
DigestBuilder& hashBuilder,
SlangInt entryPointIndex) = 0;
- /// Update the hash builder with the AST contents for this component type.
- /// The AST is associated with a Module component, so most derived ComponentType classes
- /// will simply do nothing with this.
- virtual void updateASTBasedHash(DigestBuilder& hashBuilder) = 0;
+ /// Update the hash builder with the source contents for this component type.
+ /// Module should be the only derived ComponentType class which has a meaningful
+ /// implementation; all others should do nothing.
+ virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) = 0;
/// Get the number of entry points linked into this component type.
virtual Index getEntryPointCount() = 0;
@@ -519,7 +519,7 @@ namespace Slang
DigestBuilder& hashBuilder,
SlangInt entryPointIndex) override;
- virtual void updateASTBasedHash(DigestBuilder& hashBuilder) override;
+ virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) override;
List<RefPtr<ComponentType>> const& getChildComponents() { return m_childComponents; };
Index getChildComponentCount() { return m_childComponents.getCount(); }
@@ -601,7 +601,7 @@ namespace Slang
DigestBuilder& hashBuilder,
SlangInt entryPointIndex) override;
- virtual void updateASTBasedHash(DigestBuilder& hashBuilder) override
+ virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) override
{
SLANG_UNUSED(hashBuilder);
}
@@ -794,7 +794,7 @@ namespace Slang
DigestBuilder& hashBuilder,
SlangInt entryPointIndex) override;
- virtual void updateASTBasedHash(DigestBuilder& hashBuilder) override
+ virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) override
{
SLANG_UNUSED(hashBuilder);
}
@@ -899,16 +899,16 @@ namespace Slang
return Super::computeDependencyBasedHash(entryPointIndex, targetIndex, outHash);
}
- SLANG_NO_THROW void SLANG_MCALL computeASTBasedHash(slang::Digest* outHash) SLANG_OVERRIDE
+ SLANG_NO_THROW void SLANG_MCALL computeContentsBasedHash(slang::Digest* outHash) SLANG_OVERRIDE
{
- return Super::computeASTBasedHash(outHash);
+ return Super::computeContentsBasedHash(outHash);
}
virtual void updateDependencyBasedHash(
DigestBuilder& hashBuilder,
SlangInt entryPointIndex) override;
- virtual void updateASTBasedHash(DigestBuilder& hashBuilder) override
+ virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) override
{
SLANG_UNUSED(hashBuilder);
}
@@ -1126,16 +1126,16 @@ namespace Slang
return Super::computeDependencyBasedHash(entryPointIndex, targetIndex, outHash);
}
- SLANG_NO_THROW void SLANG_MCALL computeASTBasedHash(slang::Digest* outHash) SLANG_OVERRIDE
+ SLANG_NO_THROW void SLANG_MCALL computeContentsBasedHash(slang::Digest* outHash) SLANG_OVERRIDE
{
- return Super::computeASTBasedHash(outHash);
+ return Super::computeContentsBasedHash(outHash);
}
virtual void updateDependencyBasedHash(
DigestBuilder& hashBuilder,
SlangInt entryPointIndex) override;
- virtual void updateASTBasedHash(DigestBuilder& hashBuilder) override
+ virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) override
{
SLANG_UNUSED(hashBuilder);
}
@@ -1322,16 +1322,16 @@ namespace Slang
return Super::computeDependencyBasedHash(entryPointIndex, targetIndex, outHash);
}
- SLANG_NO_THROW void SLANG_MCALL computeASTBasedHash(slang::Digest* outHash) SLANG_OVERRIDE
+ SLANG_NO_THROW void SLANG_MCALL computeContentsBasedHash(slang::Digest* outHash) SLANG_OVERRIDE
{
- return Super::computeASTBasedHash(outHash);
+ return Super::computeContentsBasedHash(outHash);
}
virtual void updateDependencyBasedHash(
DigestBuilder& hashBuilder,
SlangInt entryPointIndex) override;
- virtual void updateASTBasedHash(DigestBuilder& hashBuilder) override;
+ virtual void updateContentsBasedHash(DigestBuilder& hashBuilder) override;
/// Create a module (initially empty).
Module(Linkage* linkage, ASTBuilder* astBuilder = nullptr);
@@ -1366,6 +1366,14 @@ namespace Slang
///
void setIRModule(IRModule* irModule) { m_irModule = irModule; }
+ DigestBuilder& getContentsDigestBuilder() { return contentsBuilder; }
+
+ /// Set the contents digest for this module.
+ void setContentsDigest(slang::Digest digest) { contentsDigest = digest; }
+
+ /// Get the contents digest for this module.
+ slang::Digest getContentsDigest() { return contentsDigest; }
+
Index getEntryPointCount() SLANG_OVERRIDE { return 0; }
RefPtr<EntryPoint> getEntryPoint(Index index) SLANG_OVERRIDE { SLANG_UNUSED(index); return nullptr; }
String getEntryPointMangledName(Index index) SLANG_OVERRIDE { SLANG_UNUSED(index); return String(); }
@@ -1474,6 +1482,9 @@ namespace Slang
// and m_mangledExportSymbols holds the NodeBase* values for each index.
StringSlicePool m_mangledExportPool;
List<NodeBase*> m_mangledExportSymbols;
+
+ DigestBuilder contentsBuilder;
+ slang::Digest contentsDigest;
};
typedef Module LoadedModule;
diff --git a/source/slang/slang-preprocessor.cpp b/source/slang/slang-preprocessor.cpp
index fca8f5029..c977e44ab 100644
--- a/source/slang/slang-preprocessor.cpp
+++ b/source/slang/slang-preprocessor.cpp
@@ -32,9 +32,10 @@ void PreprocessorHandler::handleEndOfTranslationUnit(Preprocessor* preprocessor)
SLANG_UNUSED(preprocessor);
}
-void PreprocessorHandler::handleFileDependency(String const& path)
+void PreprocessorHandler::handleFileDependency(String const& path, ISlangBlob* contents)
{
SLANG_UNUSED(path);
+ SLANG_UNUSED(contents);
}
// In order to simplify the naming scheme, we will nest the implementaiton of the
@@ -2972,7 +2973,7 @@ static SlangResult readFile(
//
if( auto handler = context->m_preprocessor->handler )
{
- handler->handleFileDependency(path);
+ handler->handleFileDependency(path, *outBlob);
}
return SLANG_OK;
diff --git a/source/slang/slang-preprocessor.h b/source/slang/slang-preprocessor.h
index 4d7721d31..90e03e964 100644
--- a/source/slang/slang-preprocessor.h
+++ b/source/slang/slang-preprocessor.h
@@ -28,7 +28,7 @@ using preprocessor::Preprocessor;
struct PreprocessorHandler
{
virtual void handleEndOfTranslationUnit(Preprocessor* preprocessor);
- virtual void handleFileDependency(String const& path);
+ virtual void handleFileDependency(String const& path, ISlangBlob* contents = nullptr);
};
/// Description of a preprocessor options/dependencies
diff --git a/source/slang/slang-serialize-type-info.h b/source/slang/slang-serialize-type-info.h
index 6258a129d..b6cea58f5 100644
--- a/source/slang/slang-serialize-type-info.h
+++ b/source/slang/slang-serialize-type-info.h
@@ -326,6 +326,76 @@ struct SerialTypeInfo<Dictionary<KEY, VALUE>>
}
};
+// OrderedDictionary
+template <typename KEY, typename VALUE>
+struct SerialTypeInfo<OrderedDictionary<KEY, VALUE>>
+{
+ typedef OrderedDictionary<KEY, VALUE> NativeType;
+ struct SerialType
+ {
+ SerialIndex keys; ///< Index an array
+ SerialIndex values; ///< Index an array
+ };
+
+ typedef typename SerialTypeInfo<KEY>::SerialType KeySerialType;
+ typedef typename SerialTypeInfo<VALUE>::SerialType ValueSerialType;
+
+ enum { SerialAlignment = SLANG_ALIGN_OF(SerialIndex) };
+
+ static void toSerial(SerialWriter* writer, const void* native, void* serial)
+ {
+ auto& src = *(const NativeType*)native;
+ auto& dst = *(SerialType*)serial;
+
+ List<KeySerialType> keys;
+ List<ValueSerialType> values;
+
+ Index count = Index(src.Count());
+ keys.setCount(count);
+ values.setCount(count);
+
+ if (writer->getFlags() & SerialWriter::Flag::ZeroInitialize)
+ {
+ ::memset(keys.getBuffer(), 0, count * sizeof(KeySerialType));
+ ::memset(values.getBuffer(), 0, count * sizeof(ValueSerialType));
+ }
+
+ Index i = 0;
+ for (const auto& pair : src)
+ {
+ SerialTypeInfo<KEY>::toSerial(writer, &pair.Key, &keys[i]);
+ SerialTypeInfo<VALUE>::toSerial(writer, &pair.Value, &values[i]);
+ i++;
+ }
+
+ // When we add the array it is already converted to a serializable type, so add as SerialArray
+ dst.keys = writer->addSerialArray<KEY>(keys.getBuffer(), count);
+ dst.values = writer->addSerialArray<VALUE>(values.getBuffer(), count);
+ }
+ static void toNative(SerialReader* reader, const void* serial, void* native)
+ {
+ auto& src = *(const SerialType*)serial;
+ auto& dst = *(NativeType*)native;
+
+ // Clear it
+ dst = NativeType();
+
+ List<KEY> keys;
+ List<VALUE> values;
+
+ reader->getArray(src.keys, keys);
+ reader->getArray(src.values, values);
+
+ SLANG_ASSERT(keys.getCount() == values.getCount());
+
+ const Index count = keys.getCount();
+ for (Index i = 0; i < count; ++i)
+ {
+ dst.Add(keys[i], values[i]);
+ }
+ }
+};
+
// KeyValuePair
template<typename KEY, typename VALUE>
struct SerialTypeInfo<KeyValuePair<KEY, VALUE>>
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index c7351d6a8..361f1b193 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -1898,9 +1898,13 @@ protected:
// by applications to decide when they need to "hot reload"
// their shader code.
//
- void handleFileDependency(String const& path) SLANG_OVERRIDE
+ void handleFileDependency(String const& path, ISlangBlob* sourceBlob) SLANG_OVERRIDE
{
m_module->addFilePathDependency(path);
+ if (sourceBlob)
+ {
+ m_module->getContentsDigestBuilder().addToDigest(sourceBlob);
+ }
}
// The second task that this handler deals with is detecting
@@ -3042,6 +3046,10 @@ RefPtr<Module> Linkage::loadModule(
return nullptr;
}
+ auto builder = module->getContentsDigestBuilder();
+ builder.addToDigest(sourceBlob);
+ module->setContentsDigest(builder.finalize());
+
return module;
}
@@ -3259,10 +3267,9 @@ void Module::updateDependencyBasedHash(
SLANG_UNUSED(entryPointIndex);
}
-void Module::updateASTBasedHash(DigestBuilder& builder)
+void Module::updateContentsBasedHash(DigestBuilder& builder)
{
- auto serializedAST = ASTSerialUtil::serializeAST(getModuleDecl());
- builder.addToDigest(serializedAST);
+ builder.addToDigest(getContentsDigest());
}
void Module::addModuleDependency(Module* module)
@@ -3491,16 +3498,18 @@ SLANG_NO_THROW void SLANG_MCALL ComponentType::computeDependencyBasedHash(
// to the hash.
auto entryPointName = getEntryPoint(entryPointIndex)->getName()->text;
builder.addToDigest(entryPointName);
+ auto entryPointMangledName = getEntryPointMangledName(entryPointIndex);
+ builder.addToDigest(entryPointMangledName);
auto entryPointNameOverride = getEntryPointNameOverride(entryPointIndex);
builder.addToDigest(entryPointNameOverride);
*outHash = builder.finalize();
}
-SLANG_NO_THROW void SLANG_MCALL ComponentType::computeASTBasedHash(slang::Digest* outHash)
+SLANG_NO_THROW void SLANG_MCALL ComponentType::computeContentsBasedHash(slang::Digest* outHash)
{
DigestBuilder builder;
- updateASTBasedHash(builder);
+ updateContentsBasedHash(builder);
*outHash = builder.finalize();
}
@@ -3848,13 +3857,13 @@ void CompositeComponentType::updateDependencyBasedHash(
}
}
-void CompositeComponentType::updateASTBasedHash(DigestBuilder& builder)
+void CompositeComponentType::updateContentsBasedHash(DigestBuilder& builder)
{
auto componentCount = getChildComponentCount();
for (Index i = 0; i < componentCount; ++i)
{
- getChildComponent(i)->updateASTBasedHash(builder);
+ getChildComponent(i)->updateContentsBasedHash(builder);
}
}