ldc-developers / ldc

The LLVM-based D Compiler.
http://wiki.dlang.org/LDC
Other
1.19k stars 256 forks source link

Building on x86: std/math.d(10002): Error: shift by -28 is outside the range 0..31 #3787

Open UnitedMarsupials opened 3 years ago

UnitedMarsupials commented 3 years ago

The build of 1.26.0 here gets through 60% of the process and dies with:

std/math/algebraic.d(1073): Error: shift by -28 is outside the range 0..31
std/math/algebraic.d(818):        called from here: `powIntegralImpl(val)`
std/uni/package.d(1128):        called from here: `nextPow2(12u)`
std/uni/package.d(870): Error: template instance `std.uni.spaceFor!13u` error instantiating
std/uni/package.d(3865):        instantiated from here: `MultiArray!(BitPacked!(uint, 13u), BitPacked!(bool, 1u))`
std/uni/package.d(4299):        instantiated from here: `TrieBuilder!(bool, dchar, 1114112, sliceBits!(8u, 21u), sliceBits!(0u, 8u))`
std/regex/internal/ir.d(26):        instantiated from here: `CodepointSetTrie!(13, 8)`

The actual function is:

pragma(inline, true)
private T powIntegralImpl(PowType type, T)(T val)
{
    import core.bitop : bsr;

    if (val == 0 || (type == PowType.ceil && (val > T.max / 2 || val == T.min)))
        return 0;
    else
    {
        static if (isSigned!T)
            return cast(Unqual!T) (val < 0 ? -(T(1) << bsr(0 - val) + type) : T(1) << bsr(val) + type);
        else
            return cast(Unqual!T) (T(1) << bsr(val) + type);
    }
}

and the problem is in the second (unsigned) branch of the static if. Is there a known solution? Thank you!

Or, perhaps, my change to bsr() -- posted in #3785 -- is invalid?

JohanEngelen commented 3 years ago

std.math.algebraic does not exist in LDC 1.26. run git submodule update to set the Phobos submodule to the correct version belonging to the compiler you are building.

UnitedMarsupials commented 3 years ago

std.math.algebraic does not exist in LDC 1.26.

So, I found a new bug?

run git submodule update to set the Phobos submodule to the correct version belonging to the compiler you are building.

What's the last tag (or, at least, hash) for Phobos, that works with LDC 1.26? I wish, this was easy to find... Thank you!

dnadlinger commented 3 years ago

So, I found a new bug?

No, you are using the wrong Phobos version, or still have stale files somewhere in your source tree.

What's the last tag (or, at least, hash) for Phobos, that works with LDC 1.26? I wish, this was easy to find... Thank you!

The corresponding version is stored in the Git tree via the submodule hash. Just run git submodule update as Johan mentioned.

I wouldn't try using a newer Phobos version than actually corresponds to 1.26; at the very least, it is unsupported from our side.

UnitedMarsupials commented 3 years ago

No, you are using the wrong Phobos version

You mean, some newer LDC would've compiled that version of algebraic.d? Ok...

The corresponding version is stored in the Git tree via the submodule hash

I'm not very good with git -- and I don't want to chase moving targets. LDC had a release recently: 1.26. I'm trying to build it -- and update the FreeBSD port too.

Could you help? What's the latest Phobos version (branch, tag, or hash), that works with LDC-1.26? Same question for DRuntime, actually.

Is this not a fair question to ask of the software-maintainers?

JohanEngelen commented 3 years ago

No, you are using the wrong Phobos version

You mean, some newer LDC would've compiled that version of algebraic.d? Ok...

The corresponding version is stored in the Git tree via the submodule hash

I'm not very good with git -- and I don't want to chase moving targets. LDC had a release recently: 1.26. I'm trying to build it -- and update the FreeBSD port too.

Please google and read a bit about "git submodules".

Could you help? What's the latest Phobos version (branch, tag, or hash), that works with LDC-1.26? Same question for DRuntime, actually.

druntime @ 45e2e56, git tag ldc-v1.26.0 phobos @ b7ec908, git tag ldc-v1.26.0 You can get this info running git submodule status (if you have a fresh checkout of LDC).

Is this not a fair question to ask of the software-maintainers?

What we are saying is: if you need this information, you are doing things wrong. To build LDC, follow the simple instructions, something like: git checkout <version that you want> && git submodule update --init. Each commit of LDC supports only a one specific commit hash of druntime and phobos. The "latest" supported Phobos version is the same as the "oldest" supported Phobos version.

UnitedMarsupials commented 3 years ago

druntime @ 45e2e56, git tag ldc-v1.26.0 phobos @ b7ec908, git tag ldc-v1.26.0

Awesome! Thank you.

follow the simple instructions, something like: git checkout version

These instructions are meant for developers of the LDC itself -- not for those seeking to compile a stable version of the compiler so as to use the language. They imply working with moving targets, rather than releases.

JohanEngelen commented 3 years ago

These instructions are meant for developers of the LDC itself -- not for those seeking to compile a stable version of the compiler so as to use the language. They imply working with moving targets, rather than releases.

Wrong.

UnitedMarsupials commented 3 years ago

I used the ldc-v1.26.0 tag for both components, but am seeing the same error -- in the same line of the same function, albeit in a different source file:

std/math.d(10002): Error: shift by -28 is outside the range 0..31
std/math.d(10046):        called from here: `powIntegralImpl(val)`
std/uni/package.d(1128):        called from here: `nextPow2(12u)`
std/uni/package.d(870): Error: template instance `std.uni.spaceFor!13u` error instantiating
std/uni/package.d(3865):        instantiated from here: `MultiArray!(BitPacked!(uint, 13u), BitPacked!(bool, 1u))`
std/uni/package.d(4299):        instantiated from here: `TrieBuilder!(bool, dchar, 1114112, sliceBits!(8u, 21u), sliceBits!(0u, 8u))`
std/regex/internal/ir.d(26):        instantiated from here: `CodepointSetTrie!(13, 8)`

Is code known to work on a 32-bit platform? Is my new bsr() implementation incorrect somehow?

kinke commented 3 years ago

Is code known to work on a 32-bit platform?

It's CI tested on Linux and Windows, x86 only. But quite obviously not with an ltsmaster host compiler, which miscompiles recent LDC versions as mentioned in the release log (but in different aspects from what I've seen so far). From my POV, ltsmaster is pretty much dead by now and only an escape hatch if the other possibilities (GDC, or cross-compiling LDC) aren't an option for whatever reason (can't think of a good one, except for cross-compiling LDC itself being a bit cumbersome).

UnitedMarsupials commented 3 years ago

It's CI tested on Linux and Windows, x86 only.

Well, this error is from the new compiler (1.26.0) unable to compile Phobos. Is there a log somewhere, showing this code compiling on a 32-bit platform?

From my POV, ltsmaster is pretty much dead by now

FreeBSD port compiles ltsmaster in order to then build the new compiler. The port installs ldc-1.23 currently, and I'd like to upgrade it to 1.26. The instructions on Wiki state:

If there's no suitable prebuilt D compiler for your platform: LDC 0.17 is the last version that does not need a D compiler to be built. Thus for bootstrapping, you can first build 0.17, and then use that to build newer compiler versions. Our testing infrastructure explicitly tests that new LDC versions can be built with 0.17 (on 64-bit systems). The git branch is called ltsmaster or you can get the source for the latest 0.17 release.

That's the route I'm trying to take -- with the additional bonus of removing the "64-bit only" limitation... I'm not a D-expert, however, and I cannot tell, whether the cited code is invalid or the compiler itself is micompied to erroneously flag it as such.

Hence, this ticket...

kinke commented 3 years ago

Is there a log somewhere, showing this code compiling on a 32-bit platform?

So you don't take my word for it? :P - https://dev.azure.com/ldc-developers/ldc/_build/results?buildId=2905&view=logs&j=97a617bf-bcbd-5dfa-bba2-cfba2747b693 (Windows x86), https://dev.azure.com/ldc-developers/ldc/_build/results?buildId=2905&view=logs&j=d63d0aa7-5d01-5c9f-d5bd-b8a45119ae4e (Ubuntu 18.04 x86). From your tiny log snippet, it's not clear whether you're compiling the library or its unittests, but anyway, these 2 CI logs compile both and run them too. Compiling the libs (not the unittests) is also tested for 32-bit Android ARMv7-A, also an Azure Pipelines.

The instructions on Wiki state

Wiki pages are notoriously outdated because people using them don't update them when they hit troubles. Our README suggests using GDC instead: https://github.com/ldc-developers/ldc/#building-from-source

We have official FreeBSD builds (x64 only - the one on GitHub). The current 'port' is x64 only, so you're apparently not just trying to upgrade it, but also to add the x86 platform. Are you sure that legacy platform is worth the trouble? No idea about FreeBSD plans, but I'd at least separate the two goals from each other, as bumping to v1.26 (x64) should be a breeze.

UnitedMarsupials commented 3 years ago

Wiki pages are notoriously outdated

Well, you link to them from the project's readme...

you're apparently not just trying to upgrade it, but also to add the x86 platform

Yes. If, as you say :P , it works for 32-bit Linux, why shouldn't it work on 32-bit BSD?

From your tiny log snippet, it's not clear whether you're compiling the library or its unittests

Here it is, with the failing command -- note, that this is using the new ldc2, not the bootstrapping one from ltsmaster:

cd /var/ports/lang/ldc/work/ldc-1.26.0/runtime/phobos && /var/ports/lang/ldc/work/ldc-1.26.0/bin/ldc2 -c --output-o -conf= -w -de -dip1000 -preview=dtorfields -transition=complex -g -link-defaultlib-debug -d-debug -relocation-model=pic -I/var/ports/lang/ldc/work/ldc-1.26.0/runtime/druntime/src -I/var/ports/lang/ldc/work/ldc-1.26.0/runtime/phobos -od=/var/ports/lang/ldc/work/ldc-1.26.0/runtime/objects-debug -op etc/c/curl.d etc/c/odbc/sql.d etc/c/odbc/sqlext.d etc/c/odbc/sqltypes.d etc/c/odbc/sqlucode.d etc/c/sqlite3.d etc/c/zlib.d std/algorithm/comparison.d std/algorithm/internal.d std/algorithm/iteration.d std/algorithm/mutation.d std/algorithm/package.d std/algorithm/searching.d std/algorithm/setops.d std/algorithm/sorting.d std/array.d std/ascii.d std/base64.d std/bigint.d std/bitmanip.d std/compiler.d std/complex.d std/concurrency.d std/container/array.d std/container/binaryheap.d std/container/dlist.d std/container/package.d std/container/rbtree.d std/container/slist.d std/container/util.d std/conv.d std/csv.d std/datetime/date.d std/datetime/interval.d std/datetime/package.d std/datetime/stopwatch.d std/datetime/systime.d std/datetime/timezone.d std/demangle.d std/digest/crc.d std/digest/digest.d std/digest/hmac.d std/digest/md.d std/digest/murmurhash.d std/digest/package.d std/digest/ripemd.d std/digest/sha.d std/encoding.d std/exception.d std/experimental/allocator/building_blocks/affix_allocator.d std/experimental/allocator/building_blocks/aligned_block_list.d std/experimental/allocator/building_blocks/allocator_list.d std/experimental/allocator/building_blocks/ascending_page_allocator.d std/experimental/allocator/building_blocks/bitmapped_block.d std/experimental/allocator/building_blocks/bucketizer.d std/experimental/allocator/building_blocks/fallback_allocator.d std/experimental/allocator/building_blocks/free_list.d std/experimental/allocator/building_blocks/free_tree.d std/experimental/allocator/building_blocks/kernighan_ritchie.d std/experimental/allocator/building_blocks/null_allocator.d std/experimental/allocator/building_blocks/package.d std/experimental/allocator/building_blocks/quantizer.d std/experimental/allocator/building_blocks/region.d std/experimental/allocator/building_blocks/scoped_allocator.d std/experimental/allocator/building_blocks/segregator.d std/experimental/allocator/building_blocks/stats_collector.d std/experimental/allocator/common.d std/experimental/allocator/gc_allocator.d std/experimental/allocator/mallocator.d std/experimental/allocator/mmap_allocator.d std/experimental/allocator/package.d std/experimental/allocator/showcase.d std/experimental/allocator/typed.d std/experimental/checkedint.d std/experimental/logger/core.d std/experimental/logger/filelogger.d std/experimental/logger/multilogger.d std/experimental/logger/nulllogger.d std/experimental/logger/package.d std/experimental/typecons.d std/file.d std/format/internal/floats.d std/format/internal/read.d std/format/internal/write.d std/format/package.d std/functional.d std/getopt.d std/internal/attributes.d std/internal/cstring.d std/internal/digest/sha_SSSE3.d std/internal/math/biguintarm.d std/internal/math/biguintcore.d std/internal/math/biguintnoasm.d std/internal/math/biguintx86.d std/internal/math/errorfunction.d std/internal/math/gammafunction.d std/internal/memory.d std/internal/scopebuffer.d std/internal/test/dummyrange.d std/internal/test/range.d std/internal/test/uda.d std/internal/unicode_comp.d std/internal/unicode_decomp.d std/internal/unicode_grapheme.d std/internal/unicode_norm.d std/internal/unicode_tables.d std/internal/windows/advapi32.d std/json.d std/math.d std/mathspecial.d std/meta.d std/mmfile.d std/net/curl.d std/net/isemail.d std/numeric.d std/outbuffer.d std/package.d std/parallelism.d std/path.d std/process.d std/random.d std/range/interfaces.d std/range/package.d std/range/primitives.d std/regex/internal/backtracking.d std/regex/internal/generator.d std/regex/internal/ir.d std/regex/internal/kickstart.d std/regex/internal/parser.d std/regex/internal/tests.d std/regex/internal/tests2.d std/regex/internal/thompson.d std/regex/package.d std/signals.d std/socket.d std/stdint.d std/stdio.d std/string.d std/system.d std/traits.d std/typecons.d std/typetuple.d std/uni/package.d std/uri.d std/utf.d std/uuid.d std/variant.d std/xml.d std/zip.d std/zlib.d
std/math.d(10002): Error: shift by -28 is outside the range 0..31
std/math.d(10046):        called from here: `powIntegralImpl(val)`
std/uni/package.d(1128):        called from here: `nextPow2(12u)`
std/uni/package.d(870): Error: template instance `std.uni.spaceFor!13u` error instantiating
std/uni/package.d(3865):        instantiated from here: `MultiArray!(BitPacked!(uint, 13u), BitPacked!(bool, 1u))`
std/uni/package.d(4299):        instantiated from here: `TrieBuilder!(bool, dchar, 1114112, sliceBits!(8u, 21u), sliceBits!(0u, 8u))`
std/regex/internal/ir.d(26):        instantiated from here: `CodepointSetTrie!(13, 8)`

