mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:30:32 +00:00
3fa0a2f255
This is a reland of commit 4c1235caab
The underlying problem is addressed in https://dart-review.googlesource.com/c/sdk/+/262429.
Original change's description:
> [vm] Cleanup unused code in ClosureFunctionsCache
>
> TEST=ci
>
> Change-Id: Ia6f24545c7e2d5b0df81cab52585d17556b36c16
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/256363
> Commit-Queue: Ryan Macnak <rmacnak@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Auto-Submit: Alexander Markov <alexmarkov@google.com>
TEST=ci
Change-Id: I96bd99174e68818ca8024e72836ebd1c99cdecd5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263141
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
72 lines
2.7 KiB
C++
72 lines
2.7 KiB
C++
// 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 O(n) lookup in a growable list.
|
|
//
|
|
// Parts of the VM have certain requirements that are maintained:
|
|
//
|
|
// * parent functions need to come before inner functions
|
|
// * closure functions list can grow while iterating
|
|
// * the index of closure function must be stable
|
|
//
|
|
// If the linear lookup turns out to be too expensive, the list of closures
|
|
// could be maintained in a hash map, with the key being the token position of
|
|
// the closure. There are almost no collisions with this simple hash value.
|
|
// However, iterating over all closure functions becomes more difficult,
|
|
// especially when the list/map changes while iterating over it (see
|
|
// requirements above).
|
|
class ClosureFunctionsCache : public AllStatic {
|
|
public:
|
|
static FunctionPtr LookupClosureFunction(const Function& parent,
|
|
TokenPosition token_pos);
|
|
static FunctionPtr LookupClosureFunctionLocked(const Function& parent,
|
|
TokenPosition token_pos);
|
|
|
|
// 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_
|