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

Additional cleanup to rustc_trans #38756

Merged
merged 18 commits into from
Jan 5, 2017

Conversation

Mark-Simulacrum
Copy link
Member

@Mark-Simulacrum Mark-Simulacrum commented Jan 1, 2017

Removes BlockAndBuilder, FunctionContext, and MaybeSizedValue.

LvalueRef is used instead of MaybeSizedValue, which has the added benefit of making functions operating on Lvalues be able to take just that (since it encodes the type with an LvalueTy, which can carry discriminant information) instead of a MaybeSizedValue and a discriminant.

r? @eddyb

@Mark-Simulacrum Mark-Simulacrum changed the title Additional cleanup to Trans Additional cleanup to rustc_trans Jan 1, 2017
@@ -57,6 +79,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}

pub fn build_new_block<'b>(&self, name: &'b str) -> Builder<'a, 'tcx> {
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 call this build_sibling_block.

@@ -46,6 +50,24 @@ fn noname() -> *const c_char {
}

impl<'a, 'tcx> Builder<'a, 'tcx> {
pub fn entry_block(ccx: &'a CrateContext<'a, 'tcx>, llfn: ValueRef) -> Self {
Builder::new_block(ccx, llfn, "entry-block")
}
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I think it would be nice if this was actually encapsulated in define_fn but I'm not sure that actually works out well.

@@ -295,14 +296,16 @@ impl ArgType {
}
}

pub fn store_fn_arg(&self, bcx: &BlockAndBuilder, idx: &mut usize, dst: ValueRef) {
pub fn store_fn_arg(
&self, bcx: &Builder, idx: &mut usize, dst: ValueRef
Copy link
Member

Choose a reason for hiding this comment

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

nit: style

} else {
MaybeSizedValue::unsized_(lvalue.llval, lvalue.llextra)
LvalueRef::new_unsized_ty(lvalue.llval, lvalue.llextra, ty)
Copy link
Member

Choose a reason for hiding this comment

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

These two branches could reuse lvalue and only mutate the llval field if it needs a cast.

!self.llextra.is_null()
}

pub fn struct_field_ptr(
Copy link
Member

Choose a reason for hiding this comment

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

Is this just a helper or does this need to be public?

} else {
tr_base.llextra
LvalueRef::new_unsized(tr_base.llval, tr_base.llextra, tr_base.ty)
Copy link
Member

Choose a reason for hiding this comment

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

Again, this is just recreating tr_base.

let args = &[ptr.llval, ptr.llextra][..1 + ptr.has_extra() as usize];
if bcx.ccx.shared().type_is_sized(ty) {
assert!(lvalue.llextra == ptr::null_mut());
if drop_ty != ty {
Copy link
Member

Choose a reason for hiding this comment

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

The two conditions can be collapsed, I believe.

let llprojected = base.trans_field_ptr(bcx, field.index());
(llprojected, base.llextra)
if self.ccx.shared().type_is_sized(projected_ty.to_ty(tcx)) {
tr_base.llextra = ptr::null_mut();
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't mutate tr_base here but rather have a different variable (since it ends up in llextra anyway).

@pnkfelix pnkfelix added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 3, 2017
adt_def: adt_def,
substs: substs,
variant_index: variant_index,
};
Copy link
Member

Choose a reason for hiding this comment

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

Why not do this in the caller? Or at least at the start of the function, only once.

ptr.ty = LvalueTy::Downcast {
adt_def: adt,
substs: substs,
variant_index: Disr::from(discr).0 as usize,
Copy link
Member

Choose a reason for hiding this comment

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

How is this even a thing for AdtKind::Struct? This should never need downcasts. What is even VariantInfo?!

ty: sig.output(),
};
self.store_return(&ret_bcx, ret_dest, fn_ty.ret, op);
ret_bcx.position_at_end(ret_bcx.llbb());
Copy link
Member

Choose a reason for hiding this comment

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

The builder is dead after this point so it shouldn't be needed.

Copy link
Member

@nagisa nagisa Jan 4, 2017

Choose a reason for hiding this comment

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

The builder is dead after this point so it shouldn't be needed.

I’m confused why all the repositioning is necessary at all anymore (somebody forgot to remove the hack?) if the blocks are translated in reverse-postorder.

Can we see if the stuff sstill works if both repositions are removed?

@eddyb
Copy link
Member

eddyb commented Jan 4, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Jan 4, 2017

📌 Commit 0846c0e has been approved by eddyb

@bors
Copy link
Contributor

bors commented Jan 4, 2017

⌛ Testing commit 0846c0e with merge c5c2083...

@bors
Copy link
Contributor

bors commented Jan 4, 2017

💔 Test failed - status-travis

@Mark-Simulacrum
Copy link
Member Author

Looks like a network error? LLVM's submodule couldn't be cloned.

@eddyb
Copy link
Member

eddyb commented Jan 4, 2017

@bors retry

@bors
Copy link
Contributor

bors commented Jan 4, 2017

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

@Mark-Simulacrum
Copy link
Member Author

Rebased.

@eddyb
Copy link
Member

eddyb commented Jan 4, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Jan 4, 2017

📌 Commit b01b6e1 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Jan 5, 2017

⌛ Testing commit b01b6e1 with merge 5dd07b6...

bors added a commit that referenced this pull request Jan 5, 2017
Additional cleanup to rustc_trans

Removes `BlockAndBuilder`, `FunctionContext`, and `MaybeSizedValue`.

`LvalueRef` is used instead of `MaybeSizedValue`, which has the added benefit of making functions operating on `Lvalue`s be able to take just that (since it encodes the type with an `LvalueTy`, which can carry discriminant information) instead of a `MaybeSizedValue` and a discriminant.

r? @eddyb
@bors
Copy link
Contributor

bors commented Jan 5, 2017

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

@bors bors merged commit b01b6e1 into rust-lang:master Jan 5, 2017
@Mark-Simulacrum Mark-Simulacrum deleted the 2nd-trans-cleanup branch January 5, 2017 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants