Skip to content

Removal of import std#19

Merged
JoltedJon merged 7 commits into
Redot-Engine:masterfrom
OldDev78:no-more-import-std
May 12, 2026
Merged

Removal of import std#19
JoltedJon merged 7 commits into
Redot-Engine:masterfrom
OldDev78:no-more-import-std

Conversation

@OldDev78
Copy link
Copy Markdown
Contributor

@OldDev78 OldDev78 commented May 7, 2026

Remove import std; and use STL headers in global module fragment instead.

Summary by CodeRabbit

  • Chores
    • Updated build and preset configuration to streamline language standards, module scanning, and linker/IPO behavior; set third‑party libraries to static builds.
  • Tests
    • Migrated unit tests to doctest style for clearer assertions and test structure.
  • Improvements
    • Refined core math and definitions: added precise numeric constants, removed an obsolete constant, and adjusted module/header provisioning without changing public APIs.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b2ed9026-074f-4bef-8a1e-ed35684247e3

📥 Commits

Reviewing files that changed from the base of the PR and between c720eae and 693c398.

📒 Files selected for processing (3)
  • engine/native/core/definitions/definitions.cppm
  • engine/native/core/math/math.cppm
  • engine/native/core/math/vector4.cppm
🚧 Files skipped from review as they are similar to previous changes (1)
  • engine/native/core/definitions/definitions.cppm

📝 Walkthrough

Walkthrough

Convert C++ module units to global fragments with explicit standard headers, migrate tests from Boost.UT to doctest, update math constants/use of PI, and adjust CMake presets, compiler flags, third‑party BGFX static settings, and PIC handling.

Changes

C++ Module Refactoring & Test Framework Migration

Layer / File(s) Summary
Build Configuration & CMake Flags
CMakeLists.txt, CMakePresets.json, cmake/Compiler.cmake
Remove experimental C++ import/module flags and Clang -stdlib=libc++; add explicit C standard and CMAKE_CXX_SCAN_FOR_MODULES.
Third‑party & Core CMake
engine/native/CMakeLists.txt, engine/native/thirdparty/CMakeLists.txt, engine/native/core/CMakeLists.txt
Mark thirdparty as SYSTEM, set BGFX to static via cache variables, and pass PIC into add_modules_library(definitions).
CMake Modules & Test Wiring
cmake/Modules.cmake
Add DOCTEST_INCLUDE_DIR, comment out Boost.UT bootstrap, accept PIC in add_modules_library, stop setting global CXX_SCAN_FOR_MODULES/CXX_EXTENSIONS, set POSITION_INDEPENDENT_CODE when PIC provided, and update test targets to include doctest and link only ${LIB_TARGET}.
Module Fragment Conversion
engine/native/core/definitions/*.cppm, engine/native/core/math/*.cppm
Introduce module; global fragments and explicit <...> includes; remove import std;; qualify integer types with std:: where changed.
Definitions
engine/native/core/definitions/definitions.cppm
Remove exported constexpr int MAX_RECURSION.
Math Constants
engine/native/core/math/constants.cppm
Use std::numbers constants (e.g., SQRT13 = std::numbers::inv_sqrt3_v<double>) and add UINT32_MAX_D / UINT32_MAX_F.
Math Implementation
engine/native/core/math/math.cppm
Move standard includes into module fragment and use module PI for deg/rad conversions; other function signatures unchanged.
Vector Implementation
engine/native/core/math/vector4.cppm
Add <cmath> and <type_traits> to module fragment to support std::sqrt and std::is_standard_layout_v; implementation unchanged.
Tests / Test Implementation
engine/native/core/math/math.test.cpp
Migrate tests from Boost.UT suite/expect style to doctest TEST_CASE/REQUIRE style and update references to module constants.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Redot-Engine/DraconicEngine#12: Modifies third-party/bgfx integration and CMake submodule handling, related to third-party and engine/native CMake changes.

Suggested reviewers

  • mcdubhghlas
  • Arctis-Fireblight

Poem

A rabbit hops through modules bright,
From import std to headers light,
Tests now skip Boost and run with glee,
CMake trimmed, constants tidy as can be —
A tiny hop, a cleaner tree. 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Removal of import std' is vague and generic, using non-descriptive phrasing that doesn't clearly convey the main technical objective or scope of the changes. Consider a more specific title such as 'Replace import std with explicit STL headers in global module fragments' to better reflect the comprehensive refactoring across multiple modules and build configuration changes.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@OldDev78 OldDev78 marked this pull request as ready for review May 8, 2026 23:35
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
engine/native/core/math/constants.cppm (1)

28-29: ⚡ Quick win

UINT32_MAX_D/UINT32_MAX_F are reciprocals, not max values — rename to avoid confusion.

Both constants hold 1.0 / std::numeric_limits<uint32_t>::max() ≈ 2.33×10⁻¹⁰. The name UINT32_MAX_D is a homonym for the C macro UINT32_MAX (4294967295), so any caller reading the name without checking the definition may silently use it as if it holds the max value instead of its reciprocal.

♻️ Suggested rename
-    constexpr double UINT32_MAX_D = 1. / std::numeric_limits<uint32_t>::max();
-    constexpr float  UINT32_MAX_F = 1.f / std::numeric_limits<uint32_t>::max();
+    constexpr double INV_UINT32_MAX_D = 1. / std::numeric_limits<uint32_t>::max();
+    constexpr float  INV_UINT32_MAX_F = 1.f / std::numeric_limits<uint32_t>::max();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@engine/native/core/math/constants.cppm` around lines 28 - 29, The constants
UINT32_MAX_D and UINT32_MAX_F are actually the reciprocal of the uint32 max (1.0
/ max) and should be renamed to avoid confusion; rename them to a clearer
identifier such as UINT32_INV_MAX_D and UINT32_INV_MAX_F (or
UINT32_RECIPROCAL_MAX_D/F) in constants.cppm and update every usage site to the
new names (search for UINT32_MAX_D and UINT32_MAX_F), keeping the same types and
values and updating any comments/docstrings to match the new meaning so callers
no longer mistake them for the maximum value.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@engine/native/core/definitions/definitions.cppm`:
- Around line 1-3: The code uses std::is_arithmetic_v, std::is_trivial_v and
std::false_type but only includes <concepts>; add the missing <type_traits>
include at the top of the module unit so these type-trait identifiers are
declared (i.e., add the `#include` for <type_traits> alongside the existing
includes in the module preamble to ensure std::is_arithmetic_v,
std::is_trivial_v and std::false_type are available).

In `@engine/native/core/math/math.test.cpp`:
- Around line 7-9: The test calls draco::math::pow(2., .5) and compares it with
draco::math::SQRT2 using REQUIRE(result == expected), which can fail due to pow
not being correctly rounded; change the test to compute the left-hand side with
std::sqrt(2.0) (or draco::math::sqrt if you provide a correctly-rounded wrapper)
instead of draco::math::pow, or keep pow but replace the exact equality check
with a tolerance check (e.g., use Catch's Approx) comparing result to
std::numbers::sqrt2_v<double> or draco::math::SQRT2 to avoid 1-ULP spurious
failures.

In `@engine/native/core/math/vector4.cppm`:
- Line 99: The commented-out static_assert removed the only compile-time
guarantee that Vector4 is standard-layout, leaving the non-consteval operator[]
(which uses (&x)[i]) undefined behavior if the type changes; restore the
static_assert for std::is_standard_layout_v<Vector4> to re-establish the
invariant, or alternatively change the non-consteval operator[] implementation
in Vector4 to mirror the consteval path by using explicit member selection (x,
y, z, w) or a switch/array of pointers to members instead of (&x)[i], and add a
brief comment documenting the chosen approach.

---

Nitpick comments:
In `@engine/native/core/math/constants.cppm`:
- Around line 28-29: The constants UINT32_MAX_D and UINT32_MAX_F are actually
the reciprocal of the uint32 max (1.0 / max) and should be renamed to avoid
confusion; rename them to a clearer identifier such as UINT32_INV_MAX_D and
UINT32_INV_MAX_F (or UINT32_RECIPROCAL_MAX_D/F) in constants.cppm and update
every usage site to the new names (search for UINT32_MAX_D and UINT32_MAX_F),
keeping the same types and values and updating any comments/docstrings to match
the new meaning so callers no longer mistake them for the maximum value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8561d66f-d6f4-4132-b860-0a29c6e7afb5

📥 Commits

Reviewing files that changed from the base of the PR and between 17595c0 and d0e39e1.

📒 Files selected for processing (13)
  • CMakeLists.txt
  • CMakePresets.json
  • cmake/Compiler.cmake
  • cmake/Modules.cmake
  • engine/native/CMakeLists.txt
  • engine/native/core/definitions/definitions.cppm
  • engine/native/core/definitions/version.cppm
  • engine/native/core/math/constants.cppm
  • engine/native/core/math/math.cppm
  • engine/native/core/math/math.test.cpp
  • engine/native/core/math/vector4.cppm
  • engine/native/thirdparty/CMakeLists.txt
  • engine/native/thirdparty/doctest/doctest.h
💤 Files with no reviewable changes (2)
  • CMakeLists.txt
  • cmake/Compiler.cmake

Comment thread engine/native/core/definitions/definitions.cppm Outdated
Comment on lines +7 to +9
double result = draco::math::pow(2., .5);
constexpr double expected = draco::math::SQRT2;
REQUIRE(result == expected);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

REQUIRE(result == expected) may be unreliable — std::pow(2., 0.5) is not guaranteed to match sqrt2_v<double> exactly.

std::numbers::sqrt2_v<double> is the correctly-rounded IEEE 754 double approximation of √2. std::pow(2., 0.5) goes through the general pow implementation, which — unlike sqrt — is not required by IEEE 754 or the C++ standard to be correctly rounded. On some libm implementations, pow(2., 0.5) may return a value that is 1 ULP off from sqrt2_v<double>, causing this test to fail spuriously.

Use std::sqrt(2.) (which is correctly rounded) or a tolerance-based check:

🐛 Proposed fix
 TEST_CASE("pow") {
-    double result = draco::math::pow(2., .5);
-    constexpr double expected = draco::math::SQRT2;
-    REQUIRE(result == expected);
+    double result = draco::math::pow(2., .5);
+    constexpr double expected = draco::math::SQRT2;
+    // pow is not required to be correctly-rounded; allow 1 ULP of slack
+    REQUIRE(result == doctest::Approx(expected).epsilon(1e-15));
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
double result = draco::math::pow(2., .5);
constexpr double expected = draco::math::SQRT2;
REQUIRE(result == expected);
double result = draco::math::pow(2., .5);
constexpr double expected = draco::math::SQRT2;
// pow is not required to be correctly-rounded; allow 1 ULP of slack
REQUIRE(result == doctest::Approx(expected).epsilon(1e-15));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@engine/native/core/math/math.test.cpp` around lines 7 - 9, The test calls
draco::math::pow(2., .5) and compares it with draco::math::SQRT2 using
REQUIRE(result == expected), which can fail due to pow not being correctly
rounded; change the test to compute the left-hand side with std::sqrt(2.0) (or
draco::math::sqrt if you provide a correctly-rounded wrapper) instead of
draco::math::pow, or keep pow but replace the exact equality check with a
tolerance check (e.g., use Catch's Approx) comparing result to
std::numbers::sqrt2_v<double> or draco::math::SQRT2 to avoid 1-ULP spurious
failures.

Comment thread engine/native/core/math/vector4.cppm Outdated
JoltedJon
JoltedJon previously approved these changes May 8, 2026
Copy link
Copy Markdown
Contributor

@JoltedJon JoltedJon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a code review standpoint looks good to me. Not at computer so can't compile it right now

@OldDev78
Copy link
Copy Markdown
Contributor Author

OldDev78 commented May 9, 2026

From a code review standpoint looks good to me. Not at computer so can't compile it right now

Please test with different clang versions (>18) if possible.

Next, I'll specify clang as the compiler.

Copy link
Copy Markdown
Contributor

@JoltedJon JoltedJon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with Clang 22.1.5 works well

Copy link
Copy Markdown
Contributor

@AR-DEV-1 AR-DEV-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with Clang 20 & works as expected

@JoltedJon JoltedJon merged commit f91ca0a into Redot-Engine:master May 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants