Skip to content

Commit

Permalink
perf: Library contents are now shared between processor groups
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Dec 14, 2022
1 parent 87dcc26 commit 25dfa69
Show file tree
Hide file tree
Showing 17 changed files with 277 additions and 26 deletions.
1 change: 1 addition & 0 deletions .github/workflows/Sonarcloud-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
run: |
mkdir pr-info
echo ${{ github.event.ref }} > pr-info/ref.txt
echo -Dsonar.branch.name=${{ github.ref_name }} > pr-info/head-branch-arg.txt
- uses: actions/upload-artifact@v3
with:
Expand Down
1 change: 1 addition & 0 deletions clients/vscode-hlasmplugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#### Changed
- Macro label is the preferred go to definition target unless the request is made from the label itself
- Library contents are now shared between processor groups

## [1.5.0](https://github.com/eclipse/che-che4z-lsp-for-hlasm/compare/1.4.0...1.5.0) (2022-11-02)

Expand Down
6 changes: 2 additions & 4 deletions parser_library/src/context/source_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "copy_member.h"
#include "processing/processing_format.h"
#include "source_snapshot.h"
#include "utils/general_hashers.h"

namespace hlasm_plugin::parser_library::context {

Expand Down Expand Up @@ -103,11 +104,8 @@ class processing_frame_tree
size_t operator()(const processing_frame_node& n) const
{
constexpr auto hash = []<typename... T>(const T&... v) {
constexpr auto hash_combine = [](size_t old, size_t next) {
return old ^ (next + 0x9e3779b9 + (old << 6) + (old >> 2));
};
size_t result = 0;
((result = hash_combine(result, std::hash<T>()(v))), ...);
((result = utils::hashers::hash_combine(result, std::hash<T>()(v))), ...);
return result;
};
return hash(n.m_parent, n.frame.member_name, n.frame.resource_loc, n.frame.pos.column, n.frame.pos.line);
Expand Down
2 changes: 2 additions & 0 deletions parser_library/src/expressions/data_definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
#include "mach_expr_term.h"
#include "mach_expr_visitor.h"
#include "semantics/collector.h"
#include "utils/general_hashers.h"
#include "utils/similar.h"

namespace hlasm_plugin::parser_library::expressions {
using utils::hashers::hash_combine;

constexpr char V_type = 'V';

Expand Down
2 changes: 2 additions & 0 deletions parser_library/src/expressions/mach_expr_term.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
#include "context/ordinary_assembly/symbol_value.h"
#include "ebcdic_encoding.h"
#include "mach_expr_visitor.h"
#include "utils/general_hashers.h"
#include "utils/similar.h"

namespace hlasm_plugin::parser_library::expressions {
using utils::hashers::hash_combine;
//*********** mach_expr_constant ************

bool mach_expr_constant::do_is_similar(const mach_expression& expr) const
Expand Down
5 changes: 0 additions & 5 deletions parser_library/src/expressions/mach_expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ class mach_expression : public context::resolvable
range expr_range_;
};

inline size_t hash_combine(std::size_t old, std::size_t next)
{
return old ^ (next + 0x9e3779b9 + (old << 6) + (old >> 2));
}

} // namespace hlasm_plugin::parser_library::expressions

#endif
2 changes: 2 additions & 0 deletions parser_library/src/expressions/mach_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
#include <cassert>

#include "context/ordinary_assembly/symbol_value.h"
#include "utils/general_hashers.h"
#include "utils/similar.h"

namespace hlasm_plugin::parser_library::expressions {
using utils::hashers::hash_combine;

template<typename T>
bool mach_expr_binary<T>::do_is_similar(const mach_expression& expr) const
Expand Down
3 changes: 3 additions & 0 deletions parser_library/src/expressions/nominal_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

#include <unordered_set>

#include "utils/general_hashers.h"
#include "utils/similar.h"

using namespace hlasm_plugin::parser_library::expressions;
using namespace hlasm_plugin::parser_library::context;

using hlasm_plugin::utils::hashers::hash_combine;

nominal_value_string* nominal_value_t::access_string() { return dynamic_cast<nominal_value_string*>(this); }

nominal_value_exprs* nominal_value_t::access_exprs() { return dynamic_cast<nominal_value_exprs*>(this); }
Expand Down
21 changes: 21 additions & 0 deletions parser_library/src/workspaces/library_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define HLASMPLUGIN_PARSERLIBRARY_LOCAL_LIBRARY_H

#include <atomic>
#include <compare>
#include <memory>
#include <string>
#include <string_view>
Expand All @@ -37,6 +38,26 @@ struct library_local_options
std::vector<std::string> extensions;
bool extensions_from_deprecated_source = false;
bool optional_library = false;

#ifdef __cpp_lib_three_way_comparison
auto operator<=>(const library_local_options&) const = default;
#else
// libc++ (not even in main!!!)
bool operator<(const library_local_options& o) const
{
if (extensions < o.extensions)
return true;
if (extensions > o.extensions)
return false;
if (extensions_from_deprecated_source < o.extensions_from_deprecated_source)
return true;
if (extensions_from_deprecated_source > o.extensions_from_deprecated_source)
return false;
if (optional_library < o.optional_library)
return true;
return false;
}
#endif
};

// library holds absolute path to a directory and finds macro files in it
Expand Down
4 changes: 3 additions & 1 deletion parser_library/src/workspaces/processor_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ void processor_group::generate_suggestions(bool force)
}
}

void processor_group::invalidate_suggestions() { m_suggestions.reset(); }

std::vector<std::pair<std::string, size_t>> processor_group::suggest(std::string_view opcode, bool extended)
{
generate_suggestions(false);
Expand Down Expand Up @@ -125,7 +127,7 @@ void processor_group::collect_diags() const
}
}

void processor_group::add_library(std::unique_ptr<library> library)
void processor_group::add_library(std::shared_ptr<library> library)
{
const auto& lib = m_libs.emplace_back(std::move(library));
m_refresh_prefix.emplace(lib->refresh_url_prefix());
Expand Down
3 changes: 2 additions & 1 deletion parser_library/src/workspaces/processor_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class processor_group : public diagnosable_impl

void collect_diags() const override;

void add_library(std::unique_ptr<library> library);
void add_library(std::shared_ptr<library> library);

const std::string& name() const { return m_pg_name; }

Expand All @@ -56,6 +56,7 @@ class processor_group : public diagnosable_impl
const std::vector<preprocessor_options>& preprocessors() const { return m_prep_opts; }

void generate_suggestions(bool force = true);
void invalidate_suggestions();

std::vector<std::pair<std::string, size_t>> suggest(std::string_view s, bool extended);

Expand Down
77 changes: 64 additions & 13 deletions parser_library/src/workspaces/workspace_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "workspace_configuration.h"

#include <charconv>
#include <compare>
#include <tuple>

#include "file_manager.h"
#include "library_local.h"
Expand Down Expand Up @@ -254,6 +256,37 @@ bool workspace_configuration::is_configuration_file(const utils::resource::resou
{
return is_config_file(file) || is_b4g_config_file(file);
}

template<typename T>
inline bool operator<(const std::pair<utils::resource::resource_location, library_options>& l,
const std::tuple<const utils::resource::resource_location&, const T&>& r) noexcept
{
const auto& [lx, ly] = l;
return std::tie(lx, ly) < r;
}

template<typename T>
inline bool operator<(const std::tuple<const utils::resource::resource_location&, const T&>& l,
const std::pair<utils::resource::resource_location, library_options>& r) noexcept
{
const auto& [rx, ry] = r;
return l < std::tie(rx, ry);
}

std::shared_ptr<library> workspace_configuration::get_local_library(
const utils::resource::resource_location& url, const library_local_options& opts)
{
if (auto it = m_libraries.find(std::tie(url, opts)); it != m_libraries.end())
{
it->second.second = true;
return it->second.first;
}

auto result = std::make_shared<library_local>(m_file_manager, url, opts, m_proc_grps_loc);
m_libraries.try_emplace(std::make_pair(url, library_options(opts)), result, true);
return result;
}

void workspace_configuration::process_processor_group(const config::processor_group& pg,
std::span<const std::string> fallback_macro_extensions,
std::span<const std::string> always_recognize,
Expand Down Expand Up @@ -281,8 +314,7 @@ void workspace_configuration::process_processor_group(const config::processor_gr
rl.join(""); // Ensure that this is a directory

if (auto first_wild_card = rl.get_uri().find_first_of("*?"); first_wild_card == std::string::npos)
prc_grp.add_library(std::make_unique<library_local>(
m_file_manager, std::move(rl), std::move(lib_local_opts), m_proc_grps_loc));
prc_grp.add_library(get_local_library(rl, lib_local_opts));
else
find_and_add_libs(utils::resource::resource_location(
rl.get_uri().substr(0, rl.get_uri().find_last_of("/", first_wild_card) + 1)),
Expand All @@ -294,6 +326,22 @@ void workspace_configuration::process_processor_group(const config::processor_gr
m_proc_grps.try_emplace(std::make_pair(prc_grp.name(), alternative_root), std::move(prc_grp));
}

void workspace_configuration::process_processor_group_and_cleanup_libraries(
std::span<const config::processor_group> pgs,
std::span<const std::string> fallback_macro_extensions,
std::span<const std::string> always_recognize,
const utils::resource::resource_location& alternative_root,
std::vector<diagnostic_s>& diags)
{
for (auto& [_, l] : m_libraries)
l.second = false; // mark

for (const auto& pg : pgs)
process_processor_group(pg, fallback_macro_extensions, always_recognize, alternative_root, diags);

std::erase_if(m_libraries, [](const auto& kv) { return !kv.second.second; }); // sweep
}

bool workspace_configuration::process_program(const config::program_mapping& pgm, std::vector<diagnostic_s>& diags)
{
const auto key = std::make_pair(pgm.pgroup, utils::resource::resource_location());
Expand Down Expand Up @@ -348,12 +396,11 @@ parse_config_file_result workspace_configuration::load_and_process_config(std::v
file_ptr pgm_conf_file;
const auto pgm_conf_loaded = load_pgm_config(pgm_config, pgm_conf_file, utilized_settings_values, diags);

// process processor groups
for (const auto& pg : proc_groups.pgroups)
{
process_processor_group(
pg, proc_groups.macro_extensions, pgm_config.always_recognize, utils::resource::resource_location(), diags);
}
process_processor_group_and_cleanup_libraries(proc_groups.pgroups,
proc_groups.macro_extensions,
pgm_config.always_recognize,
utils::resource::resource_location(),
diags);

if (pgm_conf_loaded != parse_config_file_result::parsed)
{
Expand Down Expand Up @@ -502,8 +549,8 @@ parse_config_file_result workspace_configuration::parse_b4g_config_file(
return parse_config_file_result::error;
}

for (const auto& pg_def : m_proc_grps_source.pgroups)
process_processor_group(pg_def, m_proc_grps_source.macro_extensions, {}, alternative_root, conf.diags);
process_processor_group_and_cleanup_libraries(
m_proc_grps_source.pgroups, m_proc_grps_source.macro_extensions, {}, alternative_root, conf.diags);

for (const auto& [name, details] : conf.config.value().files)
{
Expand Down Expand Up @@ -589,7 +636,7 @@ void workspace_configuration::find_and_add_libs(const utils::resource::resource_
continue;

if (std::regex_match(dir.get_uri(), path_validator))
prc_grp.add_library(std::make_unique<library_local>(m_file_manager, dir, opts, m_proc_grps_loc));
prc_grp.add_library(get_local_library(dir, opts));

auto [subdir_list, return_code] = m_file_manager.list_directory_subdirs_and_symlinks(dir);
if (return_code != utils::path::list_directory_rc::done)
Expand Down Expand Up @@ -648,16 +695,20 @@ parse_config_file_result workspace_configuration::parse_configuration_file(
bool workspace_configuration::refresh_libraries(const std::vector<utils::resource::resource_location>& file_locations)
{
bool refreshed = false;

std::unordered_set<const library*> refreshed_libs;
for (auto& [_, proc_grp] : m_proc_grps)
{
if (!proc_grp.refresh_needed(file_locations))
continue;
refreshed = true;
for (auto& lib : proc_grp.libraries())
for (const auto& lib : proc_grp.libraries())
{
if (!refreshed_libs.emplace(std::to_address(lib)).second)
continue;
lib->refresh();
}
proc_grp.generate_suggestions();
proc_grp.invalidate_suggestions();
}
return refreshed;
}
Expand Down
Loading

0 comments on commit 25dfa69

Please sign in to comment.