SkSL: Rename isConstant to isCompileTimeConstant

This better reflects what the return value means, and eliminates
confusion with the SkSL concept of "const" variables, which are
not known at compile time.

Change-Id: I14973ceb36ae4ab6bad8a13bb93e1788a1b18bd9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299863
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/SkSLByteCodeGenerator.cpp b/src/sksl/SkSLByteCodeGenerator.cpp
index c484d7c..ce0dbf9 100644
--- a/src/sksl/SkSLByteCodeGenerator.cpp
+++ b/src/sksl/SkSLByteCodeGenerator.cpp
@@ -529,7 +529,7 @@
             int length = i.fBase->fType.columns();
             SkASSERT(length <= 255);
             int offset = -1;
-            if (i.fIndex->isConstant()) {
+            if (i.fIndex->isCompileTimeConstant()) {
                 int64_t index = i.fIndex->getConstantInt();
                 if (index < 0 || index >= length) {
                     fErrors.error(i.fIndex->fOffset, "Array index out of bounds.");
@@ -729,7 +729,7 @@
         case Token::Kind::TK_SHR: {
             SkASSERT(count == 1 && (tc == SkSL::TypeCategory::kSigned ||
                                     tc == SkSL::TypeCategory::kUnsigned));
-            if (!b.fRight->isConstant()) {
+            if (!b.fRight->isCompileTimeConstant()) {
                 fErrors.error(b.fRight->fOffset, "Shift amounts must be constant");
                 return false;
             }
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index d5c1293..6adc803 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -595,7 +595,7 @@
             Constructor& c = (Constructor&) expr;
             bool isFloat = c.fType.columns() > 1 ? c.fType.componentType().isFloat()
                                                  : c.fType.isFloat();
-            if (c.fType.kind() == Type::kVector_Kind && c.isConstant()) {
+            if (c.fType.kind() == Type::kVector_Kind && c.isCompileTimeConstant()) {
                 for (int i = 0; i < c.fType.columns(); ++i) {
                     if (isFloat) {
                         if (c.getFVecComponent(i) != value) {
@@ -1251,7 +1251,7 @@
         }
         case Statement::kSwitch_Kind: {
             SwitchStatement& s = (SwitchStatement&) *stmt;
-            if (s.fValue->isConstant()) {
+            if (s.fValue->isCompileTimeConstant()) {
                 // switch is constant, replace it with the case that matches
                 bool found = false;
                 SwitchCase* defaultCase = nullptr;
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
index c73e5ca..15d91c3 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -617,7 +617,7 @@
             if (!caseValue) {
                 return nullptr;
             }
-            if (!caseValue->isConstant()) {
+            if (!caseValue->isCompileTimeConstant()) {
                 fErrors.error(caseValue->fOffset, "case value must be a constant");
                 return nullptr;
             }
@@ -1593,16 +1593,16 @@
                                                       const Expression& right) const {
     // If the left side is a constant boolean literal, the right side does not need to be constant
     // for short circuit optimizations to allow the constant to be folded.
-    if (left.fKind == Expression::kBoolLiteral_Kind && !right.isConstant()) {
+    if (left.fKind == Expression::kBoolLiteral_Kind && !right.isCompileTimeConstant()) {
         return short_circuit_boolean(fContext, left, op, right);
-    } else if (right.fKind == Expression::kBoolLiteral_Kind && !left.isConstant()) {
+    } else if (right.fKind == Expression::kBoolLiteral_Kind && !left.isCompileTimeConstant()) {
         // There aren't side effects in SKSL within expressions, so (left OP right) is equivalent to
         // (right OP left) for short-circuit optimizations
         return short_circuit_boolean(fContext, right, op, left);
     }
 
     // Other than the short-circuit cases above, constant folding requires both sides to be constant
-    if (!left.isConstant() || !right.isConstant()) {
+    if (!left.isCompileTimeConstant() || !right.isCompileTimeConstant()) {
         return nullptr;
     }
     // Note that we expressly do not worry about precision and overflow here -- we use the maximum
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp
index 4103592..4516f69 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp
@@ -1071,7 +1071,7 @@
 }
 
 SpvId SPIRVCodeGenerator::writeConstantVector(const Constructor& c) {
-    SkASSERT(c.fType.kind() == Type::kVector_Kind && c.isConstant());
+    SkASSERT(c.fType.kind() == Type::kVector_Kind && c.isCompileTimeConstant());
     SpvId result = this->nextId();
     std::vector<SpvId> arguments;
     for (size_t i = 0; i < c.fArguments.size(); i++) {
@@ -1361,7 +1361,7 @@
 
 SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, OutputStream& out) {
     SkASSERT(c.fType.kind() == Type::kVector_Kind);
-    if (c.isConstant()) {
+    if (c.isCompileTimeConstant()) {
         return this->writeConstantVector(c);
     }
     // go ahead and write the arguments so we don't try to write new instructions in the middle of
@@ -2381,7 +2381,9 @@
 
 SpvId SPIRVCodeGenerator::writeTernaryExpression(const TernaryExpression& t, OutputStream& out) {
     SpvId test = this->writeExpression(*t.fTest, out);
-    if (t.fIfTrue->fType.columns() == 1 && t.fIfTrue->isConstant() && t.fIfFalse->isConstant()) {
+    if (t.fIfTrue->fType.columns() == 1 &&
+        t.fIfTrue->isCompileTimeConstant() &&
+        t.fIfFalse->isCompileTimeConstant()) {
         // both true and false are constants, can just use OpSelect
         SpvId result = this->nextId();
         SpvId trueId = this->writeExpression(*t.fIfTrue, out);
diff --git a/src/sksl/ir/SkSLBoolLiteral.h b/src/sksl/ir/SkSLBoolLiteral.h
index 85dd8c5..056aae2 100644
--- a/src/sksl/ir/SkSLBoolLiteral.h
+++ b/src/sksl/ir/SkSLBoolLiteral.h
@@ -29,7 +29,7 @@
         return false;
     }
 
-    bool isConstant() const override {
+    bool isCompileTimeConstant() const override {
         return true;
     }
 
diff --git a/src/sksl/ir/SkSLConstructor.h b/src/sksl/ir/SkSLConstructor.h
index cdd6f84..6f23276 100644
--- a/src/sksl/ir/SkSLConstructor.h
+++ b/src/sksl/ir/SkSLConstructor.h
@@ -87,9 +87,9 @@
         return result;
     }
 
-    bool isConstant() const override {
+    bool isCompileTimeConstant() const override {
         for (size_t i = 0; i < fArguments.size(); i++) {
-            if (!fArguments[i]->isConstant()) {
+            if (!fArguments[i]->isCompileTimeConstant()) {
                 return false;
             }
         }
@@ -192,7 +192,7 @@
     }
 
     SKSL_FLOAT getMatComponent(int col, int row) const override {
-        SkASSERT(this->isConstant());
+        SkASSERT(this->isCompileTimeConstant());
         SkASSERT(fType.kind() == Type::kMatrix_Kind);
         SkASSERT(col < fType.columns() && row < fType.rows());
         if (fArguments.size() == 1) {
diff --git a/src/sksl/ir/SkSLExpression.h b/src/sksl/ir/SkSLExpression.h
index c33c1a0..254d510 100644
--- a/src/sksl/ir/SkSLExpression.h
+++ b/src/sksl/ir/SkSLExpression.h
@@ -61,7 +61,7 @@
      * Returns true if this expression is constant. compareConstant must be implemented for all
      * constants!
      */
-    virtual bool isConstant() const {
+    virtual bool isCompileTimeConstant() const {
         return false;
     }
 
@@ -95,8 +95,8 @@
      * same result with no side effects.
      */
     virtual bool isConstantOrUniform() const {
-        SkASSERT(!this->isConstant() || !this->hasSideEffects());
-        return this->isConstant();
+        SkASSERT(!this->isCompileTimeConstant() || !this->hasSideEffects());
+        return this->isCompileTimeConstant();
     }
 
     virtual bool hasProperty(Property property) const = 0;
diff --git a/src/sksl/ir/SkSLFloatLiteral.h b/src/sksl/ir/SkSLFloatLiteral.h
index 9d81771..4ace0a0 100644
--- a/src/sksl/ir/SkSLFloatLiteral.h
+++ b/src/sksl/ir/SkSLFloatLiteral.h
@@ -33,7 +33,7 @@
         return false;
     }
 
-    bool isConstant() const override {
+    bool isCompileTimeConstant() const override {
         return true;
     }
 
diff --git a/src/sksl/ir/SkSLIntLiteral.h b/src/sksl/ir/SkSLIntLiteral.h
index 4977fbf..4641939 100644
--- a/src/sksl/ir/SkSLIntLiteral.h
+++ b/src/sksl/ir/SkSLIntLiteral.h
@@ -35,7 +35,7 @@
         return false;
     }
 
-    bool isConstant() const override {
+    bool isCompileTimeConstant() const override {
         return true;
     }
 
diff --git a/src/sksl/ir/SkSLNullLiteral.h b/src/sksl/ir/SkSLNullLiteral.h
index 0d04b77..8bf7960 100644
--- a/src/sksl/ir/SkSLNullLiteral.h
+++ b/src/sksl/ir/SkSLNullLiteral.h
@@ -31,7 +31,7 @@
         return false;
     }
 
-    bool isConstant() const override {
+    bool isCompileTimeConstant() const override {
         return true;
     }
 
diff --git a/src/sksl/ir/SkSLPrefixExpression.h b/src/sksl/ir/SkSLPrefixExpression.h
index ab0363e..08f8bd4 100644
--- a/src/sksl/ir/SkSLPrefixExpression.h
+++ b/src/sksl/ir/SkSLPrefixExpression.h
@@ -25,8 +25,8 @@
     , fOperand(std::move(operand))
     , fOperator(op) {}
 
-    bool isConstant() const override {
-        return fOperator == Token::Kind::TK_MINUS && fOperand->isConstant();
+    bool isCompileTimeConstant() const override {
+        return fOperator == Token::Kind::TK_MINUS && fOperand->isCompileTimeConstant();
     }
 
     bool hasProperty(Property property) const override {
diff --git a/src/sksl/ir/SkSLSetting.h b/src/sksl/ir/SkSLSetting.h
index 9a69802..50c2943 100644
--- a/src/sksl/ir/SkSLSetting.h
+++ b/src/sksl/ir/SkSLSetting.h
@@ -22,7 +22,7 @@
     : INHERITED(offset, kSetting_Kind, value->fType)
     , fName(std::move(name))
     , fValue(std::move(value)) {
-        SkASSERT(fValue->isConstant());
+        SkASSERT(fValue->isCompileTimeConstant());
     }
 
     std::unique_ptr<Expression> constantPropagate(const IRGenerator& irGenerator,
@@ -44,7 +44,7 @@
         return false;
     }
 
-    bool isConstant() const override {
+    bool isCompileTimeConstant() const override {
         return true;
     }
 
diff --git a/src/sksl/ir/SkSLSwizzle.h b/src/sksl/ir/SkSLSwizzle.h
index 040af84..4e12bee 100644
--- a/src/sksl/ir/SkSLSwizzle.h
+++ b/src/sksl/ir/SkSLSwizzle.h
@@ -106,7 +106,7 @@
 
     std::unique_ptr<Expression> constantPropagate(const IRGenerator& irGenerator,
                                                   const DefinitionMap& definitions) override {
-        if (fBase->fKind == Expression::kConstructor_Kind && fBase->isConstant()) {
+        if (fBase->fKind == Expression::kConstructor_Kind && fBase->isCompileTimeConstant()) {
             // we're swizzling a constant vector, e.g. float4(1).x. Simplify it.
             SkASSERT(fBase->fKind == Expression::kConstructor_Kind);
             if (fType.isInteger()) {
diff --git a/src/sksl/ir/SkSLVariableReference.cpp b/src/sksl/ir/SkSLVariableReference.cpp
index 2de8410..a888f95 100644
--- a/src/sksl/ir/SkSLVariableReference.cpp
+++ b/src/sksl/ir/SkSLVariableReference.cpp
@@ -53,7 +53,7 @@
 
 std::unique_ptr<Expression> VariableReference::copy_constant(const IRGenerator& irGenerator,
                                                              const Expression* expr) {
-    SkASSERT(expr->isConstant());
+    SkASSERT(expr->isCompileTimeConstant());
     switch (expr->fKind) {
         case Expression::kIntLiteral_Kind:
             return std::unique_ptr<Expression>(new IntLiteral(irGenerator.fContext,
@@ -100,12 +100,12 @@
         return irGenerator.getArg(fOffset, fVariable.fName);
     }
     if ((fVariable.fModifiers.fFlags & Modifiers::kConst_Flag) && fVariable.fInitialValue &&
-        fVariable.fInitialValue->isConstant() && fType.kind() != Type::kArray_Kind) {
+        fVariable.fInitialValue->isCompileTimeConstant() && fType.kind() != Type::kArray_Kind) {
         return copy_constant(irGenerator, fVariable.fInitialValue);
     }
     auto exprIter = definitions.find(&fVariable);
     if (exprIter != definitions.end() && exprIter->second &&
-        (*exprIter->second)->isConstant()) {
+        (*exprIter->second)->isCompileTimeConstant()) {
         return copy_constant(irGenerator, exprIter->second->get());
     }
     return nullptr;