Dependent ADL in C++ modules receives memory leak and logic fixes.
Multiple fixes addressed a memory leak and logical errors in the dependent Argument-Dependent Lookup (ADL) implementation for C++ modules, improving memory eff…
This commit addresses several issues within the dependent Argument-Dependent Lookup (ADL) logic for C++ modules, including a memory leak and inaccuracies in early exit conditions. The memory leak fix significantly reduces peak memory usage when building the std module. Additionally, the corrected logic ensures that ADL processing only considers type-dependent calls and operator expressions, and rectifies a test for early exit when all arguments are type-dependent, leading to more efficient and correct module processing.
In Details
The add_dependent_adl_entities function within module.cc is part of the C++ module infrastructure responsible for constructing the dependency graph related to Argument-Dependent Lookup (ADL). This commit addresses a memory leak by ensuring that dep_adl_info::args is initialized to nullptr and allocated only when necessary, preventing premature memory allocation during early exits. Furthermore, the ADL logic is refined to accurately identify and process only type-dependent calls and operator expressions, leveraging early exit conditions to avoid unnecessary computation. An assertion is…
For Context
C++ modules are designed to improve build times and organization by pre-compiling code and defining clear module interfaces. Argument-Dependent Lookup (ADL) is a C++ language rule that affects how the compiler finds functions, especially when you're using objects from different namespaces. When dealing with modules, the compiler needs special mechanisms to handle ADL correctly across module boundaries, which it calls "dependent ADL." This set of changes fixes several bugs in that dependent ADL mechanism, which were causing problems like memory leaks and inefficient processing. Specifically, the compiler was sometimes allocating memory it didn't need or looking for functions in the wrong way. The fixes ensure that the compiler is more precise about when it allocates memory and when it processes these complex lookup rules, ultimately making the C++ module system more stable and efficient, especially when dealing with large libraries like the standard library.