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

Support members for the new newtypes #5311

Merged
merged 62 commits into from
Apr 16, 2024

Conversation

RustanLeino
Copy link
Collaborator

This PR adds support for members of the recently expanded newtypes. In particular, inheritance of user-defined members and built-in members (such as .RotateLeft for bitvector types) are handled. Under --general-trait=full, inheritance from both newtype base types and parent traits are handled.

A newtype's inherited members can only be figured out once the newtype's base type is known. Since the base type is in general inferred, this means that member registration cannot happen until resolution has started. So, this PR moves that process from Register... to Resolve....

As part of this PR, other built-in types (char, set, ...) were added to the valuetypeDecls array. This has an effect on the --rprint output.

The PR also improves some error messages (e.g., making them more consistent by using the format type 'T') and removes some unused code that was left in abandoned #if ... directives during the resolver refresh.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

# Conflicts:
#	Source/DafnyCore/Resolver/CheckTypeCharacteristics_Visitor.cs
#	Source/DafnyCore/Rewriters/RefinementErrors.cs
#	Source/DafnyCore/Rewriters/RefinementTransformer.cs
#	docs/HowToFAQ/Errors-Refinement.md
@RustanLeino RustanLeino enabled auto-merge (squash) April 10, 2024 04:00
Copy link
Member

@MikaelMayer MikaelMayer left a comment

Choose a reason for hiding this comment

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

A few comments here and there, but I'm happy with this very well tested PR otherwise!

}
}
}
if (prevErrorCount == reporter.Count(ErrorLevel.Error)) {
Copy link
Member

Choose a reason for hiding this comment

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

This If statement has not been moved, just deleted. Could you please confirm why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for noticing. Yes, this is as intended. The RegisterInheritedMembers and InheritedTraitMembers methods had been responsible for bringing in the members from a type's trait parents. With the more general newtypes, a newtype can now inherit members also from its base type. However, the base type is, in general, not known this early in the resolution pipeline. Therefore, the functionality of RegisterInheritedMembers and InheritedTraitMembers was moved into "pass 0" of the resolver.

Source/DafnyCore/Resolver/ModuleResolver.cs Outdated Show resolved Hide resolved
@@ -1,4 +1,4 @@
git-issue-2303.dfy(5,10): Error: newtype's base type is not fully determined; add an explicit type for bound variable 'x'
git-issue-2303.dfy(5,10): Error: base type of newtype 'int0' is not fully determined; add an explicit type for bound variable 'x'
Copy link
Member

Choose a reason for hiding this comment

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

Good job making the message a bit more explicit

type seq<+T> { }

type multiset<+T> { }

type map<+T, +U> {
var Keys: set<T> // immutable
Copy link
Member

Choose a reason for hiding this comment

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

Immutable with var? Shouldn't it be const?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call. I changed the printing code to output these SpecialFields as const.

Source/DafnyCore/Resolver/PreType/PreTypeResolve.cs Outdated Show resolved Hide resolved
Copy link
Member

@MikaelMayer MikaelMayer left a comment

Choose a reason for hiding this comment

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

Looks great ! Approved a priori. Did you also ensure that the type characteristics were matched?

@RustanLeino RustanLeino merged commit db2d6ed into dafny-lang:master Apr 16, 2024
19 of 20 checks passed
@RustanLeino RustanLeino deleted the newtype-members branch April 17, 2024 17:48
@RustanLeino
Copy link
Collaborator Author

Did you also ensure that the type characteristics were matched?

No new cases needed to be checked. Unlike members inherited from a parent trait, the members that are inherited from the base type already have a body and cannot be overridden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants