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

Use collection expressions where possible #6079

Merged

Conversation

keyboardDrummer
Copy link
Member

What was changed?

  • Use collection expressions where possible

How has this been tested?

  • No additional testing needed

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

@keyboardDrummer keyboardDrummer enabled auto-merge (squash) January 24, 2025 14:06
Copy link
Contributor

@ssomayyajula ssomayyajula left a comment

Choose a reason for hiding this comment

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

(Approved from previous PR)

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 like an excellent improvement for the maintenance of the code. A few comments.

@@ -22,8 +22,9 @@ private void InitializeAttributes() {
Attributes.ContainsBool(Attributes, "split", ref splitMatch);
foreach (var c in Cases) {
if (!Attributes.Contains(c.Attributes, "split")) {
List<Expression> args = new List<Expression>();
args.Add(Expression.CreateBoolLiteral(c.Origin, splitMatch));
List<Expression> args = [
Copy link
Member

Choose a reason for hiding this comment

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

Wow nice syntax at least !

new List<TypeParameter>(new TypeParameter[] { new TypeParameter(SourceOrigin.NoToken, new Name("arg"), TypeParameter.TPVarianceSyntax.NonVariant_Strict) }),
new List<MemberDecl>(), attrs, false, null) {
[
.. new TypeParameter[]
Copy link
Member

Choose a reason for hiding this comment

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

What is this weird syntax? Am I understanding correctly that we are creating a list from an inline array? Can we just create now the list using [] ?

Comment on lines +864 to 866
Bpl.Expr.Literal(0)
];
// {:subsumption 0}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Bpl.Expr.Literal(0)
];
// {:subsumption 0}
// {:subsumption 0}
Bpl.Expr.Literal(0)
];

("p2", "Always true."),
("p3", "Always true every time."),
});
", [
Copy link
Member

Choose a reason for hiding this comment

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

Excellent that it also works with named tuples

@@ -21,7 +21,7 @@ public void TestConcatSequence() {
Thread t = new Thread(delegate () {
left.right = null;
Thread.Sleep(100); // Ensure ComputeElements() does not work immediately
left.elmts = new List<int>() { 1, 2 }.ToImmutableArray();
left.elmts = [.. new List<int>() { 1, 2 }];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
left.elmts = [.. new List<int>() { 1, 2 }];
left.elmts = [1, 2];

I hope it works !

@keyboardDrummer keyboardDrummer merged commit 77fc931 into dafny-lang:master Jan 27, 2025
22 checks passed
@keyboardDrummer keyboardDrummer deleted the collectionExpressions branch January 27, 2025 12:48
@keyboardDrummer
Copy link
Member Author

Remaining comments addressed in #6083

keyboardDrummer added a commit that referenced this pull request Jan 28, 2025
### What was changed?
Small code improvements to address comments from
#6079

### How has this been tested?
Pure refactoring

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
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.

3 participants