sun::moon_bundling::LibraryCache

sun::moon_bundling::LibraryCache

class · Source (opens in a new tab)

class sun::moon_bundling::LibraryCache

Global cache for precompiled .moon bundles Thread-safe singleton for discovering and loading precompiled libraries.

Public Functions

addBundle

public · function · Source (opens in a new tab)

void sun::moon_bundling::LibraryCache::addBundle(const std::filesystem::path &bundlePath)

Add a specific .moon bundle file.

param

  • bundlePath: Path to a .moon file

addSearchPath

public · function · Source (opens in a new tab)

void sun::moon_bundling::LibraryCache::addSearchPath(const std::filesystem::path &path)

Add a directory to search for .moon files.

param

  • path: Directory containing .moon bundles

clear

public · function · Source (opens in a new tab)

void sun::moon_bundling::LibraryCache::clear()

Clear all cached data.

extractNativeArchives

public · function · Source (opens in a new tab)

std::vector< std::string > sun::moon_bundling::LibraryCache::extractNativeArchives(const std::set< std::string > &moduleKeys, const std::filesystem::path &destDir)

Extract the native static archives carried by the bundles providing these modules into destDir, as <archive set hash>/<file name> so two versions of one library never collide and the parent directory names the hash their symbols carry.

An archive carried by several bundles with identical contents is extracted once. return: extracted archive paths, in bundle then manifest order

findBundleForModule

public · function · Source (opens in a new tab)

MoonReader * sun::moon_bundling::LibraryCache::findBundleForModule(const std::string &moduleKey)

Find the bundle containing a module (for error reporting).

Related: MoonReader

getBitcodeId

public · function · Source (opens in a new tab)

std::string sun::moon_bundling::LibraryCache::getBitcodeId(const std::string &moduleKey)

Identity of the bitcode region backing a module; modules sharing a code image share it.

Empty if the module is unknown.

getMetadata

public · function · Source (opens in a new tab)

const moon::ModuleMetadata * sun::moon_bundling::LibraryCache::getMetadata(const std::string &moduleKey)

Get metadata for a module.

param

  • moduleKey: The module key (source hash)

return: Metadata, or nullptr if not found

getSearchPaths

public · function · Source (opens in a new tab)

const std::vector< std::filesystem::path > & sun::moon_bundling::LibraryCache::getSearchPaths() const

Get all search paths.

getTargetTriple

public · function · Source (opens in a new tab)

const std::string & sun::moon_bundling::LibraryCache::getTargetTriple() const

The compilation target set above (empty = host).

hasModule

public · function · Source (opens in a new tab)

bool sun::moon_bundling::LibraryCache::hasModule(const std::string &moduleKey)

Check if a precompiled module exists.

param

  • moduleKey: The module key (source hash)

initFromEnvironment

public · function · Source (opens in a new tab)

void sun::moon_bundling::LibraryCache::initFromEnvironment()

Initialize from environment Loads lib/ and build/ subdirectories for each SUN_PATH entry.

instance

public · function · static · Source (opens in a new tab)

LibraryCache & sun::moon_bundling::LibraryCache::instance()

Get the singleton instance.

Related: LibraryCache

invalidateBundle

public · function · Source (opens in a new tab)

void sun::moon_bundling::LibraryCache::invalidateBundle(const std::filesystem::path &bundlePath)

Forgets readers for a replaced bundle after its previous compilation ends.

Search paths and other explicitly registered bundles remain available.

isInitialized

public · function · Source (opens in a new tab)

bool sun::moon_bundling::LibraryCache::isInitialized() const

Check if initialized.

loadModule

public · function · Source (opens in a new tab)

std::unique_ptr< llvm::Module > sun::moon_bundling::LibraryCache::loadModule(const std::string &moduleKey, llvm::LLVMContext &context)

Load a module's LLVM bitcode.

param

  • moduleKey: The module key (source hash)

  • context: LLVM context to create module in

return: LLVM module, or nullptr if not found/failed

preloadAll

public · function · Source (opens in a new tab)

void sun::moon_bundling::LibraryCache::preloadAll()

Preload all bundles from search paths Call once at startup for fastest subsequent access.

setTargetTriple

public · function · Source (opens in a new tab)

void sun::moon_bundling::LibraryCache::setTargetTriple(const std::string &triple)

Set the compilation target.

When several discovered bundles claim the same module (e.g. the host build/stdlib.moon and the cross build/aarch64-linux-gnu/stdlib.moon), the one compiled for this target wins. Empty means the host.

Private Functions

LibraryCache

LibraryCache()=default

private · function · Source (opens in a new tab)

sun::moon_bundling::LibraryCache::LibraryCache()=default

Creates an instance with its default state.

LibraryCache(const LibraryCache &)=delete

private · function · Source (opens in a new tab)

sun::moon_bundling::LibraryCache::LibraryCache(const LibraryCache &)=delete

Disallows copying so the owned state cannot be duplicated.

Related: LibraryCache

discoverBundles

private · function · Source (opens in a new tab)

void sun::moon_bundling::LibraryCache::discoverBundles()

Discover .moon files in search paths.

operator=

private · function · Source (opens in a new tab)

LibraryCache & sun::moon_bundling::LibraryCache::operator=(const LibraryCache &)=delete

Disallows assignment so ownership and object identity cannot be duplicated.

Related: LibraryCache

selectBundle

private · function · Source (opens in a new tab)

MoonReader * sun::moon_bundling::LibraryCache::selectBundle(const std::vector< MoonReader * > &candidates) const

Pick among bundles claiming the same module.

Preference: matching the target's architecture outranks everything (the parser opened an arch-correct bundle, and the linker must agree with it); explicit addBundle() registration breaks ties among same-arch candidates. A wrong pick is still caught by the linker's triple check.

Related: MoonReader, addBundle()

Private Fields

bundles_

private · variable · Source (opens in a new tab)

std::vector<std::unique_ptr<MoonReader> > sun::moon_bundling::LibraryCache::bundles_

No documentation comment.

Related: MoonReader

discovered_

private · variable · Source (opens in a new tab)

bool sun::moon_bundling::LibraryCache::discovered_ = false

No documentation comment.

initialized_

private · variable · Source (opens in a new tab)

bool sun::moon_bundling::LibraryCache::initialized_ = false

No documentation comment.

moduleToBundle_

private · variable · Source (opens in a new tab)

std::unordered_map<std::string, std::vector<MoonReader*> > sun::moon_bundling::LibraryCache::moduleToBundle_

No documentation comment.

Related: MoonReader

mutex_

private · variable · Source (opens in a new tab)

std::mutex sun::moon_bundling::LibraryCache::mutex_

No documentation comment.

pinnedBundles_

private · variable · Source (opens in a new tab)

std::set<MoonReader*> sun::moon_bundling::LibraryCache::pinnedBundles_

No documentation comment.

Related: MoonReader

searchPaths_

private · variable · Source (opens in a new tab)

std::vector<std::filesystem::path> sun::moon_bundling::LibraryCache::searchPaths_

No documentation comment.

targetTriple_

private · variable · Source (opens in a new tab)

std::string sun::moon_bundling::LibraryCache::targetTriple_

No documentation comment.