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