-
Notifications
You must be signed in to change notification settings - Fork 266
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
Fixes: Rust supports overriding traits #5948
base: master
Are you sure you want to change the base?
Conversation
Fixed support for hashing and equality for traits overrides Support for static functions and methods
… feat-rust-support-overriding-trait
# Conflicts: # Source/DafnyCore/Backends/Dafny/AST.dfy # Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs # Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-definitions.dfy # Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy # Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy # Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs # Source/DafnyCore/GeneratedFromDafny/DAST.cs # Source/DafnyCore/GeneratedFromDafny/DCOMP.cs # Source/DafnyCore/GeneratedFromDafny/Defs.cs # Source/DafnyCore/GeneratedFromDafny/RAST.cs # Source/DafnyRuntime/DafnyRuntimeRust/src/lib.rs # Source/DafnyRuntime/DafnyRuntimeRust/src/tests/mod.rs # Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy # Source/IntegrationTests/TestFiles/LitTests/LitTest/comp/rust/traits-datatypes.dfy.expect
# Conflicts: # Source/DafnyCore.Test/GeneratedFromDafny/DefsCoverage.cs # Source/DafnyCore/Backends/Rust/Dafny-compiler-rust-rast.dfy # Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy # Source/DafnyCore/GeneratedFromDafny/DCOMP.cs # Source/DafnyCore/GeneratedFromDafny/Defs.cs # Source/DafnyCore/GeneratedFromDafny/RAST.cs
# Conflicts: # Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs # Source/DafnyCore/Backends/Rust/Dafny-compiler-rust.dfy # Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs # Source/DafnyCore/GeneratedFromDafny/DCOMP.cs # Source/DafnyCore/Resolver/ModuleResolver.cs # Source/DafnyCore/Resolver/TypeCharacteristicChecker.cs
Caching of compilation name. Don't copy target file if same path
# Conflicts: # Source/DafnyCore/Backends/Dafny/DafnyCodeGenerator.cs # Source/DafnyCore/Backends/SinglePassCodeGenerator/SinglePassCodeGenerator.cs
Some high level comments: I'm mainly just concerned about the soundness and implementation of trait downcasting. It looks like you do this in phases:
I don't understand why the latter can't be done earlier - is there not a subtype check method in the type system refresh? |
Thank you very much for reading the PR and trying to understand the underlying logic. That's already a lot of work.
You're right that there is an issue here. The problem is that in other backends, it's fine to do something like this:
This is because other back-ends keep run-time information of the type and types are behind single references. The only sensible way to do trait downcast is to add special methods to the trait X {} so that we can test if it's a Y {} for some T. However, again, because of monomorphization, Rust prevents type parameters on functions that are in a trait with a function. Hence, the only way to do a downcast test and instantiation is if the type parameters of the subtrait can be obtained from the type parameters of X. This is what I am computing in This means indeed that users who try to downcast One problem with doing it earlier is that the subtype check depends on whether the instantiated type parameters support |
Description
The PR #5940 defined a preliminary support for value traits.
This PR fixes everything that encompasses value traits and newtypes. Here is the list of fixes.
Also some enhancements
{:extern}
on types requiring a hint when it can simply take the Dafny name, like for modules and classes.DafnyCodeGenerator.GenType
now caches its result to avoid exponential computationsI also updated the documentation regarding the use of externs
How has this been tested?
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.