diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart index 33358d898cc..aeddbc9439d 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart @@ -3786,20 +3786,18 @@ class ProgramCompiler extends ComputeOnceConstantVisitor if (recipe == '0') return env; } else { var environmentTypes = environment.functionTypeParameters; - // Create a dummy interface type to "hold" type arguments. - env = emitRtiEval( - _emitTypeParameter(environmentTypes.first), - '@<0>', - ); - // Bind remaining type arguments. - for (var i = 1; i < environmentTypes.length; i++) { - env = emitRtiBind(env, environmentTypes[i]); + // By convention we create a binding environment with "dynamic" as + // the base. + env = _emitType(const DynamicType()); + // Bind all type arguments to it. + for (var typeParameter in environmentTypes) { + env = emitRtiBind(env, typeParameter); } } return emitRtiEval(env, recipe); case RtiTypeEnvironment(): - // RTI type environments are already constructed and attached to the - // provided RTI. + // RTI type environments take the form of a preconstructed RTI that + // is accessible via a known parameter name. var env = _rtiParam; return emitRtiEval(env, recipe); case ClassTypeEnvironment(): diff --git a/pkg/dev_compiler/lib/src/kernel/compiler_new.dart b/pkg/dev_compiler/lib/src/kernel/compiler_new.dart index 7c7d24a509d..9303f38e8b2 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler_new.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler_new.dart @@ -4357,20 +4357,18 @@ class LibraryCompiler extends ComputeOnceConstantVisitor if (recipe == '0') return env; } else { var environmentTypes = environment.functionTypeParameters; - // Create a dummy interface type to "hold" type arguments. - env = emitRtiEval( - _emitTypeParameter(environmentTypes.first), - '@<0>', - ); - // Bind remaining type arguments. - for (var i = 1; i < environmentTypes.length; i++) { - env = emitRtiBind(env, environmentTypes[i]); + // By convention we create a binding environment with "dynamic" as + // the base. + env = _emitType(const DynamicType()); + // Bind all type arguments to it. + for (var typeParameter in environmentTypes) { + env = emitRtiBind(env, typeParameter); } } return emitRtiEval(env, recipe); case RtiTypeEnvironment(): - // RTI type environments are already constructed and attached to the - // provided RTI. + // RTI type environments take the form of a preconstructed RTI that + // is accessible via a known parameter name. var env = _rtiParam; return emitRtiEval(env, recipe); case ClassTypeEnvironment(): diff --git a/pkg/dev_compiler/lib/src/kernel/type_environment.dart b/pkg/dev_compiler/lib/src/kernel/type_environment.dart index 2cc3aa76cf8..1525de3b216 100644 --- a/pkg/dev_compiler/lib/src/kernel/type_environment.dart +++ b/pkg/dev_compiler/lib/src/kernel/type_environment.dart @@ -244,24 +244,24 @@ class ExtendedTypeEnvironment var baseEnvironmentNeeded = requiredParameters.any( _baseTypeEnvironment._typeParameters.contains, ); - var additionalParameters = requiredParameters.where( - _typeParameters.contains, - ); - if (additionalParameters.isEmpty) { - return baseEnvironmentNeeded - // Simply using the base environment has a compact representation - // and is already constructed. - ? _baseTypeEnvironment + var additionalParameters = requiredParameters + .where(_typeParameters.contains) + .toList(); + if (!baseEnvironmentNeeded) { + return additionalParameters.isEmpty // No type parameters are needed from this environment. - : const EmptyTypeEnvironment(); + ? const EmptyTypeEnvironment() + // A binding environment with a single parameter will be reduced to + // just the parameter. + : BindingTypeEnvironment(additionalParameters); } + // Simply using the base environment has a compact representation and at + // runtime it has already been constructed. + if (additionalParameters.isEmpty) return _baseTypeEnvironment; // This is already the exact environment needed. if (additionalParameters.length == _typeParameters.length) return this; // An extended environment with fewer additional parameters is needed. - return ExtendedTypeEnvironment( - _baseTypeEnvironment, - additionalParameters.toList(), - ); + return ExtendedTypeEnvironment(_baseTypeEnvironment, additionalParameters); } @override