From 20ea33f3321738e7c1b4cad7bdcaedcdb54dd0f0 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 11 Apr 2023 10:18:18 -0400 Subject: Artifact simplification (#2781) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP simplifying artifact interface. * Use ContainedKind. * Remove LazyCastableList. Use ContainedKind for find. * Remove ICastableList. * Remove need for ICastableList. * Remove IArtifactContainer. * Small fixes. * Small improvements around Artifact. * Make explicit find is for *representations* that can cast. Fix bug in handling casting in lookup. * Made associated items artifacts too. * Small fixes. * Small improvements around writing a container. --- source/slang/slang-compiler.cpp | 25 ++++++++++--------------- source/slang/slang-emit.cpp | 10 ++-------- source/slang/slang-options.cpp | 1 + source/slang/slang-repro.cpp | 1 + source/slang/slang.cpp | 3 ++- 5 files changed, 16 insertions(+), 24 deletions(-) (limited to 'source/slang') diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 839a4e67c..497cf3d94 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -8,6 +8,7 @@ #include "../core/slang-riff.h" #include "../core/slang-type-text-util.h" #include "../core/slang-type-convert-util.h" +#include "../core/slang-castable.h" #include "slang-check.h" #include "slang-compiler.h" @@ -1119,7 +1120,7 @@ namespace Slang ComPtr metadata; if (sourceArtifact) { - metadata = findAssociated(sourceArtifact); + metadata = findAssociatedRepresentation(sourceArtifact); // Set the source artifacts options.sourceArtifacts = makeSlice(sourceArtifact.readRef(), 1); @@ -1411,7 +1412,7 @@ namespace Slang (std::chrono::high_resolution_clock::now() - downstreamStartTime).count() * 0.000000001; getSession()->addDownstreamCompileTime(downstreamElapsedTime); - auto diagnostics = findAssociated(artifact); + auto diagnostics = findAssociatedRepresentation(artifact); if (diagnostics->getCount()) { @@ -1468,10 +1469,7 @@ namespace Slang return SLANG_FAIL; } - if (metadata) - { - artifact->addAssociated(metadata); - } + ArtifactUtil::addAssociated(artifact, metadata); // Set the artifact outArtifact.swap(artifact); @@ -1975,22 +1973,19 @@ namespace Slang { Index nameCount = 0; - auto associated = m_containerArtifact->getAssociated(); - const Count count = associated->getCount(); - for (Index i = 0; i < count; ++i) + for (auto associatedArtifact : m_containerArtifact->getAssociated()) { - IArtifact* artifact = as(associated->getAt(i)); - auto desc = artifact->getDesc(); + auto desc = associatedArtifact->getDesc(); if (isDerivedFrom(desc.payload, ArtifactPayload::SourceMap)) { StringBuilder artifactFilename; // Dump out - const char* artifactName = artifact->getName(); + const char* artifactName = associatedArtifact->getName(); if (artifactName && artifactName[0] != 0) { - SLANG_RETURN_ON_FAIL(ArtifactUtil::calcName(artifact, UnownedStringSlice(artifactName), artifactFilename)); + SLANG_RETURN_ON_FAIL(ArtifactUtil::calcName(associatedArtifact, UnownedStringSlice(artifactName), artifactFilename)); } else { @@ -2005,13 +2000,13 @@ namespace Slang baseName.append(nameCount); } - SLANG_RETURN_ON_FAIL(ArtifactUtil::calcName(artifact, baseName.getUnownedSlice(), artifactFilename)); + SLANG_RETURN_ON_FAIL(ArtifactUtil::calcName(associatedArtifact, baseName.getUnownedSlice(), artifactFilename)); nameCount ++; } ComPtr blob; - SLANG_RETURN_ON_FAIL(artifact->loadBlob(ArtifactKeep::No, blob.writeRef())); + SLANG_RETURN_ON_FAIL(associatedArtifact->loadBlob(ArtifactKeep::No, blob.writeRef())); // Try to write it out { diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index a18eed928..ca141bd7a 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -1146,10 +1146,7 @@ SlangResult CodeGenContext::emitEntryPointsSourceFromIR(ComPtr& outAr auto artifact = ArtifactUtil::createArtifactForCompileTarget(asExternal(target)); artifact->addRepresentationUnknown(StringBlob::moveCreate(finalResult)); - if (metadata) - { - artifact->addAssociated(metadata); - } + ArtifactUtil::addAssociated(artifact, metadata); if (sourceMap) { @@ -1210,10 +1207,7 @@ SlangResult emitSPIRVForEntryPointsDirectly( auto artifact = ArtifactUtil::createArtifactForCompileTarget(asExternal(codeGenContext->getTargetFormat())); artifact->addRepresentationUnknown(ListBlob::moveCreate(spirv)); - if (linkedIR.metadata) - { - artifact->addAssociated(linkedIR.metadata); - } + ArtifactUtil::addAssociated(artifact, linkedIR.metadata); outArtifact.swap(artifact); diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index d30c02484..7e24b53fe 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -20,6 +20,7 @@ #include "slang-repro.h" #include "slang-serialize-ir.h" +#include "../core/slang-castable.h" #include "../core/slang-file-system.h" #include "../core/slang-type-text-util.h" #include "../core/slang-hex-dump-util.h" diff --git a/source/slang/slang-repro.cpp b/source/slang/slang-repro.cpp index d3a65adc0..d77aa9b21 100644 --- a/source/slang/slang-repro.cpp +++ b/source/slang/slang-repro.cpp @@ -7,6 +7,7 @@ #include "../core/slang-math.h" #include "../core/slang-type-text-util.h" +#include "../core/slang-castable.h" #include "slang-options.h" diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 2f02dcfb7..597e27bb9 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -6,6 +6,7 @@ #include "../core/slang-archive-file-system.h" #include "../core/slang-type-text-util.h" #include "../core/slang-type-convert-util.h" +#include "../core/slang-castable.h" // Artifact #include "../compiler-core/slang-artifact-impl.h" @@ -5378,7 +5379,7 @@ SlangResult EndToEndCompileRequest::isParameterLocationUsed(Int entryPointIndex, return SLANG_E_INVALID_ARG; // Find a rep - auto metadata = findAssociated(artifact); + auto metadata = findAssociatedRepresentation(artifact); if (!metadata) return SLANG_E_NOT_AVAILABLE; -- cgit v1.2.3