Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: lib/src/options.dart

Issue 1015843002: Turn on infer-from-overrides by default, rename inferStaticFromOtherStatics to (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/checker/resolver.dart ('k') | lib/src/testing.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Set of flags and options passed to the compiler 5 /// Set of flags and options passed to the compiler
6 library dev_compiler.src.options; 6 library dev_compiler.src.options;
7 7
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:args/args.dart'; 10 import 'package:args/args.dart';
11 import 'package:cli_util/cli_util.dart' show getSdkDir; 11 import 'package:cli_util/cli_util.dart' show getSdkDir;
12 import 'package:dev_compiler/config.dart'; 12 import 'package:dev_compiler/config.dart';
13 import 'package:logging/logging.dart' show Level; 13 import 'package:logging/logging.dart' show Level;
14 14
15 /// Options used by our TypeResolver. 15 /// Options used by our TypeResolver.
16 class ResolverOptions { 16 class ResolverOptions {
17 /// Whether to resolve 'package:' uris using the multi-package resolver. 17 /// Whether to resolve 'package:' uris using the multi-package resolver.
18 final bool useMultiPackage; 18 final bool useMultiPackage;
19 19
20 /// Package root when resolving 'package:' urls the standard way. 20 /// Package root when resolving 'package:' urls the standard way.
21 final String packageRoot; 21 final String packageRoot;
22 22
23 /// List of paths used for the multi-package resolver. 23 /// List of paths used for the multi-package resolver.
24 final List<String> packagePaths; 24 final List<String> packagePaths;
25 25
26 /// Whether to infer return types and field types from overriden members. 26 /// Whether to infer return types and field types from overriden members.
27 final bool inferFromOverrides; 27 final bool inferFromOverrides;
28 static const inferFromOverridesDefault = false; 28 static const inferFromOverridesDefault = true;
29 29
30 /// Whether to infer types for consts and fields by looking at initializers on 30 /// Whether to infer types for consts and fields by looking at initializers on
31 /// the RHS. For example, in a constant declaration like: 31 /// the RHS. For example, in a constant declaration like:
32 /// 32 ///
33 /// const A = B; 33 /// const A = B;
34 /// 34 ///
35 /// We can infer the type of `A` based on the type of `B`. The current 35 /// We can infer the type of `A` based on the type of `B`. The current
36 /// implementation of this inference is limited to ensure the answer is 36 /// implementation of this inference is limited to ensure the answer is
37 /// deterministic when applying inference on library cycles. In the example 37 /// deterministic when applying inference on library cycles. In the example
38 /// above, `A` is inferred to have `B`'s declared type if they are both in the 38 /// above, `A` is inferred to have `B`'s declared type if they are both in the
39 /// same library cycle. However, if `B`'s definition is not in the same 39 /// same library cycle. However, if `B`'s definition is not in the same
40 /// connected component as `A`, we use `B`'s inferred type instead. 40 /// connected component as `A`, we use `B`'s inferred type instead.
41 /// 41 ///
42 /// Because this might be surprising to users, this is turned off by default. 42 /// Because this might be surprising to users, this is turned off by default.
43 /// In the future, inference might track dependencies between variables in 43 /// In the future, inference might track dependencies between variables in
44 /// more detail so that, in the example above, we can use `B`'s inferred type 44 /// more detail so that, in the example above, we can use `B`'s inferred type
45 /// always. 45 /// always.
46 final bool inferStaticsFromIdentifiers; 46 final bool inferTransitively;
47 static const inferStaticsFromIdentifiersDefault = false; 47 static const inferTransitivelyDefault = false;
48 48
49 /// Restrict inference of fields and top-levels to those that are final and 49 /// Restrict inference of fields and top-levels to those that are final and
50 /// const. 50 /// const.
51 final bool onlyInferConstsAndFinalFields; 51 final bool onlyInferConstsAndFinalFields;
52 static const onlyInferConstAndFinalFieldsDefault = false; 52 static const onlyInferConstAndFinalFieldsDefault = false;
53 53
54 ResolverOptions({this.useMultiPackage: false, this.packageRoot: 'packages/', 54 ResolverOptions({this.useMultiPackage: false, this.packageRoot: 'packages/',
55 this.packagePaths: const <String>[], 55 this.packagePaths: const <String>[],
56 this.inferFromOverrides: inferFromOverridesDefault, 56 this.inferFromOverrides: inferFromOverridesDefault,
57 this.inferStaticsFromIdentifiers: inferStaticsFromIdentifiersDefault, 57 this.inferTransitively: inferTransitivelyDefault,
58 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault}); 58 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault});
59 } 59 }
60 60
61 // TODO(vsm): Merge RulesOptions and TypeOptions 61 // TODO(vsm): Merge RulesOptions and TypeOptions
62 /// Options used by our RestrictedRules. 62 /// Options used by our RestrictedRules.
63 class RulesOptions extends TypeOptions { 63 class RulesOptions extends TypeOptions {
64 /// Whether to allow casts in constant contexts. 64 /// Whether to allow casts in constant contexts.
65 final bool allowConstCasts; 65 final bool allowConstCasts;
66 66
67 /// Whether to use covariant generics 67 /// Whether to use covariant generics
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 @override 165 @override
166 final List<String> packagePaths; 166 final List<String> packagePaths;
167 167
168 /// Whether to infer return types and field types from overriden members. 168 /// Whether to infer return types and field types from overriden members.
169 @override 169 @override
170 final bool inferFromOverrides; 170 final bool inferFromOverrides;
171 171
172 /// Whether to infer types for consts and static fields by looking at 172 /// Whether to infer types for consts and static fields by looking at
173 /// identifiers on the RHS. 173 /// identifiers on the RHS.
174 @override 174 @override
175 final bool inferStaticsFromIdentifiers; 175 final bool inferTransitively;
176 176
177 /// Restrict inference of fields and top-levels to those that are final and 177 /// Restrict inference of fields and top-levels to those that are final and
178 /// const. 178 /// const.
179 @override 179 @override
180 final bool onlyInferConstsAndFinalFields; 180 final bool onlyInferConstsAndFinalFields;
181 181
182 /// List of non-nullable types. 182 /// List of non-nullable types.
183 @override 183 @override
184 final List<String> nonnullableTypes; 184 final List<String> nonnullableTypes;
185 185
186 /// Whether to use static types for code generation. 186 /// Whether to use static types for code generation.
187 @override 187 @override
188 final bool ignoreTypes; 188 final bool ignoreTypes;
189 189
190 /// Whether to emit the source map files. 190 /// Whether to emit the source map files.
191 @override 191 @override
192 final bool emitSourceMaps; 192 final bool emitSourceMaps;
193 193
194 CompilerOptions({this.allowConstCasts: true, this.checkSdk: false, 194 CompilerOptions({this.allowConstCasts: true, this.checkSdk: false,
195 this.dumpInfo: false, this.dumpInfoFile, this.dumpSrcDir, 195 this.dumpInfo: false, this.dumpInfoFile, this.dumpSrcDir,
196 this.forceCompile: false, this.formatOutput: false, 196 this.forceCompile: false, this.formatOutput: false,
197 this.cheapTestFormat: false, this.ignoreTypes: false, this.outputDir, 197 this.cheapTestFormat: false, this.ignoreTypes: false, this.outputDir,
198 this.outputDart: false, this.useColors: true, 198 this.outputDart: false, this.useColors: true,
199 this.covariantGenerics: true, this.relaxedCasts: true, 199 this.covariantGenerics: true, this.relaxedCasts: true,
200 this.useMultiPackage: false, this.packageRoot: 'packages/', 200 this.useMultiPackage: false, this.packageRoot: 'packages/',
201 this.packagePaths: const <String>[], 201 this.packagePaths: const <String>[],
202 this.inferFromOverrides: ResolverOptions.inferFromOverridesDefault, 202 this.inferFromOverrides: ResolverOptions.inferFromOverridesDefault,
203 this.inferStaticsFromIdentifiers: ResolverOptions.inferStaticsFromIdentifi ersDefault, 203 this.inferTransitively: ResolverOptions.inferTransitivelyDefault,
204 this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinal FieldsDefault, 204 this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinal FieldsDefault,
205 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, 205 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false,
206 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE, 206 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE,
207 this.emitSourceMaps: true, this.entryPointFile: null, 207 this.emitSourceMaps: true, this.entryPointFile: null,
208 this.serverMode: false, this.port: 8080}); 208 this.serverMode: false, this.port: 8080});
209 } 209 }
210 210
211 /// Parses options from the command-line 211 /// Parses options from the command-line
212 CompilerOptions parseOptions(List<String> argv) { 212 CompilerOptions parseOptions(List<String> argv) {
213 ArgResults args = argParser.parse(argv); 213 ArgResults args = argParser.parse(argv);
(...skipping 14 matching lines...) Expand all
228 ignoreTypes: args['ignore-types'], 228 ignoreTypes: args['ignore-types'],
229 outputDart: args['dart-gen'], 229 outputDart: args['dart-gen'],
230 outputDir: args['out'], 230 outputDir: args['out'],
231 covariantGenerics: args['covariant-generics'], 231 covariantGenerics: args['covariant-generics'],
232 relaxedCasts: args['relaxed-casts'], 232 relaxedCasts: args['relaxed-casts'],
233 useColors: useColors, 233 useColors: useColors,
234 useMultiPackage: args['use-multi-package'], 234 useMultiPackage: args['use-multi-package'],
235 packageRoot: args['package-root'], 235 packageRoot: args['package-root'],
236 packagePaths: args['package-paths'].split(','), 236 packagePaths: args['package-paths'].split(','),
237 inferFromOverrides: args['infer-from-overrides'], 237 inferFromOverrides: args['infer-from-overrides'],
238 inferStaticsFromIdentifiers: args['infer-transitively'], 238 inferTransitively: args['infer-transitively'],
239 onlyInferConstsAndFinalFields: args['infer-only-finals'], 239 onlyInferConstsAndFinalFields: args['infer-only-finals'],
240 nonnullableTypes: optionsToList(args['nonnullable'], 240 nonnullableTypes: optionsToList(args['nonnullable'],
241 defaultValue: TypeOptions.NONNULLABLE_TYPES), 241 defaultValue: TypeOptions.NONNULLABLE_TYPES),
242 help: args['help'], 242 help: args['help'],
243 useMockSdk: args['mock-sdk'], 243 useMockSdk: args['mock-sdk'],
244 dartSdkPath: sdkPath, 244 dartSdkPath: sdkPath,
245 logLevel: Level.LEVELS.firstWhere((Level l) => l.name == levelName, 245 logLevel: Level.LEVELS.firstWhere((Level l) => l.name == levelName,
246 orElse: () => Level.SEVERE), 246 orElse: () => Level.SEVERE),
247 emitSourceMaps: args['source-maps'], 247 emitSourceMaps: args['source-maps'],
248 entryPointFile: args.rest.length == 0 ? null : args.rest.first, 248 entryPointFile: args.rest.length == 0 ? null : args.rest.first,
(...skipping 18 matching lines...) Expand all
267 ..addOption('nonnullable', 267 ..addOption('nonnullable',
268 abbr: 'n', 268 abbr: 'n',
269 help: 'Comma separated string of non-nullable types', 269 help: 'Comma separated string of non-nullable types',
270 defaultsTo: null) 270 defaultsTo: null)
271 ..addFlag('infer-from-overrides', 271 ..addFlag('infer-from-overrides',
272 help: 'Infer unspecified types of fields and return types from ' 272 help: 'Infer unspecified types of fields and return types from '
273 'definitions in supertypes', 273 'definitions in supertypes',
274 defaultsTo: ResolverOptions.inferFromOverridesDefault) 274 defaultsTo: ResolverOptions.inferFromOverridesDefault)
275 ..addFlag('infer-transitively', 275 ..addFlag('infer-transitively',
276 help: 'Infer consts/fields from definitions in other libraries', 276 help: 'Infer consts/fields from definitions in other libraries',
277 defaultsTo: ResolverOptions.inferStaticsFromIdentifiersDefault) 277 defaultsTo: ResolverOptions.inferTransitivelyDefault)
278 ..addFlag('infer-only-finals', 278 ..addFlag('infer-only-finals',
279 help: 'Do not infer non-const or non-final fields', 279 help: 'Do not infer non-const or non-final fields',
280 defaultsTo: ResolverOptions.onlyInferConstAndFinalFieldsDefault) 280 defaultsTo: ResolverOptions.onlyInferConstAndFinalFieldsDefault)
281 281
282 // input/output options 282 // input/output options
283 ..addOption('out', abbr: 'o', help: 'Output directory', defaultsTo: null) 283 ..addOption('out', abbr: 'o', help: 'Output directory', defaultsTo: null)
284 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) 284 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null)
285 ..addFlag('dart-gen', 285 ..addFlag('dart-gen',
286 abbr: 'd', help: 'Generate dart output', defaultsTo: false) 286 abbr: 'd', help: 'Generate dart output', defaultsTo: false)
287 ..addFlag('dart-gen-fmt', 287 ..addFlag('dart-gen-fmt',
(...skipping 19 matching lines...) Expand all
307 defaultsTo: '8080') 307 defaultsTo: '8080')
308 ..addFlag('force-compile', 308 ..addFlag('force-compile',
309 help: 'Compile code with static errors', defaultsTo: false) 309 help: 'Compile code with static errors', defaultsTo: false)
310 ..addOption('log', abbr: 'l', help: 'Logging level', defaultsTo: 'severe') 310 ..addOption('log', abbr: 'l', help: 'Logging level', defaultsTo: 'severe')
311 ..addFlag('dump-info', 311 ..addFlag('dump-info',
312 abbr: 'i', help: 'Dump summary information', defaultsTo: false) 312 abbr: 'i', help: 'Dump summary information', defaultsTo: false)
313 ..addOption('dump-info-file', 313 ..addOption('dump-info-file',
314 abbr: 'f', 314 abbr: 'f',
315 help: 'Dump info json file (requires dump-info)', 315 help: 'Dump info json file (requires dump-info)',
316 defaultsTo: null); 316 defaultsTo: null);
OLDNEW
« no previous file with comments | « lib/src/checker/resolver.dart ('k') | lib/src/testing.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698