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

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

Issue 1011933002: Handle type-inference on fields, consts, and inferable overrides (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 = false;
29 29
30 /// Whether to infer types for consts and static fields by looking at 30 /// Whether to infer types for consts and fields by looking at initializers on
31 /// identifiers on 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 and will only work if `B` is 36 /// implementation of this inference is limited to ensure the answer is
37 /// defined in a different library than `A`. Because this might be surprising 37 /// deterministic when applying inference on library cycles. In the example
38 /// to users, this is turned off by default. 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
40 /// connected component as `A`, we use `B`'s inferred type instead.
41 ///
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
44 /// more detail so that, in the example above, we can use `B`'s inferred type
45 /// always.
39 final bool inferStaticsFromIdentifiers; 46 final bool inferStaticsFromIdentifiers;
40 static const inferStaticsFromIdentifiersDefault = false; 47 static const inferStaticsFromIdentifiersDefault = false;
41 48
42 /// Whether to ignore ordering issues and do a best effort in inference. When
43 /// false, inference of top-levels and statics is limited to only consider
44 /// expressions in the RHS for which the type is known precisely without
45 /// regard of the ordering in which we apply inference. Turning this flag on
46 /// will consider more expressions, including expressions where the RHS is
47 /// another identifier (which [inferStaticsFromIdentifiers]).
48 ///
49 /// Note: this option is experimental will be removed once we have a proper
50 /// implementation of inference in the future, which should handle all
51 /// ordering concerns.
52 final bool inferInNonStableOrder;
53 static const inferInNonStableOrderDefault = false;
54
55 /// 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
56 /// const. 50 /// const.
57 final bool onlyInferConstsAndFinalFields; 51 final bool onlyInferConstsAndFinalFields;
58 static const onlyInferConstAndFinalFieldsDefault = false; 52 static const onlyInferConstAndFinalFieldsDefault = false;
59 53
60 ResolverOptions({this.useMultiPackage: false, this.packageRoot: 'packages/', 54 ResolverOptions({this.useMultiPackage: false, this.packageRoot: 'packages/',
61 this.packagePaths: const <String>[], 55 this.packagePaths: const <String>[],
62 this.inferFromOverrides: inferFromOverridesDefault, 56 this.inferFromOverrides: inferFromOverridesDefault,
63 this.inferStaticsFromIdentifiers: inferStaticsFromIdentifiersDefault, 57 this.inferStaticsFromIdentifiers: inferStaticsFromIdentifiersDefault,
64 this.inferInNonStableOrder: inferInNonStableOrderDefault,
65 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault}); 58 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault});
66 } 59 }
67 60
68 // TODO(vsm): Merge RulesOptions and TypeOptions 61 // TODO(vsm): Merge RulesOptions and TypeOptions
69 /// Options used by our RestrictedRules. 62 /// Options used by our RestrictedRules.
70 class RulesOptions extends TypeOptions { 63 class RulesOptions extends TypeOptions {
71 /// Whether to allow casts in constant contexts. 64 /// Whether to allow casts in constant contexts.
72 final bool allowConstCasts; 65 final bool allowConstCasts;
73 66
74 /// Whether to use covariant generics 67 /// Whether to use covariant generics
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 167
175 /// Whether to infer return types and field types from overriden members. 168 /// Whether to infer return types and field types from overriden members.
176 @override 169 @override
177 final bool inferFromOverrides; 170 final bool inferFromOverrides;
178 171
179 /// 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
180 /// identifiers on the RHS. 173 /// identifiers on the RHS.
181 @override 174 @override
182 final bool inferStaticsFromIdentifiers; 175 final bool inferStaticsFromIdentifiers;
183 176
184 /// Whether to ignore ordering issue, and do a best effort in inference.
185 @override
186 final bool inferInNonStableOrder;
187
188 /// 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
189 /// const. 178 /// const.
190 @override 179 @override
191 final bool onlyInferConstsAndFinalFields; 180 final bool onlyInferConstsAndFinalFields;
192 181
193 /// List of non-nullable types. 182 /// List of non-nullable types.
194 @override 183 @override
195 final List<String> nonnullableTypes; 184 final List<String> nonnullableTypes;
196 185
197 /// Whether to use static types for code generation. 186 /// Whether to use static types for code generation.
198 @override 187 @override
199 final bool ignoreTypes; 188 final bool ignoreTypes;
200 189
201 /// Whether to emit the source map files. 190 /// Whether to emit the source map files.
202 @override 191 @override
203 final bool emitSourceMaps; 192 final bool emitSourceMaps;
204 193
205 CompilerOptions({this.allowConstCasts: true, this.checkSdk: false, 194 CompilerOptions({this.allowConstCasts: true, this.checkSdk: false,
206 this.dumpInfo: false, this.dumpInfoFile, this.dumpSrcDir, 195 this.dumpInfo: false, this.dumpInfoFile, this.dumpSrcDir,
207 this.forceCompile: false, this.formatOutput: false, 196 this.forceCompile: false, this.formatOutput: false,
208 this.cheapTestFormat: false, this.ignoreTypes: false, this.outputDir, 197 this.cheapTestFormat: false, this.ignoreTypes: false, this.outputDir,
209 this.outputDart: false, this.useColors: true, 198 this.outputDart: false, this.useColors: true,
210 this.covariantGenerics: true, this.relaxedCasts: true, 199 this.covariantGenerics: true, this.relaxedCasts: true,
211 this.useMultiPackage: false, this.packageRoot: 'packages/', 200 this.useMultiPackage: false, this.packageRoot: 'packages/',
212 this.packagePaths: const <String>[], 201 this.packagePaths: const <String>[],
213 this.inferFromOverrides: ResolverOptions.inferFromOverridesDefault, 202 this.inferFromOverrides: ResolverOptions.inferFromOverridesDefault,
214 this.inferStaticsFromIdentifiers: ResolverOptions.inferStaticsFromIdentifi ersDefault, 203 this.inferStaticsFromIdentifiers: ResolverOptions.inferStaticsFromIdentifi ersDefault,
215 this.inferInNonStableOrder: ResolverOptions.inferInNonStableOrderDefault,
216 this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinal FieldsDefault, 204 this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinal FieldsDefault,
217 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, 205 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false,
218 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE, 206 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE,
219 this.emitSourceMaps: true, this.entryPointFile: null, 207 this.emitSourceMaps: true, this.entryPointFile: null,
220 this.serverMode: false, this.port: 8080}); 208 this.serverMode: false, this.port: 8080});
221 } 209 }
222 210
223 /// Parses options from the command-line 211 /// Parses options from the command-line
224 CompilerOptions parseOptions(List<String> argv) { 212 CompilerOptions parseOptions(List<String> argv) {
225 ArgResults args = argParser.parse(argv); 213 ArgResults args = argParser.parse(argv);
(...skipping 15 matching lines...) Expand all
241 outputDart: args['dart-gen'], 229 outputDart: args['dart-gen'],
242 outputDir: args['out'], 230 outputDir: args['out'],
243 covariantGenerics: args['covariant-generics'], 231 covariantGenerics: args['covariant-generics'],
244 relaxedCasts: args['relaxed-casts'], 232 relaxedCasts: args['relaxed-casts'],
245 useColors: useColors, 233 useColors: useColors,
246 useMultiPackage: args['use-multi-package'], 234 useMultiPackage: args['use-multi-package'],
247 packageRoot: args['package-root'], 235 packageRoot: args['package-root'],
248 packagePaths: args['package-paths'].split(','), 236 packagePaths: args['package-paths'].split(','),
249 inferFromOverrides: args['infer-from-overrides'], 237 inferFromOverrides: args['infer-from-overrides'],
250 inferStaticsFromIdentifiers: args['infer-transitively'], 238 inferStaticsFromIdentifiers: args['infer-transitively'],
251 inferInNonStableOrder: args['infer-eagerly'],
252 onlyInferConstsAndFinalFields: args['infer-only-finals'], 239 onlyInferConstsAndFinalFields: args['infer-only-finals'],
253 nonnullableTypes: optionsToList(args['nonnullable'], 240 nonnullableTypes: optionsToList(args['nonnullable'],
254 defaultValue: TypeOptions.NONNULLABLE_TYPES), 241 defaultValue: TypeOptions.NONNULLABLE_TYPES),
255 help: args['help'], 242 help: args['help'],
256 useMockSdk: args['mock-sdk'], 243 useMockSdk: args['mock-sdk'],
257 dartSdkPath: sdkPath, 244 dartSdkPath: sdkPath,
258 logLevel: Level.LEVELS.firstWhere((Level l) => l.name == levelName, 245 logLevel: Level.LEVELS.firstWhere((Level l) => l.name == levelName,
259 orElse: () => Level.SEVERE), 246 orElse: () => Level.SEVERE),
260 emitSourceMaps: args['source-maps'], 247 emitSourceMaps: args['source-maps'],
261 entryPointFile: args.rest.length == 0 ? null : args.rest.first, 248 entryPointFile: args.rest.length == 0 ? null : args.rest.first,
(...skipping 22 matching lines...) Expand all
284 ..addFlag('infer-from-overrides', 271 ..addFlag('infer-from-overrides',
285 help: 'Infer unspecified types of fields and return types from ' 272 help: 'Infer unspecified types of fields and return types from '
286 'definitions in supertypes', 273 'definitions in supertypes',
287 defaultsTo: ResolverOptions.inferFromOverridesDefault) 274 defaultsTo: ResolverOptions.inferFromOverridesDefault)
288 ..addFlag('infer-transitively', 275 ..addFlag('infer-transitively',
289 help: 'Infer consts/fields from definitions in other libraries', 276 help: 'Infer consts/fields from definitions in other libraries',
290 defaultsTo: ResolverOptions.inferStaticsFromIdentifiersDefault) 277 defaultsTo: ResolverOptions.inferStaticsFromIdentifiersDefault)
291 ..addFlag('infer-only-finals', 278 ..addFlag('infer-only-finals',
292 help: 'Do not infer non-const or non-final fields', 279 help: 'Do not infer non-const or non-final fields',
293 defaultsTo: ResolverOptions.onlyInferConstAndFinalFieldsDefault) 280 defaultsTo: ResolverOptions.onlyInferConstAndFinalFieldsDefault)
294 ..addFlag('infer-eagerly',
295 help: 'experimental: allows a non-stable order of transitive inference on'
296 ' consts and fields. This is used to test for possible inference with a '
297 'proper implementation in the future.',
298 defaultsTo: ResolverOptions.inferInNonStableOrderDefault)
299 281
300 // input/output options 282 // input/output options
301 ..addOption('out', abbr: 'o', help: 'Output directory', defaultsTo: null) 283 ..addOption('out', abbr: 'o', help: 'Output directory', defaultsTo: null)
302 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) 284 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null)
303 ..addFlag('dart-gen', 285 ..addFlag('dart-gen',
304 abbr: 'd', help: 'Generate dart output', defaultsTo: false) 286 abbr: 'd', help: 'Generate dart output', defaultsTo: false)
305 ..addFlag('dart-gen-fmt', 287 ..addFlag('dart-gen-fmt',
306 help: 'Generate readable dart output', defaultsTo: true) 288 help: 'Generate readable dart output', defaultsTo: true)
307 ..addOption('dump-src-to', help: 'Dump dart src code', defaultsTo: null) 289 ..addOption('dump-src-to', help: 'Dump dart src code', defaultsTo: null)
308 ..addOption('package-root', 290 ..addOption('package-root',
(...skipping 16 matching lines...) Expand all
325 defaultsTo: '8080') 307 defaultsTo: '8080')
326 ..addFlag('force-compile', 308 ..addFlag('force-compile',
327 help: 'Compile code with static errors', defaultsTo: false) 309 help: 'Compile code with static errors', defaultsTo: false)
328 ..addOption('log', abbr: 'l', help: 'Logging level', defaultsTo: 'severe') 310 ..addOption('log', abbr: 'l', help: 'Logging level', defaultsTo: 'severe')
329 ..addFlag('dump-info', 311 ..addFlag('dump-info',
330 abbr: 'i', help: 'Dump summary information', defaultsTo: false) 312 abbr: 'i', help: 'Dump summary information', defaultsTo: false)
331 ..addOption('dump-info-file', 313 ..addOption('dump-info-file',
332 abbr: 'f', 314 abbr: 'f',
333 help: 'Dump info json file (requires dump-info)', 315 help: 'Dump info json file (requires dump-info)',
334 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