Skip to content

Incorrect optimisation #7

@ltratt

Description

@ltratt

SOMpp tries to optimise ifFalse / ifTrue but does so in an incorrect way. Consider this contrived program:

T = (
    ifTrue: x = ( ^2 )

    run = (
        (self ifTrue: 3) println.
    )
)

On yksom and Java-SOM this prints out 2, but in SOM++ it prints out 3. The offending code is here:

diff --git a/src/compiler/Parser.cpp b/src/compiler/Parser.cpp
index 300dd06..276aeff 100644
--- a/src/compiler/Parser.cpp
+++ b/src/compiler/Parser.cpp
@@ -690,13 +690,6 @@ void Parser::keywordMessage(MethodGenerationContext* mgenc, bool super) {
     StdString kw = keyword();
     
     // special compilation for ifTrue and ifFalse
-    if (!super && kw == "ifTrue:") {
-        ifTrueMessage(mgenc);
-        return;
-    } else if (!super && kw == "ifFalse:") {
-        ifFalseMessage(mgenc);
-        return;
-    }
     formula(mgenc);
     while (sym == Keyword) {
         kw.append(keyword());

Basically SOMpp compiles any function called ifFalse / ifTrue into optimised versions that are only correct if the self object is a boolean. While I appreciate this is a useful optimisation for SOMpp, it seems a fairly clear violation of the intended language semantics?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions