Skip to content

C#: Implement ContentSet #17207

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

Merged
merged 3 commits into from
Aug 22, 2024
Merged

C#: Implement ContentSet #17207

merged 3 commits into from
Aug 22, 2024

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Aug 13, 2024

Storing into properties and reading out of properties takes overriding into account. For example, in

interface I
{
    string Prop { get; set; }
}

class C : I
{
    public string Prop { get; set; }

    public void M()
    {
            this.Prop = "taint";
            Sink(((I)this).Prop);
    }
}

this.Prop = "taint" stores into the property C.Prop, whereas ((I)this).Prop read from I.Prop. Before this PR, ((I)this).Prop would give rise to two read steps: one for I.Prop and one for C.Prop. In general, this meant that property reads would fan out to all possible compatible properties, which is better solved using ContentSets.

@github-actions github-actions bot added the C# label Aug 13, 2024
@hvitved hvitved force-pushed the csharp/content-set branch 3 times, most recently from c698128 to d2760b9 Compare August 13, 2024 11:32
@github-actions github-actions bot added the Java label Aug 13, 2024
@hvitved hvitved force-pushed the csharp/content-set branch from d2760b9 to d638b5c Compare August 13, 2024 13:27
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Aug 15, 2024
@hvitved hvitved marked this pull request as ready for review August 15, 2024 09:40
@hvitved hvitved requested review from a team as code owners August 15, 2024 09:40
Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

Looks very nice!

cached
newtype TContentSet =
TSingletonContent(Content c) { not c instanceof PropertyContent } or
TPropertyContentSet(Property p) { p.isUnboundDeclaration() }
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the corresponding TPropertyContent injector be deleted from TContent if Content has been replaced with ContentSet everywhere (it looks like it will require a re-write of ContentApprox)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We still need Content, so that can't be deleted. ContentSet is a type used to represent sets of Contents with just a single entity.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I get that we need the Content type. I am just trying to understand whether we need an injector for properties both as a part of Content and ContentSet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could in principle have just a single injector for TContentSet, but having two makes it more explicit that properties need special treatment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok - thank you!

this.isProperty(p1) and
p2 = result.(PropertyContent).getProperty()
|
p1 = p2
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't that follow implicitly from p1.getOverridee*().getUnboundDeclaration() = p2 as property contents are always unbound 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.

Yes, you are right.

Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

LGTM!

@hvitved hvitved merged commit d41d7c8 into github:main Aug 22, 2024
36 checks passed
@hvitved hvitved deleted the csharp/content-set branch August 22, 2024 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# Java no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants