Skip to content

C#: C#8 Nullable expressions and type annotations#1408

Merged
aibaars merged 13 commits intogithub:masterfrom
calumgrant:cs/suppress-null-expr
Jun 28, 2019
Merged

C#: C#8 Nullable expressions and type annotations#1408
aibaars merged 13 commits intogithub:masterfrom
calumgrant:cs/suppress-null-expr

Conversation

@calumgrant
Copy link
Contributor

No description provided.

@pavgust
Copy link
Contributor

pavgust commented Jun 10, 2019

This pull request introduces 3 alerts and fixes 1 when merging e219a77 into c03e804 - view on LGTM.com

new alerts:

  • 1 for Generic catch clause
  • 1 for Useless assignment to local variable
  • 1 for Futile conditional

fixed alerts:

  • 1 for Generic catch clause

This project has automated code review enabled, but doesn't use the LGTM GitHub App. Migrate over by installing the app. Read about the benefits of migrating to GitHub Apps in the blog.


Comment posted by LGTM.com

@@ -0,0 +1,17 @@
import csharp

query predicate suppressNullableWarnings(SuppressNullableWarningExpr e, Expr op) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to add an exclusion in the nullness library that this is a non-null expression.

* 1 = not null
* 2 = may be null
*/
nullable_flow_state(unique int expr: @expr ref, int value: int ref);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Delete this for now.

int id: @type_parameter_constraints ref,
int base_id: @type_or_ref ref);
int base_id: @type_or_ref ref,
int nullability: int ref);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

nullability -> annotation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe this should live on the side, for example

specific_type_parameter_annotation(id, base_id, annotation);


/** The nullability of type arguments of a constructed type or method. */
#keyset[constructedgeneric, position]
nullable_type_arguments(int constructedgeneric: @generic ref, int position: int ref, int nullability: int ref);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

generalize, nullability -> annotation

Console.WriteLine(x);
}

string? field3;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Delete

@@ -0,0 +1,144 @@
/**
* Provides predicates classes for representing the nullability of various C# declarations.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generalize this to type annotations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Including ref and out


module Nullability {
/** Holds if the flow state of the expression has determined that `e` may be null. */
predicate exprMayBeNull(Expr e) { nullable_flow_state(e, 2) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Delete for now.

}

private newtype TAnnotatedType =
TAnnotatedTypeNullability(Type type, int nullability) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generalize this, to string, string? ref, string ref, string?
Don't just talk about Nullability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Represent this as a set of integer, represented as a bit field.

class AnnotatedType extends TAnnotatedType {
Type underlyingType;

int nullability;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change this to annotation, and predicate predicate hasAnnotation(TypeAnnotation a). Maybe an IPA type for now.


/** Gets the annotated type of element `e`. */
cached
AnnotatedType getAnnotatedType(Element e) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

library predicate

@pavgust
Copy link
Contributor

pavgust commented Jun 11, 2019

This pull request introduces 1 alert and fixes 1 when merging eb20d64 into 7790ac4 - view on LGTM.com

new alerts:

  • 1 for Generic catch clause

fixed alerts:

  • 1 for Generic catch clause

This project has automated code review enabled, but doesn't use the LGTM GitHub App. Migrate over by installing the app. Read about the benefits of migrating to GitHub Apps in the blog.


Comment posted by LGTM.com

@calumgrant calumgrant force-pushed the cs/suppress-null-expr branch from eb20d64 to d9e6602 Compare June 14, 2019 10:47
@calumgrant calumgrant changed the title C#: C#8 Nullable warning suppression expressions C#: C#8 Nullable expressions and type annotations Jun 14, 2019
@pavgust
Copy link
Contributor

pavgust commented Jun 14, 2019

This pull request introduces 1 alert and fixes 1 when merging d9e6602 into 41d5d5a - view on LGTM.com

new alerts:

  • 1 for Generic catch clause

fixed alerts:

  • 1 for Generic catch clause

This project has automated code review enabled, but doesn't use the LGTM GitHub App. Migrate over by installing the app. Read about the benefits of migrating to GitHub Apps in the blog.


Comment posted by LGTM.com

@pavgust
Copy link
Contributor

pavgust commented Jun 14, 2019

This pull request introduces 1 alert and fixes 1 when merging 01895bb into 41d5d5a - view on LGTM.com

new alerts:

  • 1 for Generic catch clause

fixed alerts:

  • 1 for Generic catch clause

This project has automated code review enabled, but doesn't use the LGTM GitHub App. Migrate over by installing the app. Read about the benefits of migrating to GitHub Apps in the blog.


Comment posted by LGTM.com


/** Holds if this callable returns a `ref readonly`. */
predicate returnsRefReadonly() { ref_readonly_returns(this) }
deprecated predicate returnsRefReadonly() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Say what to use instead.

@calumgrant calumgrant force-pushed the cs/suppress-null-expr branch from 01895bb to 4356cbd Compare June 17, 2019 12:13
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

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

First review of the dbscheme changes, and (light) review of AnnotatedType.qll. I really like the design 👍

@calumgrant calumgrant force-pushed the cs/suppress-null-expr branch 2 times, most recently from e8a1288 to 6c12c88 Compare June 19, 2019 14:28
@calumgrant calumgrant marked this pull request as ready for review June 19, 2019 14:56
@calumgrant calumgrant requested a review from a team as a code owner June 19, 2019 14:56
@calumgrant calumgrant force-pushed the cs/suppress-null-expr branch from a458f40 to e60ae58 Compare June 21, 2019 12:04
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

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

Truly awesome stuff, Calum. As I have said earlier, I really like the type annotation design in QL.

@calumgrant calumgrant force-pushed the cs/suppress-null-expr branch 2 times, most recently from 8d154c4 to fc15412 Compare June 26, 2019 11:48
@calumgrant calumgrant force-pushed the cs/suppress-null-expr branch from fc15412 to 76454ed Compare June 26, 2019 19:25
@lgtm-com
Copy link

lgtm-com bot commented Jun 26, 2019

This pull request introduces 1 alert and fixes 1 when merging 76454ed into 1a9f362 - view on LGTM.com

new alerts:

  • 1 for Generic catch clause

fixed alerts:

  • 1 for Generic catch clause

@lgtm-com
Copy link

lgtm-com bot commented Jun 27, 2019

This pull request introduces 1 alert and fixes 1 when merging 2504754 into 7ff6d82 - view on LGTM.com

new alerts:

  • 1 for Generic catch clause

fixed alerts:

  • 1 for Generic catch clause

Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

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

LGTM, just two small comments.

override UnboundGenericType getUnboundGeneric() { constructed_generic(this, getTypeRef(result)) }

language[monotonicAggregates]
string annotatedTypeArgumentsToString() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Make private.


namespace Semmle.Extraction.Kinds
{
[Flags]
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is it used like a flag set in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It isn't, currently, however it is "morally" a set and could be used in that way.

@lgtm-com
Copy link

lgtm-com bot commented Jun 28, 2019

This pull request introduces 1 alert and fixes 1 when merging 4d38300 into a554369 - view on LGTM.com

new alerts:

  • 1 for Generic catch clause

fixed alerts:

  • 1 for Generic catch clause

@aibaars
Copy link
Contributor

aibaars commented Jun 28, 2019

The related internal PR has been merged.

@aibaars aibaars merged commit af68fd4 into github:master Jun 28, 2019
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.

4 participants

Comments