From 60f302c46033118ee741c2ae93093a1c5c2a93f5 Mon Sep 17 00:00:00 2001 From: Matthew A Johnson Date: Fri, 15 Sep 2023 14:24:20 +0100 Subject: [PATCH 1/6] Removing extraneous semi-colon Signed-off-by: Matthew A Johnson --- include/trieste/pass.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/trieste/pass.h b/include/trieste/pass.h index a05dc707..5cbd5339 100644 --- a/include/trieste/pass.h +++ b/include/trieste/pass.h @@ -1,6 +1,7 @@ #pragma once #include "rewrite.h" + #include namespace trieste @@ -11,7 +12,7 @@ namespace trieste constexpr flag bottomup = 1 << 0; constexpr flag topdown = 1 << 1; constexpr flag once = 1 << 2; - }; + } class PassDef; using Pass = std::shared_ptr; @@ -234,7 +235,7 @@ namespace trieste add(root); while (!path.empty()) { - auto& [node,it] = path.back(); + auto& [node, it] = path.back(); if (it != node->end()) { Node curr = *it; From 7ea2d66b47e00db7d3397db82c80c17146cc7cc6 Mon Sep 17 00:00:00 2001 From: Matthew A Johnson Date: Fri, 15 Sep 2023 16:33:43 +0100 Subject: [PATCH 2/6] Removing use of contains Signed-off-by: Matthew A Johnson --- CMakeLists.txt | 30 ++++++++++++++++++++++-------- include/trieste/wf.h | 30 +++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cd6be64..3fd02e52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,24 @@ cmake_minimum_required(VERSION 3.14.0) project(trieste VERSION 1.0.0 LANGUAGES CXX) +# ############################################# +# Options +option(TRIESTE_BUILD_SAMPLES "Specifies whether to build the samples" ON) +option(TRIESTE_USE_CXX17 "Specifies whether to target the C++17 standard" OFF) + +set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) + +# ############################################# +# Dependencies + include(FetchContent) -set(CMAKE_CXX_STANDARD 20) +if(TRIESTE_USE_CXX17) + set(CMAKE_CXX_STANDARD 17) +else() + set(CMAKE_CXX_STANDARD 20) +endif() + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(SNMALLOC_BUILD_TESTING OFF CACHE INTERNAL "Turn off snmalloc tests") @@ -12,6 +27,7 @@ if (MSVC) else() set(SNMALLOC_STATIC_LIBRARY_PREFIX "") endif() +set(SNMALLOC_USE_CXX17 ${TRIESTE_USE_CXX17}) set(RE2_BUILD_TESTING OFF CACHE INTERNAL "Turn off RE2 tests") @@ -42,12 +58,6 @@ FetchContent_Declare( FetchContent_MakeAvailable(cli11) -# ############################################# -# Options -option(TRIESTE_BUILD_SAMPLES "Specifies whether to build the samples" ON) - -set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) - # ############################################# # Create target and set properties add_library(trieste INTERFACE) @@ -68,7 +78,11 @@ target_link_libraries(trieste CLI11::CLI11 ) -target_compile_features(trieste INTERFACE cxx_std_20) +if(TRIESTE_USE_CXX17) + target_compile_definitions(trieste INTERFACE cxx_std_17) +else() + target_compile_definitions(trieste INTERFACE cxx_std_20) +endif() if(MSVC) target_compile_options(trieste INTERFACE /W4 /WX /wd5030 /bigobj) diff --git a/include/trieste/wf.h b/include/trieste/wf.h index 15518ffd..95bca534 100644 --- a/include/trieste/wf.h +++ b/include/trieste/wf.h @@ -81,10 +81,26 @@ namespace trieste tokens.end(), std::back_inserter(offsets), [&](const Token& t) { - return 1.0 / - (1.0 + - (alpha * (depth - target_depth) * - token_terminal_distance.at(t))); + + if (token_terminal_distance.find(t) != token_terminal_distance.end()) + { + unsigned long distance = token_terminal_distance.at(t); + return 1.0 / + (1.0 + + (alpha * (depth - target_depth) * + distance)); + }else{ + std::ostringstream err; + err << "Token " << t.str() << " not found in token_terminal_distance map" << std::endl; + err << "{"; + std::string delim = ""; + for(auto const& [key, val] : token_terminal_distance){ + err << delim << key.str() << ":" << val; + delim = ", "; + } + err << "}" << std::endl; + throw std::runtime_error(err.str()); + } }); // compute the cumulative distribution of P(d | c, p) @@ -165,7 +181,7 @@ namespace trieste types.end(), static_cast(0), [&](std::size_t acc, auto& type) { - if (omit.contains(type)) + if (omit.find(type) != omit.end()) { return acc + max_distance; } @@ -523,12 +539,12 @@ namespace trieste std::size_t max_distance, const Token& token) const { - if (distance.contains(token)) + if (distance.find(token) != distance.end()) { return distance[token]; } - if (!shapes.contains(token)) + if (shapes.find(token) == shapes.end()) { distance[token] = 0; } From af81b38ea232adb1f3d0eccb95747db437f47e32 Mon Sep 17 00:00:00 2001 From: Matthew A Johnson Date: Fri, 15 Sep 2023 21:51:22 +0100 Subject: [PATCH 3/6] Fixing type error Signed-off-by: Matthew A Johnson --- include/trieste/wf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/trieste/wf.h b/include/trieste/wf.h index 95bca534..fb0d62bd 100644 --- a/include/trieste/wf.h +++ b/include/trieste/wf.h @@ -84,7 +84,7 @@ namespace trieste if (token_terminal_distance.find(t) != token_terminal_distance.end()) { - unsigned long distance = token_terminal_distance.at(t); + std::size_t distance = token_terminal_distance.at(t); return 1.0 / (1.0 + (alpha * (depth - target_depth) * From 081cdcf0ddef54d9d9a2fa297a12b98cbe5e134a Mon Sep 17 00:00:00 2001 From: Matthew A Johnson Date: Fri, 15 Sep 2023 22:02:48 +0100 Subject: [PATCH 4/6] Explicit cast for size_t Signed-off-by: Matthew A Johnson --- include/trieste/source.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/trieste/source.h b/include/trieste/source.h index 55d8bf9c..65b221eb 100644 --- a/include/trieste/source.h +++ b/include/trieste/source.h @@ -41,7 +41,7 @@ namespace trieste auto source = std::make_shared(); source->origin_ = file.string(); - source->contents.resize(size); + source->contents.resize(static_cast(size)); f.read(&source->contents[0], size); if (!f) From e3eb87efe303a42f925c5ab1cba4aa1953ba7107 Mon Sep 17 00:00:00 2001 From: Matthew A Johnson Date: Sat, 16 Sep 2023 21:13:24 +0100 Subject: [PATCH 5/6] Adding some additional CI Signed-off-by: Matthew A Johnson --- .github/workflows/buildtest.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/buildtest.yml b/.github/workflows/buildtest.yml index f8d2af56..8e2f322b 100644 --- a/.github/workflows/buildtest.yml +++ b/.github/workflows/buildtest.yml @@ -17,6 +17,10 @@ jobs: - platform: "ubuntu-latest" cmake-flags: "-G Ninja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang" dependencies: "sudo apt install ninja-build" + - platform: "ubuntu-latest" + cmake-flags: "-G Ninja" + dependencies: "sudo apt install ninja-build" + - cmake-flags: "-DTRIESTE_USE_CXX_17=ON" # Don't abort runners if a single one fails fail-fast: false From d1e9bd8372db719a04c35c6888ea825058f39e58 Mon Sep 17 00:00:00 2001 From: Matthew A Johnson Date: Sat, 16 Sep 2023 21:24:05 +0100 Subject: [PATCH 6/6] Trying out a different matrix Signed-off-by: Matthew A Johnson --- .github/workflows/buildtest.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/buildtest.yml b/.github/workflows/buildtest.yml index 8e2f322b..2cac3477 100644 --- a/.github/workflows/buildtest.yml +++ b/.github/workflows/buildtest.yml @@ -12,15 +12,17 @@ jobs: matrix: platform: [ "ubuntu-latest", "macos-latest", "windows-latest" ] build-type: [ "Release", "Debug" ] + standard: [ "", "-DTRIESTE_USE_CXX17=ON" ] + compiler: [ "", "-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang" ] include: - platform: "ubuntu-latest" - cmake-flags: "-G Ninja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang" + generator: "-G Ninja" dependencies: "sudo apt install ninja-build" - - platform: "ubuntu-latest" - cmake-flags: "-G Ninja" - dependencies: "sudo apt install ninja-build" - - cmake-flags: "-DTRIESTE_USE_CXX_17=ON" + - platform: "macos-latest" + compiler: "" + - platform: "windows-latest" + compiler: "" # Don't abort runners if a single one fails fail-fast: false @@ -34,7 +36,7 @@ jobs: run: ${{ matrix.dependencies }} - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build-type}} ${{matrix.cmake-flags}} + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build-type}} ${{matrix.generator}} ${{matrix.standard}} ${{matrix.compiler}} - name: Build run: cmake --build ${{github.workspace}}/build --config ${{matrix.build-type}}