Skip to content

Commit

Permalink
A bug in the sourcerer and name lookup chicanery
Browse files Browse the repository at this point in the history
  • Loading branch information
eggrobin committed Dec 30, 2024
1 parent 6c958ef commit ca5debf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
4 changes: 3 additions & 1 deletion functions/core_math_accuracy_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "core-math/cos.h"
#include "core-math/sin.h"
#include "functions/multiprecision.hpp"
#include "glog/logging.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
Expand All @@ -13,9 +14,10 @@

namespace principia {
namespace functions {
namespace _multiprecision {
namespace _core_math_accuracy_test {

using namespace boost::multiprecision;
using namespace principia::functions::_multiprecision;
using namespace principia::testing_utilities::_approximate_quantity;
using namespace principia::testing_utilities::_is_near;

Expand Down
26 changes: 17 additions & 9 deletions functions/sin_cos_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,28 @@
#include "glog/logging.h"
#include "gtest/gtest.h"
#include "numerics/next.hpp"
#include "quantities/numbers.hpp"
#include "testing_utilities/almost_equals.hpp"
#include "numerics/sin_cos.hpp"

Check warning on line 13 in functions/sin_cos_test.cpp

View workflow job for this annotation

GitHub Actions / check-cpp

build/include

"numerics/sin_cos.hpp" already included at D:\a\Principia\Principia\functions\sin_cos_test.cpp:1
#include "quantities/numbers.hpp" // 🧙 For π.
#include "testing_utilities/almost_equals.hpp"

Check warning on line 15 in functions/sin_cos_test.cpp

View workflow job for this annotation

GitHub Actions / check-cpp

build/include

"testing_utilities/almost_equals.hpp" already included at D:\a\Principia\Principia\functions\sin_cos_test.cpp:12

// This test lives in `functions` to avoid pulling `boost` into `numerics`.
// It uses neither the `functions` nor the `numerics` namespace so that the Sin
// and Cos from both (`principia::functions::_multiprecision` and
// `principia::numerics::_sin_cos`) are made visible by the using directives
// below.

namespace principia {
namespace numerics {
namespace _sin_cos {
namespace numerics_multiprecision_tests {

using namespace boost::multiprecision;
using namespace principia::functions::_multiprecision;
using namespace principia::numerics::_next;
using namespace principia::numerics::_sin_cos;
using namespace principia::testing_utilities::_almost_equals;

namespace {

class SinCosTest : public ::testing::Test {};

TEST_F(SinCosTest, Random) {
Expand All @@ -44,8 +54,7 @@ TEST_F(SinCosTest, Random) {
double const principia_argument = uniformly_at(random);
auto const boost_argument = cpp_rational(principia_argument);
{
auto const boost_sin =
functions::_multiprecision::Sin(boost_argument);
auto const boost_sin = Sin(boost_argument);
double const principia_sin = Sin(principia_argument);
auto const sin_error =
abs(boost_sin - static_cast<cpp_bin_float_50>(principia_sin));
Expand All @@ -61,8 +70,7 @@ TEST_F(SinCosTest, Random) {
}
}
{
auto const boost_cos =
functions::_multiprecision::Cos(boost_argument);
auto const boost_cos = Cos(boost_argument);
double const principia_cos = Cos(principia_argument);
auto const cos_error =
abs(boost_cos - static_cast<cpp_bin_float_50>(principia_cos));
Expand Down Expand Up @@ -143,6 +151,6 @@ TEST_F(SinCosTest, HardReduction) {
AlmostEquals(-4.687165924254627611122582801963884e-19, 0));
}

} // namespace _sin_cos
} // namespace numerics
} // namespace
} // namespace numerics_multiprecision_tests
} // namespace principia
1 change: 1 addition & 0 deletions geometry/serialization_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "geometry/grassmann.hpp"
#include "geometry/point.hpp"
#include "quantities/quantities.hpp"
#include "quantities/serialization.hpp"

namespace principia {
namespace geometry {
Expand Down
22 changes: 9 additions & 13 deletions sourcerer/include_what_you_using.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ private static void FixIncludes(Parser.File file,
foreach (string ns in using_namespaces) {
var segments = ns.Split("::", StringSplitOptions.RemoveEmptyEntries);
var include_path = Array.Empty<string>();
bool skip = false;
if (ns == file.file_namespace_full_name) {
// Don't add an include for our own header. This matters for tests.
continue;
}
foreach (string segment in segments) {
if (segment == "principia") {
continue;
Expand All @@ -195,24 +198,17 @@ private static void FixIncludes(Parser.File file,
segment == "std") {
// We have using directives for namespaces in absl or std, don't emit
// an include for them.
skip = true;
continue;
goto next_using_directive;
} else if (segment[0] == '_') {
// Don't add an include for our own header. This matters for tests.
if (segment == file.file_namespace_simple_name) {
skip = true;
} else {
string header_filename = Regex.Replace(segment, @"^_", "");
include_path = include_path.Append(header_filename).ToArray();
}
string header_filename = Regex.Replace(segment, @"^_", "");
include_path = include_path.Append(header_filename).ToArray();
break;
} else {
include_path = include_path.Append(segment).ToArray();
}
}
if (!skip) {
new_include_paths.Add(include_path);
}
new_include_paths.Add(include_path);
next_using_directive: {}
}

// Extract the includes.
Expand Down

0 comments on commit ca5debf

Please sign in to comment.