Documentation
¶
Index ¶
- Constants
- Variables
- func Capabilities() []string
- func DiagnosticToProto(diag passes.Diagnostic, sf *source.SourceFile) *pb.Diagnostic
- func InstanceGraphToProto(rt *runtime.Context, inst *runtime.Instance, idx *symbols.Index) (*pb.Instance, []*pb.Instance)
- func InstanceToProto(rt *runtime.Context, inst *runtime.Instance, idx *symbols.Index) *pb.Instance
- func MetamodelTypeName(kind symbols.SymbolKind) string
- func ParserDiagnosticToProto(diag parser.Diagnostic, sf *source.SourceFile) *pb.Diagnostic
- func ProtoToQuantity(pq *pb.Quantity, idx *symbols.Index, sem *semantics.Model) (runtime.Value, error)
- func ProtoToValueIn(pv *pb.Value, idx *symbols.Index, sem *semantics.Model) (runtime.Value, error)
- func QuantityToProto(q *runtime.Quantity) *pb.Quantity
- func QueryPropertyNames() []string
- func SymbolToProto(sym *symbols.Symbol, idx *symbols.Index) *pb.SymbolInfo
- func SymbolToProtoIn(sym *symbols.Symbol, sc *SymbolContext) *pb.SymbolInfo
- func ValueToProto(val runtime.Value, idx *symbols.Index) *pb.Value
- func ValueToProtoIn(rt *runtime.Context, val runtime.Value, idx *symbols.Index) *pb.Value
- type Cache
- type CachedModel
- type QueryError
- type QueryErrorKind
- type Service
- func (s *Service) ApplyEdits(ctx context.Context, req *pb.ApplyEditsRequest) (*pb.ApplyEditsResponse, error)
- func (s *Service) Close()
- func (s *Service) Convert(ctx context.Context, req *pb.ConvertRequest) (*pb.ConvertResponse, error)
- func (s *Service) Evaluate(ctx context.Context, req *pb.EvaluateRequest) (*pb.EvaluateResponse, error)
- func (s *Service) EvaluateCalc(ctx context.Context, req *pb.EvaluateCalcRequest) (*pb.EvaluateCalcResponse, error)
- func (s *Service) ExecuteAction(ctx context.Context, req *pb.ExecuteActionRequest) (*pb.ExecuteActionResponse, error)
- func (s *Service) ExecuteState(ctx context.Context, req *pb.ExecuteStateRequest) (*pb.ExecuteStateResponse, error)
- func (s *Service) GetDiagnostics(ctx context.Context, req *pb.DiagnosticsRequest) (*pb.DiagnosticsResponse, error)
- func (s *Service) GetServerInfo(ctx context.Context, req *pb.ServerInfoRequest) (*pb.ServerInfoResponse, error)
- func (s *Service) GetSymbol(ctx context.Context, req *pb.GetSymbolRequest) (*pb.SymbolResponse, error)
- func (s *Service) Instantiate(ctx context.Context, req *pb.InstantiateRequest) (*pb.InstantiateResponse, error)
- func (s *Service) ParseFile(ctx context.Context, req *pb.ParseFileRequest) (*pb.ParseFileResponse, error)
- func (s *Service) Prewarm()
- func (s *Service) Query(ctx context.Context, req *pb.QueryRequest) (*pb.QueryResponse, error)
- func (s *Service) VerifyConstraint(ctx context.Context, req *pb.VerifyConstraintRequest) (*pb.VerifyConstraintResponse, error)
- func (s *Service) VerifyRequirement(ctx context.Context, req *pb.VerifyRequirementRequest) (*pb.VerifyRequirementResponse, error)
- func (s *Service) VerifySatisfaction(ctx context.Context, req *pb.VerifySatisfactionRequest) (*pb.VerifySatisfactionResponse, error)
- type SymbolContext
Constants ¶
const ( QueryPropID = "@id" QueryPropType = "@type" QueryPropName = "name" QueryPropDeclaredName = "declaredName" QueryPropQualifiedName = "qualifiedName" QueryPropOwner = "owner" QueryPropIsAbstract = "isAbstract" QueryPropElementType = "type" QueryPropMultiplicityLower = "multiplicityLower" QueryPropMultiplicityUpper = "multiplicityUpper" )
Query property names, as the SysML v2 API & Services standard's clients write them. docs/reference/api.md documents what each one reports.
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.
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.
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.
const CapabilityEvaluateSubject = "evaluate_subject"
CapabilityEvaluateSubject names the capability of evaluating an expression against an instantiated subject, rather than ignoring the subject and answering with the declared default.
const CapabilityFeatureValues = "feature_values"
CapabilityFeatureValues names the capability of populating Instance.feature_values, which replaced the pre-0.1.0 Instance.slots.
const CapabilityQuery = "query"
CapabilityQuery names the capability of the Query RPC, which evaluates a SysML v2 API & Services Query over a parsed model.
const CapabilitySymbolAttributes = "symbol_attributes"
CapabilitySymbolAttributes names the capability of populating SymbolInfo.attributes, rather than always reporting none.
const CapabilityTypeFacts = "type_facts"
CapabilityTypeFacts names the capability of populating SymbolInfo.type_info, .multiplicity and .specializations, which typed code generation requires.
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.
const CapabilityVerification = "verification"
CapabilityVerification names the capability of the verification RPCs, which answer the questions the REPL's %constraint, %requirement, %satisfy and %calc answer.
const DefaultIndexPoolSize = 4
DefaultIndexPoolSize is how many prewarmed library indexes a service keeps when IndexPoolEnvVar is unset.
const IndexPoolEnvVar = "SYSML_GRPC_INDEX_POOL"
IndexPoolEnvVar names the variable holding how many prewarmed library indexes the service keeps. Zero disables prewarming, so every cache miss builds its own index inline, as it did before the pool existed.
Variables ¶
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 ¶
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 MetamodelTypeName ¶
func MetamodelTypeName(kind symbols.SymbolKind) string
MetamodelTypeName returns the metamodel type name a symbol kind reports as `@type`, or "" for a kind that has none, which is only an unclassified declaration. An element with no type name never matches a `@type` comparison.
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 ¶
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 ¶
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 SymbolToProto ¶
SymbolToProto converts a Symbol to protobuf SymbolInfo. This is the public API for gRPC service use. It builds a conversion context of its own; a caller converting several symbols of one model should build one with NewSymbolContext and call SymbolToProtoIn, so that name resolution is memoized across the symbols.
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 ¶
ValueToProto converts runtime.Value to protobuf Value. An enumeration literal is named by its declaration, which idx supplies the qualified name of.
func ValueToProtoIn ¶
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 ¶
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 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
func (*QueryError) GRPCStatus ¶
func (e *QueryError) GRPCStatus() *status.Status
GRPCStatus maps the error onto the status the RPC fails with.
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 ¶
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 index pool size 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 (*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 releases the prewarmed indexes nobody took and waits for the background builds in flight. The service still answers afterwards, building each index 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 pool of standard library indexes 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 ¶
func (s *Service) VerifyConstraint(ctx context.Context, req *pb.VerifyConstraintRequest) (*pb.VerifyConstraintResponse, error)
VerifyConstraint evaluates a constraint definition or usage, as the REPL's %constraint does.
func (*Service) VerifyRequirement ¶
func (s *Service) VerifyRequirement(ctx context.Context, req *pb.VerifyRequirementRequest) (*pb.VerifyRequirementResponse, error)
VerifyRequirement evaluates a requirement definition or usage, as the REPL's %requirement does.
func (*Service) VerifySatisfaction ¶
func (s *Service) VerifySatisfaction(ctx context.Context, req *pb.VerifySatisfactionRequest) (*pb.VerifySatisfactionResponse, error)
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.