42#ifndef COMPILER_MODULE_LINKER_H
43#define COMPILER_MODULE_LINKER_H
108 return "Missing_Metadata";
110 return "Duplicate_Value_Export";
112 return "Duplicate_Type_Export";
118namespace Compiler_Module_Linker_Detail {
120 const std::string &name)
noexcept
122 for (
size_t i = 0; i <
metadata.size(); ++i)
123 if (
metadata.access(i).name == name)
125 return static_cast<size_t>(-1);
151 linkage.module_index = module_index;
158 result.
valid =
false;
174 linkage.visible_exports.append(
175 {item.kind, item.name, module_index,
self_metadata.name, item.declaration_span,
false});
178 for (
size_t i = 0; i <
descriptor.imports.size(); ++i)
185 return static_cast<size_t>(-1);
187 if (
dep_index ==
static_cast<size_t>(-1))
195 result.
valid =
false;
207 for (
size_t j = 0; j <
dep_metadata.exports.size(); ++j)
210 linkage.visible_exports.append(
219 for (
size_t i = 0; i <
linkage.visible_exports.size(); ++i)
222 const std::string key = std::to_string(
231 if (prev.source_module_name ==
exp.source_module_name
and prev.imported ==
exp.imported)
233 result.
valid =
false;
240 prev.source_module_name,
241 exp.source_module_name,
242 exp.declaration_span});
255 std::ostringstream
out;
256 out <<
"ModuleLinkage\n";
257 for (
size_t i = 0; i < result.
modules.size(); ++i)
259 const auto &
module = result.modules.access(i);
260 out <<
" Module(" <<
module.module_name << ") order=" << module.order_index << '\n';
261 for (
size_t j = 0; j <
module.visible_exports.size(); ++j)
263 const auto &item =
module.visible_exports.access(j);
265 <<
")) from " << item.source_module_name << (item.imported ?
" imported" :
" local")
273 for (
size_t i = 0; i < result.
issues.size(); ++i)
277 <<
" module=" <<
issue.module_name;
279 out <<
" export=" <<
issue.export_name;
280 if (
not issue.first_provider_module.empty())
281 out <<
" first=" <<
issue.first_provider_module;
282 if (
not issue.second_provider_module.empty())
283 out <<
" second=" <<
issue.second_provider_module;
Reusable source-name module dependency resolution helpers.
size_t size_t int32_t * out
size_t size() const noexcept
Return the current dimension of array.
T & access(const size_t i) const noexcept
Fast access without checking allocation and bound_min_clock checking.
Generic key-value map implemented on top of a binary search tree.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_exp_function > > exp(const __gmp_expr< T, U > &expr)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
int export_namespace_bucket(const Compiler_Module_Export_Kind kind) noexcept
size_t find_metadata_index(const DynArray< Compiler_Module_Metadata > &metadata, const std::string &name) noexcept
Main namespace for Aleph-w library functions.
Compiler_Module_Export_Kind
Export kinds currently modeled by reusable module metadata.
const char * compiler_module_linkage_issue_name(const Compiler_Module_Linkage_Issue_Kind kind) noexcept
Returns the stable debug name for one linkage issue kind.
and
Check uniqueness with explicit hash + equality functors.
Compiler_Module_Linkage_Issue_Kind
Structural issues emitted while linking module surfaces.
const char * compiler_module_export_kind_name(const Compiler_Module_Export_Kind kind) noexcept
Returns the stable debug name for one module-export kind.
Compiler_Module_Link_Result compiler_link_module_surfaces(const DynArray< Compiler_Module_Descriptor > &descriptors, const DynArray< Compiler_Module_Metadata > &metadata, const DynArray< size_t > &order)
Links direct-import module surfaces into visible top-level views.
std::string compiler_render_module_linkage(const Compiler_Module_Link_Result &result)
Renders one deterministic text artifact for linked module surfaces.
Link result over module descriptors and module metadata.
DynArray< Compiler_Module_Linkage_Issue > issues
DynArray< Compiler_Module_Linkage > modules
One structural issue reported by the reusable module linker.
std::string first_provider_module
Compiler_Module_Linkage_Issue_Kind kind
std::string second_provider_module
One linked module view under direct-import surface rules.
DynArray< size_t > direct_import_indexes
DynArray< Compiler_Module_Visible_Export > visible_exports
One visible top-level declaration in a linked module surface.
Source_Span declaration_span
std::string source_module_name
size_t source_module_index
Index in the descriptor/module array.
bool imported
false for local exports, true for direct-imported exports.
Compiler_Module_Export_Kind kind
Half-open byte range inside a source file.
Dynamic key-value map based on balanced binary search trees.