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

Saturating casts between integers and floats #45205

Merged
merged 7 commits into from Nov 8, 2017

Conversation

Projects
None yet
@rkruppe
Contributor

rkruppe commented Oct 11, 2017

Introduces a new flag, -Z saturating-float-casts, which makes code generation for int->float and float->int casts safe (undef-free), implementing the saturating semantics laid out by @jorendorff for float->int casts and overflowing to infinity for u128::MAX -> f32.
Constant evaluation in trans was changed to behave like HIR const eval already did, i.e., saturate for u128->f32 and report an error for problematic float->int casts.

Many thanks to @eddyb, whose APFloat port simplified many parts of this patch, and made HIR constant evaluation recognize dangerous float casts as mentioned above.
Also thanks to @ActuallyaDeviloper whose branchless implementation served as inspiration for this implementation.

cc #10184 #41799
fixes #45134

@rust-highfive

This comment has been minimized.

Show comment
Hide comment
@rust-highfive

rust-highfive Oct 11, 2017

Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

Collaborator

rust-highfive commented Oct 11, 2017

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@rkruppe

This comment has been minimized.

Show comment
Hide comment
@rkruppe

rkruppe Oct 11, 2017

Contributor

Incorportated the suggestions by @sunfishcode and @kennytm.

Contributor

rkruppe commented Oct 11, 2017

Incorportated the suggestions by @sunfishcode and @kennytm.

@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb

eddyb Oct 11, 2017

Member

cc @est31 @nagisa @alexcrichton Who's better qualified to review floating-point code?

Member

eddyb commented Oct 11, 2017

cc @est31 @nagisa @alexcrichton Who's better qualified to review floating-point code?

@rkruppe

This comment has been minimized.

Show comment
Hide comment
@rkruppe

rkruppe Oct 11, 2017

Contributor

What's up with travis? The run-pass test fails with an error that looks plausible and platform-independent, but I can't reproduce it (on x86_64-windows-msvc).

[00:48:14] error: internal compiler error: unexpected panic
[00:48:14] 
[00:48:14] note: the compiler unexpectedly panicked. this is a bug.
[00:48:14] 
[00:48:14] note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
[00:48:14] 
[00:48:14] note: rustc 1.22.0-dev running on x86_64-unknown-linux-gnu
[00:48:14] 
[00:48:14] thread 'rustc' panicked at 'attempt to negate with overflow', /checkout/src/librustc_apfloat/lib.rs:383:31
[00:48:14] note: Run with `RUST_BACKTRACE=1` for a backtrace.
Contributor

rkruppe commented Oct 11, 2017

What's up with travis? The run-pass test fails with an error that looks plausible and platform-independent, but I can't reproduce it (on x86_64-windows-msvc).

[00:48:14] error: internal compiler error: unexpected panic
[00:48:14] 
[00:48:14] note: the compiler unexpectedly panicked. this is a bug.
[00:48:14] 
[00:48:14] note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
[00:48:14] 
[00:48:14] note: rustc 1.22.0-dev running on x86_64-unknown-linux-gnu
[00:48:14] 
[00:48:14] thread 'rustc' panicked at 'attempt to negate with overflow', /checkout/src/librustc_apfloat/lib.rs:383:31
[00:48:14] note: Run with `RUST_BACKTRACE=1` for a backtrace.
@rkruppe

This comment has been minimized.

Show comment
Hide comment
@rkruppe

rkruppe Oct 11, 2017

Contributor

@est31 This constant isn't f32::MAX, it's f32::MAX + 0.5 ULP. Evidently the constant is not as clear as I'd hoped, so I'll figure out a way to compute it that hopefully makes it clearer what's happening.

How about

ieee::Single::largest().to_u128(128).value + (1 << (128 - ieee::Single::PRECISION - 1))

The -1 is pretty ugly as well ¯\_(ツ)_/¯

Contributor

rkruppe commented Oct 11, 2017

@est31 This constant isn't f32::MAX, it's f32::MAX + 0.5 ULP. Evidently the constant is not as clear as I'd hoped, so I'll figure out a way to compute it that hopefully makes it clearer what's happening.

How about

ieee::Single::largest().to_u128(128).value + (1 << (128 - ieee::Single::PRECISION - 1))

The -1 is pretty ugly as well ¯\_(ツ)_/¯

@rkruppe

This comment has been minimized.

Show comment
Hide comment
@rkruppe

rkruppe Oct 18, 2017

Contributor

@eddyb IIRC you wanted to run crater with the variant that errors on overflow/NaN in trans const eval? That's implemented now.

