@@ -122,7 +122,7 @@ import '../target_implementation.dart' show TargetImplementation;
122122import '../uri_translator.dart' show UriTranslator;
123123
124124import 'constant_evaluator.dart' as constants
125- show EvaluationMode, transformLibraries;
125+ show EvaluationMode, transformLibraries, transformProcedure ;
126126
127127import 'kernel_constants.dart' show KernelConstantErrorReporter;
128128
@@ -1092,26 +1092,7 @@ class KernelTarget extends TargetImplementation {
10921092
10931093 TypeEnvironment environment =
10941094 new TypeEnvironment (loader.coreTypes, loader.hierarchy);
1095- constants.EvaluationMode evaluationMode;
1096- // If nnbd is not enabled we will use weak evaluation mode. This is needed
1097- // because the SDK might be agnostic and therefore needs to be weakened
1098- // for legacy mode.
1099- assert (
1100- isExperimentEnabledGlobally (ExperimentalFlag .nonNullable) ||
1101- loader.nnbdMode == NnbdMode .Weak ,
1102- "Non-weak nnbd mode found without experiment enabled: "
1103- "${loader .nnbdMode }." );
1104- switch (loader.nnbdMode) {
1105- case NnbdMode .Weak :
1106- evaluationMode = constants.EvaluationMode .weak;
1107- break ;
1108- case NnbdMode .Strong :
1109- evaluationMode = constants.EvaluationMode .strong;
1110- break ;
1111- case NnbdMode .Agnostic :
1112- evaluationMode = constants.EvaluationMode .agnostic;
1113- break ;
1114- }
1095+ constants.EvaluationMode evaluationMode = _getConstantEvaluationMode ();
11151096
11161097 constants.transformLibraries (
11171098 loader.libraries,
@@ -1141,11 +1122,52 @@ class KernelTarget extends TargetImplementation {
11411122 ChangedStructureNotifier get changedStructureNotifier => null ;
11421123
11431124 void runProcedureTransformations (Procedure procedure) {
1125+ TypeEnvironment environment =
1126+ new TypeEnvironment (loader.coreTypes, loader.hierarchy);
1127+ constants.EvaluationMode evaluationMode = _getConstantEvaluationMode ();
1128+
1129+ constants.transformProcedure (
1130+ procedure,
1131+ backendTarget.constantsBackend (loader.coreTypes),
1132+ environmentDefines,
1133+ environment,
1134+ new KernelConstantErrorReporter (loader),
1135+ evaluationMode,
1136+ desugarSets: ! backendTarget.supportsSetLiterals,
1137+ enableTripleShift:
1138+ isExperimentEnabledGlobally (ExperimentalFlag .tripleShift),
1139+ errorOnUnevaluatedConstant: errorOnUnevaluatedConstant);
1140+ ticker.logMs ("Evaluated constants" );
1141+
11441142 backendTarget.performTransformationsOnProcedure (
11451143 loader.coreTypes, loader.hierarchy, procedure,
11461144 logger: (String msg) => ticker.logMs (msg));
11471145 }
11481146
1147+ constants.EvaluationMode _getConstantEvaluationMode () {
1148+ constants.EvaluationMode evaluationMode;
1149+ // If nnbd is not enabled we will use weak evaluation mode. This is needed
1150+ // because the SDK might be agnostic and therefore needs to be weakened
1151+ // for legacy mode.
1152+ assert (
1153+ isExperimentEnabledGlobally (ExperimentalFlag .nonNullable) ||
1154+ loader.nnbdMode == NnbdMode .Weak ,
1155+ "Non-weak nnbd mode found without experiment enabled: "
1156+ "${loader .nnbdMode }." );
1157+ switch (loader.nnbdMode) {
1158+ case NnbdMode .Weak :
1159+ evaluationMode = constants.EvaluationMode .weak;
1160+ break ;
1161+ case NnbdMode .Strong :
1162+ evaluationMode = constants.EvaluationMode .strong;
1163+ break ;
1164+ case NnbdMode .Agnostic :
1165+ evaluationMode = constants.EvaluationMode .agnostic;
1166+ break ;
1167+ }
1168+ return evaluationMode;
1169+ }
1170+
11491171 void verify () {
11501172 // TODO(ahe): How to handle errors.
11511173 verifyComponent (component);
0 commit comments