Files
sdk/runtime/vm/compiler/frontend/constant_reader.h
T
Martin Kustermann f20e6d3fa0 [vm] Remove complex logic in kernel loader for dealing with annotations
Instead of peeking into constant table and then delaying scanning of
constants by putting it in an array, which is walked again in some
future point, we simply read the annotation constants entirely without
requiring const evaluation. This works fine for pragma annotations the
VM is interested in - as there's no user-defined classes involved.

-> Loading kernel will no longer require constant evaluation to work.

Motivation for this is that [0] wants to make this delayed annotation
scanning logic even more complicated, so I prefer to remove it entirely.

[0] https://dart-review.googlesource.com/c/sdk/+/289027

TEST=ci

Change-Id: Ib859480107b6cf119d66035e66ec161ed11ddb32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290502
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-03-22 12:25:47 +00:00

65 lines
2.1 KiB
C++

// Copyright (c) 2018, 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_COMPILER_FRONTEND_CONSTANT_READER_H_
#define RUNTIME_VM_COMPILER_FRONTEND_CONSTANT_READER_H_
#if defined(DART_PRECOMPILED_RUNTIME)
#error "AOT runtime should not use compiler sources (including header files)"
#endif // defined(DART_PRECOMPILED_RUNTIME)
#include "vm/compiler/frontend/kernel_translation_helper.h"
#include "vm/hash_table.h"
#include "vm/object.h"
namespace dart {
namespace kernel {
// Reads and caches constants from the kernel constant pool.
class ConstantReader {
public:
ConstantReader(KernelReaderHelper* helper, ActiveClass* active_class);
virtual ~ConstantReader() {}
bool IsPragmaInstanceConstant(intptr_t constant_index,
intptr_t* pragma_name_constant_index,
intptr_t* pragma_options_constant_index);
bool IsStringConstant(intptr_t constant_index, const char* name);
bool GetStringConstant(intptr_t constant_index, String* out_value);
InstancePtr ReadConstantInitializer();
InstancePtr ReadConstantExpression();
ObjectPtr ReadAnnotations();
// Peeks to see if constant at the given index will evaluate to
// instance of the given clazz.
bool IsInstanceConstant(intptr_t constant_index, const Class& clazz);
// Reads a constant at the given index (possibly by recursing
// into sub-constants).
InstancePtr ReadConstant(intptr_t constant_index);
intptr_t NumConstants();
private:
InstancePtr ReadConstantInternal(intptr_t constant_index);
intptr_t NavigateToIndex(KernelReaderHelper* reader, intptr_t constant_index);
intptr_t NumConstants(KernelReaderHelper* reader);
KernelReaderHelper* helper_;
Zone* zone_;
TranslationHelper& translation_helper_;
ActiveClass* active_class_;
const Script& script_;
Object& result_;
DISALLOW_COPY_AND_ASSIGN(ConstantReader);
};
} // namespace kernel
} // namespace dart
#endif // RUNTIME_VM_COMPILER_FRONTEND_CONSTANT_READER_H_