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

Unified Diff: pkg/front_end/lib/compiler_api.dart

Issue 2417043003: Initial API for the Dart front_end package. (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/lib/compiler_api.dart
diff --git a/pkg/front_end/lib/compiler_api.dart b/pkg/front_end/lib/compiler_api.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6b697768789c8e752e265ae59eac5fcdb0ef6bbe
--- /dev/null
+++ b/pkg/front_end/lib/compiler_api.dart
@@ -0,0 +1,92 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// Defines the front end API to be used by compiler back-ends.
Siggi Cherem (dart-lang) 2016/10/13 23:22:15 nit: front end => front-end ? (that would match ba
Bob Nystrom 2016/10/13 23:56:11 /me puts on grammarian hat. (I'm kidding, of cour
Paul Berry 2016/10/14 00:09:35 I don't have a strong preference, but in my mind t
Siggi Cherem (dart-lang) 2016/10/14 16:00:49 To make sure all options are on the table: my lean
Bob Nystrom 2016/10/14 16:12:18 "frontend" doesn't collapse well as a single word
Paul Berry 2016/10/14 21:32:34 I'm happy to defer to Kathy on this question. I'l
+library front_end.compiler_api;
+
+import 'compilation_error.dart';
+import 'package:analyzer/dart/ast/ast.dart' show CompilationUnit;
+
+/// Callback used by [CompilerApi] to report errors encountered during
+/// compilation.
+typedef void ErrorHandler(CompilationError);
scheglov 2016/10/13 23:58:17 typedef void ErrorHandler(CompilationError error);
Paul Berry 2016/10/14 00:09:36 Oops. Thank you.
+
+/// Front end API for use by compiler back-ends.
+///
+/// Intended use: create a CompilerApi object, set any desired options using
Siggi Cherem (dart-lang) 2016/10/13 23:22:15 since these options are just set once, could we ma
Paul Berry 2016/10/14 00:09:36 Yeah, that's a good point. Making them named argu
Brian Wilkerson 2016/10/14 14:54:45 If you intend to deprecate the sourcesToResolvedAs
Siggi Cherem (dart-lang) 2016/10/14 16:00:48 Good point. +1 on making it a single top-level fun
Paul Berry 2016/10/14 21:32:34 After further discussion, I'm going to provisional
+/// setters, and then call [sourcesToKernel] to obtain a Dart Kernel
+/// representation of input source files.
+///
+/// At the moment, this API only supports batch-mode compilation. Its methods
+/// operate on whole source files, and do not cache intermediate results between
Siggi Cherem (dart-lang) 2016/10/13 23:22:16 design discussion: I might be jumping ahead since
Paul Berry 2016/10/14 00:09:36 I don't think it's that simple, since changes to o
Siggi Cherem (dart-lang) 2016/10/14 16:00:49 Sure - let's chat sometime later, maybe after the
+/// method calls. Support for incremental updates will be added in the future
+/// (e.g. to allow for hot reload features).
+///
+/// All of the options have reasonable defaults, so a simple client may simply
+/// do: `var kernel = new CompilerApi().sourcesToKernel([Uri.parse(...)]);`
+abstract class CompilerApi {
Siggi Cherem (dart-lang) 2016/10/13 23:22:16 minor nit: what do you think about renaming this a
Brian Wilkerson 2016/10/13 23:37:02 This doesn't provide any way to set any options, s
Paul Berry 2016/10/14 00:09:36 It's intended to be added in the future. My curre
Paul Berry 2016/10/14 00:09:36 I'd prefer not to, since the front end also needs
Siggi Cherem (dart-lang) 2016/10/14 16:00:49 Ok, makes sense. My minor concern with [CompilerA
Paul Berry 2016/10/14 21:32:34 Good suggestions. Since I'm going to try re-worki
+ /// Creates an instance of [CompilerApi] with all options set to default
+ /// values.
+ factory CompilerApi() => throw new UnimplementedError();
+
+ /// Sets the path to the Dart SDK.
+ ///
+ /// If not set, the SDK will be searched for using [Platform.script] as a
+ /// starting point.
+ void set sdkPath(String path);
+
+ /// Sets a callback to which compilation errors should be delivered.
+ ///
+ /// If not set, the first error will be reported by throwing an exception of
+ /// type [CompilationError].
+ void set onError(ErrorHandler onError);
+
+ /// Sets the path to the ".packages" file.
+ ///
+ /// If not set, the ".packages" file will be found via the standard search
+ /// algorithm.
+ void set packages(String path);
Brian Wilkerson 2016/10/13 23:37:02 Analyzer currently supports setting a 'packages' d
Paul Berry 2016/10/14 00:09:36 Since the front end isn't likely to be used until
Brian Wilkerson 2016/10/14 14:54:45 I have asked several people, and as far as I can t
Paul Berry 2016/10/14 21:32:34 We had a bunch of discussion about this, and agree
+
+ /// Sets the paths to the input summary files.
+ ///
+ /// If not set, no input summaries will be used.
+ void set inputSummaries(List<String> paths);
Brian Wilkerson 2016/10/13 23:37:02 Does this include all summary files: sdk and non-s
scheglov 2016/10/13 23:58:17 Is using summaries for pub packages an implementat
Paul Berry 2016/10/14 00:09:35 I'm not sure. Let me think about this.
Paul Berry 2016/10/14 00:09:35 I think it should be not allowed; I don't think we
Brian Wilkerson 2016/10/14 14:54:45 While it might be reasonable for the front end to
Siggi Cherem (dart-lang) 2016/10/14 16:00:49 My assumption here was also like Brian: this list
+
+ /// Sets the URI override map.
+ ///
+ /// This is a map from Uri to file path which overrides the normal URI
+ /// resolution algorithm. If not set, the normal URI resolution algorithm
+ /// will always be used.
+ void set uriOverride(Map<Uri, String> mapping);
Siggi Cherem (dart-lang) 2016/10/13 23:22:15 is this for dart:* libraries or for mappings like
Brian Wilkerson 2016/10/13 23:37:01 What is this used for? (I don't remember seeing si
Paul Berry 2016/10/14 00:09:36 It's for the mappings we have to do for Bazel. It
Siggi Cherem (dart-lang) 2016/10/14 16:00:48 Ah - if it is mainly for bazel, this might be a go
Paul Berry 2016/10/14 21:32:34 I would like to learn more about this from you.
+
+ /// Sets the platform bit mask, which determines which patch files should be
+ /// applied to the SDK.
scheglov 2016/10/13 23:58:17 It is always a single platform, right? The phrase
Paul Berry 2016/10/14 00:09:36 It's always a single platform, but it must be a po
Siggi Cherem (dart-lang) 2016/10/14 16:00:49 I wonder if we should add an enum to libraries.dar
Paul Berry 2016/10/14 21:32:34 That's a good idea, but I'm not sure how it would
Siggi Cherem (dart-lang) 2016/10/17 16:27:29 [sorry I forgot to send this comment earlier]: To
+ ///
+ /// The value should match the `PLATFORM` bit flags in
+ /// sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart. If not set, no
+ /// patch files will be applied.
+ void set platform(int value);
Brian Wilkerson 2016/10/13 23:37:02 Note that there is another definition of "platform
Paul Berry 2016/10/14 00:09:36 Acknowledged.
+
+ /// Limits the set of files which the front end is allowed to read.
+ ///
+ /// The front end will behave as though files not in this set do not exist.
+ /// If not set, the front end is allowed to read all files in the filesystem.
+ void set permittedFiles(Iterable<String> files);
Siggi Cherem (dart-lang) 2016/10/13 23:22:15 is this mainly for validation in blaze? (to check
Brian Wilkerson 2016/10/13 23:37:02 What use case does this support? (I have to wonder
Paul Berry 2016/10/14 00:09:36 For the use case, see my answer to Siggi. As to w
Paul Berry 2016/10/14 00:09:36 It's for Bazel workers. Bazel workers aren't herm
Siggi Cherem (dart-lang) 2016/10/14 16:00:49 What do you think about making the front-end herme
Paul Berry 2016/10/14 21:32:34 If we do this we won't be able to support the use
+
+ /// Sets the declared variables for use by configurable imports and constant
+ /// evaluation.
+ void set declaredVariables(Map<String, String> variables);
+
+ /// Processes the given [sources] and converts them to Dart Kernel format.
+ ///
+ /// TODO(paulberry): once Dart Kernel has been merged into the SDK, set the
Siggi Cherem (dart-lang) 2016/10/13 23:22:16 since it's already pulled into DEPS, you might be
Paul Berry 2016/10/14 00:09:36 Oh, I didn't realize that. I will make that chang
+ /// return type correctly.
+ dynamic sourcesToKernel(List<Uri> sources);
+
+ /// Processes the given [sources] and converts them to resolved ASTs.
+ ///
+ /// This is intended to be used by dev_compiler prior to its conversion to
+ /// Dart Kernel.
Siggi Cherem (dart-lang) 2016/10/13 23:22:16 + and will be deperecated in the future? OR, shou
Paul Berry 2016/10/14 00:09:36 Yes that's my intent.
Siggi Cherem (dart-lang) 2016/10/14 16:00:48 Let's keep it separate then (either on a separate
Paul Berry 2016/10/14 21:32:34 Agreed.
+ List<CompilationUnit> sourcesToResolvedAsts(List<Uri> sources);
+}

Powered by Google App Engine
This is Rietveld 408576698