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

Implement MIR pass to lower intrinsics #41024

Closed
wants to merge 2 commits into from
Closed

Implement MIR pass to lower intrinsics #41024

wants to merge 2 commits into from

Conversation

aochagavia
Copy link
Contributor

@aochagavia aochagavia commented Apr 2, 2017

Work towards #32716

The only lowering provided by this PR is for the move_val_init intrinsic.

r? @nagisa

@aochagavia
Copy link
Contributor Author

The tidy issue should be resolved now

// the cleanup code will be happily ignored and bad things will happen.

match func.ty.sty {
TypeVariants::TyFnDef(_, _, fn_sig)
Copy link
Contributor

Choose a reason for hiding this comment

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

this and the following line look kind of funny. Is this the correct way to format it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I needed to break the line somewhere to avoid the 100 width limit. Maybe I could indent the if statement. I haven't seen a similar situation earlier, so I just went with what felt natural to me.

TypeVariants::TyFnDef(_, _, fn_sig)
if fn_sig.skip_binder().abi == Abi::RustIntrinsic => {
let target = match destination {
&Some(ref d) => d.1,
Copy link
Contributor

Choose a reason for hiding this comment

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

can you do match *destnation to prevent &Some and &None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see the added value of that

Copy link
Contributor

Choose a reason for hiding this comment

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

It's the preferred style

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, in that case I will change it. Thanks for pointing it out.

args: Vec<Operand<'tcx>>,
target: BasicBlock) {
let name = &*intrinsic_name(tcx, &func);
if name == "move_val_init" {
Copy link
Contributor

Choose a reason for hiding this comment

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

will this approach encourage a long if/else if chain for every intrinsic? If so, that just seems like a nightmare to read and maintain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I expect to introduce a match in the future and write a function for each intrinsic.

@nagisa
Copy link
Member

nagisa commented Apr 3, 2017

For reference, I do not think it is worthwhile to try land this without having at least the most prominent intrinsics ported (transmute, uninit, unreachable, needs_drop, discriminant_value, ...). Intrinsics that depend on layout like size_of will have to be resolved later on in the pipeline, for example. Those are probably just fine to be left alone for now.

@aochagavia
Copy link
Contributor Author

aochagavia commented Apr 3, 2017

@nagisa do you think the current approach is sound? I will be happy to implement the remaining intrinsics, but it would be good to know whether I am going in the right direction.

@nagisa
Copy link
Member

nagisa commented Apr 3, 2017

@aochagavia I think you’ll encounter some trouble trying to port most of the intrinsics with this specific approach. Some intrinsics want to be lowered later than sooner, and the design will have to account for that.

@nagisa
Copy link
Member

nagisa commented Apr 3, 2017

I mean writing the transformation as a MIR Pass might work out, but you’ll need at least a number of these at various points.

@aochagavia
Copy link
Contributor Author

I also looked into lowering intrinsics at MIR build time, but that didn't seem very compelling either.

@aochagavia
Copy link
Contributor Author

So it looks like we need some design work before blindly lowering intrinsics. I would love to help with that, but I am no expert in Rust's internals.

@aochagavia
Copy link
Contributor Author

I have time to experiment with different possible directions, though.

@aochagavia
Copy link
Contributor Author

So if there is anything in particular that seems like it could work, feel free to tell me so I can try it out

@shepmaster shepmaster added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 14, 2017
@shepmaster
Copy link
Member

@nagisa I believe that @aochagavia is looking for a bit more guidance and direction before continuing.

@nagisa
Copy link
Member

nagisa commented Apr 14, 2017

I’m not sure there’s anything I can tell beyond what I’ve already told here. I feel like designing suitable approach would be an equivalent, in difficulty, problem as implementing the approach. The viable design could include just having a distinct pass for every single intrinsic, but that sounds untenable in a long run.

@arielb1
Copy link
Contributor

arielb1 commented Apr 18, 2017

Given its weird semantics, we are supposed to handle move_val_init in MIR construction, because we want to transform move_val_init(x, y()) to *x = call y.

@arielb1
Copy link
Contributor

arielb1 commented Apr 18, 2017

The move_val_init part is superseded by #41361. The other intrinsics should be more similar to eachother.

@shepmaster
Copy link
Member

Based on @arielb1's last comment, it sounds like there's at least a hint of a proposed sketch of a design for intrinsics other than move_val_init. Based on that, I think that it's back on @aochagavia to move the PR forward.

If there continues to be complex issues around the higher-level design, opening a thread on the internals forum might yield a deeper discussion than a PR.

@shepmaster shepmaster 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 Apr 21, 2017
@aochagavia aochagavia closed this Apr 21, 2017
@aochagavia
Copy link
Contributor Author

I am no longer interested in working on this. Thanks anyway for the feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants