unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Prevent inlining
@ 2020-02-12 17:44 Stefan Israelsson Tampe
  2020-02-12 21:49 ` Linus Björnstam
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Israelsson Tampe @ 2020-02-12 17:44 UTC (permalink / raw)
  To: guile-devel, Guile User

[-- Attachment #1: Type: text/plain, Size: 1538 bytes --]

Hi all,

Current guile inlines even variables exposed in the module interface, and I
understand that we must live with that and code around it. So here is a few
tips how to mitigate it.

The simplest way is to put this definition in a module:
------------------------
(define-module (syntax not-inline)
  #:export (not-inline))

(cond-expand
  (guile-3.0
     (define (not-inline x) x))
  ((or (guile-2.0 guile-2.2)
     (define-syntax-rule (not-inline x) x)))

-------------------------------------
And then in another module do,

(use-modules (syntax not-inline))
(define variable (not-inline 12))
(define function (not-inline (lambda () ...)))
etc

This is also an option (not perfect but you get the gist)

-----------------------------------------------------------------
(define-module (syntax define-not-inlinable)
   #:use-module (syntax not-inline)
   #:export (inline define lambda  define* lambda* define-values)
(define inline (lambda (x) x))
(define-syntax define
   (syntax-rules (inline)
      ((define (f . x) . code)
       (define f (not-inline (lambda x . code)))
      ((define f (inline x))
       (define f x))
      ((define f x)
       (define f (not-inlinable x))))
----------------------------------------------------------------------------------
using this module will make all usual define not inlineable and to enable
inlining you would
explicitly ask for it like

(define f (inline (lambda (x) (+ x 10))))

If there is a need for this I can write the modules and expose it on the
intertubes.

WDYT

/Stefan

[-- Attachment #2: Type: text/html, Size: 2227 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Prevent inlining
  2020-02-12 17:44 Prevent inlining Stefan Israelsson Tampe
@ 2020-02-12 21:49 ` Linus Björnstam
  2020-02-13  7:36   ` Stefan Israelsson Tampe
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Björnstam @ 2020-02-12 21:49 UTC (permalink / raw)
  To: Stefan Israelsson Tampe, guile-devel, Guile User

If guile ever gets cross-module Inlining in even the simplest form, this will break. This kind of inlining is probably the most secure one to rely on ever (my for loops rely on it, for example). A more future proof option is maybe to (set! ...) A variable within the same module, which makes it implicitly boxed. Slow unless guile is able to do unboxing...

Ludo used the trick here: http://git.savannah.gnu.org/cgit/guile.git/commit/?id=bf1f5422bdb364667d6761dd73454558d6dbf895

-- 
  Linus Björnstam

On Wed, 12 Feb 2020, at 18:44, Stefan Israelsson Tampe wrote:
> Hi all,
> 
> Current guile inlines even variables exposed in the module interface, 
> and I understand that we must live with that and code around it. So 
> here is a few tips how to mitigate it.
> 
> The simplest way is to put this definition in a module:
> ------------------------
> (define-module (syntax not-inline)
>  #:export (not-inline))
> 
> (cond-expand
>  (guile-3.0
>  (define (not-inline x) x))
>  ((or (guile-2.0 guile-2.2)
>  (define-syntax-rule (not-inline x) x)))
> 
> -------------------------------------
> And then in another module do,
> 
> (use-modules (syntax not-inline))
> (define variable (not-inline 12))
> (define function (not-inline (lambda () ...)))
> etc
> 
> This is also an option (not perfect but you get the gist)
> 
> -----------------------------------------------------------------
> (define-module (syntax define-not-inlinable)
>  #:use-module (syntax not-inline)
>  #:export (inline define lambda define* lambda* define-values)
> (define inline (lambda (x) x))
> (define-syntax define
>  (syntax-rules (inline)
>  ((define (f . x) . code)
>  (define f (not-inline (lambda x . code)))
>  ((define f (inline x))
>  (define f x))
>  ((define f x)
>  (define f (not-inlinable x))))
> ----------------------------------------------------------------------------------
> using this module will make all usual define not inlineable and to 
> enable inlining you would
> explicitly ask for it like
> 
> (define f (inline (lambda (x) (+ x 10))))
> 
> If there is a need for this I can write the modules and expose it on 
> the intertubes.
> 
> WDYT
> 
> /Stefan
> 
> 
> 
>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Prevent inlining
  2020-02-12 21:49 ` Linus Björnstam
@ 2020-02-13  7:36   ` Stefan Israelsson Tampe
  2020-02-13 13:38     ` Linus Björnstam
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Israelsson Tampe @ 2020-02-13  7:36 UTC (permalink / raw)
  To: Linus Björnstam; +Cc: Guile User, guile-devel

