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

Ban variables whose capability is unsound to alias #3953

Merged
merged 26 commits into from
Feb 15, 2022

Conversation

jasoncarr0
Copy link
Contributor

@jasoncarr0 jasoncarr0 commented Dec 31, 2021

This PR introduces checks around variables and other unaliasing points, to reject programs which attempt to create variables whose capabilities are inherently unsound. The checks about comptability of intersections have been moved to this check after investigation of the origin, as it is not needed for soundness, but this can be reinstated in the original location if helpful for engineering purposes.

Fixes #3931

Some generic code may still produce unsoundness after instantiating, but this change is hopefully a step-forwarding to introducing the necessary constraints.

@jasoncarr0 jasoncarr0 changed the title [WIP] Ban unstable variables Ban unstable variables Jan 16, 2022
@jasoncarr0 jasoncarr0 changed the title Ban unstable variables Ban variables whose capabillity is unsound to alias Jan 16, 2022
src/libponyc/expr/reference.c Outdated Show resolved Hide resolved
src/libponyc/type/alias.c Outdated Show resolved Hide resolved
src/libponyc/type/cap.c Show resolved Hide resolved
@SeanTAllen
Copy link
Member

I don't really understand the usage of errorframe_append but it appears that the new code doesn't use it the same as the existing code.

@SeanTAllen
Copy link
Member

I believe after reading the error closing for a while is that we are getting a fatal error like a segfault or something from some of the tests apparently perhaps when run in conjunction with others. It makes me think there's some memory clobbering or something going on.

@SeanTAllen
Copy link
Member

Ok so StableTypeTest.EphemeralIsoParameter in my testing:

has a fatal error:

/home/sean/code/ponylang/ponyc/test/libponyc/util.cc:362: Failure
Expected equality of these values:
  (void*)__null
    Which is: NULL
  program
    Which is: 0x7ff5884b7d00
/home/sean/code/ponylang/ponyc/test/libponyc/stable_type.cc:186: Failure
Expected: test_error(src, "syntax") doesn't generate new fatal failures in the current thread.
  Actual: it does.

when I have it set to only go through the "syntax" path.

From this I conclude that the vast majority of the code in this PR "can't be at fault".

I don't know if the alias.c changes would impact if we go through syntax.
or the changes in cap.c
or the changes in viewpoint.c

So I'm left with a few possible conclusions given that the same code when compiled with ponyc works fine without a kaboom.

  • This is somehow a weird interaction with other tests that arent part of the stable types suite.

It can't be internal to itself as I tried with only that test in the stable type tests.

  • There's a bug in the changes in one of the 3 files above

But I don't think they impact at the syntax stage

  • There's a bug in the test that we are triggering

  • How we compile for the test harness is surfacing a bug that we don't get for ponyc

@SeanTAllen
Copy link
Member

  • This is somehow a weird interaction with other tests that arent part of the stable types suite.

It's not this as it still happens if it is THE ONLY test at all for libponyc.tests

@SeanTAllen
Copy link
Member

This fails:

TEST_F(StableTypeTest, Foo)
{
  // parameters should reject even if never called
  const char* x =
    "interface Foo";

  DO(test_error(x, "syntax"));
}

So I'm horribly confused at this point. It fails by itself after make clean.

@SeanTAllen
Copy link
Member

I started with a totally fresh new file in case "something weird in the file".

And I get this:

image

I have no idea how this could be the case and other tests work.

Given that the test is only "see if interface Foo compiles".

@SeanTAllen
Copy link
Member

So the error we are getting back is...

image

i.e. we have a null ast after running

build_package(pass, src, _first_pkg_path, true, NULL, false);

because this goes boom

package = ast_child(program);

in

void PassTest::test_compile(const char* src, const char* pass)

@SeanTAllen
Copy link
Member

Ok so test compile requires there to be a main actor. That explains some of that.

@SeanTAllen
Copy link
Member

I think I know what might be going on.

This parameter code path isnt generating errors in the way expected.

@SeanTAllen
Copy link
Member

