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

Fix return type checking to allow aliasing for non-ephemeral return types. #3201

Merged
merged 2 commits into from
Jun 26, 2019

Conversation

jemc
Copy link
Member

@jemc jemc commented Jun 25, 2019

This PR fixes return type checking to allow aliasing for non-ephemeral return types.

I discovered this type system issue after a discussion with @rkallos in which we discussed how to fix Map.insert (and others) to not have an unreachable error case.

Looking into it further, I discovered that the type system had a simple bug that wasn't obvious due to the inconsistency in how Pony handles return type checking (the fact that using the ephemeral modifier is required to describe a unique return type, whereas on all other type specifications, the ephemeral modifier is useless).

This PR doesn't address that inconsistency, because it would be a major breaking change for the language, but this does fix the small bug that went unnoticed because of it.

The bug can be reproduced with the following code, in which get_1 and get_2 are valid and functionally identical, but the latter fails to compile:

class iso Inner
  new iso create() => None

class Container[A: Inner #any]
  var inner: A
  new create(inner': A) => inner = consume inner'
  fun get_1(): this->A => inner                        // works
  fun get_2(): this->A => let tmp = inner; consume tmp // fails

actor Main
  new create(env: Env) =>
    let o = Container[Inner iso](Inner)
    let i_1 : Inner tag = o.get_1()
    let i_2 : Inner tag = o.get_2()

Upon investigation, it turned out to be a simple boolean logic bug, in which not (A or B) was expressed as !a || !b instead of the correct !a && !b. The code comment several lines above the change expresses the intended meaning, so I know that this fixed logic reflects the code author's original intent.

@jemc jemc self-assigned this Jun 25, 2019
@SeanTAllen
Copy link
Member

Wow. Heck of a find.

@SeanTAllen SeanTAllen self-requested a review June 25, 2019 23:56
@jemc
Copy link
Member Author

jemc commented Jun 26, 2019

For posterity, I'll note that @SeanTAllen asked me in Zulip to elaborate on the "inconsistency" I mentioned above. You can find that conversation here: https://ponylang.zulipchat.com/#narrow/stream/189952-compiler-discussion/topic/return.20type.20ephemeral.20notation.20inconsistency

@jemc
Copy link
Member Author

jemc commented Jun 26, 2019

The CI failure appears to be unrelated?

@SeanTAllen
Copy link
Member

@jemc yeah, i think so, it's been flakey lately.

@jemc
Copy link
Member Author

jemc commented Jun 26, 2019

Okay, was going to kick off another CI build, but that'll take forever to finish - I'm just going to merge.

@jemc
Copy link
Member Author

jemc commented Jun 26, 2019

But first, a changelog entry was added.

@jemc jemc merged commit 550477f into master Jun 26, 2019
@jemc jemc deleted the fix/allow-alias-for-non-ephemeral-return branch June 26, 2019 01:23
@SeanTAllen
Copy link
Member

Looks like the job was straight up cancelled. Eventually cancelled jobs will get rerun. Or should. But I've been seeing them not get rerun lately. Such is life with free stuff I guess.

patches11 pushed a commit to patches11/ponyc that referenced this pull request Jun 29, 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.

2 participants