chris-morgan / mopa

MOPA: My Own Personal Any. A macro to implement all the `Any` methods on your own trait.
Other
112 stars 9 forks source link

Generalize the mopafy! macro to work on parametrized traits #4

Closed Marwes closed 4 years ago

Marwes commented 8 years ago

Adds to the mopafy! macro so that it can take traits with parameters like mopafy!(Paremetrized<A, B>).

I had to use parentheses in the variants which actually do something to avoid ambiguity but otherwise it is a quite small generalization. This does not make it possible to add trait bounds to those parameters as I do not know a good way to do this in macros but for my purposes I did not need that anyway.

Marwes commented 8 years ago

Added a commit which fixes the use of no_std which I forgot to test.

davidzchen commented 8 years ago

Are there still plans to merge this? I think this would be very useful to have.

Marwes commented 8 years ago

Rebased on top of current master. Also had to add some lang_items to the no_std examples to get them to build.

Marwes commented 8 years ago

Any chance of getting this merged and pushed to crates.io? If there are any problems with this PR I would be happy to update it.

chris-morgan commented 8 years ago

@Marwes: the modifications to the lang items: what requires that? I haven’t had any problems with running the tests or the examples on stable, beta or nightly.

Marwes commented 8 years ago

@chris-morgan I am not exactly sure why actually. I tried compiling the tests and got undefined reference errors from the linker and after looking up the signatures for the functions and adding them it compiled fine.

The best guess I can give is that I needed them due to compiling on windows and only windows versions of rustc properly check for stack overflow (the functions seem to refer to "frames"). Might be misunderstanding something though so it may be safer to remove them if it compiles fine on travis without them.

retep998 commented 8 years ago

Very likely that those lang items are Windows specific, due to SEH exceptions which are quite different than dwarf which is used on other platforms. They're unrelated to stack overflows, and rather refer to exception frames. Rust doesn't check for stack overflow, rather LLVM on Windows will inject a stack probe for any function that uses over a page of stack, and then Rust catches the SEH exception that fires when code tries to access the guard page at the top of the stack.

Marwes commented 8 years ago

@retep998 Thanks for the explanation. The guard page was the "overflow check" I thought though I was quite off base with "stack frames".

Marwes commented 8 years ago

@chris-morgan Should I remove the additional lang items and/or are there any other modifications I should make?

Limeth commented 8 years ago

This PR is useful. I hope it gets merged soon.