Make tuple constructors real const fns#61209
Conversation
This comment has been minimized.
This comment has been minimized.
src/librustc_mir/shim.rs
Outdated
There was a problem hiding this comment.
This change makes me wonder whether it would be possible to generalize build_adt_ctor to the point where we can scrap mir::AggregateKind::Adt and just call the part of build_adt_ctor that generates the field and discr initialization.
Additionally, if I'm reading this correctly, build_adt_ctor could generate a shim that allows initializing arbitrary ty::Adt. So there's nothing implementation wise that would speak against the lang team figuring out a way to obtain initialization functions for struct variants or just plain structs. cc @Centril
There was a problem hiding this comment.
cc @rust-lang/lang Not suggesting that we add this or anything, but wanted to let you know that we can now generate a function
fn foo(a: A, b: B, c: C) -> Foo {
Foo { a, b, c }
}from a struct definition
struct Foo {
a: A,
b: B,
c: C,
}In case this ever comes up as something that may be useful
There was a problem hiding this comment.
@oli-obk FWIW we already have an optimization that expands Rvalue::Aggregate into this instruction sequence so this code is already duplicated, I think?
There was a problem hiding this comment.
iirc that optimization is very expensive to run. I know we want to do little work at MIR building time, but in this case I believe it's equivalent in complexity. We can scrap that optimization if we just do it all at MIR building time.
There was a problem hiding this comment.
I meant that we could put the code generating this in that optimization until we get rid of it (rather than relying on running the optimization).
src/librustc_mir/shim.rs
Outdated
There was a problem hiding this comment.
So I guess this is pre-optimized? As opposed to Rvalue::Aggregate?
This comment has been minimized.
This comment has been minimized.
03c42ed to
0068ea0
Compare
src/test/ui/consts/const_constructor/feature-gate-const_constructor.stderr
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
|
r=me with feature gates cleaned up |
0068ea0 to
bcf8365
Compare
|
@bors r=oli-obk |
|
📌 Commit bcf8365 has been approved by |
Make tuple constructors real const fns
Mir construction special cases `Ctor(...)` to be lowered as `Ctor { 0: ... }`, which means this doesn't come up much in practice, but it seems inconsistent not to allow this.
r? @oli-obk
|
☀️ Test successful - checks-travis, status-appveyor |
Mir construction special cases
Ctor(...)to be lowered asCtor { 0: ... }, which means this doesn't come up much in practice, but it seems inconsistent not to allow this.Tracking issue: #61456
r? @oli-obk