libs

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package libs loads SysML/KerML standard-library files (bundled via embed.FS or overridden on disk) and maintains a persistent cache of their indexed symbols. See spec section 10.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadInto added in v0.1.2

func LoadInto(idx *symbols.Index)

LoadInto loads every standard library file into idx, using the symbol cache when it is available. A failure is non-fatal: it is logged, and the index stays usable for a model that does not depend on the file that failed.

func NewModelIndex added in v0.2.0

func NewModelIndex() *symbols.Index

NewModelIndex returns an index for one model to add its documents to: an overlay over the shared standard library, which the model reads but cannot write to.

func SharedBase added in v0.2.0

func SharedBase() *symbols.Index

SharedBase returns the frozen index holding the standard library, built on first use and shared by every model afterwards: the library is the same for every model and immutable once loaded, so one copy serves them all.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache persists reduced library IndexRecords to disk keyed by content hash and format version. A hit lets the loader skip lexing/parsing entirely. The same mechanism serves git dependencies (Plan 5c) since it keys purely on content.

func NewCache

func NewCache() (*Cache, error)

NewCache resolves the cache directory ($XDG_CACHE_HOME or os.UserCacheDir), appends "sysml-ls/libs", creates it, and returns a ready Cache.

func (*Cache) Load

func (c *Cache) Load(key string) (*IndexRecord, bool)

Load returns the cached record for key, or (nil, false) on any miss (absent file, read error, or decode error — all treated as a benign miss).

func (*Cache) Prune

func (c *Cache) Prune()

Prune removes records that no load has hit for maxIdleAge, and the temp files a crashed store left behind. Cache entries are otherwise never invalidated explicitly — a key that no longer matches is simply missed — so without this the directory keeps every record any library version ever produced.

func (*Cache) Store

func (c *Cache) Store(key string, rec *IndexRecord) error

Store gob-encodes rec and writes it to <dir>/<key>.idx atomically: it writes a temp file of its own then renames it into place, so a concurrent Load or a crash never observes a partially written file, and two writers of one key cannot truncate or publish each other's temp. A failed encode/write removes the temp and leaves any existing final file untouched.

type IndexRecord

type IndexRecord struct {
	Name  string
	Facts []factRecord
}

IndexRecord is the derived analysis persisted for one library document.

type Loader

type Loader struct {

	// RequireResolved makes LoadAll cache no document with an unresolved
	// specialization target, since a key does not describe the index a record was
	// built in.
	RequireResolved bool
	// contains filtered or unexported fields
}

Loader loads library files from a Source and registers them into a target index, using a Cache to skip the derivation a load would otherwise repeat. Every file is parsed and indexed on every load path, so a library contributes its declarations whether or not the cache held anything for it; a record carries only the derived facts whose derivation dominates a cold load.

func NewLoader

func NewLoader(src Source, cache *Cache) *Loader

NewLoader returns a Loader over src, using cache for persistence.

func (*Loader) Hits added in v0.2.0

func (l *Loader) Hits() int

Hits reports how many documents of the last LoadAll had their facts installed from a cache record instead of derived, which is how a caller tells a warm load from a cold one.

func (*Loader) LoadAll added in v0.2.0

func (l *Loader) LoadAll(idx *symbols.Index) error

LoadAll registers every file of the source into idx as library content and installs the derived facts of each. It loads the whole set at once because a record holds supertype names a sibling file may declare; an incomplete library is reported and not cached.

type Source

type Source interface {
	// List returns the relative paths of available library files, sorted.
	List() []string
	// Read returns the bytes of the named library file, or an error.
	Read(name string) ([]byte, error)
}

Source yields standard-library file contents by relative path (e.g. "Kernel Libraries/Kernel Data Type Library/ScalarValues.kerml").

func DefaultSource

func DefaultSource() Source

DefaultSource returns a dirSource rooted at SYSML_LIBRARY_PATH when that environment variable is set and non-empty, otherwise the embedded source.

func NewDirSource

func NewDirSource(dir string) Source

NewDirSource returns a Source that reads .kerml/.sysml files from dir.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL