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
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
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
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 ¶
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 (*Loader) Hits ¶ added in v0.2.0
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.
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 ¶
NewDirSource returns a Source that reads .kerml/.sysml files from dir.