Flutter Engine
The Flutter Engine
closure_functions_cache.h
Go to the documentation of this file.
1// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
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.
4
5#ifndef RUNTIME_VM_CLOSURE_FUNCTIONS_CACHE_H_
6#define RUNTIME_VM_CLOSURE_FUNCTIONS_CACHE_H_
7
8#include <functional>
9
10#include "vm/allocation.h"
11#include "vm/token_position.h"
12
13namespace dart {
14
15class Class;
16class Function;
17class FunctionPtr;
18
19// Implementation of cache for inner closure functions.
20//
21// This cache is populated lazily by the compiler: When compiling a function,
22// the flow graph builder will recursively traverse the kernel AST for the
23// function and any inner functions. This will cause the lazy-creation of inner
24// closure functions.
25//
26// The cache is currently implemented as a 2-level
27// Map<OutermostMemberFunction, Map<FunctionNodeKernelOffset, Function>>.
28//
29// The function is also added to the growable list in order to
30// satisfy the following requirements:
31// * closure functions list can grow while iterating
32// * the index of closure function must be stable
33//
35 public:
36 static FunctionPtr LookupClosureFunction(const Function& member_function,
37 intptr_t kernel_offset);
38 static FunctionPtr LookupClosureFunctionLocked(
39 const Function& member_function,
40 intptr_t kernel_offset);
41
42 // Normally implicit closure functions are not added to this cache, however
43 // during AOT compilation we might add those implicit closure functions
44 // that have their original functions shaken to allow ProgramWalker to
45 // discover them.
46 static void AddClosureFunctionLocked(
47 const Function& function,
48 bool allow_implicit_closure_functions = false);
49
50 static intptr_t FindClosureIndex(const Function& needle);
51 static FunctionPtr ClosureFunctionFromIndex(intptr_t idx);
52
53 // Visits all closure functions registered in the object store.
54 //
55 // Iterates in-order, thereby allowing new closures being added during the
56 // iteration.
57 //
58 // The iteration continues until either [callback] returns `false` or all
59 // closure functions have been visited.
60 static void ForAllClosureFunctions(
61 std::function<bool(const Function&)> callback);
62};
63
64} // namespace dart
65
66#endif // RUNTIME_VM_CLOSURE_FUNCTIONS_CACHE_H_
static intptr_t FindClosureIndex(const Function &needle)
static void AddClosureFunctionLocked(const Function &function, bool allow_implicit_closure_functions=false)
static FunctionPtr ClosureFunctionFromIndex(intptr_t idx)
static FunctionPtr LookupClosureFunctionLocked(const Function &member_function, intptr_t kernel_offset)
static void ForAllClosureFunctions(std::function< bool(const Function &)> callback)
static FunctionPtr LookupClosureFunction(const Function &member_function, intptr_t kernel_offset)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Dart_NativeFunction function
Definition: fuchsia.cc:51
Definition: dart_vm.cc:33