Improve error handling in SkSL ByteCode
- Allow for $floatLiteral and $intLiteral when determining type
categories. These could slip into the IR, leading to asserts.
- We weren't propagating the source text in specialize(), so errors in
the ByteCodeGenerator would actually assert about a missing fSource.
It's held by unique_ptr on Program, so we wastefully clone the
string, but we don't have that many specializations yet, so not too
bad?
Change-Id: I9c79acfb084e6dc8628625dea039c085ec46dba7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/265598
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index d4c0e2e..7bfdce1 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -1481,8 +1481,9 @@
for (auto iter = inputs.begin(); iter != inputs.end(); ++iter) {
settings.fArgs.insert(*iter);
}
+ std::unique_ptr<String> sourceCopy(new String(*program.fSource));
std::unique_ptr<Program> result(new Program(program.fKind,
- nullptr,
+ std::move(sourceCopy),
settings,
program.fContext,
program.fInheritedElements,
@@ -1621,9 +1622,12 @@
if (!this->optimize(program)) {
return nullptr;
}
+ fSource = program.fSource.get();
std::unique_ptr<ByteCode> result(new ByteCode());
ByteCodeGenerator cg(fContext.get(), &program, this, result.get());
- if (cg.generateCode()) {
+ bool success = cg.generateCode();
+ fSource = nullptr;
+ if (success) {
return result;
}
#else