Giter Club home page Giter Club logo

Comments (11)

eddyb avatar eddyb commented on August 20, 2024 1

Generative types from existentials would allow perfectly typed safe vtables from even user code ;).

from miri.

solson avatar solson commented on August 20, 2024

@Aatch tells me that they had this problem in the rustc compiler, too, and solved it by computing these trait object field offsets dynamically by reading the alignment stored in the vtable.

from miri.

solson avatar solson commented on August 20, 2024

Specifically, we need to do it dynamically for only the DST field, only when it's not the first field, and only for non-packed structs.

from miri.

solson avatar solson commented on August 20, 2024

We can make use of our size_and_align_of_dst. Here is the relevant code in rustc trans with comments.

from miri.

oli-obk avatar oli-obk commented on August 20, 2024

While I agree that this is the solution, shouldn't rustc's layout computation fail on dsts? I mean the layout is just plain wrong.

from miri.

eddyb avatar eddyb commented on August 20, 2024

@oli-obk No, the layout computation for DSTs returns information you can't possibly get otherwise.

from miri.

oli-obk avatar oli-obk commented on August 20, 2024

How about protecting the offsets field (access only through an accessor) in case sized: false?

from miri.

eddyb avatar eddyb commented on August 20, 2024

@oli-obk You still need the offset of the last field. It's correct in terms of being the base offset but each backend has to generate its own dynamic alignment code. I don't think it's possible to ergonomically hide it.

from miri.

solson avatar solson commented on August 20, 2024

@eddyb We could ergonomically hide it if MIR desugared to a form with explicit vtable accesses and expanded DST field offsets to MIR statements doing this offset calculation in a backend-independent way. =)

from miri.

solson avatar solson commented on August 20, 2024

Unfortunately MIR is typed, so you would need.... vtable types? A person can dream, though.

from miri.

eddyb avatar eddyb commented on August 20, 2024

I mean, other than using the generative typing trick through lifetime HRTB.

from miri.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.