Skip to content

Commit e8c58a7

Browse files
jensjohacommit-bot@chromium.org
authored andcommitted
[CFE] Add ability to compare CompilerOptions
This is (intended to be) a small step towards removing the batch compiler. Change-Id: I201c56b6d33420f91d2f4b989682670cd8d6a387 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138508 Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 40507e7 commit e8c58a7

File tree

5 files changed

+93
-2
lines changed

5 files changed

+93
-2
lines changed

pkg/compiler/lib/src/kernel/dart2js_target.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ bool maybeEnableNative(Uri uri) {
5050

5151
/// A kernel [Target] to configure the Dart Front End for dart2js.
5252
class Dart2jsTarget extends Target {
53+
@override
5354
final TargetFlags flags;
5455
@override
5556
final String name;

pkg/dev_compiler/lib/src/kernel/target.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'kernel_helpers.dart';
2323
class DevCompilerTarget extends Target {
2424
DevCompilerTarget(this.flags);
2525

26+
@override
2627
final TargetFlags flags;
2728

2829
WidgetCreatorTracker _widgetTracker;

pkg/front_end/lib/src/api_prototype/compiler_options.dart

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import 'file_system.dart' show FileSystem;
2525

2626
import 'standard_file_system.dart' show StandardFileSystem;
2727

28+
import '../api_unstable/util.dart';
29+
2830
export 'package:_fe_analyzer_shared/src/messages/diagnostic_message.dart'
2931
show DiagnosticMessage;
3032

@@ -102,7 +104,7 @@ class CompilerOptions {
102104
/// When this option is `true`, [sdkSummary] must be null.
103105
bool compileSdk = false;
104106

105-
@deprecated
107+
@Deprecated("Unused internally.")
106108
bool chaseDependencies;
107109

108110
/// Patch files to apply on the core libraries for a specific target platform.
@@ -119,6 +121,7 @@ class CompilerOptions {
119121
/// directly, while relative URIs are resolved from the [sdkRoot].
120122
// TODO(sigmund): provide also a flag to load this data from a file (like
121123
// libraries.json)
124+
@Deprecated("Unused internally.")
122125
Map<String, List<Uri>> targetPatches = <String, List<Uri>>{};
123126

124127
/// Enable or disable experimental features. Features mapping to `true` are
@@ -153,6 +156,7 @@ class CompilerOptions {
153156

154157
/// Deprecated. Has no affect on front-end.
155158
// TODO(dartbug.com/37514) Remove this field once DDK removes its uses of it.
159+
@Deprecated("Unused internally.")
156160
bool enableAsserts = false;
157161

158162
/// Whether to show verbose messages (mainly for debugging and performance
@@ -232,6 +236,65 @@ class CompilerOptions {
232236
String currentSdkVersion = "${kernel.defaultLanguageVersionMajor}"
233237
"."
234238
"${kernel.defaultLanguageVersionMinor}";
239+
240+
bool equivalent(CompilerOptions other,
241+
{bool ignoreOnDiagnostic: true,
242+
bool ignoreVerbose: true,
243+
bool ignoreVerify: true,
244+
bool ignoreDebugDump: true}) {
245+
if (sdkRoot != other.sdkRoot) return false;
246+
if (librariesSpecificationUri != other.librariesSpecificationUri) {
247+
return false;
248+
}
249+
if (!ignoreOnDiagnostic) {
250+
if (onDiagnostic != other.onDiagnostic) return false;
251+
}
252+
if (packagesFileUri != other.packagesFileUri) return false;
253+
if (!equalLists(additionalDills, other.additionalDills)) return false;
254+
if (sdkSummary != other.sdkSummary) return false;
255+
if (!equalMaps(declaredVariables, other.declaredVariables)) return false;
256+
if (fileSystem != other.fileSystem) return false;
257+
if (compileSdk != compileSdk) return false;
258+
// chaseDependencies aren't used anywhere, so ignored here.
259+
// targetPatches aren't used anywhere, so ignored here.
260+
if (!equalMaps(experimentalFlags, other.experimentalFlags)) return false;
261+
if (!equalMaps(environmentDefines, other.environmentDefines)) return false;
262+
if (errorOnUnevaluatedConstant != other.errorOnUnevaluatedConstant) {
263+
return false;
264+
}
265+
if (target != other.target) {
266+
if (target.runtimeType != other.target.runtimeType) return false;
267+
if (target.name != other.target.name) return false;
268+
if (target.flags != other.target.flags) return false;
269+
}
270+
// enableAsserts is not used anywhere, so ignored here.
271+
if (!ignoreVerbose) {
272+
if (verbose != other.verbose) return false;
273+
}
274+
if (!ignoreVerify) {
275+
if (verify != other.verify) return false;
276+
}
277+
if (!ignoreDebugDump) {
278+
if (debugDump != other.debugDump) return false;
279+
}
280+
if (omitPlatform != other.omitPlatform) return false;
281+
if (setExitCodeOnProblem != other.setExitCodeOnProblem) return false;
282+
if (embedSourceText != other.embedSourceText) return false;
283+
if (throwOnErrorsForDebugging != other.throwOnErrorsForDebugging) {
284+
return false;
285+
}
286+
if (throwOnWarningsForDebugging != other.throwOnWarningsForDebugging) {
287+
return false;
288+
}
289+
if (skipForDebugging != other.skipForDebugging) return false;
290+
if (bytecode != other.bytecode) return false;
291+
if (writeFileOnCrashReport != other.writeFileOnCrashReport) return false;
292+
if (nnbdMode != other.nnbdMode) return false;
293+
if (performNnbdChecks != other.performNnbdChecks) return false;
294+
if (currentSdkVersion != other.currentSdkVersion) return false;
295+
296+
return true;
297+
}
235298
}
236299

237300
/// Parse experimental flag arguments of the form 'flag' or 'no-flag' into a map

pkg/kernel/lib/target/targets.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,32 @@ class TargetFlags {
2222
this.forceLateLoweringForTesting = false,
2323
this.forceNoExplicitGetterCallsForTesting = false,
2424
this.enableNullSafety = false});
25+
26+
bool operator ==(other) {
27+
if (other is! TargetFlags) return false;
28+
TargetFlags o = other;
29+
if (trackWidgetCreation != o.trackWidgetCreation) return false;
30+
if (forceLateLoweringForTesting != o.forceLateLoweringForTesting) {
31+
return false;
32+
}
33+
if (forceNoExplicitGetterCallsForTesting !=
34+
o.forceNoExplicitGetterCallsForTesting) {
35+
return false;
36+
}
37+
if (enableNullSafety != o.enableNullSafety) return false;
38+
return true;
39+
}
40+
41+
int get hashCode {
42+
int hash = 485786;
43+
hash = 0x3fffffff & (hash * 31 + (hash ^ trackWidgetCreation.hashCode));
44+
hash = 0x3fffffff &
45+
(hash * 31 + (hash ^ forceLateLoweringForTesting.hashCode));
46+
hash = 0x3fffffff &
47+
(hash * 31 + (hash ^ forceNoExplicitGetterCallsForTesting.hashCode));
48+
hash = 0x3fffffff & (hash * 31 + (hash ^ enableNullSafety.hashCode));
49+
return hash;
50+
}
2551
}
2652

2753
typedef Target _TargetBuilder(TargetFlags flags);
@@ -87,6 +113,7 @@ class ConstantsBackend {
87113

88114
/// A target provides backend-specific options for generating kernel IR.
89115
abstract class Target {
116+
TargetFlags get flags;
90117
String get name;
91118

92119
/// A list of URIs of required libraries, not including dart:core.

pkg/vm/bin/kernel_service.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ abstract class Compiler {
139139
parseExperimentalArguments(expFlags),
140140
onError: (msg) => errors.add(msg))
141141
..environmentDefines = new EnvironmentMap()
142-
..enableAsserts = enableAsserts
143142
..nnbdMode = nullSafety ? NnbdMode.Strong : NnbdMode.Weak
144143
..onDiagnostic = (DiagnosticMessage message) {
145144
bool printMessage;

0 commit comments

Comments
 (0)