(That it's implemented now also means this shouldn't be merged in the current state until we've had a crater run.)

Contributor

rkruppe commented Oct 18, 2017

@eddyb IIRC you wanted to run crater with the variant that errors on overflow/NaN in trans const eval? That's implemented now.

(That it's implemented now also means this shouldn't be merged in the current state until we've had a crater run.)

@kennytm

This comment has been minimized.

Show comment
Hide comment
@kennytm
Member

kennytm commented Oct 18, 2017

@bors try

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Oct 18, 2017

Contributor

⌛️ Trying commit 3c3082f with merge cc787eb...

Contributor

bors commented Oct 18, 2017

⌛️ Trying commit 3c3082f with merge cc787eb...

bors added a commit that referenced this pull request Oct 18, 2017

Auto merge of #45205 - rkruppe:saturating-casts, r=<try>
Saturating casts between integers and floats

Introduces a new flag, `-Z saturating-float-casts`, which makes code generation for int->float and float->int casts safe (`undef`-free), implementing [the saturating semantics laid out by](#10184 (comment)) @jorendorff for float->int casts and overflowing to infinity for `u128::MAX` -> `f32`. Constant evaluation in trans also behaves the same way &ndash; even without the -Z flag, because it doesn't affect run time or type checking.
The HIR constant evaluator is unaffected because it currently works correctly for u128->f32 and returns an error for problematic float->casts. That error is conservatively correct and we should be careful to not accept more code in constant expressions.

Many thanks to @eddyb, whose APFloat port simplified many parts of this patch, and made HIR constant evaluation recognize dangerous float casts as mentioned above.
Also thanks to @ActuallyaDeviloper whose branchless implementation served as inspiration for this implementation.

cc #10184 #41799
fixes #45134
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Oct 18, 2017

Contributor

☀️ Test successful - status-travis
State: approved= try=True

Contributor

bors commented Oct 18, 2017

☀️ Test successful - status-travis
State: approved= try=True

@aidanhs

This comment has been minimized.

Show comment
Hide comment
@aidanhs

aidanhs Oct 20, 2017

Member

This is behind a couple of other crater runs so will start being cratered in ~4 days.

Member

aidanhs commented Oct 20, 2017

This is behind a couple of other crater runs so will start being cratered in ~4 days.

@rkruppe

This comment has been minimized.

Show comment
Hide comment
@rkruppe

rkruppe Oct 27, 2017

Contributor

Ping @aidanhs, what's the status of the crater run?

Contributor

rkruppe commented Oct 27, 2017

Ping @aidanhs, what's the status of the crater run?

@aidanhs

This comment has been minimized.

Show comment
Hide comment
@aidanhs

aidanhs Oct 28, 2017

Member

Crater run started - sorry for the delay, I've had a busy week!

Member

aidanhs commented Oct 28, 2017

Crater run started - sorry for the delay, I've had a busy week!

@rkruppe

This comment has been minimized.

Show comment
Hide comment
@rkruppe

rkruppe Nov 6, 2017

Contributor

@alexcrichton The runtime code generation changes are gated on an ordinary -Z flag, so it's opt-in and can only be opted-into with nightly compilers. However, like most/all(?) -Z flags, it works without -Z unstable-options, if that's what you mean by unstable.

The trans const eval changes are not gated by anything. Those bring the backend's interpretation of the casts in line with the HIR-based const eval's interpretation, so I'm more inclined to classify them as a minor bug fix.

Contributor

rkruppe commented Nov 6, 2017

@alexcrichton The runtime code generation changes are gated on an ordinary -Z flag, so it's opt-in and can only be opted-into with nightly compilers. However, like most/all(?) -Z flags, it works without -Z unstable-options, if that's what you mean by unstable.

The trans const eval changes are not gated by anything. Those bring the backend's interpretation of the casts in line with the HIR-based const eval's interpretation, so I'm more inclined to classify them as a minor bug fix.

@rkruppe

This comment has been minimized.

Show comment
Hide comment
@rkruppe

rkruppe Nov 6, 2017

Contributor

Updated to address @eddyb's questions.

Contributor

rkruppe commented Nov 6, 2017

Updated to address @eddyb's questions.

@alexcrichton

This comment has been minimized.

Show comment
Hide comment
@alexcrichton

alexcrichton Nov 6, 2017

Member

Ok that all sounds great to me! Sounds like r=eddyb when CI is green

Member

alexcrichton commented Nov 6, 2017

Ok that all sounds great to me! Sounds like r=eddyb when CI is green

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Nov 7, 2017

Contributor

☔️ The latest upstream changes (presumably #45666) made this pull request unmergeable. Please resolve the merge conflicts.

Contributor

bors commented Nov 7, 2017

☔️ The latest upstream changes (presumably #45666) made this pull request unmergeable. Please resolve the merge conflicts.

rkruppe added some commits Oct 9, 2017

Saturating casts between integers and floats (both directions).
This affects regular code generation as well as constant evaluation in trans,
but not the HIR constant evaluator because that one returns an error for
overflowing casts and NaN-to-int casts. That error is conservatively
correct and we should be careful to not accept more code in constant
expressions.
The changes to code generation are guarded by a new -Z flag, to be able
to evaluate the performance impact. The trans constant evaluation changes
are unconditional because they have no run time impact and don't affect
type checking either.
@rkruppe

This comment has been minimized.

Show comment
Hide comment
@rkruppe

rkruppe Nov 7, 2017

Contributor

Rebased. Travis is green.

Contributor

rkruppe commented Nov 7, 2017

Rebased. Travis is green.

@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb

eddyb Nov 7, 2017

Member

@bors r+

Member

eddyb commented Nov 7, 2017

@bors r+

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Nov 7, 2017

Contributor

📌 Commit ce46649 has been approved by eddyb

Contributor

bors commented Nov 7, 2017

📌 Commit ce46649 has been approved by eddyb

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Nov 7, 2017

Contributor

⌛️ Testing commit ce46649 with merge 3da3997...

Contributor

bors commented Nov 7, 2017

⌛️ Testing commit ce46649 with merge 3da3997...

bors added a commit that referenced this pull request Nov 7, 2017

Auto merge of #45205 - rkruppe:saturating-casts, r=eddyb
Saturating casts between integers and floats

Introduces a new flag, `-Z saturating-float-casts`, which makes code generation for int->float and float->int casts safe (`undef`-free), implementing [the saturating semantics laid out by](#10184 (comment)) @jorendorff for float->int casts and overflowing to infinity for `u128::MAX` -> `f32`.
Constant evaluation in trans was changed to behave like HIR const eval already did, i.e., saturate for u128->f32 and report an error for problematic float->int casts.

Many thanks to @eddyb, whose APFloat port simplified many parts of this patch, and made HIR constant evaluation recognize dangerous float casts as mentioned above.
Also thanks to @ActuallyaDeviloper whose branchless implementation served as inspiration for this implementation.

cc #10184 #41799
fixes #45134
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Nov 8, 2017

Contributor

💔 Test failed - status-travis

Contributor

bors commented Nov 8, 2017

💔 Test failed - status-travis

@kennytm

This comment has been minimized.

Show comment
Hide comment
@kennytm

kennytm Nov 8, 2017

Member

asmjs does not support i128 (Unsupported: %1826 = fptosi float %1825 to i128)

cc #45676.

[01:32:24] failures:
[01:32:24] 
[01:32:24] ---- [run-pass] run-pass/saturating-float-casts.rs stdout ----
[01:32:24] 	
[01:32:24] error: compilation failed!
[01:32:24] status: exit code: 101
[01:32:24] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/run-pass/saturating-float-casts.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "--target=asmjs-unknown-emscripten" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/saturating-float-casts.stage2-asmjs-unknown-emscripten.js" "-Crpath" "-O" "-Lnative=/checkout/obj/build/asmjs-unknown-emscripten/native/rust-test-helpers" "-Z" "saturating-float-casts" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/saturating-float-casts.stage2-asmjs-unknown-emscripten.aux"
[01:32:24] stdout:
[01:32:24] ------------------------------------------
[01:32:24] 
[01:32:24] ------------------------------------------
[01:32:24] stderr:
[01:32:24] ------------------------------------------
[01:32:24] error: linking with `emcc` failed: exit code: 1
[01:32:24]   |
[01:32:24]   = note: "emcc" "-s" "DISABLE_EXCEPTION_CATCHING=0" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/saturating-float-casts.saturating_float_casts0.rcgu.o" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/saturating-float-casts.stage2-asmjs-unknown-emscripten.js" "-s" "EXPORTED_FUNCTIONS=[\"_main\",\"_rust_eh_personality\"]" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/saturating-float-casts.crate.allocator.rcgu.o" "-O2" "--memory-init-file" "0" "-g0" "-s" "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "-L" "/checkout/obj/build/asmjs-unknown-emscripten/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/saturating-float-casts.stage2-asmjs-unknown-emscripten.aux" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libtest-183e233b7c075ec2.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libterm-08fb69f2f719b59c.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libgetopts-4f65f6654127877d.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libstd-2b35d1b36dfa7e3a.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libpanic_unwind-5bef2c52ac19d279.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libunwind-3830ae5679a0b739.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/liballoc_system-9ff2c67f40fe5858.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/liblibc-e1c7eeeb00260d82.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/liballoc-bad119b0f880de53.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libstd_unicode-c87147d9878a34a6.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/librand-efb9ae917b0ef713.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libcore-f61c023fb8fcfea8.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libcompiler_builtins-709204c2e3fe5ec9.rlib" "-l" "c" "-s" "ERROR_ON_UNDEFINED_SYMBOLS=1"
[01:32:24]   = note: Unsupported:   %1826 = fptosi float %1825 to i128
[01:32:24]           LLVM ERROR: Instruction not yet supported for integer types larger than 64 bits
[01:32:24]           Traceback (most recent call last):
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13//emcc", line 13, in <module>
[01:32:24]               emcc.run()
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/emcc.py", line 1526, in run
[01:32:24]               final = shared.Building.emscripten(final, append_ext=False, extra_args=extra_args)
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/tools/shared.py", line 1963, in emscripten
[01:32:24]               call_emscripten(cmdline)
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/emscripten.py", line 2190, in _main
[01:32:24]               temp_files.run_and_clean(lambda: main(
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/tools/tempfiles.py", line 78, in run_and_clean
[01:32:24]               return func()
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/emscripten.py", line 2195, in <lambda>
[01:32:24]               DEBUG=DEBUG,
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/emscripten.py", line 2095, in main
[01:32:24]               temp_files=temp_files, DEBUG=DEBUG)
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/emscripten.py", line 93, in emscript
[01:32:24]               backend_output = compile_js(infile, settings, temp_files, DEBUG)
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/emscripten.py", line 127, in compile_js
[01:32:24]               backend_output = open(temp_js).read()
[01:32:24]           IOError: [Errno 2] No such file or directory: '/tmp/tmptj926K.4.js'
[01:32:24]           
[01:32:24] 
[01:32:24] error: aborting due to previous error
[01:32:24] 
[01:32:24] 
[01:32:24] ------------------------------------------
[01:32:24] 
[01:32:24] thread '[run-pass] run-pass/saturating-float-casts.rs' panicked at 'explicit panic', /checkout/src/tools/compiletest/src/runtest.rs:2498:8
[01:32:24] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:32:24] 
[01:32:24] 
[01:32:24] failures:
[01:32:24]     [run-pass] run-pass/saturating-float-casts.rs
[01:32:24] 
[01:32:24] test result: �[31mFAILED�(B�[m. 2678 passed; 1 failed; 144 ignored; 0 measured; 0 filtered out
Member

kennytm commented Nov 8, 2017

asmjs does not support i128 (Unsupported: %1826 = fptosi float %1825 to i128)

cc #45676.

[01:32:24] failures:
[01:32:24] 
[01:32:24] ---- [run-pass] run-pass/saturating-float-casts.rs stdout ----
[01:32:24] 	
[01:32:24] error: compilation failed!
[01:32:24] status: exit code: 101
[01:32:24] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/run-pass/saturating-float-casts.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "--target=asmjs-unknown-emscripten" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/saturating-float-casts.stage2-asmjs-unknown-emscripten.js" "-Crpath" "-O" "-Lnative=/checkout/obj/build/asmjs-unknown-emscripten/native/rust-test-helpers" "-Z" "saturating-float-casts" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/saturating-float-casts.stage2-asmjs-unknown-emscripten.aux"
[01:32:24] stdout:
[01:32:24] ------------------------------------------
[01:32:24] 
[01:32:24] ------------------------------------------
[01:32:24] stderr:
[01:32:24] ------------------------------------------
[01:32:24] error: linking with `emcc` failed: exit code: 1
[01:32:24]   |
[01:32:24]   = note: "emcc" "-s" "DISABLE_EXCEPTION_CATCHING=0" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/saturating-float-casts.saturating_float_casts0.rcgu.o" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/saturating-float-casts.stage2-asmjs-unknown-emscripten.js" "-s" "EXPORTED_FUNCTIONS=[\"_main\",\"_rust_eh_personality\"]" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/saturating-float-casts.crate.allocator.rcgu.o" "-O2" "--memory-init-file" "0" "-g0" "-s" "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "-L" "/checkout/obj/build/asmjs-unknown-emscripten/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/saturating-float-casts.stage2-asmjs-unknown-emscripten.aux" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libtest-183e233b7c075ec2.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libterm-08fb69f2f719b59c.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libgetopts-4f65f6654127877d.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libstd-2b35d1b36dfa7e3a.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libpanic_unwind-5bef2c52ac19d279.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libunwind-3830ae5679a0b739.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/liballoc_system-9ff2c67f40fe5858.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/liblibc-e1c7eeeb00260d82.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/liballoc-bad119b0f880de53.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libstd_unicode-c87147d9878a34a6.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/librand-efb9ae917b0ef713.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libcore-f61c023fb8fcfea8.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/asmjs-unknown-emscripten/lib/libcompiler_builtins-709204c2e3fe5ec9.rlib" "-l" "c" "-s" "ERROR_ON_UNDEFINED_SYMBOLS=1"
[01:32:24]   = note: Unsupported:   %1826 = fptosi float %1825 to i128
[01:32:24]           LLVM ERROR: Instruction not yet supported for integer types larger than 64 bits
[01:32:24]           Traceback (most recent call last):
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13//emcc", line 13, in <module>
[01:32:24]               emcc.run()
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/emcc.py", line 1526, in run
[01:32:24]               final = shared.Building.emscripten(final, append_ext=False, extra_args=extra_args)
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/tools/shared.py", line 1963, in emscripten
[01:32:24]               call_emscripten(cmdline)
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/emscripten.py", line 2190, in _main
[01:32:24]               temp_files.run_and_clean(lambda: main(
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/tools/tempfiles.py", line 78, in run_and_clean
[01:32:24]               return func()
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/emscripten.py", line 2195, in <lambda>
[01:32:24]               DEBUG=DEBUG,
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/emscripten.py", line 2095, in main
[01:32:24]               temp_files=temp_files, DEBUG=DEBUG)
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/emscripten.py", line 93, in emscript
[01:32:24]               backend_output = compile_js(infile, settings, temp_files, DEBUG)
[01:32:24]             File "/emsdk-portable/emscripten/1.37.13/emscripten.py", line 127, in compile_js
[01:32:24]               backend_output = open(temp_js).read()
[01:32:24]           IOError: [Errno 2] No such file or directory: '/tmp/tmptj926K.4.js'
[01:32:24]           
[01:32:24] 
[01:32:24] error: aborting due to previous error
[01:32:24] 
[01:32:24] 
[01:32:24] ------------------------------------------
[01:32:24] 
[01:32:24] thread '[run-pass] run-pass/saturating-float-casts.rs' panicked at 'explicit panic', /checkout/src/tools/compiletest/src/runtest.rs:2498:8
[01:32:24] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:32:24] 
[01:32:24] 
[01:32:24] failures:
[01:32:24]     [run-pass] run-pass/saturating-float-casts.rs
[01:32:24] 
[01:32:24] test result: �[31mFAILED�(B�[m. 2678 passed; 1 failed; 144 ignored; 0 measured; 0 filtered out
@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb

eddyb Nov 8, 2017

Member

@bors r+

Member

eddyb commented Nov 8, 2017

@bors r+

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Nov 8, 2017

Contributor

📌 Commit ef0b999 has been approved by eddyb

Contributor

bors commented Nov 8, 2017

📌 Commit ef0b999 has been approved by eddyb

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Nov 8, 2017

Contributor

⌛️ Testing commit ef0b999 with merge 7ca430d...

Contributor

bors commented Nov 8, 2017

⌛️ Testing commit ef0b999 with merge 7ca430d...

bors added a commit that referenced this pull request Nov 8, 2017

Auto merge of #45205 - rkruppe:saturating-casts, r=eddyb
Saturating casts between integers and floats

Introduces a new flag, `-Z saturating-float-casts`, which makes code generation for int->float and float->int casts safe (`undef`-free), implementing [the saturating semantics laid out by](#10184 (comment)) @jorendorff for float->int casts and overflowing to infinity for `u128::MAX` -> `f32`.
Constant evaluation in trans was changed to behave like HIR const eval already did, i.e., saturate for u128->f32 and report an error for problematic float->int casts.

Many thanks to @eddyb, whose APFloat port simplified many parts of this patch, and made HIR constant evaluation recognize dangerous float casts as mentioned above.
Also thanks to @ActuallyaDeviloper whose branchless implementation served as inspiration for this implementation.

cc #10184 #41799
fixes #45134
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Nov 8, 2017

Contributor

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing 7ca430d to master...

Contributor

bors commented Nov 8, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing 7ca430d to master...

@bors bors merged commit ef0b999 into rust-lang:master Nov 8, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment