GithubHelp home page GithubHelp logo

Join points at return? about ward HOT 5 OPEN

evincarofautumn avatar evincarofautumn commented on June 15, 2024
Join points at return?

from ward.

Comments (5)

evincarofautumn avatar evincarofautumn commented on June 15, 2024

It doesn’t currently, and it doesn’t need to, but that would be a good enhancement.

Basically, we don’t have a lot of code using functions that affect permissions around control flow, and where we do, Ward already complains about it and it’s easy to refactor. Stuff like:

void foo ()
{
  lock ();
  if (bar ()) {
    unlock ();
    return 0;
  }
  baz ();
  unlock ();
  return 1;
}

from ward.

lambdageek avatar lambdageek commented on June 15, 2024

hmm. i'm not entirely convinced we'll always have conflicts if we just treat return as a fallthru. or perhaps we will but they might be difficult to understand. but it does look like the right thing would happen for things like lock/unlock, so i'm content to revisit this in the future.

from ward.

evincarofautumn avatar evincarofautumn commented on June 15, 2024

An easy hack would be to convert the graph to a tree by duplicating segments, maybe with sharing so there’s no actual copying:

if (a ()) goto skip;
b ();
skip: c ();

(a → { b, c }, b → c) ⇒ (a & (c1 | b & c2))

  a          a
 / \        / \
b   |  =>  b   |
 \ /       |   |
  c        c   c

But of course this doesn’t work with back-edges.

from ward.

evincarofautumn avatar evincarofautumn commented on June 15, 2024

It occurs to me that we could also decompose call trees into one “function” for each basic block. So the example you gave could be:

foo = foo1
foo1 = f1 & (foo2 | foo3)
foo2 = f2 & foo4
foo3 = f3 & foo4
foo4 = 0

(Then during inference, some basic optimisations like TCO would show up: when we’re inferring a node in tail position, we wouldn’t need to add another stack frame.)

from ward.

lambdageek avatar lambdageek commented on June 15, 2024

Yea I think I basically agree with this. One property that we should have is that we enjoy an abstraction property: it should be sound to abstract out any CallTree into a separate toplevel function and have an inference result that is no less precise than before. (I think in general abstraction may lose precision - not sure if that can happen in ward).

I'm not sure what you mean about TCO or stack frames

from ward.

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.