-
-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shrink Loc from 12 to 4 bytes #20777
Conversation
Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#20777" |
c7bbd75
to
c06d923
Compare
c06d923
to
8cf72d8
Compare
After a quick glance, it looks like LDC only ever creates default-constructed |
I see a few instances my end. At a quick glance, only one use of which I can't rewrite in a minute.
-> Getting a location for debug info |
8cf72d8
to
8279c48
Compare
Would it help if I exposed |
e72dcd1
to
954bfe3
Compare
Does anyone know how to debug this segfault on Ubuntu 22.04 x86, DMD (latest)?
|
I would first try dustmiting |
You could hack Line 69 in af002fc
|
954bfe3
to
28e86e5
Compare
Can you run dustmite on CI? I don't have a 32-bit pc, so I can't reproduce it locally. Maybe I should try setting up a VM.
Thanks, I'll give it a try Edit: the stack trace is now more informative
|
28e86e5
to
c3f79c7
Compare
Hmm, dust mite is probably overkill, you might be able to manually bisect the |
065be3d
to
2587c22
Compare
compiler/src/dmd/location.d
Outdated
// https://github.com/dlang/dmd/pull/20777#issuecomment-2614128849 | ||
static if (size_t.sizeof == 4) version(linux) | ||
{ | ||
uint dummy; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I found a fix 🤦
Clearly the optimization is just too good for i386 Linux to handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want DigitalMars instead of Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The failure is specific to Ubuntu x86, Windows x86 works fine. It's also specific to DMD compiled with DMD latest, not DMD bootstrap. It happens when calling StructDeclaration.setZeroInit(bool)
, which is a simple bit field setter. this
is not null
, and setting this.bitFields = 0
doesn't trigger it, so what kind of memory access even triggers the segfault? I truly can't explain this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the stack frame is really shallow (13 frames), I can't imagine it hitting the guard page
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a bug in the old DMD bootstrap compiler, then please use both version(linux)
(or Posix, I can't imagine this to be Linux specific) and version(DigitalMars)
, so that the ugly workaround doesn't apply when using LDC or GDC (incl. x86 builds of those compilers themselves, as they hardly use DMD as a host compiler).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also specific to DMD compiled with DMD latest, not DMD bootstrap.
Oh sorry, I misread that - so even worse, a regression in recent versions?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#20786 indicates that the regression was introduced in DMD v2.105.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the investigation!
version(DigitalMars)
How do I put that in the C++ header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By chance, I do have a debian 12 x86 VM to hand, and couldn't reproduce the segfault with the host compiler being either 2.104, 2.105, or 2.109.
Not sure it's really worth getting an ubuntu 22.04 x86 VM set up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I put that in the C++ header?
See dcompat.h
https://github.com/dlang/dmd/blob/master/compiler/src/dmd/root/dcompat.h#L42-L43
2587c22
to
94eb22e
Compare
521cd1b
to
78c8d3b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few last remarks for gdc/ldc compat. Otherwise looks fine.
78c8d3b
to
7d40082
Compare
7d40082
to
beacb51
Compare
Instead of storing separate filename, line, column fields in
Loc
, make it a 4-byte index into a data structure.Firstly, this adds easy
fileOffset
access toLoc
without needingversion (DMDLIB)
anymore (which increases Loc.sizeof from 12 to 16). Secondly, this reduces memory consumption and page faults:When compiling Phobos unittests:
So RAM usage basically goes from 16GB to 15Gb.
As you can see the total time is still slightly larger, because retrieving a loc's line / column data now requires a binary search instead of just reading a variable. However, this can still be optimized further.
I'll document this more later, for now I'm focusing on testing if it works.
Edit: documentation on how it works can be found in comment above
struct BaseLoc