@@ -1882,6 +1882,45 @@ class SsaInstructionSimplifier extends HBaseVisitor
18821882 if (node.isRedundant(_closedWorld)) return node.checkedInput;
18831883 return node;
18841884 }
1885+
1886+ @override
1887+ HInstruction visitInstanceEnvironment(HInstanceEnvironment node) {
1888+ HInstruction instance = node.inputs.single;
1889+
1890+ // Store-forward instance types of created instances and constant instances.
1891+ //
1892+ // Forwarding the type might cause the instance (HCreate, constant etc) to
1893+ // become dead. This might cause us to lose track of that fact that there
1894+ // are type expressions from within the instance's class scope, so breaking
1895+ // the algorithm for generating the per-type runtime type information. The
1896+ // fix is to register the classes as created here in case the instance
1897+ // becomes dead.
1898+ //
1899+ // TODO(sra): It would be cleaner to track on HLoadType, HTypeEval, etc
1900+ // which class scope(s) they originated from. If the type expressions become
1901+ // dead, the references to the scope type variables become dead.
1902+
1903+ if (instance is HCreate) {
1904+ if (instance.hasRtiInput) {
1905+ instance.instantiatedTypes?.forEach(_registry.registerInstantiation);
1906+ return instance.inputs.last;
1907+ }
1908+ return node;
1909+ }
1910+
1911+ if (instance is HConstant) {
1912+ ConstantValue constantValue = instance.constant;
1913+ if (constantValue is ConstructedConstantValue) {
1914+ _registry.registerInstantiation(constantValue.type);
1915+ return HLoadType(constantValue.type, instance.instructionType);
1916+ }
1917+ return node;
1918+ }
1919+
1920+ // TODO(sra): Store-forward list literal types.
1921+
1922+ return node;
1923+ }
18851924}
18861925
18871926class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase {
0 commit comments