RE: Bug when using program as key of mapping

View: New views
10 Messages — Rating Filter:   Alert me  

RE: Bug when using program as key of mapping

by 郭雪松 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!

Everyone not agree with me ? give me a response please.

I think it is important to make a constant of class a really constant, don’t you think so?


RE: Bug when using program as key of mapping‏
发件人:
雪松 郭 (zenothing@...)
发送时间:
2009年8月26日 8:05:49
收件人:
grubba@...; peterpan@...
抄送:
pike@... (pike@...)
I see. But it sould still be considered as a bug.
 
I modified your class A as following:
 
class A {
 class B {
  mixed b() {
   return A.C;
   //return C;
  }
 }
 class C {
 }
}

Since C is a constant of class A, B.b() reference a constant of its parent scope.
Why it should be considered as whatever PROGRAM_USES_PARENT ?
 
I think A.C has the same position of constants such as "hello", 1,2,3 ...
 
If the class referenced A.C become a function, then the classes referenced any constant string or number should be function too.
 
"A program is no more a constant because it reference another constant"? it's a joke!
 


Xuesong Guo



Re: Bug when using program as key of mapping

by Martin Stjernholm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

<peterpan@...> wrote:

> I think it is important to make a constant of class a really
> constant, don’t you think so?

You're right that pike could do a better job in that case, but I
regard it as a lack of optimization rather than a bug. I wouldn't rely
on classes being constant since they easily can get a parent pointer
through internal implementation changes.

It's probably not that easy to fix the optimization you want since the
property of not being constant spreads: Consider in your example that
A.C is changed to refer to a nonconstant in A. Then A.C gets a parent
pointer and is no longer constant, and that causes A.B to refer to a
nonconstant so it gets a parent pointer and becomes nonconstant too. I
reckon this propagation could be problematic in the pike compiler
since it's only two pass and would have to sort it out already in the
first pass.

Anyway, you can work around the problem by using e.g. all_constants():

  class A {
    class B {
      mixed b() {
        return all_constants()->MyA->C;
      }
    }
    class C {
    }
  }

  int main()
  {
    all_constants()->MyA = A;
    werror ("%O\n", functionp (A()->B));
  }

Yes, that's ugly, but it works. Just note that all_constants()
contains all top level identifiers, so watch out so you don't override
something accidentally.


> I see. But it sould still be considered as a bug.
>  
> I modified your class A as following:
>  
> class A {
>  class B {
>   mixed b() {
>    return A.C;
>    //return C;
>   }
>  }
>  class C {
>  }
> }
>
> Since C is a constant of class A, B.b() reference a constant of its parent scope.
> Why it should be considered as whatever PROGRAM_USES_PARENT ?
>  
> I think A.C has the same position of constants such as "hello", 1,2,3 ...
>  
> If the class referenced A.C become a function, then the classes referenced any constant string or number should be function too.
>  
> "A program is no more a constant because it reference another constant"? it's a joke!
>  
>
>
> Xuesong Guo


答复: Bug when using program as key of mapping

by 郭雪松 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How about adding a keyword ' hide_parent' to forbid a class or function access vars in parent?
For example:

 class A {
  hide_parent class B {
   mixed b() {
    return A.C;
    //return C;
   }
  }
  hide_parent class C {
  }
 }

If B or C reference any var in A, throw a error.


-----邮件原件-----
发件人: Martin Stjernholm [mailto:mast@...]
发送时间: 2009年10月9日 22:59
收件人: peterpan@...
抄送: 'Pike mailinglist'
主题: Re: Bug when using program as key of mapping

<peterpan@...> wrote:

> I think it is important to make a constant of class a really
> constant, don’t you think so?

You're right that pike could do a better job in that case, but I
regard it as a lack of optimization rather than a bug. I wouldn't rely
on classes being constant since they easily can get a parent pointer
through internal implementation changes.

It's probably not that easy to fix the optimization you want since the
property of not being constant spreads: Consider in your example that
A.C is changed to refer to a nonconstant in A. Then A.C gets a parent
pointer and is no longer constant, and that causes A.B to refer to a
nonconstant so it gets a parent pointer and becomes nonconstant too. I
reckon this propagation could be problematic in the pike compiler
since it's only two pass and would have to sort it out already in the
first pass.

Anyway, you can work around the problem by using e.g. all_constants():

  class A {
    class B {
      mixed b() {
        return all_constants()->MyA->C;
      }
    }
    class C {
    }
  }

  int main()
  {
    all_constants()->MyA = A;
    werror ("%O\n", functionp (A()->B));
  }

Yes, that's ugly, but it works. Just note that all_constants()
contains all top level identifiers, so watch out so you don't override
something accidentally.


> I see. But it sould still be considered as a bug.
>  
> I modified your class A as following:
>  
> class A {
>  class B {
>   mixed b() {
>    return A.C;
>    //return C;
>   }
>  }
>  class C {
>  }
> }
>
> Since C is a constant of class A, B.b() reference a constant of its parent scope.
> Why it should be considered as whatever PROGRAM_USES_PARENT ?
>  
> I think A.C has the same position of constants such as "hello", 1,2,3 ...
>  
> If the class referenced A.C become a function, then the classes referenced any constant string or number should be function too.
>  
> "A program is no more a constant because it reference another constant"? it's a joke!
>  
>
>
> Xuesong Guo


Re: 答复: Bug when using program as key of mapping

by Martin Bähr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, Oct 10, 2009 at 12:43:16PM +0800, 郭雪松 wrote:
> How about adding a keyword ' hide_parent' to forbid a class or function access vars in parent?
> If B or C reference any var in A, throw a error.

doesn't private do exactly that?

greetings, martin.
--
cooperative communication with sTeam      -     caudium, pike, roxen and unix
searching contract jobs:  programming, training and administration - anywhere
--
pike programmer      working in china                   community.gotpike.org
foresight developer  foresightlinux.org                        open-steam.org
unix sysadmin        iaeste.(tuwien.ac|or).at                     caudium.org
Martin Bähr          http://www.iaeste.or.at/~mbaehr/            is.schon.org


答复: 答复: Bug when using program as key of mapping

by 郭雪松 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

'private' not.

class A {
  int t;
  private class C1 {
          void create()
          {
                  t=1; //it's ok
          }
  }
  hide_parent class C2 {
          void create()
          {
                  t=1; //throw a error
          }
  }
}


-----邮件原件-----
发件人: Martin Bähr [mailto:mbaehr@...]
发送时间: 2009年10月10日 14:13
收件人: 郭雪松
抄送: pike@...; mast@...
主题: Re: 答复: Bug when using program as key of mapping

On Sat, Oct 10, 2009 at 12:43:16PM +0800, 郭雪松 wrote:
> How about adding a keyword ' hide_parent' to forbid a class or function access vars in parent?
> If B or C reference any var in A, throw a error.

doesn't private do exactly that?

greetings, martin.
--
cooperative communication with sTeam      -     caudium, pike, roxen and unix
searching contract jobs:  programming, training and administration - anywhere
--
pike programmer      working in china                   community.gotpike.org
foresight developer  foresightlinux.org                        open-steam.org
unix sysadmin        iaeste.(tuwien.ac|or).at                     caudium.org
Martin Bähr          http://www.iaeste.or.at/~mbaehr/            is.schon.org


Re: 答复: 答复: Bug when using program as key of mapping

by Martin Bähr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, Oct 10, 2009 at 02:43:03PM +0800, 郭雪松 wrote:

> 'private' not.
>
> class A {
>   int t;
>   private class C1 {
>  void create()
>  {
>  t=1; //it's ok
>  }
>   }
>   hide_parent class C2 {
>  void create()
>  {
>  t=1; //throw a error
>  }
>   }
> }

ahh, you want to lock out access to the outer class.
then why is C2 inside of A at all?

you could write:
class A { ... }
class C2 { ... }

greetings, martin.
--
cooperative communication with sTeam      -     caudium, pike, roxen and unix
searching contract jobs:  programming, training and administration - anywhere
--
pike programmer      working in china                   community.gotpike.org
foresight developer  foresightlinux.org                        open-steam.org
unix sysadmin        iaeste.(tuwien.ac|or).at                     caudium.org
Martin Bähr          http://www.iaeste.or.at/~mbaehr/            is.schon.org


