Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split inference rules #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JohannesMeierSE
Copy link
Collaborator

Contributes a refactoring for inference rules of operators and functions:

  • split the responsibilities in individual properties (checking the current element VS get its children/operands)
  • might be a bit less compact
  • developed the idea together with @Lotes

@@ -34,27 +34,33 @@ export function createTypir(domainNodeEntry: AstNode): Typir {
}
}

// extract inference rules, which is possible here thanks to the unified structure of the Langium grammar (but this is not possible in general!)
const binaryInferenceRule: InferOperatorWithMultipleOperands<BinaryExpression> = {
filter: isBinaryExpression,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AS already discussed, this is very Langium-specific. Having one filter function could be enough. You could create a isNumericOperator for +,-,* and /. Maybe even bind this to the name first.

const isNumericOperator = operator.createBinaryOperator(['+', '-', '*', '/'], (node, name) => isBinaryExpression(node) && node.op == name));
//returns also "node is BinaryExpression"
const inferenceRule = operators.createExpandRule(isNumericOperator, node => [node.left, node.right]);

But I also see that you cannot reuse it like you did... it is weird somehow to uncouple from the operator name.

I think we need to be careful what mix with what. It is confusing to see the inference rule in you example being used for <, and for +. What is an "inference rule"? Does it make sense to call it like this here? For me this feels confusing, because you say you infer something to grasp a type information, but on the other side you are splitting a node into child nodes...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the operands are required for inference, since in case of overloaded operators/functions, the types of the operands need to be checked.

On the other hand, filter, match and operands are used for validations as well, since the assigned values to these operands need to respect the declared types of the operands.

I totally agree, the names and the design of the "inference rules" is still unclear!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants