From 57a1168875ad9bb0c944d4077ba71b3dac5a1e74 Mon Sep 17 00:00:00 2001 From: Tess Strickland Date: Thu, 4 Jan 2024 14:44:29 +0000 Subject: [PATCH] [pkg/vm] Create @pragma("vm:platform-const-if", ) annotation If a static field or getter is annotated with @pragma("vm:platform-const-if", ) and const evaluates to true, then uses of the static field or getter are const evaluated when a target operating system is available. If const evaluates to any other value, then the annotation is ignored. For example, when runtime-only code is guarded like the following, using Flutter's kDebugMode constant, then debug mode Flutter programs can alter the defaultTargetPlatform for testing, but in release mode, the defaultTargetPlatform getter is const evaluated and code guarded with defaultTargetPlatform checks can be eliminated if unreachable: @pragma("vm:platform-const-if", !kDebugMode) TargetPlatform get defaultTargetPlatform { ... assert(() { if (Platform.environment.containsKey('FLUTTER_TEST')) { result = TestPlatform.android; } return true; }()); if (kDebugMode && platform.debugDefaultTargetPlatformOverride != null) { result = platform.debugDefaultTargetPlatformOverride; } ... } TEST=pkg/vm/test/transformations/vm_constant_evaluator Change-Id: I55b88502a908c56cf42a761dd06741f15c8a23d9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333220 Reviewed-by: Alexander Markov Reviewed-by: Chloe Stefantsova Commit-Queue: Tess Strickland --- .../src/fasta/kernel/constant_evaluator.dart | 46 ++-- pkg/vm/lib/kernel_front_end.dart | 4 +- pkg/vm/lib/transformations/pragma.dart | 40 ++- .../unreachable_code_elimination.dart | 37 ++- .../vm_constant_evaluator.dart | 124 ++++------ pkg/vm/test/common_test_utils.dart | 6 +- .../unreachable_code_elimination_test.dart | 5 +- .../vm_constant_evaluator_test.dart | 47 +++- .../platform_testcases.dart | 118 ++++++++- ...atform_testcases.dart.android.debug.expect | 188 +++++++++++++++ ...ases.dart.android.debug.withAsserts.expect | 228 ++++++++++++++++++ .../platform_testcases.dart.android.expect | 62 ++++- ..._testcases.dart.android.withAsserts.expect | 192 +++++++++++++++ ...atform_testcases.dart.fuchsia.debug.expect | 188 +++++++++++++++ ...ases.dart.fuchsia.debug.withAsserts.expect | 228 ++++++++++++++++++ .../platform_testcases.dart.fuchsia.expect | 42 +++- ..._testcases.dart.fuchsia.withAsserts.expect | 192 +++++++++++++++ .../platform_testcases.dart.ios.debug.expect | 188 +++++++++++++++ ...estcases.dart.ios.debug.withAsserts.expect | 228 ++++++++++++++++++ .../platform_testcases.dart.ios.expect | 42 +++- ...form_testcases.dart.ios.withAsserts.expect | 192 +++++++++++++++ ...platform_testcases.dart.linux.debug.expect | 188 +++++++++++++++ ...tcases.dart.linux.debug.withAsserts.expect | 228 ++++++++++++++++++ .../platform_testcases.dart.linux.expect | 42 +++- ...rm_testcases.dart.linux.withAsserts.expect | 192 +++++++++++++++ ...platform_testcases.dart.macos.debug.expect | 188 +++++++++++++++ ...tcases.dart.macos.debug.withAsserts.expect | 228 ++++++++++++++++++ .../platform_testcases.dart.macos.expect | 42 +++- ...rm_testcases.dart.macos.withAsserts.expect | 192 +++++++++++++++ ...atform_testcases.dart.windows.debug.expect | 188 +++++++++++++++ ...ases.dart.windows.debug.withAsserts.expect | 228 ++++++++++++++++++ .../platform_testcases.dart.windows.expect | 42 +++- ..._testcases.dart.windows.withAsserts.expect | 192 +++++++++++++++ runtime/docs/pragmas.md | 1 + 34 files changed, 4181 insertions(+), 167 deletions(-) create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.withAsserts.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.withAsserts.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.withAsserts.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.withAsserts.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.withAsserts.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.withAsserts.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.withAsserts.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.withAsserts.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.withAsserts.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.withAsserts.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.withAsserts.expect create mode 100644 pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.withAsserts.expect diff --git a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart index d1217262ab2..1f669ee699f 100644 --- a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart +++ b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart @@ -763,8 +763,12 @@ class ConstantsTransformer extends RemovingTransformer { if (shouldInline(target.initializer!)) { return evaluateAndTransformWithContext(node, node); } - } else if (target is Procedure && target.kind == ProcedureKind.Method) { - return evaluateAndTransformWithContext(node, node); + } else if (target is Procedure) { + if (target.kind == ProcedureKind.Method) { + return evaluateAndTransformWithContext(node, node); + } else if (target.kind == ProcedureKind.Getter && enableConstFunctions) { + return evaluateAndTransformWithContext(node, node); + } } return super.visitStaticGet(node, removalSentinel); } @@ -2443,7 +2447,8 @@ class ConstantEvaluator implements ExpressionVisitor { final EvaluationMode evaluationMode; final bool enableTripleShift; - final bool enableConstFunctions; + final bool enableAsserts; + bool enableConstFunctions; bool inExtensionTypeConstConstructor = false; final Map canonicalizationCache; @@ -2488,6 +2493,7 @@ class ConstantEvaluator implements ExpressionVisitor { this._environmentDefines, this.typeEnvironment, this.errorReporter, {this.enableTripleShift = false, this.enableConstFunctions = false, + this.enableAsserts = true, this.errorOnUnevaluatedConstant = false, this.evaluationMode = EvaluationMode.weak}) : numberSemantics = backend.numberSemantics, @@ -3692,6 +3698,7 @@ class ConstantEvaluator implements ExpressionVisitor { /// Returns [null] on success and an error-"constant" on failure, as such the /// return value should be checked. AbortConstant? checkAssert(AssertStatement statement) { + if (!enableAsserts) return null; final Constant condition = _evaluateSubexpression(statement.condition); if (condition is AbortConstant) return condition; @@ -4577,27 +4584,23 @@ class ConstantEvaluator implements ExpressionVisitor { @override Constant visitStaticGet(StaticGet node) { - return withNewEnvironment(() { - final Member target = node.target; - visitedLibraries.add(target.enclosingLibrary); - if (target is Field) { - if (target.isConst) { - return evaluateExpressionInContext(target, target.initializer!); - } - return createEvaluationErrorConstant( - node, - templateConstEvalInvalidStaticInvocation - .withArguments(target.name.text)); - } else if (target is Procedure && target.kind == ProcedureKind.Method) { + final Member target = node.target; + visitedLibraries.add(target.enclosingLibrary); + if (target is Field && target.isConst) { + return withNewEnvironment( + () => evaluateExpressionInContext(target, target.initializer!)); + } else if (target is Procedure) { + if (target.kind == ProcedureKind.Method) { // TODO(johnniwinther): Remove this. This should never occur. return canonicalize(new StaticTearOffConstant(target)); - } else { - return createEvaluationErrorConstant( - node, - templateConstEvalInvalidStaticInvocation - .withArguments(target.name.text)); + } else if (target.kind == ProcedureKind.Getter && enableConstFunctions) { + return _handleFunctionInvocation(target.function, [], [], {}); } - }); + } + return createEvaluationErrorConstant( + node, + templateConstEvalInvalidStaticInvocation + .withArguments(target.name.text)); } @override @@ -5617,6 +5620,7 @@ class StatementConstantEvaluator implements StatementVisitor { @override ExecutionStatus visitAssertBlock(AssertBlock node) { + if (!exprEvaluator.enableAsserts) return const ProceedStatus(); throw new UnsupportedError( 'Statement constant evaluation does not support ${node.runtimeType}.'); } diff --git a/pkg/vm/lib/kernel_front_end.dart b/pkg/vm/lib/kernel_front_end.dart index 0b6c91fdcec..74143beae02 100644 --- a/pkg/vm/lib/kernel_front_end.dart +++ b/pkg/vm/lib/kernel_front_end.dart @@ -577,7 +577,9 @@ Future runGlobalTransformations( final os = targetOS != null ? TargetOS.fromString(targetOS)! : null; final evaluator = vm_constant_evaluator.VMConstantEvaluator.create( target, component, os, nnbdMode, - environmentDefines: environmentDefines, coreTypes: coreTypes); + enableAsserts: enableAsserts, + environmentDefines: environmentDefines, + coreTypes: coreTypes); unreachable_code_elimination.transformComponent( target, component, evaluator, enableAsserts); diff --git a/pkg/vm/lib/transformations/pragma.dart b/pkg/vm/lib/transformations/pragma.dart index 999787aecb2..0479735e8d7 100644 --- a/pkg/vm/lib/transformations/pragma.dart +++ b/pkg/vm/lib/transformations/pragma.dart @@ -15,60 +15,66 @@ const kResultTypeUsesPassedTypeArguments = const kVmRecognizedPragmaName = "vm:recognized"; const kVmDisableUnboxedParametersPragmaName = "vm:disable-unboxed-parameters"; const kVmKeepNamePragmaName = "vm:keep-name"; +const kVmPlatformConstPragmaName = "vm:platform-const"; +const kVmPlatformConstIfPragmaName = "vm:platform-const-if"; // Pragmas recognized by dart2wasm const kWasmEntryPointPragmaName = "wasm:entry-point"; const kWasmExportPragmaName = "wasm:export"; -abstract class ParsedPragma { - const ParsedPragma(); -} +abstract class ParsedPragma {} enum PragmaEntryPointType { Default, GetterOnly, SetterOnly, CallOnly } enum PragmaRecognizedType { AsmIntrinsic, GraphIntrinsic, Other } -class ParsedEntryPointPragma extends ParsedPragma { +class ParsedEntryPointPragma implements ParsedPragma { final PragmaEntryPointType type; const ParsedEntryPointPragma(this.type); } -class ParsedResultTypeByTypePragma extends ParsedPragma { +class ParsedResultTypeByTypePragma implements ParsedPragma { final DartType type; final bool resultTypeUsesPassedTypeArguments; const ParsedResultTypeByTypePragma( this.type, this.resultTypeUsesPassedTypeArguments); } -class ParsedResultTypeByPathPragma extends ParsedPragma { +class ParsedResultTypeByPathPragma implements ParsedPragma { final String path; const ParsedResultTypeByPathPragma(this.path); } -class ParsedNonNullableResultType extends ParsedPragma { +class ParsedNonNullableResultType implements ParsedPragma { const ParsedNonNullableResultType(); } -class ParsedRecognized extends ParsedPragma { +class ParsedRecognized implements ParsedPragma { final PragmaRecognizedType type; const ParsedRecognized(this.type); } -class ParsedDisableUnboxedParameters extends ParsedPragma { +class ParsedDisableUnboxedParameters implements ParsedPragma { const ParsedDisableUnboxedParameters(); } -class ParsedKeepNamePragma extends ParsedPragma { +class ParsedKeepNamePragma implements ParsedPragma { const ParsedKeepNamePragma(); } +class ParsedPlatformConstPragma implements ParsedPragma { + const ParsedPlatformConstPragma(); +} + abstract class PragmaAnnotationParser { /// May return 'null' if the annotation does not represent a recognized /// @pragma. ParsedPragma? parsePragma(Expression annotation); + + Iterable parsedPragmas(Iterable node); } -class ConstantPragmaAnnotationParser extends PragmaAnnotationParser { +class ConstantPragmaAnnotationParser implements PragmaAnnotationParser { final CoreTypes coreTypes; final Target target; @@ -166,6 +172,14 @@ class ConstantPragmaAnnotationParser extends PragmaAnnotationParser { return const ParsedDisableUnboxedParameters(); case kVmKeepNamePragmaName: return ParsedKeepNamePragma(); + case kVmPlatformConstPragmaName: + return ParsedPlatformConstPragma(); + case kVmPlatformConstIfPragmaName: + if (options is! BoolConstant) { + throw "ERROR: Non-boolean option to '$kVmPlatformConstIfPragmaName' " + "pragma: $options"; + } + return options.value ? ParsedPlatformConstPragma() : null; case kWasmEntryPointPragmaName: return ParsedEntryPointPragma(PragmaEntryPointType.Default); case kWasmExportPragmaName: @@ -175,4 +189,8 @@ class ConstantPragmaAnnotationParser extends PragmaAnnotationParser { return null; } } + + Iterable parsedPragmas( + Iterable annotations) => + annotations.map(parsePragma).whereType(); } diff --git a/pkg/vm/lib/transformations/unreachable_code_elimination.dart b/pkg/vm/lib/transformations/unreachable_code_elimination.dart index 091d0f83553..4c6b788c64d 100644 --- a/pkg/vm/lib/transformations/unreachable_code_elimination.dart +++ b/pkg/vm/lib/transformations/unreachable_code_elimination.dart @@ -48,25 +48,10 @@ class SimpleUnreachableCodeElimination extends RemovingTransformer { return constant is BoolConstant ? constant.value : null; } - Expression _makeConstantExpression(Constant constant, Expression node) { - if (constant is UnevaluatedConstant && - constant.expression is InvalidExpression) { - return constant.expression; - } - ConstantExpression constantExpression = new ConstantExpression( - constant, node.getStaticType(_staticTypeContext!)) - ..fileOffset = node.fileOffset; - if (node is FileUriExpression) { - return new FileUriConstantExpression(constantExpression.constant, - type: constantExpression.type, fileUri: node.fileUri) - ..fileOffset = node.fileOffset; - } - return constantExpression; - } - Expression _createBoolConstantExpression(bool value, Expression node) => - _makeConstantExpression( - constantEvaluator.canonicalize(BoolConstant(value)), node); + ConstantExpression(constantEvaluator.makeBoolConstant(value), + node.getStaticType(_staticTypeContext!)) + ..fileOffset = node.fileOffset; Statement _makeEmptyBlockIfEmptyStatement(Statement node, TreeNode parent) => node is EmptyStatement ? (Block([])..parent = parent) : node; @@ -219,11 +204,21 @@ class SimpleUnreachableCodeElimination extends RemovingTransformer { if (target is Field && target.isConst) { throw 'StaticGet from const field $target should be evaluated by front-end: $node'; } - if (!constantEvaluator.transformerShouldEvaluateExpression(node)) { - return node; + + if (!constantEvaluator.hasTargetOS || + !constantEvaluator.isPlatformConst(target)) { + return super.visitStaticGet(node, removalSentinel); } + final result = constantEvaluator.evaluate(_staticTypeContext!, node); - return _makeConstantExpression(result, node); + + if (result is UnevaluatedConstant && + result.expression is InvalidExpression) { + return result.expression; + } + + final type = node.getStaticType(_staticTypeContext!); + return ConstantExpression(result, type)..fileOffset = node.fileOffset; } @override diff --git a/pkg/vm/lib/transformations/vm_constant_evaluator.dart b/pkg/vm/lib/transformations/vm_constant_evaluator.dart index 63ab64ea12b..2a09c0e1303 100644 --- a/pkg/vm/lib/transformations/vm_constant_evaluator.dart +++ b/pkg/vm/lib/transformations/vm_constant_evaluator.dart @@ -11,24 +11,16 @@ import 'package:kernel/type_environment.dart'; import 'package:front_end/src/base/nnbd_mode.dart'; import 'package:front_end/src/fasta/kernel/constant_evaluator.dart' - show - AbortConstant, - AbortStatus, - ConstantEvaluator, - ErrorReporter, - EvaluationMode, - ProceedStatus, - ReturnStatus, - SimpleErrorReporter, - StatementConstantEvaluator; + show ConstantEvaluator, ErrorReporter, EvaluationMode, SimpleErrorReporter; import '../target_os.dart'; +import 'pragma.dart'; /// Evaluates uses of static fields and getters using VM-specific and /// platform-specific knowledge. /// -/// [targetOS] represents the target operating system and is used when -/// evaluating static fields and getters annotated with "vm:platform-const". +/// The provided [TargetOS], when non-null, is used when evaluating static +/// fields and getters annotated with "vm:platform-const". /// /// To avoid restricting getters annotated with "vm:platform-const" to be just /// a single return statement whose body is evaluated, we treat annotated @@ -39,8 +31,7 @@ class VMConstantEvaluator extends ConstantEvaluator { final Map _constantFields = {}; final Class? _platformClass; - final Class _pragmaClass; - final Field _pragmaName; + final PragmaAnnotationParser _pragmaParser; VMConstantEvaluator( DartLibrarySupport dartLibrarySupport, @@ -50,25 +41,26 @@ class VMConstantEvaluator extends ConstantEvaluator { TypeEnvironment typeEnvironment, ErrorReporter errorReporter, this._targetOS, + this._pragmaParser, {bool enableTripleShift = false, bool enableConstFunctions = false, + bool enableAsserts = true, bool errorOnUnevaluatedConstant = false, EvaluationMode evaluationMode = EvaluationMode.weak}) : _platformClass = typeEnvironment.coreTypes.platformClass, - _pragmaClass = typeEnvironment.coreTypes.pragmaClass, - _pragmaName = typeEnvironment.coreTypes.pragmaName, super(dartLibrarySupport, backend, component, environmentDefines, typeEnvironment, errorReporter, enableTripleShift: enableTripleShift, enableConstFunctions: enableConstFunctions, + enableAsserts: enableAsserts, errorOnUnevaluatedConstant: errorOnUnevaluatedConstant, evaluationMode: evaluationMode) { // Only add Platform fields if the Platform class is part of the component // being evaluated. - final os = _targetOS; - if (os != null && _platformClass != null) { - _constantFields['operatingSystem'] = StringConstant(os.name); - _constantFields['pathSeparator'] = StringConstant(os.pathSeparator); + if (_targetOS != null && _platformClass != null) { + _constantFields['operatingSystem'] = StringConstant(_targetOS!.name); + _constantFields['pathSeparator'] = + StringConstant(_targetOS!.pathSeparator); } } @@ -78,6 +70,7 @@ class VMConstantEvaluator extends ConstantEvaluator { bool enableTripleShift = false, bool enableConstFunctions = false, bool enableConstructorTearOff = false, + bool enableAsserts = true, bool errorOnUnevaluatedConstant = false, Map? environmentDefines, CoreTypes? coreTypes, @@ -97,89 +90,62 @@ class VMConstantEvaluator extends ConstantEvaluator { component, environmentDefines, typeEnvironment, - SimpleErrorReporter(), + const SimpleErrorReporter(), targetOS, + ConstantPragmaAnnotationParser(coreTypes, target), enableTripleShift: enableTripleShift, enableConstFunctions: enableConstFunctions, + enableAsserts: enableAsserts, errorOnUnevaluatedConstant: errorOnUnevaluatedConstant, evaluationMode: EvaluationMode.fromNnbdMode(nnbdMode)); } - /// Used for methods and fields with initializers where the method body or - /// field initializer must evaluate to a constant value when a target - /// operating system is provided. - static const _constPragmaName = "vm:platform-const"; + bool get hasTargetOS => _targetOS != null; - bool _hasAnnotation(Annotatable node, String name) { - for (final annotation in node.annotations) { - if (annotation is ConstantExpression) { - final constant = annotation.constant; - if (constant is InstanceConstant && - constant.classNode == _pragmaClass && - constant.fieldValues[_pragmaName.fieldReference] == - StringConstant(name)) { - return true; - } - } - } - return false; - } - - bool _isPlatformConst(Member node) => _hasAnnotation(node, _constPragmaName); - - bool transformerShouldEvaluateExpression(Expression node) => - _targetOS != null && node is StaticGet && _isPlatformConst(node.target); - - Constant _executePlatformConstBody(Statement statement) { - final status = statement.accept(StatementConstantEvaluator(this)); - if (status is AbortStatus) return status.error; - // Happens if there is no return statement in a void Function(...) body. - if (status is ProceedStatus) return canonicalize(NullConstant()); - if (status is ReturnStatus) { - final value = status.value; - return value != null ? value : canonicalize(NullConstant()); - } - // Other statuses denote intermediate states and not final ones. - throw 'No valid constant returned after executing $statement'; - } + bool isPlatformConst(Member member) => _pragmaParser + .parsedPragmas(member.annotations) + .isNotEmpty; @override Constant visitStaticGet(StaticGet node) { - assert(_targetOS != null); + assert(hasTargetOS); final target = node.target; // This visitor can be called recursively while evaluating an abstraction // over the Platform getters and fields, so check that the visited node has // an appropriately annotated target. - if (!_isPlatformConst(target)) return super.visitStaticGet(node); + if (!isPlatformConst(target)) return super.visitStaticGet(node); - return withNewEnvironment(() { - final nameText = target.name.text; - visitedLibraries.add(target.enclosingLibrary); + visitedLibraries.add(target.enclosingLibrary); - // First, check for the fields in Platform whose initializers should not - // be evaluated, but instead uses of the field should just be replaced - // directly with an already calculated constant. - if (target is Field && target.enclosingClass == _platformClass) { - final constant = _constantFields[nameText]; + if (target is Field) { + // If this is a special Platform field that has a pre-calculated value + // for the given operating system, just use the canonicalized value. + if (target.enclosingClass == _platformClass) { + final constant = _constantFields[target.name.text]; if (constant != null) { return canonicalize(constant); } } - late Constant result; - if (target is Field && target.initializer != null) { - result = evaluateExpressionInContext(target, target.initializer!); - } else if (target is Procedure && target.isGetter) { - final body = target.function.body!; - result = _executePlatformConstBody(body); - } - if (result is AbortConstant) { - throw "The body or initialization of member '$nameText' does not " - "evaluate to a constant value for the specified target operating " - "system '$_targetOS'."; + final initializer = target.initializer; + if (initializer == null) { + throw 'Cannot const evaluate annotated field with no initializer'; } + return withNewEnvironment( + () => evaluateExpressionInContext(target, initializer)); + } + + if (target is Procedure && target.kind == ProcedureKind.Getter) { + // Temporarily enable const functions and use the base class to evaluate + // the getter with appropriate caching/recursive evaluation checks. + final oldEnableConstFunctions = enableConstFunctions; + enableConstFunctions = true; + final result = super.visitStaticGet(node); + enableConstFunctions = oldEnableConstFunctions; return result; - }); + } + + throw 'Expected annotated field with initializer or getter, got $target'; } } diff --git a/pkg/vm/test/common_test_utils.dart b/pkg/vm/test/common_test_utils.dart index 5bd142209e5..b8402e5a0d7 100644 --- a/pkg/vm/test/common_test_utils.dart +++ b/pkg/vm/test/common_test_utils.dart @@ -157,8 +157,8 @@ void compareResultWithExpectationsFile( String actual, { String expectFilePostfix = '', }) { - final expectFile = - new File('${source.toFilePath()}$expectFilePostfix.expect'); + final baseFilename = '${source.toFilePath()}$expectFilePostfix'; + final expectFile = new File('$baseFilename.expect'); final expected = expectFile.existsSync() ? expectFile.readAsStringSync() : ''; if (actual != expected) { @@ -167,7 +167,7 @@ void compareResultWithExpectationsFile( print(" Updated $expectFile"); } else { if (bool.fromEnvironment(kDumpActualResult)) { - new File(source.toFilePath() + '.actual').writeAsStringSync(actual); + new File('$baseFilename.actual').writeAsStringSync(actual); } Difference diff = findFirstDifference(actual, expected); fail(""" diff --git a/pkg/vm/test/transformations/unreachable_code_elimination_test.dart b/pkg/vm/test/transformations/unreachable_code_elimination_test.dart index a71c182f105..e59fcd6f5ac 100644 --- a/pkg/vm/test/transformations/unreachable_code_elimination_test.dart +++ b/pkg/vm/test/transformations/unreachable_code_elimination_test.dart @@ -34,8 +34,9 @@ runTestCase(Uri source) async { 'test.define.isTrue': 'true', 'test.define.isFalse': 'false' }); - final evaluator = - VMConstantEvaluator.create(target, component, targetOS, nnbdMode); + final evaluator = VMConstantEvaluator.create( + target, component, targetOS, nnbdMode, + enableAsserts: enableAsserts); component = transformComponent(target, component, evaluator, enableAsserts); verifyComponent( target, VerificationStage.afterGlobalTransformations, component); diff --git a/pkg/vm/test/transformations/vm_constant_evaluator_test.dart b/pkg/vm/test/transformations/vm_constant_evaluator_test.dart index ea615ce39d4..7b944c542ee 100644 --- a/pkg/vm/test/transformations/vm_constant_evaluator_test.dart +++ b/pkg/vm/test/transformations/vm_constant_evaluator_test.dart @@ -21,8 +21,26 @@ import '../common_test_utils.dart'; final String pkgVmDir = Platform.script.resolve('../..').toFilePath(); -runTestCase(Uri source, TargetOS os, String postfix) async { - final enableAsserts = false; +class TestCase { + final TargetOS os; + final bool debug; + final bool enableAsserts; + + const TestCase(this.os, {required this.debug, required this.enableAsserts}); + + String postfix() { + String result = '.${os.name}'; + if (debug) { + result += '.debug'; + } + if (enableAsserts) { + result += '.withAsserts'; + } + return result; + } +} + +runTestCase(Uri source, TestCase testCase) async { final soundNullSafety = true; final nnbdMode = NnbdMode.Strong; final target = @@ -30,17 +48,21 @@ runTestCase(Uri source, TargetOS os, String postfix) async { Component component = await compileTestCaseToKernelProgram(source, target: target, environmentDefines: { - 'test.define.isTrue': 'true', - 'test.define.isFalse': 'false' + 'test.define.debug': testCase.debug ? 'true' : 'false', + 'test.define.enableAsserts': testCase.enableAsserts ? 'true' : 'false', }); - final evaluator = VMConstantEvaluator.create(target, component, os, nnbdMode); - component = transformComponent(target, component, evaluator, enableAsserts); + final evaluator = VMConstantEvaluator.create( + target, component, testCase.os, nnbdMode, + enableAsserts: testCase.enableAsserts); + component = + transformComponent(target, component, evaluator, testCase.enableAsserts); verifyComponent( target, VerificationStage.afterGlobalTransformations, component); final actual = kernelLibraryToString(component.mainMethod!.enclosingLibrary); - compareResultWithExpectationsFile(source, actual, expectFilePostfix: postfix); + compareResultWithExpectationsFile(source, actual, + expectFilePostfix: testCase.postfix()); } main() { @@ -53,9 +75,14 @@ main() { .reversed) { if (entry.path.endsWith(".dart")) { for (final os in TargetOS.values) { - final postfix = '.${os.name}'; - test('${entry.path}$postfix', - () => runTestCase(entry.uri, os, postfix)); + for (final enableAsserts in [true, false]) { + for (final debug in [true, false]) { + final testCase = + TestCase(os, debug: debug, enableAsserts: enableAsserts); + test('${entry.path}${testCase.postfix()}', + () => runTestCase(entry.uri, testCase)); + } + } } } } diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart index bb3f21414a1..86b94c8eb43 100644 --- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart @@ -112,7 +112,7 @@ TestPlatform get defaultTestPlatform { if (Platform.isLinux) return TestPlatform.linux; if (Platform.isMacOS) return TestPlatform.macos; if (Platform.isWindows) return TestPlatform.windows; - throw 'Unexpected platform'; + throw 'Unexpected platform: ${Platform.operatingSystem}'; } void testPragma(int i) { @@ -136,8 +136,117 @@ void testPragma(int i) { case TestPlatform.windows: print("is windows"); break; - default: - throw "Unexpected platform"; + } +} + +const bool kDebugMode = bool.fromEnvironment('test.define.debug'); + +TestPlatform? debugDefaultTestPlatform; + +@pragma("vm:platform-const-if", !kDebugMode) +TestPlatform get defaultTestPlatformOverridableWhenDebug { + late TestPlatform result; + if (Platform.isAndroid) { + result = TestPlatform.android; + } + if (Platform.isFuchsia) { + result = TestPlatform.fuchsia; + } + if (Platform.isIOS) { + result = TestPlatform.ios; + } + if (Platform.isLinux) { + result = TestPlatform.linux; + } + if (Platform.isMacOS) { + result = TestPlatform.macos; + } + if (Platform.isWindows) { + result = TestPlatform.windows; + } + if (kDebugMode && debugDefaultTestPlatform != null) { + result = debugDefaultTestPlatform!; + } + return result; +} + +void testConditionalPragma(int i) { + print(defaultTestPlatformOverridableWhenDebug); + switch (defaultTestPlatformOverridableWhenDebug) { + case TestPlatform.android: + print("is android"); + break; + case TestPlatform.fuchsia: + print("is fuchsia"); + break; + case TestPlatform.ios: + print("is ios"); + break; + case TestPlatform.linux: + print("is linux"); + break; + case TestPlatform.macos: + print("is macos"); + break; + case TestPlatform.windows: + print("is windows"); + break; + } +} + +const bool enableAsserts = bool.fromEnvironment('test.define.enableAsserts'); + +@pragma("vm:platform-const-if", !enableAsserts) +TestPlatform get defaultTestPlatformOverridableWithAsserts { + late TestPlatform result; + if (Platform.isAndroid) { + result = TestPlatform.android; + } + if (Platform.isFuchsia) { + result = TestPlatform.fuchsia; + } + if (Platform.isIOS) { + result = TestPlatform.ios; + } + if (Platform.isLinux) { + result = TestPlatform.linux; + } + if (Platform.isMacOS) { + result = TestPlatform.macos; + } + if (Platform.isWindows) { + result = TestPlatform.windows; + } + assert(() { + if (Platform.environment.containsKey('FLUTTER_TEST')) { + result = TestPlatform.android; + } + return true; + }()); + return result; +} + +void testConditionalPragmaWithAsserts(int i) { + print(defaultTestPlatformOverridableWithAsserts); + switch (defaultTestPlatformOverridableWithAsserts) { + case TestPlatform.android: + print("is android"); + break; + case TestPlatform.fuchsia: + print("is fuchsia"); + break; + case TestPlatform.ios: + print("is ios"); + break; + case TestPlatform.linux: + print("is linux"); + break; + case TestPlatform.macos: + print("is macos"); + break; + case TestPlatform.windows: + print("is windows"); + break; } } @@ -152,4 +261,7 @@ main(List args) { testWindows(i); testSwitchStatements(i); testPragma(i); + debugDefaultTestPlatform = TestPlatform.android; + testConditionalPragma(i); + testConditionalPragmaWithAsserts(i); } diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.expect new file mode 100644 index 00000000000..e17f6ac7101 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.expect @@ -0,0 +1,188 @@ +library #lib; +import self as self; +import "dart:core" as core; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C21; +static method testAndroid(core::int i) → void { + final core::bool b = #C20; + core::print(b); + { + final core::String os = #C2; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is android"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C3; + throw "Unexpected platform: ${#C2}"; +} +static method testPragma(core::int i) → void { + core::print(#C3); + #L2: + { + core::print("is android"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C3; + } + if(!(self::debugDefaultTestPlatform == null)) { + result = self::debugDefaultTestPlatform!; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWhenDebug); + #L3: + switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L4: + case #C3: + { + core::print("is android"); + break #L3; + } + #L5: + case #C6: + { + core::print("is fuchsia"); + break #L3; + } + #L6: + case #C9: + { + core::print("is ios"); + break #L3; + } + #L7: + case #C12: + { + core::print("is linux"); + break #L3; + } + #L8: + case #C15: + { + core::print("is macos"); + break #L3; + } + #L9: + case #C18: + { + core::print("is windows"); + break #L3; + } + } +} +@#C28 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C3; + } + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(#C3); + #L10: + { + core::print("is android"); + break #L10; + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = true + #C21 = false + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} + #C28 = core::pragma {name:#C26, options:#C20} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.withAsserts.expect new file mode 100644 index 00000000000..566f17554db --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.debug.withAsserts.expect @@ -0,0 +1,228 @@ +library #lib; +import self as self; +import "dart:core" as core; +import "dart:io" as io; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C20; +static method testAndroid(core::int i) → void { + final core::bool b = #C20; + core::print(b); + { + final core::String os = #C2; + core::print(os); + final core::String sep = #C21; + core::print(sep); + } +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C22; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C22; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C22; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C22; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C22; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is android"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C3; + throw "Unexpected platform: ${#C2}"; +} +static method testPragma(core::int i) → void { + core::print(#C3); + #L2: + { + core::print("is android"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C3; + } + if(!(self::debugDefaultTestPlatform == null)) { + result = self::debugDefaultTestPlatform!; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWhenDebug); + #L3: + switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L4: + case #C3: + { + core::print("is android"); + break #L3; + } + #L5: + case #C6: + { + core::print("is fuchsia"); + break #L3; + } + #L6: + case #C9: + { + core::print("is ios"); + break #L3; + } + #L7: + case #C12: + { + core::print("is linux"); + break #L3; + } + #L8: + case #C15: + { + core::print("is macos"); + break #L3; + } + #L9: + case #C18: + { + core::print("is windows"); + break #L3; + } + } +} +@#C27 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C3; + } + assert((() → core::bool { + if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) { + result = #C3; + } + return true; + })(){() → core::bool}); + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWithAsserts); + #L10: + switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L11: + case #C3: + { + core::print("is android"); + break #L10; + } + #L12: + case #C6: + { + core::print("is fuchsia"); + break #L10; + } + #L13: + case #C9: + { + core::print("is ios"); + break #L10; + } + #L14: + case #C12: + { + core::print("is linux"); + break #L10; + } + #L15: + case #C15: + { + core::print("is macos"); + break #L10; + } + #L16: + case #C18: + { + core::print("is windows"); + break #L10; + } + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = true + #C21 = "/" + #C22 = false + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C22} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.expect index 149bd4a4632..b002a4b962f 100644 --- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.expect +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.expect @@ -18,34 +18,37 @@ class TestPlatform extends core::_Enum /*isEnum*/ { method _enumToString() → core::String return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; } +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C20; static method testAndroid(core::int i) → void { - final core::bool b = #C20; + final core::bool b = #C21; core::print(b); { final core::String os = #C2; core::print(os); - final core::String sep = #C21; + final core::String sep = #C22; core::print(sep); } } static method testFuchsia(core::int i) → void { - final core::bool b = #C22; + final core::bool b = #C20; core::print(b); } static method testIOS(core::int i) → void { - final core::bool b = #C22; + final core::bool b = #C20; core::print(b); } static method testLinux(core::int i) → void { - final core::bool b = #C22; + final core::bool b = #C20; core::print(b); } static method testMacOS(core::int i) → void { - final core::bool b = #C22; + final core::bool b = #C20; core::print(b); } static method testWindows(core::int i) → void { - final core::bool b = #C22; + final core::bool b = #C20; core::print(b); } static method testSwitchStatements(core::int i) → void { @@ -58,7 +61,7 @@ static method testSwitchStatements(core::int i) → void { @#C25 static get defaultTestPlatform() → self::TestPlatform { return #C3; - throw "Unexpected platform"; + throw "Unexpected platform: ${#C2}"; } static method testPragma(core::int i) → void { core::print(#C3); @@ -68,6 +71,38 @@ static method testPragma(core::int i) → void { break #L2; } } +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C3; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(#C3); + #L3: + { + core::print("is android"); + break #L3; + } +} +@#C27 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C3; + } + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(#C3); + #L4: + { + core::print("is android"); + break #L4; + } +} static method main(core::List args) → dynamic { if(args.{core::Iterable::isEmpty}{core::bool}) return; @@ -80,6 +115,9 @@ static method main(core::List args) → dynamic { self::testWindows(i); self::testSwitchStatements(i); self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); } constants { #C1 = 0 @@ -101,10 +139,12 @@ constants { #C17 = "windows" #C18 = self::TestPlatform {index:#C16, _name:#C17} #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] - #C20 = true - #C21 = "/" - #C22 = false + #C20 = false + #C21 = true + #C22 = "/" #C23 = "vm:platform-const" #C24 = null #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} } diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.withAsserts.expect new file mode 100644 index 00000000000..d1c848a8074 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.android.withAsserts.expect @@ -0,0 +1,192 @@ +library #lib; +import self as self; +import "dart:core" as core; +import "dart:io" as io; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C21; +static method testAndroid(core::int i) → void { + final core::bool b = #C21; + core::print(b); + { + final core::String os = #C2; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is android"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C3; + throw "Unexpected platform: ${#C2}"; +} +static method testPragma(core::int i) → void { + core::print(#C3); + #L2: + { + core::print("is android"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C3; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(#C3); + #L3: + { + core::print("is android"); + break #L3; + } +} +@#C28 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C3; + } + assert((() → core::bool { + if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) { + result = #C3; + } + return true; + })(){() → core::bool}); + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWithAsserts); + #L4: + switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L5: + case #C3: + { + core::print("is android"); + break #L4; + } + #L6: + case #C6: + { + core::print("is fuchsia"); + break #L4; + } + #L7: + case #C9: + { + core::print("is ios"); + break #L4; + } + #L8: + case #C12: + { + core::print("is linux"); + break #L4; + } + #L9: + case #C15: + { + core::print("is macos"); + break #L4; + } + #L10: + case #C18: + { + core::print("is windows"); + break #L4; + } + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = false + #C21 = true + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} + #C28 = core::pragma {name:#C26, options:#C20} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.expect new file mode 100644 index 00000000000..0c51b94a7a5 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.expect @@ -0,0 +1,188 @@ +library #lib; +import self as self; +import "dart:core" as core; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C21; +static method testAndroid(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C20; + core::print(b); + { + final core::String os = #C5; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testIOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is fuchsia"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C6; + throw "Unexpected platform: ${#C5}"; +} +static method testPragma(core::int i) → void { + core::print(#C6); + #L2: + { + core::print("is fuchsia"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C6; + } + if(!(self::debugDefaultTestPlatform == null)) { + result = self::debugDefaultTestPlatform!; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWhenDebug); + #L3: + switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L4: + case #C3: + { + core::print("is android"); + break #L3; + } + #L5: + case #C6: + { + core::print("is fuchsia"); + break #L3; + } + #L6: + case #C9: + { + core::print("is ios"); + break #L3; + } + #L7: + case #C12: + { + core::print("is linux"); + break #L3; + } + #L8: + case #C15: + { + core::print("is macos"); + break #L3; + } + #L9: + case #C18: + { + core::print("is windows"); + break #L3; + } + } +} +@#C28 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C6; + } + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(#C6); + #L10: + { + core::print("is fuchsia"); + break #L10; + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = true + #C21 = false + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} + #C28 = core::pragma {name:#C26, options:#C20} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.withAsserts.expect new file mode 100644 index 00000000000..8d701b20d3b --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.debug.withAsserts.expect @@ -0,0 +1,228 @@ +library #lib; +import self as self; +import "dart:core" as core; +import "dart:io" as io; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C20; +static method testAndroid(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C20; + core::print(b); + { + final core::String os = #C5; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testIOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is fuchsia"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C6; + throw "Unexpected platform: ${#C5}"; +} +static method testPragma(core::int i) → void { + core::print(#C6); + #L2: + { + core::print("is fuchsia"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C6; + } + if(!(self::debugDefaultTestPlatform == null)) { + result = self::debugDefaultTestPlatform!; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWhenDebug); + #L3: + switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L4: + case #C3: + { + core::print("is android"); + break #L3; + } + #L5: + case #C6: + { + core::print("is fuchsia"); + break #L3; + } + #L6: + case #C9: + { + core::print("is ios"); + break #L3; + } + #L7: + case #C12: + { + core::print("is linux"); + break #L3; + } + #L8: + case #C15: + { + core::print("is macos"); + break #L3; + } + #L9: + case #C18: + { + core::print("is windows"); + break #L3; + } + } +} +@#C27 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C6; + } + assert((() → core::bool { + if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) { + result = #C3; + } + return true; + })(){() → core::bool}); + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWithAsserts); + #L10: + switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L11: + case #C3: + { + core::print("is android"); + break #L10; + } + #L12: + case #C6: + { + core::print("is fuchsia"); + break #L10; + } + #L13: + case #C9: + { + core::print("is ios"); + break #L10; + } + #L14: + case #C12: + { + core::print("is linux"); + break #L10; + } + #L15: + case #C15: + { + core::print("is macos"); + break #L10; + } + #L16: + case #C18: + { + core::print("is windows"); + break #L10; + } + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = true + #C21 = false + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.expect index b95d833d875..2147848a6b8 100644 --- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.expect +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.expect @@ -18,6 +18,9 @@ class TestPlatform extends core::_Enum /*isEnum*/ { method _enumToString() → core::String return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; } +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C20; static method testAndroid(core::int i) → void { final core::bool b = #C20; core::print(b); @@ -58,7 +61,7 @@ static method testSwitchStatements(core::int i) → void { @#C25 static get defaultTestPlatform() → self::TestPlatform { return #C6; - throw "Unexpected platform"; + throw "Unexpected platform: ${#C5}"; } static method testPragma(core::int i) → void { core::print(#C6); @@ -68,6 +71,38 @@ static method testPragma(core::int i) → void { break #L2; } } +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C6; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(#C6); + #L3: + { + core::print("is fuchsia"); + break #L3; + } +} +@#C27 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C6; + } + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(#C6); + #L4: + { + core::print("is fuchsia"); + break #L4; + } +} static method main(core::List args) → dynamic { if(args.{core::Iterable::isEmpty}{core::bool}) return; @@ -80,6 +115,9 @@ static method main(core::List args) → dynamic { self::testWindows(i); self::testSwitchStatements(i); self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); } constants { #C1 = 0 @@ -107,4 +145,6 @@ constants { #C23 = "vm:platform-const" #C24 = null #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} } diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.withAsserts.expect new file mode 100644 index 00000000000..8cbcf605f22 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.fuchsia.withAsserts.expect @@ -0,0 +1,192 @@ +library #lib; +import self as self; +import "dart:core" as core; +import "dart:io" as io; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C21; +static method testAndroid(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C21; + core::print(b); + { + final core::String os = #C5; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testIOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is fuchsia"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C6; + throw "Unexpected platform: ${#C5}"; +} +static method testPragma(core::int i) → void { + core::print(#C6); + #L2: + { + core::print("is fuchsia"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C6; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(#C6); + #L3: + { + core::print("is fuchsia"); + break #L3; + } +} +@#C28 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C6; + } + assert((() → core::bool { + if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) { + result = #C3; + } + return true; + })(){() → core::bool}); + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWithAsserts); + #L4: + switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L5: + case #C3: + { + core::print("is android"); + break #L4; + } + #L6: + case #C6: + { + core::print("is fuchsia"); + break #L4; + } + #L7: + case #C9: + { + core::print("is ios"); + break #L4; + } + #L8: + case #C12: + { + core::print("is linux"); + break #L4; + } + #L9: + case #C15: + { + core::print("is macos"); + break #L4; + } + #L10: + case #C18: + { + core::print("is windows"); + break #L4; + } + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = false + #C21 = true + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} + #C28 = core::pragma {name:#C26, options:#C20} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.expect new file mode 100644 index 00000000000..46d102457e6 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.expect @@ -0,0 +1,188 @@ +library #lib; +import self as self; +import "dart:core" as core; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C21; +static method testAndroid(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); + { + final core::String os = #C8; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testLinux(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is ios"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C9; + throw "Unexpected platform: ${#C8}"; +} +static method testPragma(core::int i) → void { + core::print(#C9); + #L2: + { + core::print("is ios"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C9; + } + if(!(self::debugDefaultTestPlatform == null)) { + result = self::debugDefaultTestPlatform!; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWhenDebug); + #L3: + switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L4: + case #C3: + { + core::print("is android"); + break #L3; + } + #L5: + case #C6: + { + core::print("is fuchsia"); + break #L3; + } + #L6: + case #C9: + { + core::print("is ios"); + break #L3; + } + #L7: + case #C12: + { + core::print("is linux"); + break #L3; + } + #L8: + case #C15: + { + core::print("is macos"); + break #L3; + } + #L9: + case #C18: + { + core::print("is windows"); + break #L3; + } + } +} +@#C28 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C9; + } + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(#C9); + #L10: + { + core::print("is ios"); + break #L10; + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = true + #C21 = false + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} + #C28 = core::pragma {name:#C26, options:#C20} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.withAsserts.expect new file mode 100644 index 00000000000..b68e6905226 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.debug.withAsserts.expect @@ -0,0 +1,228 @@ +library #lib; +import self as self; +import "dart:core" as core; +import "dart:io" as io; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C20; +static method testAndroid(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); + { + final core::String os = #C8; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testLinux(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is ios"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C9; + throw "Unexpected platform: ${#C8}"; +} +static method testPragma(core::int i) → void { + core::print(#C9); + #L2: + { + core::print("is ios"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C9; + } + if(!(self::debugDefaultTestPlatform == null)) { + result = self::debugDefaultTestPlatform!; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWhenDebug); + #L3: + switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L4: + case #C3: + { + core::print("is android"); + break #L3; + } + #L5: + case #C6: + { + core::print("is fuchsia"); + break #L3; + } + #L6: + case #C9: + { + core::print("is ios"); + break #L3; + } + #L7: + case #C12: + { + core::print("is linux"); + break #L3; + } + #L8: + case #C15: + { + core::print("is macos"); + break #L3; + } + #L9: + case #C18: + { + core::print("is windows"); + break #L3; + } + } +} +@#C27 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C9; + } + assert((() → core::bool { + if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) { + result = #C3; + } + return true; + })(){() → core::bool}); + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWithAsserts); + #L10: + switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L11: + case #C3: + { + core::print("is android"); + break #L10; + } + #L12: + case #C6: + { + core::print("is fuchsia"); + break #L10; + } + #L13: + case #C9: + { + core::print("is ios"); + break #L10; + } + #L14: + case #C12: + { + core::print("is linux"); + break #L10; + } + #L15: + case #C15: + { + core::print("is macos"); + break #L10; + } + #L16: + case #C18: + { + core::print("is windows"); + break #L10; + } + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = true + #C21 = false + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.expect index 21c480b80a8..35738061415 100644 --- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.expect +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.expect @@ -18,6 +18,9 @@ class TestPlatform extends core::_Enum /*isEnum*/ { method _enumToString() → core::String return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; } +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C20; static method testAndroid(core::int i) → void { final core::bool b = #C20; core::print(b); @@ -58,7 +61,7 @@ static method testSwitchStatements(core::int i) → void { @#C25 static get defaultTestPlatform() → self::TestPlatform { return #C9; - throw "Unexpected platform"; + throw "Unexpected platform: ${#C8}"; } static method testPragma(core::int i) → void { core::print(#C9); @@ -68,6 +71,38 @@ static method testPragma(core::int i) → void { break #L2; } } +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C9; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(#C9); + #L3: + { + core::print("is ios"); + break #L3; + } +} +@#C27 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C9; + } + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(#C9); + #L4: + { + core::print("is ios"); + break #L4; + } +} static method main(core::List args) → dynamic { if(args.{core::Iterable::isEmpty}{core::bool}) return; @@ -80,6 +115,9 @@ static method main(core::List args) → dynamic { self::testWindows(i); self::testSwitchStatements(i); self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); } constants { #C1 = 0 @@ -107,4 +145,6 @@ constants { #C23 = "vm:platform-const" #C24 = null #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} } diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.withAsserts.expect new file mode 100644 index 00000000000..db02a83b3f9 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.ios.withAsserts.expect @@ -0,0 +1,192 @@ +library #lib; +import self as self; +import "dart:core" as core; +import "dart:io" as io; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C21; +static method testAndroid(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); + { + final core::String os = #C8; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testLinux(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is ios"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C9; + throw "Unexpected platform: ${#C8}"; +} +static method testPragma(core::int i) → void { + core::print(#C9); + #L2: + { + core::print("is ios"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C9; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(#C9); + #L3: + { + core::print("is ios"); + break #L3; + } +} +@#C28 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C9; + } + assert((() → core::bool { + if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) { + result = #C3; + } + return true; + })(){() → core::bool}); + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWithAsserts); + #L4: + switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L5: + case #C3: + { + core::print("is android"); + break #L4; + } + #L6: + case #C6: + { + core::print("is fuchsia"); + break #L4; + } + #L7: + case #C9: + { + core::print("is ios"); + break #L4; + } + #L8: + case #C12: + { + core::print("is linux"); + break #L4; + } + #L9: + case #C15: + { + core::print("is macos"); + break #L4; + } + #L10: + case #C18: + { + core::print("is windows"); + break #L4; + } + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = false + #C21 = true + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} + #C28 = core::pragma {name:#C26, options:#C20} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.expect new file mode 100644 index 00000000000..875821e1d02 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.expect @@ -0,0 +1,188 @@ +library #lib; +import self as self; +import "dart:core" as core; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C21; +static method testAndroid(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C20; + core::print(b); + { + final core::String os = #C11; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testMacOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is linux"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C12; + throw "Unexpected platform: ${#C11}"; +} +static method testPragma(core::int i) → void { + core::print(#C12); + #L2: + { + core::print("is linux"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C12; + } + if(!(self::debugDefaultTestPlatform == null)) { + result = self::debugDefaultTestPlatform!; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWhenDebug); + #L3: + switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L4: + case #C3: + { + core::print("is android"); + break #L3; + } + #L5: + case #C6: + { + core::print("is fuchsia"); + break #L3; + } + #L6: + case #C9: + { + core::print("is ios"); + break #L3; + } + #L7: + case #C12: + { + core::print("is linux"); + break #L3; + } + #L8: + case #C15: + { + core::print("is macos"); + break #L3; + } + #L9: + case #C18: + { + core::print("is windows"); + break #L3; + } + } +} +@#C28 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C12; + } + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(#C12); + #L10: + { + core::print("is linux"); + break #L10; + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = true + #C21 = false + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} + #C28 = core::pragma {name:#C26, options:#C20} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.withAsserts.expect new file mode 100644 index 00000000000..16a95038685 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.debug.withAsserts.expect @@ -0,0 +1,228 @@ +library #lib; +import self as self; +import "dart:core" as core; +import "dart:io" as io; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C20; +static method testAndroid(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C20; + core::print(b); + { + final core::String os = #C11; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testMacOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is linux"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C12; + throw "Unexpected platform: ${#C11}"; +} +static method testPragma(core::int i) → void { + core::print(#C12); + #L2: + { + core::print("is linux"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C12; + } + if(!(self::debugDefaultTestPlatform == null)) { + result = self::debugDefaultTestPlatform!; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWhenDebug); + #L3: + switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L4: + case #C3: + { + core::print("is android"); + break #L3; + } + #L5: + case #C6: + { + core::print("is fuchsia"); + break #L3; + } + #L6: + case #C9: + { + core::print("is ios"); + break #L3; + } + #L7: + case #C12: + { + core::print("is linux"); + break #L3; + } + #L8: + case #C15: + { + core::print("is macos"); + break #L3; + } + #L9: + case #C18: + { + core::print("is windows"); + break #L3; + } + } +} +@#C27 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C12; + } + assert((() → core::bool { + if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) { + result = #C3; + } + return true; + })(){() → core::bool}); + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWithAsserts); + #L10: + switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L11: + case #C3: + { + core::print("is android"); + break #L10; + } + #L12: + case #C6: + { + core::print("is fuchsia"); + break #L10; + } + #L13: + case #C9: + { + core::print("is ios"); + break #L10; + } + #L14: + case #C12: + { + core::print("is linux"); + break #L10; + } + #L15: + case #C15: + { + core::print("is macos"); + break #L10; + } + #L16: + case #C18: + { + core::print("is windows"); + break #L10; + } + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = true + #C21 = false + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.expect index 95c3bbebf32..5b0f1d0ffc9 100644 --- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.expect +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.expect @@ -18,6 +18,9 @@ class TestPlatform extends core::_Enum /*isEnum*/ { method _enumToString() → core::String return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; } +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C20; static method testAndroid(core::int i) → void { final core::bool b = #C20; core::print(b); @@ -58,7 +61,7 @@ static method testSwitchStatements(core::int i) → void { @#C25 static get defaultTestPlatform() → self::TestPlatform { return #C12; - throw "Unexpected platform"; + throw "Unexpected platform: ${#C11}"; } static method testPragma(core::int i) → void { core::print(#C12); @@ -68,6 +71,38 @@ static method testPragma(core::int i) → void { break #L2; } } +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C12; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(#C12); + #L3: + { + core::print("is linux"); + break #L3; + } +} +@#C27 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C12; + } + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(#C12); + #L4: + { + core::print("is linux"); + break #L4; + } +} static method main(core::List args) → dynamic { if(args.{core::Iterable::isEmpty}{core::bool}) return; @@ -80,6 +115,9 @@ static method main(core::List args) → dynamic { self::testWindows(i); self::testSwitchStatements(i); self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); } constants { #C1 = 0 @@ -107,4 +145,6 @@ constants { #C23 = "vm:platform-const" #C24 = null #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} } diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.withAsserts.expect new file mode 100644 index 00000000000..1499db84196 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.linux.withAsserts.expect @@ -0,0 +1,192 @@ +library #lib; +import self as self; +import "dart:core" as core; +import "dart:io" as io; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C21; +static method testAndroid(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C21; + core::print(b); + { + final core::String os = #C11; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testMacOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is linux"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C12; + throw "Unexpected platform: ${#C11}"; +} +static method testPragma(core::int i) → void { + core::print(#C12); + #L2: + { + core::print("is linux"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C12; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(#C12); + #L3: + { + core::print("is linux"); + break #L3; + } +} +@#C28 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C12; + } + assert((() → core::bool { + if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) { + result = #C3; + } + return true; + })(){() → core::bool}); + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWithAsserts); + #L4: + switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L5: + case #C3: + { + core::print("is android"); + break #L4; + } + #L6: + case #C6: + { + core::print("is fuchsia"); + break #L4; + } + #L7: + case #C9: + { + core::print("is ios"); + break #L4; + } + #L8: + case #C12: + { + core::print("is linux"); + break #L4; + } + #L9: + case #C15: + { + core::print("is macos"); + break #L4; + } + #L10: + case #C18: + { + core::print("is windows"); + break #L4; + } + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = false + #C21 = true + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} + #C28 = core::pragma {name:#C26, options:#C20} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.expect new file mode 100644 index 00000000000..cad2da90e99 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.expect @@ -0,0 +1,188 @@ +library #lib; +import self as self; +import "dart:core" as core; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C21; +static method testAndroid(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); + { + final core::String os = #C14; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testWindows(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is macos"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C15; + throw "Unexpected platform: ${#C14}"; +} +static method testPragma(core::int i) → void { + core::print(#C15); + #L2: + { + core::print("is macos"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C15; + } + if(!(self::debugDefaultTestPlatform == null)) { + result = self::debugDefaultTestPlatform!; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWhenDebug); + #L3: + switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L4: + case #C3: + { + core::print("is android"); + break #L3; + } + #L5: + case #C6: + { + core::print("is fuchsia"); + break #L3; + } + #L6: + case #C9: + { + core::print("is ios"); + break #L3; + } + #L7: + case #C12: + { + core::print("is linux"); + break #L3; + } + #L8: + case #C15: + { + core::print("is macos"); + break #L3; + } + #L9: + case #C18: + { + core::print("is windows"); + break #L3; + } + } +} +@#C28 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C15; + } + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(#C15); + #L10: + { + core::print("is macos"); + break #L10; + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = true + #C21 = false + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} + #C28 = core::pragma {name:#C26, options:#C20} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.withAsserts.expect new file mode 100644 index 00000000000..53ea0733bf3 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.debug.withAsserts.expect @@ -0,0 +1,228 @@ +library #lib; +import self as self; +import "dart:core" as core; +import "dart:io" as io; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C20; +static method testAndroid(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); + { + final core::String os = #C14; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testWindows(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is macos"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C15; + throw "Unexpected platform: ${#C14}"; +} +static method testPragma(core::int i) → void { + core::print(#C15); + #L2: + { + core::print("is macos"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C15; + } + if(!(self::debugDefaultTestPlatform == null)) { + result = self::debugDefaultTestPlatform!; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWhenDebug); + #L3: + switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L4: + case #C3: + { + core::print("is android"); + break #L3; + } + #L5: + case #C6: + { + core::print("is fuchsia"); + break #L3; + } + #L6: + case #C9: + { + core::print("is ios"); + break #L3; + } + #L7: + case #C12: + { + core::print("is linux"); + break #L3; + } + #L8: + case #C15: + { + core::print("is macos"); + break #L3; + } + #L9: + case #C18: + { + core::print("is windows"); + break #L3; + } + } +} +@#C27 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C15; + } + assert((() → core::bool { + if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) { + result = #C3; + } + return true; + })(){() → core::bool}); + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWithAsserts); + #L10: + switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L11: + case #C3: + { + core::print("is android"); + break #L10; + } + #L12: + case #C6: + { + core::print("is fuchsia"); + break #L10; + } + #L13: + case #C9: + { + core::print("is ios"); + break #L10; + } + #L14: + case #C12: + { + core::print("is linux"); + break #L10; + } + #L15: + case #C15: + { + core::print("is macos"); + break #L10; + } + #L16: + case #C18: + { + core::print("is windows"); + break #L10; + } + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = true + #C21 = false + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.expect index 26513c18b02..3929ac61e3e 100644 --- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.expect +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.expect @@ -18,6 +18,9 @@ class TestPlatform extends core::_Enum /*isEnum*/ { method _enumToString() → core::String return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; } +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C20; static method testAndroid(core::int i) → void { final core::bool b = #C20; core::print(b); @@ -58,7 +61,7 @@ static method testSwitchStatements(core::int i) → void { @#C25 static get defaultTestPlatform() → self::TestPlatform { return #C15; - throw "Unexpected platform"; + throw "Unexpected platform: ${#C14}"; } static method testPragma(core::int i) → void { core::print(#C15); @@ -68,6 +71,38 @@ static method testPragma(core::int i) → void { break #L2; } } +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C15; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(#C15); + #L3: + { + core::print("is macos"); + break #L3; + } +} +@#C27 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C15; + } + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(#C15); + #L4: + { + core::print("is macos"); + break #L4; + } +} static method main(core::List args) → dynamic { if(args.{core::Iterable::isEmpty}{core::bool}) return; @@ -80,6 +115,9 @@ static method main(core::List args) → dynamic { self::testWindows(i); self::testSwitchStatements(i); self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); } constants { #C1 = 0 @@ -107,4 +145,6 @@ constants { #C23 = "vm:platform-const" #C24 = null #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} } diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.withAsserts.expect new file mode 100644 index 00000000000..2a3049708f8 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.macos.withAsserts.expect @@ -0,0 +1,192 @@ +library #lib; +import self as self; +import "dart:core" as core; +import "dart:io" as io; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C21; +static method testAndroid(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); + { + final core::String os = #C14; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testWindows(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is macos"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C15; + throw "Unexpected platform: ${#C14}"; +} +static method testPragma(core::int i) → void { + core::print(#C15); + #L2: + { + core::print("is macos"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C15; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(#C15); + #L3: + { + core::print("is macos"); + break #L3; + } +} +@#C28 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C15; + } + assert((() → core::bool { + if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) { + result = #C3; + } + return true; + })(){() → core::bool}); + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWithAsserts); + #L4: + switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L5: + case #C3: + { + core::print("is android"); + break #L4; + } + #L6: + case #C6: + { + core::print("is fuchsia"); + break #L4; + } + #L7: + case #C9: + { + core::print("is ios"); + break #L4; + } + #L8: + case #C12: + { + core::print("is linux"); + break #L4; + } + #L9: + case #C15: + { + core::print("is macos"); + break #L4; + } + #L10: + case #C18: + { + core::print("is windows"); + break #L4; + } + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = false + #C21 = true + #C22 = "/" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} + #C28 = core::pragma {name:#C26, options:#C20} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.expect new file mode 100644 index 00000000000..75eff0c41ad --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.expect @@ -0,0 +1,188 @@ +library #lib; +import self as self; +import "dart:core" as core; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C21; +static method testAndroid(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C20; + core::print(b); + { + final core::String os = #C17; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is windows"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C18; + throw "Unexpected platform: ${#C17}"; +} +static method testPragma(core::int i) → void { + core::print(#C18); + #L2: + { + core::print("is windows"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C18; + } + if(!(self::debugDefaultTestPlatform == null)) { + result = self::debugDefaultTestPlatform!; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWhenDebug); + #L3: + switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L4: + case #C3: + { + core::print("is android"); + break #L3; + } + #L5: + case #C6: + { + core::print("is fuchsia"); + break #L3; + } + #L6: + case #C9: + { + core::print("is ios"); + break #L3; + } + #L7: + case #C12: + { + core::print("is linux"); + break #L3; + } + #L8: + case #C15: + { + core::print("is macos"); + break #L3; + } + #L9: + case #C18: + { + core::print("is windows"); + break #L3; + } + } +} +@#C28 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C18; + } + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(#C18); + #L10: + { + core::print("is windows"); + break #L10; + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = true + #C21 = false + #C22 = "\\" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} + #C28 = core::pragma {name:#C26, options:#C20} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.withAsserts.expect new file mode 100644 index 00000000000..8cb053ccc39 --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.debug.withAsserts.expect @@ -0,0 +1,228 @@ +library #lib; +import self as self; +import "dart:core" as core; +import "dart:io" as io; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C20; +static method testAndroid(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C21; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C20; + core::print(b); + { + final core::String os = #C17; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is windows"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C18; + throw "Unexpected platform: ${#C17}"; +} +static method testPragma(core::int i) → void { + core::print(#C18); + #L2: + { + core::print("is windows"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C18; + } + if(!(self::debugDefaultTestPlatform == null)) { + result = self::debugDefaultTestPlatform!; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWhenDebug); + #L3: + switch(self::defaultTestPlatformOverridableWhenDebug) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L4: + case #C3: + { + core::print("is android"); + break #L3; + } + #L5: + case #C6: + { + core::print("is fuchsia"); + break #L3; + } + #L6: + case #C9: + { + core::print("is ios"); + break #L3; + } + #L7: + case #C12: + { + core::print("is linux"); + break #L3; + } + #L8: + case #C15: + { + core::print("is macos"); + break #L3; + } + #L9: + case #C18: + { + core::print("is windows"); + break #L3; + } + } +} +@#C27 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C18; + } + assert((() → core::bool { + if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) { + result = #C3; + } + return true; + })(){() → core::bool}); + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWithAsserts); + #L10: + switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L11: + case #C3: + { + core::print("is android"); + break #L10; + } + #L12: + case #C6: + { + core::print("is fuchsia"); + break #L10; + } + #L13: + case #C9: + { + core::print("is ios"); + break #L10; + } + #L14: + case #C12: + { + core::print("is linux"); + break #L10; + } + #L15: + case #C15: + { + core::print("is macos"); + break #L10; + } + #L16: + case #C18: + { + core::print("is windows"); + break #L10; + } + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = true + #C21 = false + #C22 = "\\" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} +} diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.expect index f1086024a36..42711839208 100644 --- a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.expect +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.expect @@ -18,6 +18,9 @@ class TestPlatform extends core::_Enum /*isEnum*/ { method _enumToString() → core::String return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; } +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C20; static method testAndroid(core::int i) → void { final core::bool b = #C20; core::print(b); @@ -58,7 +61,7 @@ static method testSwitchStatements(core::int i) → void { @#C25 static get defaultTestPlatform() → self::TestPlatform { return #C18; - throw "Unexpected platform"; + throw "Unexpected platform: ${#C17}"; } static method testPragma(core::int i) → void { core::print(#C18); @@ -68,6 +71,38 @@ static method testPragma(core::int i) → void { break #L2; } } +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C18; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(#C18); + #L3: + { + core::print("is windows"); + break #L3; + } +} +@#C27 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C18; + } + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(#C18); + #L4: + { + core::print("is windows"); + break #L4; + } +} static method main(core::List args) → dynamic { if(args.{core::Iterable::isEmpty}{core::bool}) return; @@ -80,6 +115,9 @@ static method main(core::List args) → dynamic { self::testWindows(i); self::testSwitchStatements(i); self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); } constants { #C1 = 0 @@ -107,4 +145,6 @@ constants { #C23 = "vm:platform-const" #C24 = null #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} } diff --git a/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.withAsserts.expect b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.withAsserts.expect new file mode 100644 index 00000000000..a16c5280f4d --- /dev/null +++ b/pkg/vm/testcases/transformations/vm_constant_evaluator/platform_testcases.dart.windows.withAsserts.expect @@ -0,0 +1,192 @@ +library #lib; +import self as self; +import "dart:core" as core; +import "dart:io" as io; + +import "dart:io"; + +class TestPlatform extends core::_Enum /*isEnum*/ { + static const field core::List values = #C19; + enum-element static const field self::TestPlatform android = #C3; + enum-element static const field self::TestPlatform fuchsia = #C6; + enum-element static const field self::TestPlatform ios = #C9; + enum-element static const field self::TestPlatform linux = #C12; + enum-element static const field self::TestPlatform macos = #C15; + enum-element static const field self::TestPlatform windows = #C18; + const synthetic constructor •(core::int #index, core::String #name) → self::TestPlatform + : super core::_Enum::•(#index, #name) + ; + method _enumToString() → core::String + return "TestPlatform.${this.{core::_Enum::_name}{core::String}}"; +} +static const field core::bool kDebugMode = #C20; +static field self::TestPlatform? debugDefaultTestPlatform; +static const field core::bool enableAsserts = #C21; +static method testAndroid(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testFuchsia(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testIOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testLinux(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testMacOS(core::int i) → void { + final core::bool b = #C20; + core::print(b); +} +static method testWindows(core::int i) → void { + final core::bool b = #C21; + core::print(b); + { + final core::String os = #C17; + core::print(os); + final core::String sep = #C22; + core::print(sep); + } +} +static method testSwitchStatements(core::int i) → void { + #L1: + { + core::print("is windows"); + break #L1; + } +} +@#C25 +static get defaultTestPlatform() → self::TestPlatform { + return #C18; + throw "Unexpected platform: ${#C17}"; +} +static method testPragma(core::int i) → void { + core::print(#C18); + #L2: + { + core::print("is windows"); + break #L2; + } +} +@#C27 +static get defaultTestPlatformOverridableWhenDebug() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C18; + } + return result; +} +static method testConditionalPragma(core::int i) → void { + core::print(#C18); + #L3: + { + core::print("is windows"); + break #L3; + } +} +@#C28 +static get defaultTestPlatformOverridableWithAsserts() → self::TestPlatform { + late self::TestPlatform result; + { + result = #C18; + } + assert((() → core::bool { + if(io::Platform::environment.{core::Map::containsKey}("FLUTTER_TEST"){(core::Object?) → core::bool}) { + result = #C3; + } + return true; + })(){() → core::bool}); + return result; +} +static method testConditionalPragmaWithAsserts(core::int i) → void { + core::print(self::defaultTestPlatformOverridableWithAsserts); + #L4: + switch(self::defaultTestPlatformOverridableWithAsserts) /* isExplicitlyExhaustive, self::TestPlatform */ { + #L5: + case #C3: + { + core::print("is android"); + break #L4; + } + #L6: + case #C6: + { + core::print("is fuchsia"); + break #L4; + } + #L7: + case #C9: + { + core::print("is ios"); + break #L4; + } + #L8: + case #C12: + { + core::print("is linux"); + break #L4; + } + #L9: + case #C15: + { + core::print("is macos"); + break #L4; + } + #L10: + case #C18: + { + core::print("is windows"); + break #L4; + } + } +} +static method main(core::List args) → dynamic { + if(args.{core::Iterable::isEmpty}{core::bool}) + return; + final core::int i = core::int::parse(args.{core::List::[]}(0){(core::int) → core::String}); + self::testAndroid(i); + self::testFuchsia(i); + self::testIOS(i); + self::testLinux(i); + self::testMacOS(i); + self::testWindows(i); + self::testSwitchStatements(i); + self::testPragma(i); + self::debugDefaultTestPlatform = #C3; + self::testConditionalPragma(i); + self::testConditionalPragmaWithAsserts(i); +} +constants { + #C1 = 0 + #C2 = "android" + #C3 = self::TestPlatform {index:#C1, _name:#C2} + #C4 = 1 + #C5 = "fuchsia" + #C6 = self::TestPlatform {index:#C4, _name:#C5} + #C7 = 2 + #C8 = "ios" + #C9 = self::TestPlatform {index:#C7, _name:#C8} + #C10 = 3 + #C11 = "linux" + #C12 = self::TestPlatform {index:#C10, _name:#C11} + #C13 = 4 + #C14 = "macos" + #C15 = self::TestPlatform {index:#C13, _name:#C14} + #C16 = 5 + #C17 = "windows" + #C18 = self::TestPlatform {index:#C16, _name:#C17} + #C19 = [#C3, #C6, #C9, #C12, #C15, #C18] + #C20 = false + #C21 = true + #C22 = "\\" + #C23 = "vm:platform-const" + #C24 = null + #C25 = core::pragma {name:#C23, options:#C24} + #C26 = "vm:platform-const-if" + #C27 = core::pragma {name:#C26, options:#C21} + #C28 = core::pragma {name:#C26, options:#C20} +} diff --git a/runtime/docs/pragmas.md b/runtime/docs/pragmas.md index 4e274b4dabf..0d853b750d6 100644 --- a/runtime/docs/pragmas.md +++ b/runtime/docs/pragmas.md @@ -15,6 +15,7 @@ These pragmas are part of the VM's API and are safe for use in external code. | `vm:invisible` | Allows to mark a function as invisible so it will not appear on stack traces. | | `vm:always-consider-inlining` | Marks a function which particularly benefits from inlining and specialization in context of the caller (for example, when concrete types of arguments are known). Inliner will not give up after one failed inlining attempt and will continue trying to inline this function. | | `vm:platform-const` | Marks a static getter or a static field with an initializer where the getter body or field initializer evaluates to a constant value if the target operating system is known. | +| `vm:platform-const-if` | Like `vm:platform-const`, but takes a boolean argument and constant evaluation of the annotated member is only performed if the argument const evaluates to true. | | `weak-tearoff-reference` | [Declaring a static weak reference intrinsic method.](compiler/pragmas_recognized_by_compiler.md#declaring-a-static-weak-reference-intrinsic-method) | | `vm:isolate-unsendable` | Marks a class, instances of which won't be allowed to be passed through ports or sent between isolates. | | `vm:awaiter-link` | [Specifying variable to follow for awaiter stack unwinding](awaiter_stack_traces.md) |