grpc

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: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QueryPropID                = corequery.PropertyID
	QueryPropType              = corequery.PropertyType
	QueryPropName              = corequery.PropertyName
	QueryPropDeclaredName      = corequery.PropertyDeclaredName
	QueryPropQualifiedName     = corequery.PropertyQualifiedName
	QueryPropOwner             = corequery.PropertyOwner
	QueryPropIsAbstract        = corequery.PropertyIsAbstract
	QueryPropElementType       = corequery.PropertyElementType
	QueryPropMultiplicityLower = corequery.PropertyMultiplicityLower
	QueryPropMultiplicityUpper = corequery.PropertyMultiplicityUpper
)

Query property names, as the SysML v2 API & Services standard's clients write them. docs/reference/api.md documents what each one reports.

View Source
const CapabilityApplyEdits = "apply_edits"

CapabilityApplyEdits names the capability of the ApplyEdits RPC, which edits a parsed model's own source, preserving everything the edit did not touch.

View Source
const CapabilityAuthoring = "authoring"

CapabilityAuthoring names add-member and delete source authoring operations.

View Source
const CapabilityConvert = "convert"

CapabilityConvert names the capability of the Convert RPC, which writes a model back out as SysML notation or RDF Turtle. The RDF direction is experimental, which the response says per conversion.

View Source
const CapabilityEnumValues = "enum_values"

CapabilityEnumValues names the capability of carrying an enumeration literal as Value.enum_literal, rather than reporting it as an unsupported null.

View Source
const CapabilityEvaluateSubject = "evaluate_subject"

CapabilityEvaluateSubject names the capability of evaluating an expression against an instantiated subject.

View Source
const CapabilityFeatureValues = "feature_values"

CapabilityFeatureValues names the capability of populating Instance.feature_values, which replaced the pre-0.1.0 Instance.slots.

View Source
const CapabilityInlineLanguage = "inline_language"

CapabilityInlineLanguage names explicit language selection for inline content.

View Source
const CapabilityOSLCQuery = "oslc_query"

CapabilityOSLCQuery names the capability of evaluating OSLC Query text.

View Source
const CapabilityQuery = "query"

CapabilityQuery names the capability of the Query RPC, which evaluates a SysML v2 API & Services Query over a parsed model.

View Source
const CapabilityStrictConformance = "strict_conformance"

CapabilityStrictConformance names ParseFileRequest.strict_conformance, which asks whether the source is conforming SysML v2.

View Source
const CapabilitySymbolAttributes = "symbol_attributes"

CapabilitySymbolAttributes names the capability of populating SymbolInfo.attributes, rather than always reporting none.

View Source
const CapabilityTypeFacts = "type_facts"

CapabilityTypeFacts names the capability of populating SymbolInfo.type_info, .multiplicity and .specializations, which typed code generation requires.

View Source
const CapabilityUnsetValue = "unset_value"

CapabilityUnsetValue names the capability of reporting a valueless feature of a value type as Value.unset, rather than as the empty object it materializes.

View Source
const CapabilityVerification = "verification"

CapabilityVerification names the capability of the verification RPCs, which answer the questions the REPL's %constraint, %requirement, %satisfy and %calc answer.

View Source
const DefaultIndexPrewarm = 4

DefaultIndexPrewarm is the value IndexPrewarmEnvVar takes when unset: any positive value prewarms, since one library index now serves every model.

View Source
const IndexPrewarmEnvVar = "SYSML_GRPC_INDEX_POOL"

IndexPrewarmEnvVar names the variable saying whether the service builds the standard library index before the requests that need it. Zero disables prewarming, so the first request builds it.

Variables

View Source
var (
	// ErrQuantityNeedsIndex reports a quantity converted from the wire without
	// the model's symbols, which its base units can only be resolved against.
	ErrQuantityNeedsIndex = errors.New("a quantity needs the model's symbols to be converted from the wire")

	// ErrUnknownBaseUnit reports a base unit the model does not declare, so no
	// unit can be rebuilt from the reduction naming it.
	ErrUnknownBaseUnit = errors.New("unknown base unit")

	// ErrNotAMeasurementUnit reports a reduction naming a symbol that is not a
	// measurement unit, which nothing is measured in.
	ErrNotAMeasurementUnit = errors.New("not a measurement unit")

	// ErrUnitScaleUnusable reports a unit reduction whose scale is zero or
	// undefined, which no magnitude can be converted through.
	ErrUnitScaleUnusable = errors.New("unit scale is not a usable ratio")

	// ErrUnitNotReduced reports a named unit sent without its reduction, over
	// which alone commensurability is decided.
	ErrUnitNotReduced = errors.New("unit carries no reduction to base units")
	// ErrUnsetNotAccepted reports the unset arm arriving as an input. It reports
	// that a feature value holds no value, which is something to read, not to supply.
	ErrUnsetNotAccepted = errors.New("unset is not a value a caller can supply")
)

Functions

func Capabilities

func Capabilities() []string

Capabilities returns the capability names this build of the service reports.

func DiagnosticToProto

func DiagnosticToProto(diag passes.Diagnostic, sf *source.SourceFile) *pb.Diagnostic

DiagnosticToProto converts a passes.Diagnostic to protobuf.

func InstanceGraphToProto

func InstanceGraphToProto(rt *runtime.Context, inst *runtime.Instance, idx *symbols.Index) (*pb.Instance, []*pb.Instance)

InstanceGraphToProto converts inst and every instance reachable from it. The root is returned first; runtime instances live only for the duration of a request, so the whole reachable graph is serialized while the context is alive.

Expansion stops at a child whose type is already on the path, at maxGraphDepth and at maxGraphInstances: reading a composite feature value materializes the object it holds, so a self-referential part would otherwise instantiate forever. An unexpanded child stays a bare instance id.

func InstanceToProto

func InstanceToProto(rt *runtime.Context, inst *runtime.Instance, idx *symbols.Index) *pb.Instance

InstanceToProto converts runtime.Instance to protobuf Instance. Feature values are read through Instance.GetFeatureValue, so a derived default is evaluated against the instance rather than reported as unmaterialized.

func ParserDiagnosticToProto

func ParserDiagnosticToProto(diag parser.Diagnostic, sf *source.SourceFile) *pb.Diagnostic

ParserDiagnosticToProto converts a parser.Diagnostic to protobuf.

func ProtoToQuantity

func ProtoToQuantity(pq *pb.Quantity, idx *symbols.Index, sem *semantics.Model) (runtime.Value, error)

ProtoToQuantity rebuilds a quantity from the wire: the magnitude as sent, in the unit as written, over the base units idx resolves its reduction to.

func ProtoToValueIn

func ProtoToValueIn(pv *pb.Value, idx *symbols.Index, sem *semantics.Model) (runtime.Value, error)

ProtoToValueIn converts a protobuf Value to a runtime.Value in the model idx and sem describe, resolving a quantity's base units against them. Inverse of ValueToProto.

func QuantityToProto

func QuantityToProto(q *runtime.Quantity) *pb.Quantity

QuantityToProto marshals a quantity: the magnitude in the unit written, plus what that unit reduces to. Reports nil for a magnitude that is not a number.

func QueryPropertyNames

func QueryPropertyNames() []string

QueryPropertyNames returns every queryable property name, sorted. It is what an unknown-property error lists, and what docs/reference/api.md's table documents.

func SymbolToProtoIn

func SymbolToProtoIn(sym *symbols.Symbol, sc *SymbolContext) *pb.SymbolInfo

SymbolToProtoIn converts a Symbol to protobuf SymbolInfo in an existing conversion context.

func ValueToProto

func ValueToProto(val runtime.Value, idx *symbols.Index) *pb.Value

ValueToProto converts runtime.Value to protobuf Value. An enumeration literal is named by its declaration, which idx supplies the qualified name of.

func ValueToProtoIn

func ValueToProtoIn(rt *runtime.Context, val runtime.Value, idx *symbols.Index) *pb.Value

ValueToProtoIn converts a value read from a live context, which is what tells an object holding no value from one with features: the former crosses as the unset arm, as every other surface reads it. rt may be nil for a value no context materialized.

Types

type Cache

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

Cache is an LRU cache for parsed models keyed by content hash

func NewCache

func NewCache(maxSize int) (*Cache, error)

NewCache creates a cache with the specified max size. It returns an error if maxSize is not positive.

func (*Cache) Get

func (c *Cache) Get(hash string) (*CachedModel, bool)

Get retrieves a model from cache, returns (model, true) on hit

func (*Cache) Put

func (c *Cache) Put(hash string, model *CachedModel)

Put adds a model to cache, evicting LRU if at capacity

type CachedModel

type CachedModel struct {
	Root        *ast.RootNamespace
	Index       *symbols.Index      // For symbol lookups by FQN
	Source      *source.SourceFile  // For diagnostic line/col mapping
	ParseDiags  []parser.Diagnostic // Parser diagnostics
	PassesDiags []passes.Diagnostic // Semantic pass diagnostics (name-resolution, type, constraint)
	// contains filtered or unexported fields
}

CachedModel holds parsed model data with semantic analysis results

func (*CachedModel) SymbolContext

func (m *CachedModel) SymbolContext() *SymbolContext

SymbolContext returns the conversion context for this model, building it on first use. Name resolution and the semantic relations derived from it are memoized in it, so every symbol converted from one cached model shares one.

type ConnectAdapter added in v0.3.0

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

ConnectAdapter serves the same Service through the Connect handler signatures, so one implementation answers every protocol Connect speaks.

func NewConnectAdapter added in v0.3.0

func NewConnectAdapter(svc *Service) *ConnectAdapter

NewConnectAdapter wraps a Service as a Connect handler.

func (*ConnectAdapter) ApplyEdits added in v0.3.0

ApplyEdits edits a parsed model's own source.

func (*ConnectAdapter) Convert added in v0.3.0

Convert writes a model out as SysML notation or RDF Turtle.

func (*ConnectAdapter) Evaluate added in v0.3.0

Evaluate evaluates an expression against a parsed model.

func (*ConnectAdapter) EvaluateCalc added in v0.3.0

EvaluateCalc evaluates a calculation with the arguments given.

func (*ConnectAdapter) ExecuteAction added in v0.3.0

ExecuteAction runs an action to completion.

func (*ConnectAdapter) ExecuteState added in v0.3.0

ExecuteState runs a state machine over the events given.

func (*ConnectAdapter) GetDiagnostics added in v0.3.0

GetDiagnostics returns the diagnostics of a parsed model.

func (*ConnectAdapter) GetServerInfo added in v0.3.0

GetServerInfo reports what this build of the service can do.

func (*ConnectAdapter) GetSymbol added in v0.3.0

GetSymbol returns symbol information by qualified name.

func (*ConnectAdapter) Instantiate added in v0.3.0

Instantiate materializes an instance of a definition.

func (*ConnectAdapter) ParseFile added in v0.3.0

ParseFile parses a model and returns its hash.

func (*ConnectAdapter) Query added in v0.3.0

Query evaluates a SysML v2 API & Services Query over a parsed model.

func (*ConnectAdapter) VerifyConstraint added in v0.3.0

VerifyConstraint evaluates a constraint and returns its verdict.

func (*ConnectAdapter) VerifyRequirement added in v0.3.0

VerifyRequirement evaluates a requirement and returns its verdict.

func (*ConnectAdapter) VerifySatisfaction added in v0.3.0

VerifySatisfaction evaluates satisfaction relationships in a model.

type QueryError

type QueryError struct {
	Kind    QueryErrorKind
	Message string
}

QueryError is a query the service refuses to evaluate. It reports itself as INVALID_ARGUMENT, since every kind is a fault in the query, not in the model.

func (*QueryError) Error

func (e *QueryError) Error() string

type QueryErrorKind

type QueryErrorKind int

QueryErrorKind classifies why a query could not be evaluated. Every kind fails the call: answering with no elements would read as "nothing matched".

const (
	// QueryErrUnknownProperty is a property no queryable property names.
	QueryErrUnknownProperty QueryErrorKind = iota + 1
	// QueryErrMalformedConstraint is a constraint with no form, no operator or
	// no operand.
	QueryErrMalformedConstraint
	// QueryErrUnorderedProperty is > or < on a property that is not ordered.
	QueryErrUnorderedProperty
	// QueryErrUnparsableValue is an operand the operator cannot compare.
	QueryErrUnparsableValue
	// QueryErrUnknownScope is a scope naming an element the model does not have.
	QueryErrUnknownScope
)

type Service

type Service struct {
	pb.UnimplementedSysMLServiceServer
	// contains filtered or unexported fields
}

Service implements SysMLServiceServer

func NewService

func NewService(cacheSize int, version string) (*Service, error)

NewService creates a gRPC service with specified cache size, reporting version as its build version. It returns an error if cacheSize is not positive, if a budget variable holds anything but a positive integer, or if the prewarm setting is not a non-negative integer. It does not load the standard library: call Prewarm to have that happen in the background, ahead of the requests that need it.

func NewServiceWithUnavailableCapabilitiesForTesting added in v0.3.0

func NewServiceWithUnavailableCapabilitiesForTesting(cacheSize int, version string, unavailable []string) (*Service, error)

NewServiceWithUnavailableCapabilitiesForTesting creates a service that deliberately lacks named capabilities for conformance testing.

func (*Service) ApplyEdits

func (s *Service) ApplyEdits(ctx context.Context, req *pb.ApplyEditsRequest) (*pb.ApplyEditsResponse, error)

ApplyEdits edits the source a model was parsed from and returns the edited notation, so a client can change a model and write it back with its comments and layout intact. Argument faults fail the call; an edit the engine refuses is reported in the response's error, failure kind and diagnostics.

