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 drop glue for unsized value pass two arguments instead of *(data, meta) #38511

Merged
merged 1 commit into from
Dec 23, 2016

Conversation

Mark-Simulacrum
Copy link
Member

Fixes #36457

r? @eddyb

@@ -87,6 +87,14 @@ impl MaybeSizedValue {
pub fn has_meta(&self) -> bool {
!self.meta.is_null()
}

pub fn to_args(&self) -> Vec<ValueRef> {
Copy link
Member

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.

Copy link
Member

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))
Copy link
Member

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));
Copy link
Member

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[..]
Copy link
Member

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);
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

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

Outdated comment.

@Mark-Simulacrum Mark-Simulacrum force-pushed the drop-glue branch 2 times, most recently from 942f015 to 303db8b Compare December 21, 2016 16:57
let t = g.ty();

let value = get_param(llfn, 0);
Copy link
Member

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);
Copy link
Member

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]);
Copy link
Member

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.

bcx = normal_bcx;
} else {
llret = bcx.call(callee.reify(bcx.ccx),
&[ptr.value, ptr.meta][..1 + ptr.has_meta() as usize], None);
Copy link
Member

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?

@Mark-Simulacrum Mark-Simulacrum force-pushed the drop-glue branch 2 times, most recently from 72c048f to 5ee90f5 Compare December 21, 2016 18:34
@eddyb
Copy link
Member

eddyb commented Dec 21, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Dec 21, 2016

📌 Commit 5ee90f5 has been approved by eddyb

@eddyb
Copy link
Member

eddyb commented Dec 21, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Dec 21, 2016

📌 Commit afc2dcd has been approved by eddyb

@bors
Copy link
Contributor

bors commented Dec 22, 2016

⌛ Testing commit afc2dcd with merge 94bb66d...

@bors
Copy link
Contributor

bors commented Dec 22, 2016

💔 Test failed - auto-mac-32-opt

@bluss
Copy link
Member

bluss commented Dec 22, 2016

@bors retry force clean

@bors
Copy link
Contributor

bors commented Dec 22, 2016

⌛ Testing commit afc2dcd with merge c44e5d5...

@bors
Copy link
Contributor

bors commented Dec 22, 2016

💔 Test failed - auto-mac-32-opt

@eddyb
Copy link
Member

eddyb commented Dec 22, 2016

@bors retry

@bors
Copy link
Contributor

bors commented Dec 23, 2016

⌛ Testing commit afc2dcd with merge ce4461f...

bors added a commit that referenced this pull request Dec 23, 2016
Make drop glue for unsized value pass two arguments instead of *(data, meta)

Fixes #36457

r? @eddyb
@bors bors merged commit afc2dcd into rust-lang:master Dec 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants