unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Refactoring dynamic roots
@ 2005-01-24 20:55 Marius Vollmer
  2005-01-25 10:03 ` Andy Wingo
  2005-01-28 21:04 ` Kevin Ryde
  0 siblings, 2 replies; 12+ messages in thread
From: Marius Vollmer @ 2005-01-24 20:55 UTC (permalink / raw)


Hi,

I have a dim plan for redoing dynamic roots in a more useful way and I
like to test the ideas out on you.

Right now, dynamic roots are useful mainly for two things: controlling
continuations so that they don't jump past you, and isolating changes
to the 'dynamic state' (the values of all fluids and the current
ports) of Guile.  I want to separate these two functionalities since
you might want one without the other.  Also, entering a dynamic root
now unwinds the active dynamic-winds to the root and winds them back
when leaving the root.  This might not be wanted and is potentially
expensive.

Also, the roles of dynamic roots in Guile is not as clear now as it
could be, in my view, and cleaning them up will make the internals a
lot simpler, I hope.

** Controlling continuations

Controlling continuations is useful when invoking Scheme callbacks
from C code in a situation where the C code must guarantee that the
callback returns exactly once.

There is a proposal for this in workbook/extensions/dynamic-root.text,
but I want to simplify this even more by not caring about an exception
handler.  Error handling needs to be taken care of anyway, and I think
it is more flexible to not include it in these functions.  For
example, I hope that we have a way in the future to directly specify
an error handler that is called in the dynamic context of the error
and not in the dynamic context from where it was installed.  That
might mean that we have two ways to handle errors and I think it will
be easier to offer them when not too many functions deal with the
business of setting up error handlers.

 - void *scm_c_with_continuation_barrier (void *(func)(void *), void *data)

 Call FUNC on DATA and do not allow the invocation of continuations
 that would cross the invocation to scm_with_continuation_barrier.
 Such an attempt causes an error to be signaled.

 Throws (such as errors) that are not caught from within FUNC are
 caught by scm_with_continuation_barrier.  In that case, a short
 message is printed to the current error port and NULL is returned.

 Thus, scm_with_continuation_barrier returns exactly once.

 [ The docs for scm_with_guile would state that it includes an
   implicit call to scm_c_with_continuation_barrier. ]

 - with-continuation-barrier proc

 Like scm_c_with_continuation_barrier but return '#f' for uncaught
 throws.

** Controlling the dynamic state

The other thing that dynamic roots do is to isolate changes to the
dynamic state.  For example, calls to set-current-output-port or
fluid-set! have no effects outside of a dynamic root.  This might be
useful when running arbitrary code since the caller can protect itself
from unexpected changes to the dynamic state.  (This is not _that_
useful for sandboxing code since the code can of course change the
global state of Guile arbitrarily unless other measures are taken.)

Of course, when running arbitrary code, it is nice to give it its own
dynamic state and to use that dynamic state from one run to the next.
This can not be done with dynamic roots right now since each call to
call-with-dynamic-root creates a new root.  Therefore, the functions
below allow one to create a 'dynamic state' object that can be reused.
I think it would be nice to have 'eval' take such an object as its
second arg.  The dynamic state contains the current module, and in
that way the dynamic state might be a better representation of an
execution environment than just a module.

The implementation would be like this: each thread has a pointer to a
'current dynamic state object'.  The list of active dynamic-winds is
separate from this.  References to fluids and current ports, etc are
made to this current dynamic state object.  Evaluating code with a
different dynamic state object swaps this object in and out via
dynamic-wind.  It wont probably be the case i the beginning, but it
might be good to let a dynamic state object be just the values of the
fluids, nothing more, and do all dynamic state stuff such as the ports
with fluids.

 - make-dynamic-state [parent]

 Make a new dynamic state object and initialize it from PARENT.  When
 PARENT is omitted, the current dynamic state object is used.

 - current-dynamic-state

 Return the current dynamic state object.

 - set-current-dynamic-state state

 Make STATE the current dynamic state object.  Using
 with-dynamic-state is usually more appropriate.  [But since it is
 harmless to provide this function, we do anyway.]

 - with-dynamic-state state proc

 Call PROC while STATE is the current dynamic state object.  This
 behaves like dynamic-wind, swapping the current dynamic states when
 control flow crosses.

 - with-new-dynamic-state proc

 The same as (with-dynamic-state (make-dynamic-state) proc).

 - eval FORM [STATE]

 When the second argument to eval is a dynamic state object, evaluate
 FORM from within a suitable call to with-dynamic-state.

 - void scm_frame_dynamic_state (SCM state)

 Set the current dynamic state to STATE while the current frame is
 active.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: Refactoring dynamic roots
  2005-01-24 20:55 Refactoring dynamic roots Marius Vollmer
