Overriding Typesystem Rules

37 views
Skip to first unread message

ni...@donnelly.cc

unread,
May 28, 2018, 9:43:07 AM5/28/18
to mbeddr-discuss
I am attempting to override the typesystem rules that pertain to operators for a C++ implementation. The type rules I've written work as intended, however there seems to be some problem when building them. Sometimes, when the typesystem is built, the overridden rules work correctly. If I rebuild the typesystem after making zero changes whatsoever, then it sometimes ignores my rules and uses the ones from mbeddr.core.

An example of the override sections of the typesystem rule:

And here are typesystem traces for both (no changes between the code itself, just in what gets reported as an error. The only difference is that things were rebuilt for the second image, and now a different type rule is being applied.
      

This happens with all of my operator overloads independently. That is, the correct rules may be used for binary operators and assignment operators, but array access operators won't work. Then a rebuild of the typesystem might fix one and break another, or do nothing. Very strange. Is this a generation ordering problem? Is there something obvious I am missing?

Any help would be appreciated.

Daniel Ratiu

unread,
May 28, 2018, 1:45:55 PM5/28/18
to mbeddr-...@googlegroups.com
Hi,

I assume that the language containing the overloaded rule is enabled on the model containing the test code.

1) does the rebuild of the type-system rules go well? (are there errors occurring?)
2) would it help clearing the caches AND restarting MPS? ("File -> Invalidate Caches / Restart ...")


Dan


--
You received this message because you are subscribed to the Google Groups "mbeddr-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mbeddr-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ni...@donnelly.cc

unread,
May 29, 2018, 2:17:11 AM5/29/18
to mbeddr-discuss
Hi Dan,

The typesystem is building without any errors. Invalidating caches and restarting didn't seem to work either.

Regards,
Nick
To unsubscribe from this group and stop receiving emails from it, send an email to mbeddr-discus...@googlegroups.com.

Kolja Dummann

unread,
May 29, 2018, 3:07:26 AM5/29/18
to ni...@donnelly.cc, mbeddr-...@googlegroups.com
Hi Nick,

I think rather then using inference rules with overrides and isApplicable I would suggest using inequation replacement rules. Theses rules do not depend on the structure of the model but can write condition over the types. They are executed after the type system has established a solution and you want to “post process” it. It is usually much more robust to use this overriding rules. 

It also takes away the need to subconcept the expression because you can contribute them from any language. 

See the replacement rules section in the docs:



Cheers,
Kolja

Kolja Dummann
Rüderner Straße 2

70329 Stuttgart
Skype: kolja_dummann
 

ni...@donnelly.cc

unread,
May 29, 2018, 4:46:48 AM5/29/18
to mbeddr-discuss
Kolja,

Thanks for the suggestion. After reading through the documentation on the rules, I'm not sure in what way these solve my problem. Perhaps you could elucidate further?

I should mention that the use case here is overloading operators in C++, so the return type of an expression like "a + b" in the image might return an entirely different type than a or b altogether (see below). The expression types are not subtyped. The implementation I have currently does work, it's just that, for whatever reason, MPS isn't choosing to apply the same rules every time.


When the error appears for "a + b" the typesystem trace shows:

But when the error doesn't appear, (even though no actual changes to the typesystem rules have occurred beyond adding a newline and building it again) the trace shows:

Regards,
Nick
Reply all
Reply to author
Forward
0 new messages