mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:20:10 +01:00
Move subtree sizes over to TreeAndSubtrees, using the different structure to represent the additional parse work that occurs, as well as making it clear which functions require the extra information. My intent is to make it hard to use this by accident. The subtree size is still tracked during Parse::Tree construction. I think a lot of that can be cleaned up, although we use it during placeholder assignment so it may take some work. I wanted to see what people thought about this before taking action on such a change. I'm using a 1m line source file generated by #4124 for testing. Command is `time bazel-bin/toolchain/install/prefix_root/bin/carbon compile --phase=check --dump-mem-usage ~/tmp/data.carbon` At head, what I'm seeing is: ``` ... parse_tree_.node_impls_: used_bytes: 61516116 reserved_bytes: 61516116 ... Total: used_bytes: 447814230 reserved_bytes: 551663894 ... 1.43s user 0.14s system 99% cpu 1.565 total ``` With `Tree::Verify` disabled completely, it looks like: ``` parse_tree_.node_impls_: used_bytes: 41010744 reserved_bytes: 41010744 ... Total: used_bytes: 427308858 reserved_bytes: 531158522 ... 1.20s user 0.13s system 99% cpu 1.332 total ``` Re-enabling just the basic verification (what is now `Tree::Verify`), I'm seeing maybe 0.05s slower, but that's within noise for my system. I do see variability in my timing results, and overall I think this is a 0.2s +/- 0.1s improvement versus the earlier (always testing `Extract` code) implementation. That's opt; debug builds will be unaffected, because the same checking occurs as before. Note, the subtree size is a third of the node representation, which is why I'm showing the decrease in memory usage here.
197 lines
4.5 KiB
Python
197 lines
4.5 KiB
Python
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
# Exceptions. See /LICENSE for license information.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
|
|
load("//testing/fuzzing:rules.bzl", "cc_fuzz_test")
|
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
filegroup(
|
|
name = "testdata",
|
|
data = glob(["testdata/**/*.carbon"]),
|
|
)
|
|
|
|
cc_library(
|
|
name = "node_kind",
|
|
srcs = ["node_kind.cpp"],
|
|
hdrs = [
|
|
"node_ids.h",
|
|
"node_kind.h",
|
|
"typed_nodes.h",
|
|
],
|
|
textual_hdrs = ["node_kind.def"],
|
|
deps = [
|
|
"//common:check",
|
|
"//common:enum_base",
|
|
"//common:ostream",
|
|
"//toolchain/base:index_base",
|
|
"//toolchain/lex:token_index",
|
|
"//toolchain/lex:token_kind",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "typed_nodes_test",
|
|
size = "small",
|
|
srcs = ["typed_nodes_test.cpp"],
|
|
deps = [
|
|
":node_kind",
|
|
":parse",
|
|
":tree",
|
|
"//testing/base:gtest_main",
|
|
"//toolchain/diagnostics:diagnostic_emitter",
|
|
"//toolchain/diagnostics:mocks",
|
|
"//toolchain/lex",
|
|
"//toolchain/lex:tokenized_buffer",
|
|
"@googletest//:gtest",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "context",
|
|
srcs = ["context.cpp"],
|
|
hdrs = ["context.h"],
|
|
deps = [
|
|
":node_kind",
|
|
":precedence",
|
|
":state",
|
|
":tree",
|
|
"//common:check",
|
|
"//common:ostream",
|
|
"//common:vlog",
|
|
"//toolchain/lex:token_kind",
|
|
"//toolchain/lex:tokenized_buffer",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "parse",
|
|
srcs = ["parse.cpp"] +
|
|
# Glob handler files to avoid missing any.
|
|
glob([
|
|
"handle_*.cpp",
|
|
]),
|
|
hdrs = [
|
|
"handle.h",
|
|
"parse.h",
|
|
],
|
|
deps = [
|
|
":context",
|
|
":node_kind",
|
|
":state",
|
|
":tree",
|
|
"//common:check",
|
|
"//common:ostream",
|
|
"//toolchain/base:pretty_stack_trace_function",
|
|
"//toolchain/base:value_store",
|
|
"//toolchain/diagnostics:diagnostic_emitter",
|
|
"//toolchain/lex:token_kind",
|
|
"//toolchain/lex:tokenized_buffer",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "state",
|
|
srcs = ["state.cpp"],
|
|
hdrs = ["state.h"],
|
|
textual_hdrs = ["state.def"],
|
|
deps = ["//common:enum_base"],
|
|
)
|
|
|
|
cc_library(
|
|
name = "tree",
|
|
srcs = [
|
|
"extract.cpp",
|
|
"tree.cpp",
|
|
"tree_and_subtrees.cpp",
|
|
],
|
|
hdrs = [
|
|
"tree.h",
|
|
"tree_and_subtrees.h",
|
|
],
|
|
deps = [
|
|
":node_kind",
|
|
"//common:check",
|
|
"//common:error",
|
|
"//common:ostream",
|
|
"//common:struct_reflection",
|
|
"//toolchain/lex:tokenized_buffer",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "tree_test",
|
|
size = "small",
|
|
srcs = ["tree_test.cpp"],
|
|
deps = [
|
|
":node_kind",
|
|
":parse",
|
|
":tree",
|
|
"//common:ostream",
|
|
"//testing/base:gtest_main",
|
|
"//testing/base:test_raw_ostream",
|
|
"//toolchain/base:value_store",
|
|
"//toolchain/diagnostics:diagnostic_emitter",
|
|
"//toolchain/diagnostics:mocks",
|
|
"//toolchain/lex",
|
|
"//toolchain/lex:tokenized_buffer",
|
|
"//toolchain/testing:yaml_test_helpers",
|
|
"@googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_fuzz_test(
|
|
name = "parse_fuzzer",
|
|
size = "small",
|
|
srcs = ["parse_fuzzer.cpp"],
|
|
corpus = glob(["fuzzer_corpus/*"]),
|
|
deps = [
|
|
":parse",
|
|
"//common:check",
|
|
"//testing/fuzzing:libfuzzer_header",
|
|
"//toolchain/base:value_store",
|
|
"//toolchain/diagnostics:diagnostic_emitter",
|
|
"//toolchain/diagnostics:null_diagnostics",
|
|
"//toolchain/lex",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "tree_node_diagnostic_converter",
|
|
hdrs = ["tree_node_diagnostic_converter.h"],
|
|
deps = [
|
|
":tree",
|
|
"//toolchain/diagnostics:diagnostic_emitter",
|
|
"//toolchain/lex:tokenized_buffer",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "precedence",
|
|
srcs = ["precedence.cpp"],
|
|
hdrs = ["precedence.h"],
|
|
deps = [
|
|
"//common:check",
|
|
"//toolchain/lex:token_kind",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "precedence_test",
|
|
size = "small",
|
|
srcs = ["precedence_test.cpp"],
|
|
deps = [
|
|
":precedence",
|
|
"//testing/base:gtest_main",
|
|
"//toolchain/lex:token_kind",
|
|
"@googletest//:gtest",
|
|
],
|
|
)
|