@ 2005-01-25 10:03 ` Andy Wingo
  2005-01-28 21:03   ` Kevin Ryde
  2005-02-01 16:23   ` Marius Vollmer
  2005-01-28 21:04 ` Kevin Ryde
  1 sibling, 2 replies; 12+ messages in thread
From: Andy Wingo @ 2005-01-25 10:03 UTC (permalink / raw)


Hi Marius,


On Mon, 2005-01-24 at 21:55 +0100, Marius Vollmer wrote:
> I have a dim plan for redoing dynamic roots in a more useful way and I
> like to test the ideas out on you.

Yay :)

> Also, entering a dynamic root
> now unwinds the active dynamic-winds to the root and winds them back
> when leaving the root.  This might not be wanted and is potentially
> expensive.

Whenever I've been tempted to use a dynamic root for something, this has
been a sticking point. Probably because of the conflation of
continuation barriers and new dynamic states, as you are calling them.

> ** Controlling the dynamic state

It does sound like a good idea to have ports be represented by fluids
underneath.

Have you seen http://srfi.schemers.org/srfi-39/srfi-39.html -- Parameter
objects? As long as we're redesigning, no harm in using a standard
interface to the problem.

Cheers,
-- 
Andy Wingo
http://wingolog.org/



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: Refactoring dynamic roots
  2005-01-25 10:03 ` Andy Wingo
@ 2005-01-28 21:03   ` Kevin Ryde
  2005-01-29  0:13     ` Marius Vollmer
  2005-02-01 16:23   ` Marius Vollmer
  1 sibling, 1 reply; 12+ messages in thread
From: Kevin Ryde @ 2005-01-28 21:03 UTC (permalink / raw)
  Cc: guile-user

Andy Wingo <wingo@pobox.com> writes:
>
> Have you seen http://srfi.schemers.org/srfi-39/srfi-39.html -- Parameter
> objects? As long as we're redesigning, no harm in using a standard
> interface to the problem.

I added some ugly code to make srfi-39.scm do what the spec says for
current-input-port etc.  (Actually, maybe current-load-port should be
added there too.)

Making them fluids would be easier.  Users of the ports in libguile
could either call scm_fluid_ref, or have a guarantee there's always 4
entries in the root->fluids vector and fetch directly.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: Refactoring dynamic roots
  2005-01-24 20:55 Refactoring dynamic roots Marius Vollmer
  2005-01-25 10:03 ` Andy Wingo
@ 2005-01-28 21:04 ` Kevin Ryde
  2005-01-29  0:17   ` Marius Vollmer
  1 sibling, 1 reply; 12+ messages in thread
From: Kevin Ryde @ 2005-01-28 21:04 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer <marius.vollmer@uni-dortmund.de> writes:
>
> The other thing that dynamic roots do is to isolate changes to the
> dynamic state.  For example, calls to set-current-output-port or
> fluid-set! have no effects outside of a dynamic root.  This might be
> useful when running arbitrary code since the caller can protect itself
> from unexpected changes to the dynamic state.  (This is not _that_
> useful for sandboxing code since the code can of course change the
> global state of Guile arbitrarily unless other measures are taken.)

I'm unsure about this bit.  If you trust the code enough not to mangle
global variables, can't you trust it enough not to mangle fluids too?


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: Refactoring dynamic roots
  2005-01-28 21:03   ` Kevin Ryde
@ 2005-01-29  0:13     ` Marius Vollmer
  2005-01-29 17:10       ` Neil Jerram
  0 siblings, 1 reply; 12+ messages in thread
From: Marius Vollmer @ 2005-01-29  0:13 UTC (permalink / raw)
  Cc: guile-user

Kevin Ryde <user42@zip.com.au> writes:

> Making them fluids would be easier.

In my working copy, current input port etc are now fluids.  There is
no dynamic state that isn't a fluid.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: Refactoring dynamic roots
  2005-01-28 21:04 ` Kevin Ryde
@ 2005-01-29  0:17   ` Marius Vollmer
  2005-02-01 23:43     ` Kevin Ryde
  0 siblings, 1 reply; 12+ messages in thread
From: Marius Vollmer @ 2005-01-29  0:17 UTC (permalink / raw)
  Cc: guile-user

Kevin Ryde <user42@zip.com.au> writes:

> Marius Vollmer <marius.vollmer@uni-dortmund.de> writes:
>>
>> The other thing that dynamic roots do is to isolate changes to the
>> dynamic state.  For example, calls to set-current-output-port or
>> fluid-set! have no effects outside of a dynamic root.  This might be
>> useful when running arbitrary code since the caller can protect itself
>> from unexpected changes to the dynamic state.  (This is not _that_
>> useful for sandboxing code since the code can of course change the
>> global state of Guile arbitrarily unless other measures are taken.)
>
> I'm unsure about this bit.  If you trust the code enough not to mangle
> global variables, can't you trust it enough not to mangle fluids too?

Hmm, it is probably not so much about trust, but about being nice to
the code that you run: you want to give it its own dynamic state
because that is very useful.

Of course you have to trust the code that you run.  If you do not
trust it but want to run it anyway, my answer would be to isolate the
whole guile process with the means provided by the OS, such as
chrooting it, running it as nobody, etc.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: Refactoring dynamic roots
  2005-01-29  0:13     ` Marius Vollmer
@ 2005-01-29 17:10       ` Neil Jerram
  2005-02-01 16:20         ` Marius Vollmer
  0 siblings, 1 reply; 12+ messages in thread
From: Neil Jerram @ 2005-01-29 17:10 UTC (permalink / raw)
  Cc: Guile Gnu

Marius Vollmer wrote:
> 
> In my working copy, current input port etc are now fluids.  There is
> no dynamic state that isn't a fluid.
> 

Which reminds me of the one thought I had, namely globally replacing 
"dynamic-state" in your proposal by "fluid-state".  To my mind, this 
would have the advantage that it would be obvious that fluids were 
connected with the fluid-state.

(Alternatively, could change "make-fluid" etc. to "make-dynamic"; but 
I'm assuming that the term "fluid" is more established in the standards 
and literature - is this correct?)

(In general, by the way, I'm very happy with this and your other recent 
proposals.)

Regards,
	Neil


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: Refactoring dynamic roots
  2005-01-29 17:10       ` Neil Jerram
@ 2005-02-01 16:20         ` Marius Vollmer
  2005-02-02  5:56           ` Neil Jerram
  0 siblings, 1 reply; 12+ messages in thread
From: Marius Vollmer @ 2005-02-01 16:20 UTC (permalink / raw)
  Cc: Guile Gnu

Neil Jerram <neil@ossau.uklinux.net> writes:

> Marius Vollmer wrote:
>> In my working copy, current input port etc are now fluids.  There is
>> no dynamic state that isn't a fluid.
>>
>
> Which reminds me of the one thought I had, namely globally replacing
> "dynamic-state" in your proposal by "fluid-state".  To my mind, this
> would have the advantage that it would be obvious that fluids were
> connected with the fluid-state.

Hmm.  Fluids are part of the dynamic state, and right now, they are
the only things in the dynamic state, so you have a point.  On the
other hand, there are also 'parameters' that are built on top of
fluids and provide an alternative interface, and thus, we could call
the dynamic state "parameter state"...

I am more comfortable just calling it the "dynamic state".

> (Alternatively, could change "make-fluid" etc. to "make-dynamic"; but
> I'm assuming that the term "fluid" is more established in the
> standards and literature - is this correct?)

There are many things called fluids, and they are mostly concerned
about simulating dynamic scope, I think.

> (In general, by the way, I'm very happy with this and your other
> recent proposals.)

Thanks!


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: Refactoring dynamic roots
  2005-01-25 10:03 ` Andy Wingo
  2005-01-28 21:03   ` Kevin Ryde
@ 2005-02-01 16:23   ` Marius Vollmer
  1 sibling, 0 replies; 12+ messages in thread
