-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Miri: basic dyn* support #107728
Miri: basic dyn* support #107728
Conversation
The Miri subtree was changed cc @rust-lang/miri Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
Indeed I confirmed if I weaken the |
b03d793
to
f815d0f
Compare
@@ -193,7 +193,7 @@ fn layout_of_uncached<'tcx>( | |||
} | |||
|
|||
ty::Dynamic(_, _, ty::DynStar) => { | |||
let mut data = scalar_unit(Int(dl.ptr_sized_integer(), false)); | |||
let mut data = scalar_unit(Pointer(AddressSpace::DATA)); |
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.
This seems to cause issues.
Invalid InsertValueInst operands!
%15 = insertvalue { ptr, ptr } undef, i64 %14, 0
in function _ZN3box13make_dyn_star17h0c15bb343f1925bdE
LLVM ERROR: Broken function found, compilation aborted!
Probably somewhere in the backend something still assumes an integer type here, and inserts an i64
into this { ptr, ptr }
?
@@ -193,7 +193,7 @@ fn layout_of_uncached<'tcx>( | |||
} | |||
|
|||
ty::Dynamic(_, _, ty::DynStar) => { | |||
let mut data = scalar_unit(Int(dl.ptr_sized_integer(), false)); | |||
let mut data = scalar_unit(Pointer(AddressSpace::DATA)); |
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.
This seems to cause issues.
---- [ui] tests/ui/dyn-star/box.rs stdout ----
error: test compilation failed although it shouldn't!
status: exit status: 101
command: "/home/r/src/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "/home/r/src/rust/rustc/tests/ui/dyn-star/box.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--remap-path-prefix=/home/r/src/rust/rustc/tests/ui=fake-test-src-base" "-C" "prefer-dynamic" "-o" "/home/r/src/rust/rustc/build/x86_64-unknown-linux-gnu/test/ui/dyn-star/box/a" "-Crpath" "-Cdebuginfo=0" "-Lnative=/home/r/src/rust/rustc/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/home/r/src/rust/rustc/build/x86_64-unknown-linux-gnu/test/ui/dyn-star/box/auxiliary" "-C" "opt-level=0"
stdout: none
--- stderr -------------------------------
Invalid InsertValueInst operands!
%15 = insertvalue { ptr, ptr } undef, i64 %14, 0
in function _ZN3box13make_dyn_star17h0c15bb343f1925bdE
LLVM ERROR: Broken function found, compilation aborted!
Probably somewhere in the backend something still assumes an integer type here, and inserts an i64
into this { ptr, ptr }
? This actually casts a Box to dyn*
, so the input value is a pointer -- no idea where the i64
comes from.
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.
Looking at the LLVM IR on current nightly
%10 = ptrtoint ptr %_4.i to i64, !dbg !1309
%11 = insertvalue { i64, ptr } undef, i64 %10, 0, !dbg !1310
%12 = insertvalue { i64, ptr } %11, ptr @vtable.1, 1, !dbg !1310
We are generating a ptrtoint
?!? That doesn't sound right at all. We shouldn't be generating such a cursed operation unless the user actually asked for it.
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.
Oh, I just found #102641...
We should be doing the opposite: if the input is an integer, we should cast/transmute/bit/cast/whatever it to a pointer.
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.
Strangely just removing that pointer type hack seems to work? I would have expected errors from where we cast usize to dyn* (I think we are now inserting an i64
where a ptr
should go) but strangely, there are no such errors...
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.
Ah, on CI it does fail. CI uses an older, pre-ptr
version of LLVM.
14be9c7
to
47d7047
Compare
5cb9603
to
345d8d0
Compare
This totally makes sense, and I'd be up for rewriting it to split them apart. The reason I added the layout as a field within the same variant originally was that, at least in the front parts of the compiler, they generally are pretty similar. For a lot of the type system, the only difference between But yeah, later on the layouts are quite different, and it's not just too hard to do |
345d8d0
to
5cbdc7c
Compare
So looks like something is inserting bitcasts, and that works fine on recent LLVM but old LLVM doesn't like them? Probably the change to using a pointer ABI should be its own PR, a prerequisite to this one. @eholk is that something you could help with? |
Yeah, probably. Ideally we'd insert the equivalent of There is also a bitcast coming from somewhere that we do not want... or maybe that's some automatic thing the codegen backend is doing when an immediate of one type is used in a situation that expects another type? |
@compiler-errors - go for it! I was going to spend some time this afternoon splitting |
This comment has been minimized.
This comment has been minimized.
74aca1d
to
10eae16
Compare
This comment has been minimized.
This comment has been minimized.
…s-ptr, r=eholk Make `dyn*`'s value backend type a pointer One tweak on top of Ralf's commit should fix using `usize` as a `dyn*`-coercible type, and should fix when we're using various other pointer types when LLVM opaque pointers is disabled. r? `@eholk` but feel free to reassign cc rust-lang#107728 (comment) `@RalfJung`
This comment has been minimized.
This comment has been minimized.
74c45f4
to
ad6dd60
Compare
edit: race condition, you pushed faster lol |
ok, another try :) |
r=me on your commits, and I think this is good to go. |
@bors r=RalfJung,oli-obk |
☀️ Test successful - checks-actions |
1 similar comment
☀️ Test successful - checks-actions |
Finished benchmarking commit (f715e43): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. |
…tic, r=eholk Don't ICE when encountering `dyn*` in statics or consts Since we have properly implemented `dyn*` support in CTFE (rust-lang#107728), let's not ICE here anymore. Fixes rust-lang#105777 r? `@eholk`
As usual I am very unsure about the dynamic dispatch stuff, but it passes even the
Pin<&mut dyn* Trait>
test so that is something.TBH I think it was a mistake to make
dyn Trait
anddyn* Trait
part of the sameTyKind
variant. Almost everywhere in Miri this lead to the wrong default behavior, resulting in strange ICEs instead of nice "unimplemented" messages. The two types describe pretty different runtime data layout after all.Strangely I did not need to do the equivalent of this diff in Miri. Maybe that is because the unsizing logic matches on
ty::Dynamic(.., ty::Dyn)
already? Inunsized_info
I don't think thetarget_dyn_kind
can beDynStar
, since then it wouldn't be unsized!r? @oli-obk Cc @eholk (dyn-star) #102425