-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 drop glue for unsized value pass two arguments instead of *(data, meta) #38511
Conversation
@@ -87,6 +87,14 @@ impl MaybeSizedValue { | |||
pub fn has_meta(&self) -> bool { | |||
!self.meta.is_null() | |||
} | |||
|
|||
pub fn to_args(&self) -> Vec<ValueRef> { |
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.
Unnecessary allocation IMO. I'd rather have some helper that takes a MaybeSizedValue
and drops 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.
Actually, there's only two places so I'd rather just have allocation-less logic in both of them, this might work:
let args = &[x.value, x.meta][..1 + x.has_meta() as usize];
You could also make a helper for "argument count".
let t = g.ty(); | ||
|
||
let args = if ccx.shared().type_is_sized(t) { | ||
MaybeSizedValue::sized(get_param(llfn, 0)) |
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.
I'd move the first argument out (data
), and also call this v
or value
or ptr
, not args
.
|bb, vv| drop_ty(bb, MaybeSizedValue::sized(vv), unit_ty)); | ||
} else { | ||
cx = tvec::slice_for_each(&cx, value.value, unit_ty, value.meta, | ||
|bb, _vv| drop_ty(bb, value, unit_ty)); |
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 can't be right. You should assert that the unit_ty
is sized (or don't, really, it can never be right now).
bcx.store(lvalue.llextra, base::get_meta(&bcx, scratch)); | ||
scratch | ||
unsized_args = [lvalue.llval, lvalue.llextra]; | ||
&unsized_args[..] |
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.
I'd rather have what I suggested before here too, one line turning an lvalue
into an argument slice.
} else { | ||
bcx.call(drop_fn, &[llvalue], cleanup_bundle); | ||
bcx.call(drop_fn, args, cleanup_bundle); |
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.
Here's the cool part: since the ABI is identical for the drop glue and drop_in_place
, you can just change callee.data
to Fn(drop_fn)
and mutate intrinsic
to None
. You can replace the pointer cast of an argument with a cast of drop_fn
to the LLVM type of fn_ty
(which means the if
has to be moved lower down to where fn_ty
is declared).
let sig = tcx.mk_fn_sig(iter::once(tcx.mk_mut_ptr(tcx.types.i8)), tcx.mk_nil(), false); | ||
let sig = tcx.mk_fn_sig(iter::once(tcx.mk_mut_ptr(t)), tcx.mk_nil(), false); | ||
|
||
debug!("predefine_drop_glue: sig={}", sig); | ||
|
||
// Create a FnType for fn(*mut i8) and substitute the real type in | ||
// later - that prevents FnType from splitting fat pointers 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.
Outdated comment.
942f015
to
303db8b
Compare
let t = g.ty(); | ||
|
||
let value = get_param(llfn, 0); |
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 this meant you started using value
below noo 😞, I'd rather you change it back.
scratch | ||
}; | ||
drop_ty(&cx, val, field_ty); | ||
drop_ty(&cx, MaybeSizedValue::unsized_(llfld_a, value.meta), field_ty); |
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 should really create a MaybeSizedValue
in a variable (I'd copy the original and only change the data pointer) then have a separate single drop_ty
call.
@@ -458,65 +467,12 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { | |||
} | |||
|
|||
let ptr = self.trans_operand(&bcx, &args[0]); |
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 needs to go away.
b547921
to
0c45a4d
Compare
bcx = normal_bcx; | ||
} else { | ||
llret = bcx.call(callee.reify(bcx.ccx), | ||
&[ptr.value, ptr.meta][..1 + ptr.has_meta() as usize], None); |
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.
Can you lift the arguments out of the if-let
/else
?
72c048f
to
5ee90f5
Compare
@bors r+ |
📌 Commit 5ee90f5 has been approved by |
5ee90f5
to
afc2dcd
Compare
@bors r+ |
📌 Commit afc2dcd has been approved by |
⌛ Testing commit afc2dcd with merge 94bb66d... |
💔 Test failed - auto-mac-32-opt |
@bors retry force clean |
⌛ Testing commit afc2dcd with merge c44e5d5... |
💔 Test failed - auto-mac-32-opt |
@bors retry |
Fixes #36457
r? @eddyb