Giter Site home page Giter Site logo

Comments (5)

stepancheg avatar stepancheg commented on June 29, 2024

I'll fix it.

from clay.

stepancheg avatar stepancheg commented on June 29, 2024

It is harder than I though. There are too much compiler internals that I don't understand. I give up.

from clay.

galchinsky avatar galchinsky commented on June 29, 2024

Isn't this enough?

diff --git a/compiler/codegen.cpp b/compiler/codegen.cpp
index 783e967..baccdf0 100644
--- a/compiler/codegen.cpp
+++ b/compiler/codegen.cpp
@@ -3547,6 +3547,11 @@ void codegenCallByName(InvokeEntry* entry,

     ++ctx->inlineDepth;

+    ++ctx->callByNameDepth;
+    if (ctx->callByNameDepth > 100) {
+        error("Alias stack overflow");
+    }
+
     EnvPtr bodyEnv = new Env(entry->env);
     bodyEnv->callByNameExprHead = callable;

@@ -3631,6 +3636,8 @@ void codegenCallByName(InvokeEntry* entry,

     --ctx->inlineDepth;
     assert(ctx->inlineDepth >= 0);
+    --ctx->callByNameDepth;
+    assert(ctx->callByNameDepth >= 0);
 }


diff --git a/compiler/codegen.hpp b/compiler/codegen.hpp
index 7fe6bd5..467a9c6 100644
--- a/compiler/codegen.hpp
+++ b/compiler/codegen.hpp
@@ -140,6 +140,8 @@ struct CodegenContext {
     int inlineDepth:31;
     bool checkExceptions:1;

+    int callByNameDepth;
+
     CodegenContext()
         : llvmFunc(NULL),
           initBuilder(NULL),
@@ -147,7 +149,8 @@ struct CodegenContext {
           valueForStatics(NULL),
           exceptionValue(NULL),
           inlineDepth(0),
-          checkExceptions(true)
+          checkExceptions(true),
+          callByNameDepth(0)
     {
     }

@@ -158,7 +161,8 @@ struct CodegenContext {
           valueForStatics(NULL),
           exceptionValue(NULL),
           inlineDepth(0),
-          checkExceptions(true)
+          checkExceptions(true),
+          callByNameDepth(0)
     {
     }

from clay.

stepancheg avatar stepancheg commented on June 29, 2024

@galchinsky Well, it is definitely better than current stack overlfow in the compiler. I'd commit your solution.

from clay.

stepancheg avatar stepancheg commented on June 29, 2024

@galchinsky OK, I'll commit your version with several tests I've written earlier. And everyone is welcome to write proper solution, that explicitly detects recursion.

from clay.

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.