func (*Service) Close

func (s *Service) Close()

Close waits for a background library build in flight and releases the service's reference to the shared index. The service still answers afterwards, building the library on the request that needs it.

func (*Service) Convert

func (s *Service) Convert(ctx context.Context, req *pb.ConvertRequest) (*pb.ConvertResponse, error)

Convert writes a model in another representation, so a client can save a model it read rather than only inspect it. Argument faults fail the call; a model the converter refuses is reported in the response's error and diagnostics.

func (*Service) Evaluate

func (s *Service) Evaluate(ctx context.Context, req *pb.EvaluateRequest) (*pb.EvaluateResponse, error)

Evaluate evaluates a SysML expression in the context of a parsed model

func (*Service) EvaluateCalc

func (s *Service) EvaluateCalc(ctx context.Context, req *pb.EvaluateCalcRequest) (*pb.EvaluateCalcResponse, error)

EvaluateCalc invokes a calculation, as the REPL's %calc does: a calc usage named with no arguments is evaluated from its own members and reports every output feature it computes (SysML 7.17); anything else is invoked with the arguments given, bound positionally.

func (*Service) ExecuteAction

func (s *Service) ExecuteAction(ctx context.Context, req *pb.ExecuteActionRequest) (*pb.ExecuteActionResponse, error)

ExecuteAction executes an action definition

func (*Service) ExecuteState

func (s *Service) ExecuteState(ctx context.Context, req *pb.ExecuteStateRequest) (*pb.ExecuteStateResponse, error)

ExecuteState executes a state machine

func (*Service) GetDiagnostics

func (s *Service) GetDiagnostics(ctx context.Context, req *pb.DiagnosticsRequest) (*pb.DiagnosticsResponse, error)

GetDiagnostics retrieves all diagnostics for a parsed model (parser + semantic passes)

func (*Service) GetServerInfo

func (s *Service) GetServerInfo(ctx context.Context, req *pb.ServerInfoRequest) (*pb.ServerInfoResponse, error)

GetServerInfo reports the service's build version and capabilities. A service too old to have this RPC fails the call with UNIMPLEMENTED, which is itself the answer that it predates every capability.

func (*Service) GetSymbol

func (s *Service) GetSymbol(ctx context.Context, req *pb.GetSymbolRequest) (*pb.SymbolResponse, error)

GetSymbol retrieves symbol information by FQN

func (*Service) Instantiate

func (s *Service) Instantiate(ctx context.Context, req *pb.InstantiateRequest) (*pb.InstantiateResponse, error)

Instantiate creates a runtime instance of a part/usage

func (*Service) ParseFile

func (s *Service) ParseFile(ctx context.Context, req *pb.ParseFileRequest) (*pb.ParseFileResponse, error)

ParseFile parses a SysML file and caches the result

func (*Service) Prewarm

func (s *Service) Prewarm()

Prewarm starts building the service's standard library index in the background, so the first model to arrive is not the one that pays for the library. It returns immediately and is safe to call more than once.

func (*Service) Query

func (s *Service) Query(ctx context.Context, req *pb.QueryRequest) (*pb.QueryResponse, error)

Query evaluates a SysML v2 API & Services Query against a parsed model.

func (*Service) VerifyConstraint

VerifyConstraint evaluates a constraint definition or usage, as the REPL's %constraint does.

func (*Service) VerifyRequirement

VerifyRequirement evaluates a requirement definition or usage, as the REPL's %requirement does.

func (*Service) VerifySatisfaction

VerifySatisfaction evaluates the satisfaction assertions a model states, as the REPL's %satisfy does: every one, or, given a symbol, the ones that element states — or that element itself when it is a named satisfy assertion.

type SymbolContext

type SymbolContext struct {
	Index     *symbols.Index
	Resolver  *resolve.Resolver
	Semantics *semantics.Model
	// contains filtered or unexported fields
}

SymbolContext holds what converting a symbol to proto needs besides the symbol: its index, and the resolver and semantic model that answer what its declared names refer to. Their memoization is why it is shared per model.

The resolver and semantic model memoize into plain maps, so a shared context must be used by one goroutine at a time; Lock serializes concurrent conversions of the same model.

func NewSymbolContext

func NewSymbolContext(idx *symbols.Index) *SymbolContext

NewSymbolContext builds a conversion context over a symbol index.

func (*SymbolContext) Lock

func (sc *SymbolContext) Lock() func()

Lock takes exclusive use of the context's resolver and semantic model, and returns the function releasing it.

Jump to

Keyboard shortcuts

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