From: Marius Vollmer @ 2005-02-01 16:23 UTC (permalink / raw)
  Cc: guile-user

Andy Wingo <wingo@pobox.com> writes:

> Have you seen http://srfi.schemers.org/srfi-39/srfi-39.html -- Parameter
> objects? As long as we're redesigning, no harm in using a standard
> interface to the problem.

We have an implementation of SRFI-39, it uses fluids at the core.
Maybe we should switch the roles sometime, making parameters the basic
mechanism and basing fluids on them.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: Refactoring dynamic roots
  2005-01-29  0:17   ` Marius Vollmer
@ 2005-02-01 23:43     ` Kevin Ryde
  2005-02-02 13:55       ` Marius Vollmer
  0 siblings, 1 reply; 12+ messages in thread
From: Kevin Ryde @ 2005-02-01 23:43 UTC (permalink / raw)
  Cc: guile-user

Marius Vollmer <mvo@zagadka.de> writes:
>
> you want to give it its own dynamic state because that is very
> useful.

Do you have an example in mind?

Splitting out dynamic state is probably quite clean, but I can't think
of an actual use for it.  I would imagine normal use is just to
with-fluid or whatever on selected fluids/parameters/current-ports
which have an influence on whatever is done.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: Refactoring dynamic roots
  2005-02-01 16:20         ` Marius Vollmer
@ 2005-02-02  5:56           ` Neil Jerram
  0 siblings, 0 replies; 12+ messages in thread
From: Neil Jerram @ 2005-02-02  5:56 UTC (permalink / raw)
  Cc: Guile Gnu

Marius Vollmer wrote:
> 
> I am more comfortable just calling it the "dynamic state".
> 

Fair enough - it was just a thought.

	Neil


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: Refactoring dynamic roots
  2005-02-01 23:43     ` Kevin Ryde
@ 2005-02-02 13:55       ` Marius Vollmer
  0 siblings, 0 replies; 12+ messages in thread
From: Marius Vollmer @ 2005-02-02 13:55 UTC (permalink / raw)
  Cc: guile-user

Kevin Ryde <user42@zip.com.au> writes:

> Marius Vollmer <mvo@zagadka.de> writes:
>>
>> you want to give it its own dynamic state because that is very
>> useful.
>
> Do you have an example in mind?

Hmm, maybe running a repl: the code managing the repl and the cde that
is actually evaluated in it might each want to have their own dynamic
state.  For example, the current module of the evaluated code will
likely be different from the current module of the code that manages
the repl.

The behavior of eval would become more clean, in general.  For
example

  (eval '(define-module (foo)) (current-module))

will temporarily set the current module to (foo) as a side effect of
define-module, but eval will revert it to the module that was current
when eval was called.  If you want the current module change to stick,
you would have to use primitive-eval.

In contrast, you could use a dynamic state to carry 'dynamic state
information' from one call to eval to the next but while still being
isolated from changes to this state.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

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

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-24 20:55 Refactoring dynamic roots Marius Vollmer
2005-01-25 10:03 ` Andy Wingo
2005-01-28 21:03   ` Kevin Ryde
2005-01-29  0:13     ` Marius Vollmer
2005-01-29 17:10       ` Neil Jerram
2005-02-01 16:20         ` Marius Vollmer
2005-02-02  5:56           ` Neil Jerram
2005-02-01 16:23   ` Marius Vollmer
2005-01-28 21:04 ` Kevin Ryde
2005-01-29  0:17   ` Marius Vollmer
2005-02-01 23:43     ` Kevin Ryde
2005-02-02 13:55       ` Marius Vollmer

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).