Skip to content
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

Make <*const/mut T>::offset_from const fn #63810

Merged
merged 7 commits into from
Nov 3, 2019

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Aug 22, 2019

This reenables offset_of cc @mjbshaw after #63075 broke it

@rust-highfive
Copy link
Collaborator

r? @varkor

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 22, 2019
@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 22, 2019

cc @RalfJung this moves the logic of exact_div from miri to the engine

@rust-highfive

This comment has been minimized.

src/libcore/ptr/mod.rs Outdated Show resolved Hide resolved
src/libcore/ptr/mod.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

In terms of const safety this seems fine, since it return an integer that actually is a true integer. It is an unsafe operation, but the cases where it fails during CTFE are all also UB at run-time, but there is no "unconst" weirdness. So this seems reaosonable to me.

This reenables offset_of cc @mjbshaw after #63075 broke it

Well, assuming "all the feature gates". ;)

@mjbshaw
Copy link
Contributor

mjbshaw commented Aug 23, 2019

Thank you for putting this together!

@varkor varkor assigned RalfJung and unassigned varkor Aug 24, 2019
@RalfJung RalfJung added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 25, 2019
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-08-30T01:00:34.6319473Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-08-30T01:00:34.6506952Z ##[command]git config gc.auto 0
2019-08-30T01:00:34.6583798Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-08-30T01:00:34.6659132Z ##[command]git config --get-all http.proxy
2019-08-30T01:00:34.6809809Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/63810/merge:refs/remotes/pull/63810/merge
---
2019-08-30T02:03:48.0598293Z .................................................................................................... 1500/8976
2019-08-30T02:03:53.7714407Z .................................................................................................... 1600/8976
2019-08-30T02:04:06.5898456Z ..................................................i...............i................................. 1700/8976
2019-08-30T02:04:15.0011523Z .................................................................................................... 1800/8976
2019-08-30T02:04:29.4461125Z .........................................iiiii...................................................... 1900/8976
2019-08-30T02:04:40.3601132Z .................................................................................................... 2100/8976
2019-08-30T02:04:42.9872492Z .................................................................................................... 2200/8976
2019-08-30T02:04:47.0262787Z .................................................................................................... 2300/8976
2019-08-30T02:04:54.8508027Z .................................................................................................... 2400/8976
---
2019-08-30T02:07:55.3139143Z ............................i...............i....................................................... 4700/8976
2019-08-30T02:08:07.3078232Z .................................................................................................... 4800/8976
2019-08-30T02:08:13.5149918Z .................................................................................................... 4900/8976
2019-08-30T02:08:24.2692775Z .................................................................................................... 5000/8976
2019-08-30T02:08:30.0047253Z .........ii.ii...................................................................................... 5100/8976
2019-08-30T02:08:43.1335726Z .................................................................................................... 5300/8976
2019-08-30T02:08:51.4910581Z ........................................................................i........................... 5400/8976
2019-08-30T02:08:58.7932234Z .................................................................................................... 5500/8976
2019-08-30T02:09:05.3767700Z .................................................................................................... 5600/8976
2019-08-30T02:09:05.3767700Z .................................................................................................... 5600/8976
2019-08-30T02:09:16.1484645Z ..................................................................ii...i..ii...........i............ 5700/8976
2019-08-30T02:09:41.7645744Z .................................................................................................... 5900/8976
2019-08-30T02:09:52.1348028Z .................................................................................................... 6000/8976
2019-08-30T02:09:52.1348028Z .................................................................................................... 6000/8976
2019-08-30T02:09:58.9908737Z ...................................................................i..ii............................ 6100/8976
2019-08-30T02:10:28.3476976Z .................................................................................................... 6300/8976
2019-08-30T02:10:30.4812566Z ......................i............................................................................. 6400/8976
2019-08-30T02:10:32.7149802Z ..............................................................................................i..... 6500/8976
2019-08-30T02:10:35.5150966Z .................................................................................................... 6600/8976
---
2019-08-30T02:15:19.7974133Z  finished in 21.279
2019-08-30T02:15:19.8176827Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-30T02:15:20.0039691Z 
2019-08-30T02:15:20.0043503Z running 149 tests
2019-08-30T02:15:23.3104416Z i....iii......iii..iiii....i.............................i..i..................i....i.........ii.i.i 100/149
2019-08-30T02:15:25.2602978Z ..iiii..............i.........iii.i......ii......
2019-08-30T02:15:25.2603615Z 
2019-08-30T02:15:25.2606915Z  finished in 5.443
2019-08-30T02:15:25.2791596Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-30T02:15:25.4373278Z 
---
2019-08-30T02:15:27.5343572Z  finished in 2.255
2019-08-30T02:15:27.5522996Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-30T02:15:27.7118433Z 
2019-08-30T02:15:27.7119139Z running 9 tests
2019-08-30T02:15:27.7120330Z iiiiiiiii
2019-08-30T02:15:27.7123128Z 
2019-08-30T02:15:27.7123398Z  finished in 0.160
2019-08-30T02:15:27.7297645Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-30T02:15:27.9245740Z 
---
2019-08-30T02:15:46.1664821Z  finished in 18.436
2019-08-30T02:15:46.1868827Z Check compiletest suite=debuginfo mode=debuginfo-gdb+lldb (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-30T02:15:46.3616896Z 
2019-08-30T02:15:46.3617536Z running 123 tests
2019-08-30T02:16:10.4653965Z .iiiii...i.....i..i...i..i.i.i..i.ii..i.i.....i..i....ii..........iiii..........i...ii...i.......ii. 100/123
2019-08-30T02:16:15.3935125Z i.i.i......iii.i.....ii
2019-08-30T02:16:15.3937109Z 
2019-08-30T02:16:15.3941383Z  finished in 29.207
2019-08-30T02:16:15.3954240Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-08-30T02:16:15.3955677Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2019-08-30T02:30:24.3599198Z 
2019-08-30T02:30:24.3599956Z    Doc-tests core
2019-08-30T02:30:29.5551103Z 
2019-08-30T02:30:29.5580251Z running 2379 tests
2019-08-30T02:30:42.0071186Z ......iiiii......................................................................................... 100/2379
2019-08-30T02:30:54.5404931Z .........................................................................ii......................... 200/2379
2019-08-30T02:31:24.7131542Z .................................................................................................... 400/2379
2019-08-30T02:31:24.7131542Z .................................................................................................... 400/2379
2019-08-30T02:31:35.8217270Z ..............................i..i.................iiii............................................. 500/2379
2019-08-30T02:31:59.2136432Z .................................................................................................... 700/2379
2019-08-30T02:32:10.9282931Z .................................................................................................... 800/2379
2019-08-30T02:32:23.1439731Z .................................................................................................... 900/2379
2019-08-30T02:32:35.0943743Z .................................................................................................... 1000/2379
---
2019-08-30T02:35:32.9195544Z 
2019-08-30T02:35:32.9195589Z stderr:
2019-08-30T02:35:32.9195928Z thread 'main' panicked at 'assertion failed: `(left == right)`
2019-08-30T02:35:32.9195986Z   left: `4611686018427387902`,
2019-08-30T02:35:32.9196260Z  right: `-2`', ptr/mod.rs:11:5
2019-08-30T02:35:32.9196357Z 
2019-08-30T02:35:32.9196385Z 
2019-08-30T02:35:32.9196678Z ---- ptr/mod.rs - ptr::*mut T::offset_from (line 2017) stdout ----
2019-08-30T02:35:32.9196737Z Test executable failed (exit code 101).
2019-08-30T02:35:32.9196737Z Test executable failed (exit code 101).
2019-08-30T02:35:32.9196834Z 
2019-08-30T02:35:32.9196896Z stderr:
2019-08-30T02:35:32.9197167Z thread 'main' panicked at 'assertion failed: `(left == right)`
2019-08-30T02:35:32.9197224Z   left: `4611686018427387902`,
2019-08-30T02:35:32.9197461Z  right: `-2`', ptr/mod.rs:11:5
2019-08-30T02:35:32.9197584Z 
2019-08-30T02:35:32.9197612Z 
2019-08-30T02:35:32.9197640Z 
2019-08-30T02:35:32.9197702Z failures:
---
2019-08-30T02:35:32.9198385Z 
2019-08-30T02:35:32.9502174Z error: test failed, to rerun pass '--doc'
2019-08-30T02:35:32.9519240Z 
2019-08-30T02:35:32.9519743Z 
2019-08-30T02:35:32.9521231Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "2" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/src/libtest/Cargo.toml" "-p" "core" "--" "--quiet"
2019-08-30T02:35:32.9521691Z 
2019-08-30T02:35:32.9521748Z 
2019-08-30T02:35:32.9533711Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-08-30T02:35:32.9533798Z Build completed unsuccessfully in 1:27:51
2019-08-30T02:35:32.9533798Z Build completed unsuccessfully in 1:27:51
2019-08-30T02:35:32.9587811Z == clock drift check ==
2019-08-30T02:35:32.9605904Z   local time: Fri Aug 30 02:35:32 UTC 2019
2019-08-30T02:35:33.0465779Z   network time: Fri, 30 Aug 2019 02:35:33 GMT
2019-08-30T02:35:33.0470273Z == end clock drift check ==
2019-08-30T02:35:33.5518814Z ##[error]Bash exited with code '1'.
2019-08-30T02:35:33.5554802Z ##[section]Starting: Checkout
2019-08-30T02:35:33.5556450Z ==============================================================================
2019-08-30T02:35:33.5556516Z Task         : Get sources
2019-08-30T02:35:33.5556557Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@JohnCSimon
Copy link
Member

Ping from triage
@oli-obk @mjbshaw @RalfJung
Hi! This PR has sat un touched for 8 days. Thanks.

@oli-obk
Copy link
Contributor Author

oli-obk commented Sep 7, 2019

Ooops, on it. Thanks for the ping

@oli-obk
Copy link
Contributor Author

oli-obk commented Sep 10, 2019

Resolved review comments

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-09-10T18:59:36.5634888Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-09-10T18:59:36.5838748Z ##[command]git config gc.auto 0
2019-09-10T18:59:36.5920105Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-09-10T18:59:36.5950596Z ##[command]git config --get-all http.proxy
2019-09-10T18:59:36.6127018Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/63810/merge:refs/remotes/pull/63810/merge
---
2019-09-10T20:02:33.6416291Z .................................................................................................... 1500/9008
2019-09-10T20:02:39.8791734Z .................................................................................................... 1600/9008
2019-09-10T20:02:53.0986196Z .........................................................i...............i.......................... 1700/9008
2019-09-10T20:03:01.2988227Z .................................................................................................... 1800/9008
2019-09-10T20:03:16.8221286Z ................................................iiiii............................................... 1900/9008
2019-09-10T20:03:28.4441311Z .................................................................................................... 2100/9008
2019-09-10T20:03:31.9471776Z .................................................................................................... 2200/9008
2019-09-10T20:03:34.9990582Z .................................................................................................... 2300/9008
2019-09-10T20:03:43.3324242Z .................................................................................................... 2400/9008
---
2019-09-10T20:06:45.1755058Z ....................................i..............i................................................ 4700/9008
2019-09-10T20:06:57.0025550Z .................................................................................................... 4800/9008
2019-09-10T20:07:03.9670711Z .................................................................................................... 4900/9008
2019-09-10T20:07:14.9136350Z .................................................................................................... 5000/9008
2019-09-10T20:07:21.3180427Z ..................ii.ii............................................................................. 5100/9008
2019-09-10T20:07:32.2678186Z .................................................................................................... 5300/9008
2019-09-10T20:07:43.0265213Z .................................................................................i.................. 5400/9008
2019-09-10T20:07:51.4073163Z .................................................................................................... 5500/9008
2019-09-10T20:07:57.5066679Z .................................................................................................... 5600/9008
2019-09-10T20:07:57.5066679Z .................................................................................................... 5600/9008
2019-09-10T20:08:08.5210160Z ...........................................................................ii...i..ii...........i... 5700/9008
2019-09-10T20:08:34.6282535Z .................................................................................................... 5900/9008
2019-09-10T20:08:44.8902416Z .................................................................................................... 6000/9008
2019-09-10T20:08:44.8902416Z .................................................................................................... 6000/9008
2019-09-10T20:08:51.9073812Z .............................................................................i..ii.................. 6100/9008
2019-09-10T20:09:22.8263893Z .................................................................................................... 6300/9008
2019-09-10T20:09:25.1022973Z ....................................i............................................................... 6400/9008
2019-09-10T20:09:27.4070972Z .................................................................................................... 6500/9008
2019-09-10T20:09:30.1575913Z ........i........................................................................................... 6600/9008
---
2019-09-10T20:14:24.5502958Z  finished in 20.293
2019-09-10T20:14:24.5707554Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-09-10T20:14:24.7425611Z 
2019-09-10T20:14:24.7427536Z running 150 tests
2019-09-10T20:14:28.1979672Z i....iii......iii..iiii....i.............................i..i..................i....i.........ii.i.i 100/150
2019-09-10T20:14:30.2842770Z ..iiii..............i.........iii.i.......ii......
2019-09-10T20:14:30.2845035Z 
2019-09-10T20:14:30.2854118Z  finished in 5.715
2019-09-10T20:14:30.3048539Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-09-10T20:14:30.4711059Z 
---
2019-09-10T20:14:32.6384000Z  finished in 2.332
2019-09-10T20:14:32.6570927Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-09-10T20:14:32.8188142Z 
2019-09-10T20:14:32.8188602Z running 9 tests
2019-09-10T20:14:32.8189752Z iiiiiiiii
2019-09-10T20:14:32.8190172Z 
2019-09-10T20:14:32.8194207Z  finished in 0.162
2019-09-10T20:14:32.8382585Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-09-10T20:14:33.0177415Z 
---
2019-09-10T20:14:52.1306638Z  finished in 19.292
2019-09-10T20:14:52.1524277Z Check compiletest suite=debuginfo mode=debuginfo-gdb+lldb (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-09-10T20:14:52.3187229Z 
2019-09-10T20:14:52.3187519Z running 123 tests
2019-09-10T20:15:16.9436108Z .iiiii...i.....i..i...i..i.i.i..i.ii..i.i.....i..i....ii..........iiii..........i...ii...i.......ii. 100/123
2019-09-10T20:15:21.7967553Z i.i.i......iii.i.....ii
2019-09-10T20:15:21.7969383Z 
2019-09-10T20:15:21.7972768Z  finished in 29.644
2019-09-10T20:15:21.7979360Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-09-10T20:15:21.7981470Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2019-09-10T20:29:40.4289462Z 
2019-09-10T20:29:40.4291256Z    Doc-tests core
2019-09-10T20:29:45.6589332Z 
2019-09-10T20:29:45.6590390Z running 2400 tests
2019-09-10T20:29:56.9620937Z ......iiiii......................................................................................... 100/2400
2019-09-10T20:30:07.9130121Z ...........................................................................ii....................... 200/2400
2019-09-10T20:30:20.5131868Z .................................................................................................i.. 300/2400
2019-09-10T20:30:34.1721226Z .................................................................................................... 400/2400
2019-09-10T20:30:44.7761312Z ............................................i..i.................iiii............................... 500/2400
2019-09-10T20:31:05.7307379Z .................................................................................................... 700/2400
2019-09-10T20:31:16.4177454Z .................................................................................................... 800/2400
2019-09-10T20:31:27.3095594Z .................................................................................................... 900/2400
2019-09-10T20:31:38.1737104Z .................................................................................................... 1000/2400
---
2019-09-10T20:34:15.3078206Z 
2019-09-10T20:34:15.3078251Z stderr:
2019-09-10T20:34:15.3078827Z thread 'main' panicked at 'assertion failed: `(left == right)`
2019-09-10T20:34:15.3078874Z   left: `4611686018427387902`,
2019-09-10T20:34:15.3080366Z  right: `-2`', ptr/mod.rs:11:5
2019-09-10T20:34:15.3081240Z 
2019-09-10T20:34:15.3081469Z 
2019-09-10T20:34:15.3085514Z ---- ptr/mod.rs - ptr::*mut T::offset_from (line 2017) stdout ----
2019-09-10T20:34:15.3085797Z Test executable failed (exit code 101).
2019-09-10T20:34:15.3085797Z Test executable failed (exit code 101).
2019-09-10T20:34:15.3085828Z 
2019-09-10T20:34:15.3085982Z stderr:
2019-09-10T20:34:15.3086230Z thread 'main' panicked at 'assertion failed: `(left == right)`
2019-09-10T20:34:15.3086275Z   left: `4611686018427387902`,
2019-09-10T20:34:15.3086490Z  right: `-2`', ptr/mod.rs:11:5
2019-09-10T20:34:15.3086733Z 
2019-09-10T20:34:15.3086757Z 
2019-09-10T20:34:15.3086797Z 
2019-09-10T20:34:15.3086831Z failures:
---
2019-09-10T20:34:15.3087390Z 
2019-09-10T20:34:15.3115357Z error: test failed, to rerun pass '--doc'
2019-09-10T20:34:15.3124603Z 
2019-09-10T20:34:15.3124761Z 
2019-09-10T20:34:15.3125744Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "2" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/src/libtest/Cargo.toml" "-p" "core" "--" "--quiet"
2019-09-10T20:34:15.3137991Z 
2019-09-10T20:34:15.3138019Z 
2019-09-10T20:34:15.3138060Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-09-10T20:34:15.3138104Z Build completed unsuccessfully in 1:27:30
2019-09-10T20:34:15.3138104Z Build completed unsuccessfully in 1:27:30
2019-09-10T20:34:15.3201890Z == clock drift check ==
2019-09-10T20:34:15.3213634Z   local time: Tue Sep 10 20:34:15 UTC 2019
2019-09-10T20:34:15.4751914Z   network time: Tue, 10 Sep 2019 20:34:15 GMT
2019-09-10T20:34:15.4756123Z == end clock drift check ==
2019-09-10T20:34:16.0392598Z ##[error]Bash exited with code '1'.
2019-09-10T20:34:16.0432630Z ##[section]Starting: Checkout
2019-09-10T20:34:16.0434464Z ==============================================================================
2019-09-10T20:34:16.0434511Z Task         : Get sources
2019-09-10T20:34:16.0434567Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@RalfJung
Copy link
Member

LGTM, but what about the CI failure?

Also, do you have a Miri branch matching this? I guess the exact_div there should call into the method you added here.

@RalfJung
Copy link
Member

RalfJung commented Nov 2, 2019

@bors r=RalfJung,nikic

@bors
Copy link
Contributor

bors commented Nov 2, 2019

📌 Commit b93f48f has been approved by RalfJung,nikic

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 2, 2019
@bors
Copy link
Contributor

bors commented Nov 2, 2019

⌛ Testing commit b93f48f with merge 6c1b220...

bors added a commit that referenced this pull request Nov 2, 2019
Make <*const/mut T>::offset_from `const fn`

This reenables offset_of cc @mjbshaw 	after #63075 broke it
@bors
Copy link
Contributor

bors commented Nov 3, 2019

☀️ Test successful - checks-azure
Approved by: RalfJung,nikic
Pushing 6c1b220 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 3, 2019
@bors bors merged commit b93f48f into rust-lang:master Nov 3, 2019
bors added a commit to rust-lang/miri that referenced this pull request Nov 3, 2019
Use the upstream `exact_div` implementation

introduced in rust-lang/rust#63810
@RalfJung
Copy link
Member

RalfJung commented Nov 3, 2019

And merely 10 weeks later, we finally landed this. :D

@mjbshaw
Copy link
Contributor

mjbshaw commented Nov 3, 2019

Thanks for pushing this through!

@RalfJung
Copy link
Member

RalfJung commented Nov 3, 2019

@mjbshaw so what would be a good next step? We could equip the memoffset crate with support for const-context offset_of on nightly compilers?

I'd rather centralize the efforts for this in one place than everyone copy-pasting different variants of the same idea.^^

@mjbshaw
Copy link
Contributor

mjbshaw commented Nov 3, 2019

I don't plan on using the memoffset crate. I've already written some code to make use of offset_from, so at this point the next step is to finish plumbing it through the rest of my crate (which I'm in the process of doing).

@RalfJung
Copy link
Member

RalfJung commented Nov 3, 2019

Given our past experience with lots of incorrect variants of this code spread across half a dozen crates, I think it would be better to share a single known-good implementation that can also be centrally updated.

@RalfJung
Copy link
Member

RalfJung commented Nov 3, 2019

In particular, that code still uses &(*s).field, which is incorrect as it creates a reference to uninitialized data. At the very least that should be called out in comments as causing UB; but it would be better if we could share that code so that once Rust finally properly supports this operation, we only have to fix it in one place.

@mjbshaw
Copy link
Contributor

mjbshaw commented Nov 3, 2019

I generally agree, but I think the macro should live in core, not some third-party crate. If the macro were in core I'd use it.

Computing field offsets is one of the less-risky (comparatively speaking) things my crate does...

@RalfJung
Copy link
Member

RalfJung commented Nov 3, 2019

I see. Well seems like I cannot change your mind. ;)

I'll Cc you on the PR that adds const support to memoffset; would be good if we could work together on that and synchronize our approaches.

Comment on lines +241 to +242
let a = self.read_immediate(args[0])?.to_scalar()?.to_ptr()?;
let b = self.read_immediate(args[1])?.to_scalar()?.to_ptr()?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I just realized this is wrong... we need to support integers here as well.

This caused a regression in https://github.com/RalfJung/miri-test-libstd.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#66083 fixes that.

@oli-obk oli-obk deleted the const_offset_from branch November 5, 2019 11:28
jumbatm added a commit to jumbatm/rust that referenced this pull request Dec 27, 2019
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Dec 30, 2019
Clean up const-hack PRs now that const if / match exist.

Closes rust-lang#67627.

Cleans up these merged PRs tagged with `const-hack`:

- rust-lang#63810
- rust-lang#63786
- rust-lang#61635
- rust-lang#58044

reverting their contents to have the match or if expressions they originally contained.

r? @oli-obk

There's one more PR in those tagged with `const-hack` that originally wasn't merged (rust-lang#65107). Reading the thread, it looks like it was originally closed because the `const-hack` for the checked arithmetic non-negligibly hurt performance, and because there was no way to manipulate the returned Option at compile time anyway (with neither const if nor const match). Would you like me to add these changes to the changes from this PR here too, now that we have the necessary features?
@RalfJung RalfJung removed the const-hack This PR introduced a hack to make things valid in `const fn`. label Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet