Revert "Removed name string field from SkSLType"

This reverts commit 2df03e64bf.

Reason for revert: Unhappy bots

Original change's description:
> Removed name string field from SkSLType
>
> This field wasn't really necessary, and was just bloating Type and
> causing a lot of extra String creation. This one change reduces the
> size of a new Compiler by ~2.4KB.
>
> Change-Id: Ie90c565d669d2caaa61056015ea2119fe61c1844
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/423298
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> Reviewed-by: John Stiles <johnstiles@google.com>

TBR=brianosman@google.com,ethannicholas@google.com,johnstiles@google.com,skcq-be@skia-corp.google.com.iam.gserviceaccount.com

Change-Id: I3959961d00749addc99cf97b6e2d50a172bf4b25
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/433158
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2021-07-26 19:56:23 +00:00 committed by SkCQ
parent 3465365fbd
commit 917fef7ba7
8 changed files with 31 additions and 39 deletions

View File

@ -1041,7 +1041,7 @@ std::unique_ptr<SkSL::InterfaceBlock> IRGenerator::convertInterfaceBlock(const A
}
}
const Type* type = old->takeOwnershipOfSymbol(Type::MakeStructType(intf.fOffset,
id.fTypeName,
String(id.fTypeName),
fields));
int arraySize = 0;
if (id.fIsArray) {

View File

@ -494,7 +494,8 @@ ASTNode::ID Parser::structDeclaration() {
"struct '" + this->text(name) + "' must contain at least one field");
return ASTNode::ID::Invalid();
}
std::unique_ptr<Type> newType = Type::MakeStructType(name.fOffset, this->text(name), fields);
std::unique_ptr<Type> newType = Type::MakeStructType(name.fOffset, String(this->text(name)),
fields);
if (struct_is_too_deeply_nested(*newType, kMaxStructDepth)) {
this->error(name.fOffset, "struct '" + this->text(name) + "' is too deeply nested");
return ASTNode::ID::Invalid();

View File

@ -153,9 +153,8 @@ const Symbol* Rehydrator::symbol() {
} else {
name += "[" + to_string(count) + "]";
}
skstd::string_view nameChars(*fSymbolTable->takeOwnershipOfString(std::move(name)));
const Type* result = fSymbolTable->takeOwnershipOfSymbol(
Type::MakeArrayType(nameChars, *componentType, count));
Type::MakeArrayType(name, *componentType, count));
this->addSymbol(id, result);
return result;
}
@ -200,9 +199,8 @@ const Symbol* Rehydrator::symbol() {
const Type* type = this->type();
fields.emplace_back(m, fieldName, type);
}
skstd::string_view nameChars(*fSymbolTable->takeOwnershipOfString(std::move(name)));
const Type* result = fSymbolTable->takeOwnershipOfSymbol(
Type::MakeStructType(/*offset=*/-1, nameChars, std::move(fields)));
Type::MakeStructType(/*offset=*/-1, name, std::move(fields)));
this->addSymbol(id, result);
return result;
}

View File

@ -3056,7 +3056,7 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool a
fProgram.fPool->attachToThread();
}
const Type* rtFlipStructType = fProgram.fSymbols->takeOwnershipOfSymbol(
Type::MakeStructType(type.fOffset, type.name(), std::move(fields)));
Type::MakeStructType(type.fOffset, String(type.name()), std::move(fields)));
const Variable* modifiedVar = fProgram.fSymbols->takeOwnershipOfSymbol(
std::make_unique<Variable>(intfVar.fOffset,
&intfVar.modifiers(),
@ -3589,7 +3589,7 @@ void SPIRVCodeGenerator::addRTFlipUniform(int offset) {
/*flags=*/0),
SKSL_RTFLIP_NAME,
fContext.fTypes.fFloat2.get());
skstd::string_view name = "sksl_synthetic_uniforms";
String name("sksl_synthetic_uniforms");
const Type* intfStruct =
fSynthetics.takeOwnershipOfSymbol(Type::MakeStructType(/*offset=*/-1, name, fields));
int binding = fProgram.fConfig->fSettings.fRTFlipBinding;
@ -3637,7 +3637,7 @@ void SPIRVCodeGenerator::addRTFlipUniform(int offset) {
}
InterfaceBlock intf(/*offset=*/-1,
intfVar,
String(name),
name,
/*instanceName=*/"",
/*arraySize=*/0,
std::make_shared<SymbolTable>(&fErrors, /*builtin=*/false));

View File

@ -204,7 +204,7 @@ DSLType Struct(skstd::string_view name, SkTArray<DSLField> fields) {
skslFields.emplace_back(field.fModifiers.fModifiers, field.fName, &field.fType.skslType());
}
const SkSL::Type* result = DSLWriter::SymbolTable()->add(Type::MakeStructType(/*offset=*/-1,
name,
String(name),
skslFields));
DSLWriter::ProgramElements().push_back(std::make_unique<SkSL::StructDefinition>(/*offset=*/-1,
*result));

View File

@ -127,12 +127,8 @@ const Type* SymbolTable::addArrayDimension(const Type* type, int arraySize) {
String arrayName = (arraySize != Type::kUnsizedArray)
? String::printf("%s[%d]", baseName.c_str(), arraySize)
: String::printf("%s[]", baseName.c_str());
SymbolTable* owner = this;
while (owner->fParent && !owner->fParent->fBuiltin) {
owner = owner->fParent.get();
}
skstd::string_view nameChars(*owner->takeOwnershipOfString(std::move(arrayName)));
type = this->takeOwnershipOfSymbol(Type::MakeArrayType(nameChars, *type, arraySize));
type = this->takeOwnershipOfSymbol(Type::MakeArrayType(std::move(arrayName),
*type, arraySize));
}
return type;
}

View File

@ -23,8 +23,8 @@ class ArrayType final : public Type {
public:
static constexpr TypeKind kTypeKind = TypeKind::kArray;
ArrayType(skstd::string_view name, const char* abbrev, const Type& componentType, int count)
: INHERITED(name, abbrev, kTypeKind)
ArrayType(String name, const char* abbrev, const Type& componentType, int count)
: INHERITED(std::move(name), abbrev, kTypeKind)
, fComponentType(componentType)
, fCount(count) {
// Allow either explicitly-sized or unsized arrays.
@ -170,9 +170,9 @@ class MatrixType final : public Type {
public:
static constexpr TypeKind kTypeKind = TypeKind::kMatrix;
MatrixType(skstd::string_view name, const char* abbrev, const Type& componentType,
int8_t columns, int8_t rows)
: INHERITED(name, abbrev, kTypeKind)
MatrixType(String name, const char* abbrev, const Type& componentType, int8_t columns,
int8_t rows)
: INHERITED(std::move(name), abbrev, kTypeKind)
, fComponentType(componentType.as<ScalarType>())
, fColumns(columns)
, fRows(rows) {
@ -293,7 +293,7 @@ class StructType final : public Type {
public:
static constexpr TypeKind kTypeKind = TypeKind::kStruct;
StructType(int offset, skstd::string_view name, std::vector<Field> fields)
StructType(int offset, String name, std::vector<Field> fields)
: INHERITED(std::move(name), "S", kTypeKind, offset)
, fFields(std::move(fields)) {}
@ -315,9 +315,8 @@ class VectorType final : public Type {
public:
static constexpr TypeKind kTypeKind = TypeKind::kVector;
VectorType(skstd::string_view name, const char* abbrev, const Type& componentType,
int8_t columns)
: INHERITED(name, abbrev, kTypeKind)
VectorType(String name, const char* abbrev, const Type& componentType, int8_t columns)
: INHERITED(std::move(name), abbrev, kTypeKind)
, fComponentType(componentType.as<ScalarType>())
, fColumns(columns) {
SkASSERT(columns >= 2 && columns <= 4);
@ -350,8 +349,7 @@ private:
int8_t fColumns;
};
std::unique_ptr<Type> Type::MakeArrayType(skstd::string_view name, const Type& componentType,
int columns) {
std::unique_ptr<Type> Type::MakeArrayType(String name, const Type& componentType, int columns) {
return std::make_unique<ArrayType>(std::move(name), componentType.abbreviatedName(),
componentType, columns);
}
@ -386,8 +384,7 @@ std::unique_ptr<Type> Type::MakeScalarType(const char* name, const char* abbrev,
}
std::unique_ptr<Type> Type::MakeStructType(int offset, skstd::string_view name,
std::vector<Field> fields) {
std::unique_ptr<Type> Type::MakeStructType(int offset, String name, std::vector<Field> fields) {
return std::make_unique<StructType>(offset, std::move(name), std::move(fields));
}
@ -592,12 +589,12 @@ const Type* Type::clone(SymbolTable* symbolTable) const {
// This type actually needs to be cloned into the destination SymbolTable.
switch (this->typeKind()) {
case TypeKind::kArray:
return symbolTable->add(Type::MakeArrayType(this->name(), this->componentType(),
this->columns()));
return symbolTable->add(Type::MakeArrayType(String(this->name()), this->componentType(),
this->columns()));
case TypeKind::kStruct:
return symbolTable->add(std::make_unique<StructType>(this->fOffset,
this->name(),
String(this->name()),
this->fields()));
default:

View File

@ -8,7 +8,6 @@
#ifndef SKSL_TYPE
#define SKSL_TYPE
#include "include/core/SkStringView.h"
#include "include/private/SkSLModifiers.h"
#include "include/private/SkSLSymbol.h"
#include "src/sksl/SkSLPosition.h"
@ -107,8 +106,7 @@ public:
/** Creates an array type. */
static constexpr int kUnsizedArray = -1;
static std::unique_ptr<Type> MakeArrayType(skstd::string_view name, const Type& componentType,
int columns);
static std::unique_ptr<Type> MakeArrayType(String name, const Type& componentType, int columns);
/**
* Create a generic type which maps to the listed types--e.g. $genType is a generic type which
@ -140,8 +138,7 @@ public:
Type::TypeKind typeKind);
/** Creates a struct type with the given fields. */
static std::unique_ptr<Type> MakeStructType(int offset, skstd::string_view name,
std::vector<Field> fields);
static std::unique_ptr<Type> MakeStructType(int offset, String name, std::vector<Field> fields);
/** Create a texture type. */
static std::unique_ptr<Type> MakeTextureType(const char* name, SpvDim_ dimensions,
@ -521,9 +518,11 @@ public:
bool checkForOutOfRangeLiteral(const Context& context, const Expression& expr) const;
protected:
Type(skstd::string_view name, const char* abbrev, TypeKind kind, int offset = -1)
: INHERITED(offset, kSymbolKind, name)
Type(String name, const char* abbrev, TypeKind kind, int offset = -1)
: INHERITED(offset, kSymbolKind, /*name=*/"")
, fNameString(std::move(name))
, fTypeKind(kind) {
fName = fNameString;
SkASSERT(strlen(abbrev) <= kMaxAbbrevLength);
strcpy(fAbbreviatedName, abbrev);
}
@ -533,6 +532,7 @@ private:
using INHERITED = Symbol;
String fNameString;
char fAbbreviatedName[kMaxAbbrevLength + 1] = {};
TypeKind fTypeKind;
};