Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That might work if Bel didn't have threads. But it does, so it doesn't.

Also, assigning the body is not the only way to undermine compilation. You can change a function into a non-function (by changing its first or second element) and vice versa. You can change a function's environment. You can change its argument list. You can modify the body of a function while it is being evaluated. You can change anything about a function at any time.



You can still do escape analysis. You wouldn't even need to be very advanced with it since most code won't do anything close to modifying and expression that's in the process of evaluating.


You clearly don't know what escape analysis is or how it works. Escape analysis applies only to data allocated at run-time. Programs are generally written before they are run (this is the reason that "run-time" is even a thing) and the functions that comprise them in a Bel program are generally globally bound with DEF. Escape analysis doesn't work on globally bound data. It has already escaped before your program even starts to run.


You can look at where a name is used, I say "escape analysis" here because that is the technique closest to what you would be doing. It gets the idea across quite well. At the fundamental level, you are analysing a program to see which parts of it access which values. In this case assessing if a piece code bound to a global variable "escapes" into the rest of the program as data. The objectives and techniques are similar. This is quite clearly possible.


Escape analysis is a well-established term of art:

https://en.wikipedia.org/wiki/Escape_analysis

"In compiler optimization, escape analysis is a method for determining the dynamic scope of pointers..."

In the case of global bindings, there is nothing to analyze. Global bindings do not have dynamic scope, they have global scope. (Duh.)

> This is quite clearly possible.

OK, you believe what you want. But I'll bet you $100 that you can't even write a program that reliably determines whether or not a list is a valid Bel function, let alone one that does "escape analysis" on an entire Bel code base (whatever you think that might actually mean).

Here, I'll get you started:

    (def is-a-function? (l)
      (and (id (car l) 'lit)
           (id (cadr l) 'clo)
           ...


> valid Bel function

What do you mean by this? Can valid functions produce errors? Does a valid function need to halt?

> In the case of global bindings, there is nothing to analyze

A global name will be used in the program text a finite number of times. You can treat each usage as an the creation of a new value and do escape analysis on it. Doing this on all usages of a variable can determine that the none of these values escape and therefore the value cannot be passed to a list mutating function and is safe to optimise.


> What do you mean by this?

Whatever the spec says.

> You can treat each usage as an the creation of a new value

No, you can't, because aliasing.

https://en.wikipedia.org/wiki/Aliasing_(computing)

You really are totally clueless.


That's not an explanation, and quite frankly it's entirely unrelated. You can quite easily guarantee a top-level variable isn't initially aliased by looking at the form that assigned it. In most cases this will be a literal which is a fresh, unaliased value. If the value becomes aliased to more than one name, that means one instance of it escaped, so you will detect that when doing escape analysis. It's really quite simple logic.

> Whatever the spec says.

Well the document does mention a check for validity.

  (def variable? (v)
       (if (atom v)
           (no (literal v))
           (caris v vmark)))
  
  (def valid-special-param? ((t-or-o (o var) (o expr) . rest))
       (and (valid-params? var)
            ;; t parameters must have a type check.
            (or (id t-or-o o) expr)
            (no rest)))
  
  (def valid-params? (p)
       (if (no p) t
           (variable? p) t
           (or (caris p t) (caris p o)) (valid-special-param? p)
           (and (id (type p) 'pair)
                (valid-params? (car p))
                (valid-params? (cdr p)))))
  
  (def valid-top-params? (p)
       (and (no (caris p o)) (valid-params? p)))
  
  (def valid-function? ((o lit) (o clo) (o env) (o params) (o body) . rest)
       (and (id lit 'lit)
            (id clo 'clo)
            ;; Env, a proper list of pairs of symbols and bindings.
            (and (proper env)
                 (all [id (type _) 'pair] env)
                 (all variable? (map car env)))
            (valid-top-params? params)))
I think this should work, but I don't think it's worth $100.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: