Coder Social home page Coder Social logo

Untraslatable goto-s about jsil HOT 4 CLOSED

sq avatar sq commented on September 14, 2024
Untraslatable goto-s

from jsil.

Comments (4)

kg avatar kg commented on September 14, 2024

This usually indicates that the compiler generated a goto that the current goto translation algorithm can't express correctly in JS. I think it's possible to express it but the current algorithm needs to be rewritten to support it. I haven't yet encountered any code that actually depends on these gotos.

from jsil.

matra774 avatar matra774 commented on September 14, 2024

The code tha depends is quite simple. Here is the examlpe:
IEnumerable strings = Enumerable.Repeat("I like programming.", 15);

With ILSPY it decompiles into:

// System.Linq.Enumerable.<CreateRepeatIterator>d__57<TResult>
bool IEnumerator.MoveNext()
{
switch (this.<>1__state)
{
case 0:
    this.<>1__state = -1;
    this.<i>5__58 = 0;
    break;

case 1:
    this.<>1__state = -1;
    this.<i>5__58++;
    break;

default:
    goto IL_6D;
}
bool result;
if (this.<i>5__58 >= this.count)
{
    IL_6D:
    result = false;
}
else
{
    this.<>2__current = this.element;
    this.<>1__state = 1;
    result = true;
}
return result;
}

The problem is the goto IL_6D in the first switch, which actually just jumps into another if statement, which sets the result to false.

The JSIL generates the following code:

$asm03.System.Linq.Enumerable.$lCreateRepeatIterator$gd__57$b1.prototype.IEnumerator_MoveNext = function () {
var __label0__ = "__entry0__";
__step0__:
while (true) {
    switch (__label0__) {
        case "__entry0__":
            switch (this.$state) {
                case 0:
                    this.$state = -1;
                    this.i = 0;
                    break;
                case 1:
                    this.$state = -1;
                    ++this.i;
                    break;
                default:
                    JSIL.UntranslatableInstruction("goto", "IL_6D");
            }
            if (this.i >= this.count) {
                var __label1__ = "__entry1__";
                __step1__:
                while (true) {
                    switch (__label1__) {
                        case "__entry1__":
                            __label1__ = "IL_6D";
                            continue __step1__;
                            break;
                        case "IL_6D":
                            var result = false;
                            break __step1__;
                    }
                }
            } else {
                this.$current = this.element;
                this.$state = 1;
                result = true;
            }
            return result;
            break __step0__;
    }
}
};

from jsil.

kg avatar kg commented on September 14, 2024

I think your problem is fixed by 94fe808.

from jsil.

kg avatar kg commented on September 14, 2024

Closer examination revealed a second bug where the body of the if statement's true clause was left empty when I hoisted the label out of it. That bug is particularly sneaky because you can't reproduce it with hand-written C#; only IL produced by the C# compiler for yield return contains gotos structured like this.

from jsil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.