答复: 答复: 答复: Bug when using program as key of mapping

by 郭雪松 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I want C2 to be a constant inside A.

-----邮件原件-----
发件人: 'Martin Bähr' [mailto:mbaehr@...]
发送时间: 2009年10月10日 15:09
收件人: 郭雪松
抄送: pike@...; mast@...
主题: Re: 答复: 答复: Bug when using program as key of mapping

On Sat, Oct 10, 2009 at 02:43:03PM +0800, 郭雪松 wrote:

> 'private' not.
>
> class A {
>   int t;
>   private class C1 {
>  void create()
>  {
>  t=1; //it's ok
>  }
>   }
>   hide_parent class C2 {
>  void create()
>  {
>  t=1; //throw a error
>  }
>   }
> }

ahh, you want to lock out access to the outer class.
then why is C2 inside of A at all?

you could write:
class A { ... }
class C2 { ... }

greetings, martin.
--
cooperative communication with sTeam      -     caudium, pike, roxen and unix
searching contract jobs:  programming, training and administration - anywhere
--
pike programmer      working in china                   community.gotpike.org
foresight developer  foresightlinux.org                        open-steam.org
unix sysadmin        iaeste.(tuwien.ac|or).at                     caudium.org
Martin Bähr          http://www.iaeste.or.at/~mbaehr/            is.schon.org


Re: 答复: 答复: 答复: Bug when using program as key of mapping

by Martin Bähr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, Oct 10, 2009 at 03:24:20PM +0800, 郭雪松 wrote:
> I want C2 to be a constant inside A.

but why?
you aparently do not want C2 to depend on the context that A provides.

if it is a simple access issue you could probably do:

class C2_ { ... }
class A
{
  constant C2 = C2_;
}

greetings, martin.
--
cooperative communication with sTeam      -     caudium, pike, roxen and unix
searching contract jobs:  programming, training and administration - anywhere
--
pike programmer      working in china                   community.gotpike.org
foresight developer  foresightlinux.org                        open-steam.org
unix sysadmin        iaeste.(tuwien.ac|or).at                     caudium.org
Martin Bähr          http://www.iaeste.or.at/~mbaehr/            is.schon.org


答复: Bug when using program as key of mapping

by 郭雪松 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Because class A is a single file A.pike, and C2 belong to A, take C2 out and add a file C2.pike is boring.

-----邮件原件-----
发件人: 'Martin Bähr' [mailto:mbaehr@...]
发送时间: 2009年10月10日 15:41
收件人: 郭雪松
抄送: pike@...; mast@...
主题: Re: 答复: 答复: 答复: Bug when using program as key of mapping

On Sat, Oct 10, 2009 at 03:24:20PM +0800, 郭雪松 wrote:
> I want C2 to be a constant inside A.

but why?
you aparently do not want C2 to depend on the context that A provides.

if it is a simple access issue you could probably do:

class C2_ { ... }
class A
{
  constant C2 = C2_;
}

greetings, martin.
--
cooperative communication with sTeam      -     caudium, pike, roxen and unix
searching contract jobs:  programming, training and administration - anywhere
--
pike programmer      working in china                   community.gotpike.org
foresight developer  foresightlinux.org                        open-steam.org
unix sysadmin        iaeste.(tuwien.ac|or).at                     caudium.org
Martin Bähr          http://www.iaeste.or.at/~mbaehr/            is.schon.org


Re: 答复: Bug when using program as key of mapping

by Martin Stjernholm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

郭雪松 <peterpan@...> wrote:

> Because class A is a single file A.pike, and C2 belong to A, take C2
> out and add a file C2.pike is boring.

Understandable, but adding a keyword to control an aspect of an
implementation detail is quite boring too. This is what a real
"static" property should do.

In the meantime, there are ways to work around it. Another option
could be to have a module.pmod top level instead and put both the
inner classes and the outer class there. Then at least they are in the
same file. They might not be constant in the sense that they'll lack
parent pointers, but they will be just as much singletons as other
constants.