From 00746bf09047cdf01c19dac513a532bcf3ed3ea3 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Wed, 9 Jul 2025 14:41:19 +0800 Subject: Stable names and backwards compat for serialized IR modules (#7644) * stable names * tests, options and ci for stable names * Add back compat design document * fix warnings * formatting * comment * neaten * regenerate command line reference * consolidate ci scripts * faster ci * remove libreadline * Move new function to end of interface --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index b616eb555..090e34e9a 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -763,7 +763,7 @@ SlangResult Session::_readBuiltinModule( // to deserialize the IR module. // RefPtr irModule; - readSerializedModuleIR(irChunk, this, sourceLocReader, irModule); + SLANG_RETURN_ON_FAIL(readSerializedModuleIR(irChunk, this, sourceLocReader, irModule)); irModule->setName(module->getNameObj()); module->setIRModule(irModule); @@ -1368,6 +1368,7 @@ Linkage::Linkage(Session* session, ASTBuilder* astBuilder, Linkage* builtinLinka , m_sourceManager(&m_defaultSourceManager) , m_astBuilder(astBuilder) , m_cmdLineContext(new CommandLineContext()) + , m_stringSlicePool(StringSlicePool::Style::Default) { getNamePool()->setRootNamePool(session->getRootNamePool()); @@ -1663,6 +1664,47 @@ SLANG_NO_THROW slang::IModule* SLANG_MCALL Linkage::loadModuleFromIRBlob( return loadModuleFromBlob(moduleName, path, source, ModuleBlobType::IR, outDiagnostics); } +SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::loadModuleInfoFromIRBlob( + slang::IBlob* source, + SlangInt& outModuleVersion, + const char*& outModuleCompilerVersion, + const char*& outModuleName) +{ + // We start by reading the content of the file as + // an in-memory RIFF container. + // + auto rootChunk = RIFF::RootChunk::getFromBlob(source); + if (!rootChunk) + { + return SLANG_FAIL; + } + + auto moduleChunk = ModuleChunk::find(rootChunk); + if (!moduleChunk) + { + return SLANG_FAIL; + } + + auto irChunk = moduleChunk->findIR(); + if (!irChunk) + { + return SLANG_FAIL; + } + + RefPtr irModule; + String compilerVersion; + UInt version; + String name; + SLANG_RETURN_ON_FAIL(readSerializedModuleInfo(irChunk, compilerVersion, version, name)); + const auto compilerVersionSlice = m_stringSlicePool.addAndGetSlice(compilerVersion); + const auto nameSlice = m_stringSlicePool.addAndGetSlice(name); + outModuleCompilerVersion = compilerVersionSlice.begin(); + outModuleName = nameSlice.begin(); + outModuleVersion = SlangInt(version); + + return SLANG_OK; +} + SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::createCompositeComponentType( slang::IComponentType* const* componentTypes, SlangInt componentTypeCount, @@ -6801,7 +6843,7 @@ SlangResult Linkage::loadSerializedModuleContents( module->setModuleDecl(moduleDecl); RefPtr irModule; - readSerializedModuleIR(irChunk, session, sourceLocReader, irModule); + SLANG_RETURN_ON_FAIL(readSerializedModuleIR(irChunk, session, sourceLocReader, irModule)); module->setIRModule(irModule); // The handling of file dependencies is complicated, because of -- cgit v1.2.3