LionWeb-io / specification

Specifications of the LionWeb initiative
http://lionweb.io/specification/
7 stars 0 forks source link

Define language for Typesystem as derived model #178

Open enikao opened 1 year ago

enikao commented 1 year ago

We need to calculate the type of a node in several contexts, including validation (e.g. "do the types of these assigned nodes match?") and scoping (e.g. "which members does the thing on the left side of the dot have?").

dslmeinte commented 1 year ago

I think there's a language hierarchy here. I wrote some things up in the context of computation of constraints: let's see whether we can get through enough of the agenda to also table that?

joswarmer commented 1 year ago

@dslmeinte Please explain, I cannot place language hierarchy in the context of this question.

dslmeinte commented 1 year ago

The general text I wrote is below, but I need to put it in a good spot in the specification repo still, through a PR.


A constraint conceptually consist of the following data:

For every node in the model, do the following:

Note: constraints that check cardinality defined in the language's M2 are generic, and should not have to be stated explicitly.

In practice, it might be advantageous to allow expand the notion of a constraint as follows:

A constraint checker is a language service that, given a model and a collection of constraints, executes all constraints on every node in the model, and reports back violations in the form of a derived model consisting of issues.

Typical examples:

A language architecture for constraints could look as follows:

(*) Either as a full-blown external DSL, or through an existing programming language with suitable support in the form of a library/framework/internal DSL.

This represents the ideal / the royal way / the point on the horizon, but is quite unrealistic to achieve in the short to middle-long run - at least, in the context of being an effort that happens “purely” within the LionWeb group.

In theory, KernelF would be a great fit as an expression language. In practice, its implementation (its type system, specifically) is quite MPS-specific. This would eventually warrant coming up with a “new KernelF” that's defined in a technology-aspecific way - e.g. using LionWeb for the M2s. Implementing an interpreter as a reference would be good enough. Generating code would probably be more performant, although using GraalVM might prove a helpful here as well.

An expression language would encompass a number of separate aspects:

enikao commented 1 year ago

I think there are different understandings of this language: This language is used to send calculated types of nodes as derived model over the wire. It is not meant to describe the rules how to calculate a type.

Example: Assume the language discussed here is called LionWeb-typesystem.

We have an original model that contains something like MPS' BaseLanguage. Node with id 123 is of concept MethodDeclaration. If we ask for the derived model of node 123 for LionWeb-typesystem, we might get back a node of concept UserDefinedType with some features like name=List, baseType=->java.util.List, collection=true.

So LionWeb-typesystem only contains concepts to describe UserDefinedType, PrimitiveType, EnumType (or something similar). It does not say anything how a processor would calculate that type based on the MethodDeclaration instance with id 123.