Skip to content

Commit 16fb254

Browse files
committed
[tint] Add a diag::List to tint::Failure
Use this to describe _why_ the function failed. Use this in most places that currently errors with std::string. This preserves the diagnostic metadata, which would otherwise get baked into a string. Remove Diagnostic::code. It was never used, and is just consuming memory. Make Diagnostic use tint::Vector instead of std::vector. Add some magic so that 'operator<<(STREAM, Failure)' can be used with unformattable SUCCESS / FAILURE types. Simplifies test that check for success. Change-Id: I2e474c5387c3fbe68cb6b6c48b123d2597ef82e6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/152546 Kokoro: Kokoro <[email protected]> Reviewed-by: dan sinclair <[email protected]>
1 parent 0bc9de8 commit 16fb254

File tree

143 files changed

+1012
-857
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+1012
-857
lines changed

src/dawn/native/CompilationMessages.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,7 @@ MaybeError OwnedCompilationMessages::AddMessage(const tint::diag::Diagnostic& di
148148
fileStart + offsetInBytes, lengthInBytes)));
149149
}
150150

151-
if (diagnostic.code) {
152-
mMessageStrings.push_back(std::string(diagnostic.code) + ": " + diagnostic.message);
153-
} else {
154-
mMessageStrings.push_back(diagnostic.message);
155-
}
151+
mMessageStrings.push_back(diagnostic.message);
156152

157153
mMessages.push_back({nullptr, nullptr, tintSeverityToMessageType(diagnostic.severity), lineNum,
158154
linePosInBytes, offsetInBytes, lengthInBytes, linePosInUTF16,

src/dawn/native/d3d/ShaderUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ MaybeError TranslateToHLSL(d3d::HlslCompilationRequest r,
254254

255255
TRACE_EVENT0(tracePlatform.UnsafeGetValue(), General, "tint::hlsl::writer::Generate");
256256
auto result = tint::hlsl::writer::Generate(transformedProgram, options);
257-
DAWN_INVALID_IF(!result, "An error occured while generating HLSL: %s", result.Failure());
257+
DAWN_INVALID_IF(!result, "An error occurred while generating HLSL:\n%s",
258+
result.Failure().reason.str());
258259

259260
compiledShader->usesVertexIndex = usesVertexIndex;
260261
compiledShader->usesInstanceIndex = usesInstanceIndex;

src/dawn/native/metal/ShaderModuleMTL.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@
281281

282282
TRACE_EVENT0(r.platform.UnsafeGetValue(), General, "tint::msl::writer::Generate");
283283
auto result = tint::msl::writer::Generate(program, options);
284-
DAWN_INVALID_IF(!result, "An error occured while generating MSL: %s.",
285-
result.Failure());
284+
DAWN_INVALID_IF(!result, "An error occurred while generating MSL:\n%s",
285+
result.Failure().reason.str());
286286

287287
// Metal uses Clang to compile the shader as C++14. Disable everything in the -Wall
288288
// category. -Wunused-variable in particular comes up a lot in generated code, and some

src/dawn/native/opengl/ShaderModuleGL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ ResultOrError<GLuint> ShaderModule::CompileShader(
299299
tintOptions.texture_builtins_from_uniform = r.textureBuiltinsFromUniform;
300300

301301
auto result = tint::glsl::writer::Generate(program, tintOptions, r.entryPointName);
302-
DAWN_INVALID_IF(!result, "An error occured while generating GLSL: %s.",
303-
result.Failure());
302+
DAWN_INVALID_IF(!result, "An error occurred while generating GLSL:\n%s",
303+
result.Failure().reason.str());
304304

305305
return GLSLCompilation{{std::move(result->glsl), needsPlaceholderSampler,
306306
result->needs_internal_uniform_buffer,

src/dawn/native/vulkan/ShaderModuleVk.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ ResultOrError<ShaderModule::ModuleAndSpirv> ShaderModule::GetHandleAndSpirv(
359359

360360
TRACE_EVENT0(r.platform.UnsafeGetValue(), General, "tint::spirv::writer::Generate()");
361361
auto tintResult = tint::spirv::writer::Generate(program, options);
362-
DAWN_INVALID_IF(!tintResult, "An error occured while generating SPIR-V: %s.",
363-
tintResult.Failure());
362+
DAWN_INVALID_IF(!tintResult, "An error occurred while generating SPIR-V\n%s",
363+
tintResult.Failure().reason.str());
364364

365365
CompiledSpirv result;
366366
result.spirv = std::move(tintResult.Get().spirv);

src/dawn/tests/mocks/platform/CachingInterfaceMock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
EXPECT_EQ(N, after - before); \
3535
} while (0)
3636

37-
// Check that |HitN| cache hits occured, and |AddN| entries were added.
37+
// Check that |HitN| cache hits occurred, and |AddN| entries were added.
3838
// Usage: EXPECT_CACHE_STATS(myMockCache, Hit(42), Add(3), ...)
3939
// Hit / Add help readability, and enforce the args are passed correctly in the expected order.
4040
#define EXPECT_CACHE_STATS(cache, HitN, AddN, statement) \

src/dawn/tests/unittests/native/CommandBufferEncodingTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ TEST_F(CommandBufferEncodingTests, ComputePassEncoderIndirectDispatchStateRestor
274274
}
275275

276276
// Test that after restoring state, it is fully applied to the state tracker
277-
// and does not leak state changes that occured between a snapshot and the
277+
// and does not leak state changes that occurred between a snapshot and the
278278
// state restoration.
279279
TEST_F(CommandBufferEncodingTests, StateNotLeakedAfterRestore) {
280280
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();

src/tint/api/tint.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void Initialize() {
5858
tint::Program::printer = [](const tint::Program& program) {
5959
auto result = wgsl::writer::Generate(program, {});
6060
if (!result) {
61-
return "error: " + result.Failure();
61+
return result.Failure().reason.str();
6262
}
6363
return result->wgsl;
6464
};

src/tint/cmd/bench/main_bench.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ std::variant<tint::Source::File, Error> LoadInputFile(std::string name) {
109109
}
110110
auto result = tint::wgsl::writer::Generate(program, {});
111111
if (!result) {
112-
return Error{result.Failure()};
112+
return Error{result.Failure().reason.str()};
113113
}
114114
return tint::Source::File(path, result->wgsl);
115115
}

src/tint/cmd/tint/main.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,9 @@ of the hash codes in the comma separated list of hashes)");
400400
options.ShowHelp(std::cout);
401401
};
402402

403-
auto result = options.Parse(std::cerr, arguments);
403+
auto result = options.Parse(arguments);
404404
if (!result) {
405-
std::cerr << std::endl;
405+
std::cerr << result.Failure() << std::endl;
406406
show_usage();
407407
return false;
408408
}

0 commit comments

Comments
 (0)