Yup, issue confirmed look at the output when run with ponyc:

~/pony-scratch/stable-test ➜ /home/sean/code/ponylang/ponyc/build/debug/ponyc
Building builtin -> /home/sean/code/ponylang/ponyc/packages/builtin
Building . -> /home/sean/pony-scratch/stable-test
Generating
 Reachability
 Selector painting
 Data prototypes
 Data types
 Function prototypes
 Functions
 Descriptors
Optimising
Writing ./stable-test.o
Linking ./stable-test
Error:
/home/sean/pony-scratch/stable-test/main.pony:5:14: illegal type for parameter
  fun bad(a: A iso^) =>

We made it to link AND we reported an error. That means the error isnt reported correctly "as an error".

@SeanTAllen
Copy link
Member

the return false here is the fix:

image

@SeanTAllen
Copy link
Member

I need to do some stuff now, but Ill continue fixing up later and push changes.

@SeanTAllen
Copy link
Member

Ok I have the tests passing.

@SeanTAllen
Copy link
Member

I fixed what I believe was a bug in the new code in viewpoint.c.

You had

              a_with = consume_type(with, TK_NONE);
            {
              ast_t* c_with = consume_type(with, TK_NONE);
              if (c_with != NULL)
              {
                a_with = with;

but a_with is already with
so I changed to a_with = c_with

as I assume that was what you intended.


I removed the verify_definitions that you noted wasn't needed.


Did some small cleanup.


Added what appeared to be some missing frame appending for errors


There's still some cleanup but I think this should be much further along.


I've pushed to the branch so you'll need to pull.

@SeanTAllen SeanTAllen force-pushed the ban-unstable-variables branch from ab0cad5 to 69e607c Compare February 5, 2022 00:24
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 5, 2022
@SeanTAllen SeanTAllen self-assigned this Feb 14, 2022
@SeanTAllen
Copy link
Member

I'll be doing the last of the fixes for this soon-ish.

@SeanTAllen
Copy link
Member

@jasoncarr0 do you have time to give this a quick review to make sure it looks good? if not, i can move ahead as i believe i got everything from our conversations handled. i feel "pretty darn confident" on that.

* Normalizes the capability and alias modifier to apply aliasing
* and remove unnecessary ephemeral modifiers.
*/
void cap_aliasing(token_id* cap, token_id* eph);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this worth leaving in? Or should we revert

Copy link
Member

Choose a reason for hiding this comment

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

It is still used elsewhere.

@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Feb 15, 2022
@ponylang-main
Copy link
Contributor

Hi @jasoncarr0,

The changelog - fixed label was added to this pull request; all PRs with a changelog label need to have release notes included as part of the PR. If you haven't added release notes already, please do.

Release notes are added by creating a uniquely named file in the .release-notes directory. We suggest you call the file 3953.md to match the number of this pull request.

The basic format of the release notes (using markdown) should be:

## Title

End user description of changes, why it's important,
problems it solves etc.

If a breaking change, make sure to include 1 or more
examples what code would look like prior to this change
and how to update it to work after this change.

Thanks.

@SeanTAllen SeanTAllen mentioned this pull request Feb 15, 2022
65 tasks
@SeanTAllen SeanTAllen changed the title Ban variables whose capabillity is unsound to alias Ban variables whose capability is unsound to alias Feb 15, 2022
@SeanTAllen SeanTAllen merged commit 3ea2647 into main Feb 15, 2022
@SeanTAllen SeanTAllen deleted the ban-unstable-variables branch February 15, 2022 19:22
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Feb 15, 2022
github-actions bot pushed a commit that referenced this pull request Feb 15, 2022
github-actions bot pushed a commit that referenced this pull request Feb 15, 2022
@SeanTAllen SeanTAllen restored the ban-unstable-variables branch February 16, 2022 01:19
github-actions bot pushed a commit that referenced this pull request Feb 16, 2022
SeanTAllen added a commit that referenced this pull request Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ephemeral RefCap shouldn't be an assignable refcap type
4 participants