Jump to page: 1 2
Thread overview
[Issue 4397] New: D1 const does not work
Jun 27, 2010
nfxjfg@gmail.com
[Issue 4397] D1 const/CTFE does not work
Jul 12, 2010
nfxjfg@gmail.com
[Issue 4397] const/CTFE does not work
Jul 12, 2010
nfxjfg@gmail.com
Jul 26, 2010
Don
Jul 28, 2010
Sobirari Muhomori
Jul 28, 2010
Don
Jul 28, 2010
nfxjfg@gmail.com
Jul 28, 2010
nfxjfg@gmail.com
Jul 29, 2010
Sobirari Muhomori
Jul 29, 2010
Don
Jul 29, 2010
Christian Kamm
Sep 01, 2010
nfxjfg@gmail.com
Oct 23, 2010
nfxjfg@gmail.com
Jan 07, 2011
nfxjfg@gmail.com
Jan 07, 2011
Brad Roberts
Feb 02, 2012
yebblies
Feb 02, 2012
Don
Mar 19, 2013
Don
Apr 18, 2013
Don
June 27, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4397

           Summary: D1 const does not work
           Product: D
           Version: D1 & D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: regression
          Priority: P1
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: nfxjfg@gmail.com


--- Comment #0 from nfxjfg@gmail.com 2010-06-27 10:30:32 PDT ---
In the following example, foo() will create an array literal on each call, instead of returning a statically shared / compile time value. On D2, the same may happen when using enum instead of const (I didn't test it).

In many cases, this codegen bug may go unnoticed, which makes it just worse.

$ cat rtz.d
struct X {
    int[] a;
}

const cX = X([1,2]);

X foo() {
    return cX;
}

$ dmd -c rtz.d
$ objdump -d -Mintel rtz.o -r
...
00000000 <_D3rtz3fooFZS3rtz1X>:
   0:   55                      push   ebp
   1:   8b ec                   mov    ebp,esp
   3:   83 ec 08                sub    esp,0x8
   6:   53                      push   ebx
   7:   6a 02                   push   0x2
   9:   6a 01                   push   0x1
   b:   6a 02                   push   0x2
   d:   b8 00 00 00 00          mov    eax,0x0
                        e: R_386_32     _D11TypeInfo_Ai6__initZ
  12:   50                      push   eax
  13:   e8 fc ff ff ff          call   14 <_D3rtz3fooFZS3rtz1X+0x14>
                        14: R_386_PC32  _d_arrayliteralT
  18:   89 c1                   mov    ecx,eax
  1a:   bb 02 00 00 00          mov    ebx,0x2
  1f:   89 5d f8                mov    DWORD PTR [ebp-0x8],ebx
  22:   89 4d fc                mov    DWORD PTR [ebp-0x4],ecx
  25:   8b 55 fc                mov    edx,DWORD PTR [ebp-0x4]
  28:   8b 45 f8                mov    eax,DWORD PTR [ebp-0x8]
  2b:   83 c4 10                add    esp,0x10
  2e:   5b                      pop    ebx
  2f:   c9                      leave
  30:   c3                      ret

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 12, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4397


nfxjfg@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|D1 const does not work      |D1 const/CTFE does not work


--- Comment #1 from nfxjfg@gmail.com 2010-07-11 22:02:35 PDT ---
Does anyone know a workaround for this?
It's starting to get annoying, and Walter probably died, so it will take a
while until this is fixed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 12, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4397


nfxjfg@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|D1 const/CTFE does not work |const/CTFE does not work


--- Comment #2 from nfxjfg@gmail.com 2010-07-11 22:04:16 PDT ---
(Wrong code on v2.046 too, when switching const with enum.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 26, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4397


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au
           Severity|regression                  |major


--- Comment #3 from Don <clugdbug@yahoo.com.au> 2010-07-26 01:25:23 PDT ---
This generated code is identical on 1.020: this is not a regression.
Downgrading to major.
I don't see any evidence that it's wrong-code, either: it seems to be a
performance issue. Finally, it looks like a duplicate of bug 2356.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 28, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4397



--- Comment #4 from Sobirari Muhomori <dfj1esp02@sneakemail.com> 2010-07-28 12:04:59 PDT ---
Shouldn't literals be immutable and the code - invalid?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 28, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4397



--- Comment #5 from Don <clugdbug@yahoo.com.au> 2010-07-28 12:29:57 PDT ---
(In reply to comment #4)
> Shouldn't literals be immutable and the code - invalid?

I think they *should*. I argued strongly for immutable array literals. But I
lost.
So the code is valid, but likely to be very slow for a very long time.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 28, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4397



--- Comment #6 from nfxjfg@gmail.com 2010-07-28 13:05:25 PDT ---
It's not valid. This is a systems programming language, and the compiler can't just randomly insert memory allocations. What if you wrote a kernel in D? I insist on the wrong-code keyword.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 28, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4397



--- Comment #7 from nfxjfg@gmail.com 2010-07-28 13:06:29 PDT ---
>and the compiler can't just randomly insert memory allocations.
Add "that are not supposed to be there".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4397



--- Comment #8 from Sobirari Muhomori <dfj1esp02@sneakemail.com> 2010-07-28 19:57:40 PDT ---
Well... there can be a problem with immutable literals because immutability is
transitive... hmm...
Even if literals aren't immutable, compiler can still catch assignment of
literal to mutable array and report error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4397


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|wrong-code                  |performance


--- Comment #9 from Don <clugdbug@yahoo.com.au> 2010-07-28 23:01:36 PDT ---
(In reply to comment #8)
> Well... there can be a problem with immutable literals because immutability is
> transitive... hmm...
> Even if literals aren't immutable, compiler can still catch assignment of
> literal to mutable array and report error.

But it is EXPLICITLY LEGAL to assign a literal to a mutable array. There is an
invisible dup by design. I don't like this, I argued strongly against it, but
it's in there. This isn't wrong code.
(Similarly, you can write const C x = new C; The C will be allocated on the
heap, even though it will never change afterwards).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2