[-- Attachment #1: Type: text/plain, Size: 2678 bytes --]

No even if you have cross module inlining you will still be able to tell i
a module will allow inlining or not else you will break quite a lot of nice
scheme idioms.
This means that this is indeed future proof.

On Wed, Feb 12, 2020 at 10:50 PM Linus Björnstam <
linus.bjornstam@veryfast.biz> wrote:

> If guile ever gets cross-module Inlining in even the simplest form, this
> will break. This kind of inlining is probably the most secure one to rely
> on ever (my for loops rely on it, for example). A more future proof option
> is maybe to (set! ...) A variable within the same module, which makes it
> implicitly boxed. Slow unless guile is able to do unboxing...
>
> Ludo used the trick here:
> http://git.savannah.gnu.org/cgit/guile.git/commit/?id=bf1f5422bdb364667d6761dd73454558d6dbf895
>
> --
>   Linus Björnstam
>
> On Wed, 12 Feb 2020, at 18:44, Stefan Israelsson Tampe wrote:
> > Hi all,
> >
> > Current guile inlines even variables exposed in the module interface,
> > and I understand that we must live with that and code around it. So
> > here is a few tips how to mitigate it.
> >
> > The simplest way is to put this definition in a module:
> > ------------------------
> > (define-module (syntax not-inline)
> >  #:export (not-inline))
> >
> > (cond-expand
> >  (guile-3.0
> >  (define (not-inline x) x))
> >  ((or (guile-2.0 guile-2.2)
> >  (define-syntax-rule (not-inline x) x)))
> >
> > -------------------------------------
> > And then in another module do,
> >
> > (use-modules (syntax not-inline))
> > (define variable (not-inline 12))
> > (define function (not-inline (lambda () ...)))
> > etc
> >
> > This is also an option (not perfect but you get the gist)
> >
> > -----------------------------------------------------------------
> > (define-module (syntax define-not-inlinable)
> >  #:use-module (syntax not-inline)
> >  #:export (inline define lambda define* lambda* define-values)
> > (define inline (lambda (x) x))
> > (define-syntax define
> >  (syntax-rules (inline)
> >  ((define (f . x) . code)
> >  (define f (not-inline (lambda x . code)))
> >  ((define f (inline x))
> >  (define f x))
> >  ((define f x)
> >  (define f (not-inlinable x))))
> >
> ----------------------------------------------------------------------------------
> > using this module will make all usual define not inlineable and to
> > enable inlining you would
> > explicitly ask for it like
> >
> > (define f (inline (lambda (x) (+ x 10))))
> >
> > If there is a need for this I can write the modules and expose it on
> > the intertubes.
> >
> > WDYT
> >
> > /Stefan
> >
> >
> >
> >
>

[-- Attachment #2: Type: text/html, Size: 3426 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Prevent inlining
  2020-02-13  7:36   ` Stefan Israelsson Tampe
@ 2020-02-13 13:38     ` Linus Björnstam
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Björnstam @ 2020-02-13 13:38 UTC (permalink / raw)
  To: Stefan Israelsson Tampe; +Cc: Guile User, guile-devel

Will it not inline "(not-inline x)" and then peval it to x? What are you trying to avoid? I am out on very deep water here, now I am just genuinely curious :D
-- 
  Linus Björnstam

On Thu, 13 Feb 2020, at 08:36, Stefan Israelsson Tampe wrote:
> No even if you have cross module inlining you will still be able to 
> tell i a module will allow inlining or not else you will break quite a 
> lot of nice scheme idioms.
> This means that this is indeed future proof.
> 
> On Wed, Feb 12, 2020 at 10:50 PM Linus Björnstam 
> <linus.bjornstam@veryfast.biz> wrote:
> > If guile ever gets cross-module Inlining in even the simplest form, this will break. This kind of inlining is probably the most secure one to rely on ever (my for loops rely on it, for example). A more future proof option is maybe to (set! ...) A variable within the same module, which makes it implicitly boxed. Slow unless guile is able to do unboxing...
> > 
> >  Ludo used the trick here: http://git.savannah.gnu.org/cgit/guile.git/commit/?id=bf1f5422bdb364667d6761dd73454558d6dbf895
> > 
> >  -- 
> >  Linus Björnstam
> > 
> >  On Wed, 12 Feb 2020, at 18:44, Stefan Israelsson Tampe wrote:
> >  > Hi all,
> >  > 
> >  > Current guile inlines even variables exposed in the module interface, 
> >  > and I understand that we must live with that and code around it. So 
> >  > here is a few tips how to mitigate it.
> >  > 
> >  > The simplest way is to put this definition in a module:
> >  > ------------------------
> >  > (define-module (syntax not-inline)
> >  > #:export (not-inline))
> >  > 
> >  > (cond-expand
> >  > (guile-3.0
> >  > (define (not-inline x) x))
> >  > ((or (guile-2.0 guile-2.2)
> >  > (define-syntax-rule (not-inline x) x)))
> >  > 
> >  > -------------------------------------
> >  > And then in another module do,
> >  > 
> >  > (use-modules (syntax not-inline))
> >  > (define variable (not-inline 12))
> >  > (define function (not-inline (lambda () ...)))
> >  > etc
> >  > 
> >  > This is also an option (not perfect but you get the gist)
> >  > 
> >  > -----------------------------------------------------------------
> >  > (define-module (syntax define-not-inlinable)
> >  > #:use-module (syntax not-inline)
> >  > #:export (inline define lambda define* lambda* define-values)
> >  > (define inline (lambda (x) x))
> >  > (define-syntax define
> >  > (syntax-rules (inline)
> >  > ((define (f . x) . code)
> >  > (define f (not-inline (lambda x . code)))
> >  > ((define f (inline x))
> >  > (define f x))
> >  > ((define f x)
> >  > (define f (not-inlinable x))))
> >  > ----------------------------------------------------------------------------------
> >  > using this module will make all usual define not inlineable and to 
> >  > enable inlining you would
> >  > explicitly ask for it like
> >  > 
> >  > (define f (inline (lambda (x) (+ x 10))))
> >  > 
> >  > If there is a need for this I can write the modules and expose it on 
> >  > the intertubes.
> >  > 
> >  > WDYT
> >  > 
> >  > /Stefan
> >  > 
> >  > 
> >  > 
> >  >



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-13 13:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-12 17:44 Prevent inlining Stefan Israelsson Tampe
2020-02-12 21:49 ` Linus Björnstam
2020-02-13  7:36   ` Stefan Israelsson Tampe
2020-02-13 13:38     ` Linus Björnstam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).