Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ group("flutter") {
"$flutter_root/third_party/txt",
]

if (flutter_runtime_mode != "debug") {
public_deps += [
"$flutter_root/lib/snapshot:entry_points_json_files",
]
}

if (!is_fuchsia && !is_fuchsia_host) {
if (current_toolchain == host_toolchain) {
public_deps += [
Expand Down
36 changes: 27 additions & 9 deletions frontend_server/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ ArgParser _argParser = new ArgParser(allowTrailingOptions: true)
..addFlag('strong',
help: 'Run compiler in strong mode (uses strong mode semantics)',
defaultsTo: false)
..addFlag('tfa',
help:
'Enable global type flow analysis and related transformations in AOT mode.',
defaultsTo: false)
..addFlag('link-platform',
help:
'When in batch mode, link platform kernel file into result kernel file.'
Expand Down Expand Up @@ -145,7 +149,7 @@ class _FrontendCompiler implements CompilerInterface {
BinaryPrinterFactory printerFactory;

CompilerOptions _compilerOptions;
Uri _entryPoint;
Uri _mainSource;
ArgResults _options;

IncrementalCompiler _generator;
Expand All @@ -155,7 +159,7 @@ class _FrontendCompiler implements CompilerInterface {
final bool trackWidgetCreation;
WidgetCreatorTracker widgetCreatorTracker;

void setEntrypointFilename(String filename) {
void setMainSourceFilename(String filename) {
final Uri filenameUri = Uri.base.resolveUri(new Uri.file(filename));
_kernelBinaryFilenameFull = _options['output-dill'] ?? '$filename.dill';
_kernelBinaryFilenameIncremental =
Expand All @@ -164,7 +168,7 @@ class _FrontendCompiler implements CompilerInterface {
? '${_options["output-dill"]}.incremental.dill'
: '$filename.incremental.dill';
_kernelBinaryFilename = _kernelBinaryFilenameFull;
_entryPoint = filenameUri;
_mainSource = filenameUri;
}

@override
Expand All @@ -174,7 +178,7 @@ class _FrontendCompiler implements CompilerInterface {
IncrementalCompiler generator,
}) async {
_options = options;
setEntrypointFilename(filename);
setMainSourceFilename(filename);
final String boundaryKey = new Uuid().generateV4();
_outputStream.writeln('result $boundaryKey');
final Uri sdkRoot = _ensureFolderPath(options['sdk-root']);
Expand All @@ -201,8 +205,21 @@ class _FrontendCompiler implements CompilerInterface {
sdkRoot.resolve(platformKernelDill)
];
}
program = await _runWithPrintRedirection(() =>
compileToKernel(_entryPoint, compilerOptions, aot: options['aot']));
final bool aot = options['aot'];
final List<String> entryPoints = <String>[];
if (aot) {
for (String entryPointsFile in <String>[
'entry_points.json',
'entry_points_extra.json',
]) {
entryPoints.add(sdkRoot.resolve(entryPointsFile).toFilePath());
}
}
program = await _runWithPrintRedirection(() => compileToKernel(
_mainSource, compilerOptions,
aot: aot,
useGlobalTypeFlowAnalysis: options['tfa'],
entryPoints: entryPoints));
}
runFlutterSpecificKernelTransforms(program);
if (program != null) {
Expand Down Expand Up @@ -279,9 +296,10 @@ class _FrontendCompiler implements CompilerInterface {
_outputStream.writeln('result $boundaryKey');
await invalidateIfBootstrapping();
if (filename != null) {
setEntrypointFilename(filename);
setMainSourceFilename(filename);
}
final Program deltaProgram = await _generator.compile(entryPoint: _entryPoint);
final Program deltaProgram =
await _generator.compile(entryPoint: _mainSource);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you renamed _entryPoint to _mainSource this now looks weird.
Any other alternative names for newly introduced entryPoints? tfaEntryPoints?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look.

I agree that there is still a little bit of disambiguation left.

Eventually I'd like to switch all precompilation to use new entry points format (or remove all entry points files and replace them with Dart annotations), so I would prefer not to use 'tfa' in their name (as they may be used in other places too). These are lists of entry points into Dart code from embedder/native code.

What do you think about renaming 'entryPoint' argument of IncrementalCompiler?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is fine too.

runFlutterSpecificKernelTransforms(deltaProgram);
final IOSink sink = new File(_kernelBinaryFilename).openWrite();
final BinaryPrinter printer = printerFactory.newBinaryPrinter(sink);
Expand Down Expand Up @@ -309,7 +327,7 @@ class _FrontendCompiler implements CompilerInterface {
}

IncrementalCompiler _createGenerator(Uri bootstrapDill) {
return new IncrementalCompiler(_compilerOptions, _entryPoint,
return new IncrementalCompiler(_compilerOptions, _mainSource,
bootstrapDill: bootstrapDill);
}

Expand Down
37 changes: 37 additions & 0 deletions lib/snapshot/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import("$flutter_root/lib/ui/dart_ui.gni")
import("//third_party/dart/utils/compile_platform.gni")
import("//third_party/dart/utils/generate_entry_points_json.gni")

if (is_fuchsia) {
import("//build/dart/toolchain.gni")
Expand Down Expand Up @@ -293,3 +294,39 @@ group("kernel_platform_files") {
":strong_platform",
]
}

generate_entry_points_json_with_gen_snapshot("entry_points_json") {
input = "$flutter_root/lib/snapshot/snapshot.dart"
output = "$root_out_dir/flutter_patched_sdk/entry_points.json"
dart_ui = "$flutter_root/lib/ui/ui.dart"
vmservice_io = "//third_party/dart/runtime/bin/vmservice/vmservice_io.dart"
dart_vm_entry_points_txt = "$flutter_root/runtime/dart_vm_entry_points.txt"
dart_io_entries_txt = "//third_party/dart/runtime/bin/dart_io_entries.txt"

extra_inputs = [
dart_ui,
vmservice_io,
dart_vm_entry_points_txt,
dart_io_entries_txt,
]

extra_args = [
"--await_is_keyword",
"--url_mapping=dart:ui," + rebase_path(dart_ui),
"--url_mapping=dart:vmservice_io," + rebase_path(vmservice_io),
"--causal_async_stacks",
"--embedder_entry_points_manifest=" + rebase_path(dart_vm_entry_points_txt),
"--embedder_entry_points_manifest=" + rebase_path(dart_io_entries_txt),
]
}

copy_entry_points_extra_json("entry_points_extra_json") {
output = "$root_out_dir/flutter_patched_sdk/entry_points_extra.json"
}

group("entry_points_json_files") {
public_deps = [
":entry_points_json",
":entry_points_extra_json",
]
}