Use ConstructorCompound::Make when optimizing swizzles.

Constructor::Convert is a very heavy hammer which does error-checking
and lots of logic to identify the right constructor type to use. It cuts
out a lot of redundant work to call the desired method
`ConstructorCompound::Make` directly instead.

Change-Id: Icf9e513dbce223c2b27ccd0d11dc08eea849ff39
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/539821
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/ir/BUILD.bazel b/src/sksl/ir/BUILD.bazel
index d8cd99b..fbddfe0 100644
--- a/src/sksl/ir/BUILD.bazel
+++ b/src/sksl/ir/BUILD.bazel
@@ -948,7 +948,6 @@
         ":SkSLConstructorCompound_hdr",
         ":SkSLConstructorScalarCast_hdr",
         ":SkSLConstructorSplat_hdr",
-        ":SkSLConstructor_hdr",
         ":SkSLLiteral_hdr",
         ":SkSLSwizzle_hdr",
         "//include/sksl:SkSLErrorReporter_hdr",
diff --git a/src/sksl/ir/SkSLSwizzle.cpp b/src/sksl/ir/SkSLSwizzle.cpp
index ae56878..481bd00 100644
--- a/src/sksl/ir/SkSLSwizzle.cpp
+++ b/src/sksl/ir/SkSLSwizzle.cpp
@@ -11,7 +11,6 @@
 #include "src/sksl/SkSLAnalysis.h"
 #include "src/sksl/SkSLConstantFolder.h"
 #include "src/sksl/SkSLProgramSettings.h"
-#include "src/sksl/ir/SkSLConstructor.h"
 #include "src/sksl/ir/SkSLConstructorCompound.h"
 #include "src/sksl/ir/SkSLConstructorCompoundCast.h"
 #include "src/sksl/ir/SkSLConstructorScalarCast.h"
@@ -110,7 +109,7 @@
 
 static std::unique_ptr<Expression> optimize_constructor_swizzle(const Context& context,
                                                                 Position pos,
-                                                                const AnyConstructor& base,
+                                                                const ConstructorCompound& base,
                                                                 ComponentArray components) {
     auto baseArguments = base.argumentSpan();
     std::unique_ptr<Expression> replacement;
@@ -228,11 +227,11 @@
         }
     }
 
-    // Wrap the new argument list in a constructor.
-    return Constructor::Convert(context,
-                                pos,
-                                componentType.toCompound(context, swizzleSize, /*rows=*/1),
-                                std::move(newArgs));
+    // Wrap the new argument list in a compound constructor.
+    return ConstructorCompound::Make(context,
+                                     pos,
+                                     componentType.toCompound(context, swizzleSize, /*rows=*/1),
+                                     std::move(newArgs));
 }
 
 std::unique_ptr<Expression> Swizzle::Convert(const Context& context,
@@ -519,9 +518,9 @@
                        : ConstructorScalarCast::Make(context, pos, castType, std::move(swizzled));
     }
 
-    // Optimize swizzles of constructors.
-    if (value->isAnyConstructor()) {
-        const AnyConstructor& ctor = value->asAnyConstructor();
+    // Swizzles on compound constructors, like `half4(1, 2, 3, 4).yw`, can become `half2(2, 4)`.
+    if (value->is<ConstructorCompound>()) {
+        const ConstructorCompound& ctor = value->as<ConstructorCompound>();
         if (auto replacement = optimize_constructor_swizzle(context, pos, ctor, components)) {
             return replacement;
         }