using GDC instead

Sigh, so I'll have to port gdc first...

Are you sure that legacy platform is worth the trouble?

The only machine, on which I actually need to compile D-code (a command-line client for Microsoft's OneDrive) is a FreeBSD-11/i386 VM...

UnitedMarsupials commented 3 years ago

https://dev.azure.com/ldc-developers/ldc/_build/results?buildId=2905&view=logs&j=d63d0aa7-5d01-5c9f-d5bd-b8a45119ae4e (Ubuntu 18.04 x86).

I'm sorry, @kinke, I'm having a problem deciphering those fancy pages -- and I'm not sure, the druntime and phobos are built there... Perhaps, you could offer a direct link to where the older math.d (or the newer algebraic.d) are compiled on a 32-bit system?

Also, I'd love to add a "test" (or "check") stage to FreeBSD port -- both for the ltsmaster (which the port builds first), and the new compiler. is it as simple as a ninja-target? Which one?

Thank you!

kinke commented 3 years ago

and I'm not sure, the druntime and phobos are built there

I already told you they are built there, but as you won't take my word for it and cannot 'decipher' the 'fancy' logs either, I'm absolutely not willing to put any more effort into convincing you about a trivial fact. Wrt. testing, that's all in the CI logs too (look for ctest command lines).

UnitedMarsupials commented 3 years ago

as you won't take my word for it

I don't mean to imply, you're lying, but you may be mistaken... Don't be angry -- just show the stupid stranger the proof...