MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / findMissingRequiredExport

Function findMissingRequiredExport

lib/validator/component_validator.cpp:128–157  ·  view source on GitHub ↗

Returns the first export in `RequiredIT` missing from the instance at `ProvidedInstIdx`, or whose stored SortType doesn't match the required sort kind. nullopt ⇒ Provided is a sort-kind subtype of RequiredIT. Only the sort kind is compared; deep structural subtype between the required externdesc and the provided export's inferred type is not yet implemented.

Source from the content-addressed store, hash-verified

126// required externdesc and the provided export's inferred type is not yet
127// implemented.
128std::optional<std::string>
129findMissingRequiredExport(const ComponentContext &Ctx, uint32_t ProvidedInstIdx,
130 const AST::Component::InstanceType &RequiredIT) {
131 const auto &Exports = Ctx.getInstance(ProvidedInstIdx);
132 for (const auto &Decl : RequiredIT.getDecl()) {
133 if (!Decl.isExportDecl()) {
134 continue;
135 }
136 const auto &Exp = Decl.getExport();
137 auto It = Exports.find(std::string(Exp.getName()));
138 if (It == Exports.end()) {
139 return std::string(Exp.getName());
140 }
141 auto RequiredST = descTypeToSortType(Exp.getExternDesc().getDescType());
142 if (!RequiredST.has_value()) {
143 // `(core module)` required-exports can't be compared against
144 // InstanceExport::ST (component-side only). Skip symmetrically with
145 // populateInstanceFromType; will be revisited when InstanceExport
146 // gains a core-sort variant.
147 spdlog::debug(" findMissingRequiredExport: skipping `(core module)` "
148 "required-export '{}'"sv,
149 Exp.getName());
150 continue;
151 }
152 if (It->second.ST != *RequiredST) {
153 return std::string(Exp.getName());
154 }
155 }
156 return std::nullopt;
157}
158
159// Resolve a type index in `Comp`'s own type index space to an InstanceType.
160// Returns nullptr when the index does not refer to an inline InstanceType

Callers 1

validateMethod · 0.85

Calls 10

descTypeToSortTypeFunction · 0.85
debugFunction · 0.85
isExportDeclMethod · 0.80
getDescTypeMethod · 0.80
getInstanceMethod · 0.45
getDeclMethod · 0.45
findMethod · 0.45
getNameMethod · 0.45
endMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected