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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Dependency of const vars on non-const vars is not rejected #514

Closed
acoglio opened this issue Dec 28, 2020 · 2 comments 路 Fixed by #672
Closed

[Bug] Dependency of const vars on non-const vars is not rejected #514

acoglio opened this issue Dec 28, 2020 · 2 comments 路 Fixed by #672
Assignees
Labels
bug Something isn't working

Comments

@acoglio
Copy link
Collaborator

acoglio commented Dec 28, 2020

馃悰 Bug Report

It looks like currently const variables may depend on non-const variables.

Steps to Reproduce

The two programs below are accepted by the Leo compiler.

Code snippet to reproduce

// program 1:
function main(x: u8) -> u8 {
    const c = x + 1;
    return c + 1
}

// program 2:
function main() -> u8 {
    let a = 1u8;
    const c = a + 1;
    return c + 2
}```

#### Stack trace & error message

No errors, everything goes through.

## Expected Behavior

In program 1 above, `x` does not have a known value at compile time, so the value of a `const` should not depend on it.

In program 2 above, `a` happens to have a known value at compile time, but it was agreed in a Slack discussion that in general a `const` variable should only depend on other `const` variables and on literals, not on `let` variables.

The type checking/inference code should enforce the constancy of the expressions assigned to `const` variables. This constancy can be checked and calculated analogously to mutability and types -- i.e. every expression has a type, a mutability, and a constancy.

## Your Environment

Leo 1.0.7
Rust 1.48.0
macOS 10.15.7
@acoglio acoglio added the bug Something isn't working label Dec 28, 2020
@acoglio
Copy link
Collaborator Author

acoglio commented Dec 28, 2020

Also see proposal #515. If that is accepted and implemented, no action would be required on this bug. (The const variables in programs 1 and 2 above would become let variables.)

@collinc97
Copy link
Collaborator

With the implementation of #617 this issue is still relevant.

bors bot added a commit that referenced this issue Feb 18, 2021
668: Bump rand_core from 0.6.1 to 0.6.2 r=collinc97 a=dependabot-preview[bot]

Bumps [rand_core](https://github.com/rust-random/rand) from 0.6.1 to 0.6.2.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/rust-random/rand/blob/master/CHANGELOG.md">rand_core's changelog</a>.</em></p>
<blockquote>
<h2>[0.6.2] - 2019-01-04</h2>
<h3>Additions</h3>
<ul>
<li>Add <code>Default</code> for <code>ThreadRng</code> (<a href="https://github-redirect.dependabot.com/rust-random/rand/issues/657">#657</a>)</li>
<li>Move <code>rngs::OsRng</code> to <code>rand_os</code> sub-crate; clean up code; use as dependency (<a href="https://github-redirect.dependabot.com/rust-random/rand/issues/643">#643</a>) ##BLOCKER##</li>
<li>Add <code>rand_xoshiro</code> sub-crate, plus benchmarks (<a href="https://github-redirect.dependabot.com/rust-random/rand/issues/642">#642</a>, <a href="https://github-redirect.dependabot.com/rust-random/rand/issues/668">#668</a>)</li>
</ul>
<h3>Fixes</h3>
<ul>
<li>Fix bias in <code>UniformInt::sample_single</code> (<a href="https://github-redirect.dependabot.com/rust-random/rand/issues/662">#662</a>)</li>
<li>Use <code>autocfg</code> instead of <code>rustc_version</code> for rustc version detection (<a href="https://github-redirect.dependabot.com/rust-random/rand/issues/664">#664</a>)</li>
<li>Disable <code>i128</code> and <code>u128</code> if the <code>target_os</code> is <code>emscripten</code> (<a href="https://github-redirect.dependabot.com/rust-random/rand/issues/671">#671</a>: work-around Emscripten limitation)</li>
<li>CI fixes (<a href="https://github-redirect.dependabot.com/rust-random/rand/issues/660">#660</a>, <a href="https://github-redirect.dependabot.com/rust-random/rand/issues/671">#671</a>)</li>
</ul>
<h3>Optimisations</h3>
<ul>
<li>Optimise memory usage of <code>UnitCircle</code> and <code>UnitSphereSurface</code> distributions (no PR)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/rust-random/rand/commit/3a03c9eb5350e03a3f540dba2ee34e0984f2c2c2"><code>3a03c9e</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/rust-random/rand/issues/1096">#1096</a> from tmandry/patch-1</li>
<li><a href="https://github.com/rust-random/rand/commit/2cf5120dd5642f6bdb8d5359ddc6bb459489a2d9"><code>2cf5120</code></a> Bump to 0.6.2</li>
<li><a href="https://github.com/rust-random/rand/commit/390a7b1049fa5ba1d627feaef2a1629e0e7826b4"><code>390a7b1</code></a> Fix assertions inside read_{u32,u64}_into</li>
<li><a href="https://github.com/rust-random/rand/commit/6ecbe2626b2cc6110a25c97b1702b347574febc7"><code>6ecbe26</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/rust-random/rand/issues/1089">#1089</a> from dhardy/work</li>
<li><a href="https://github.com/rust-random/rand/commit/8821743325303e4deb6c4a6c934f0e2eb9680205"><code>8821743</code></a> Prepare 0.8.3</li>
<li><a href="https://github.com/rust-random/rand/commit/fa615efd91f83fe8e56799cfa9217d67f7625fb7"><code>fa615ef</code></a> Feature gate choose_multiple_weighted on std</li>
<li><a href="https://github.com/rust-random/rand/commit/22dec87aac43e0e92eb15fa85b2de6da5b3c95b7"><code>22dec87</code></a> CI: more accurate no-default-feature and nightly test targets</li>
<li><a href="https://github.com/rust-random/rand/commit/6a6b9fd06dbf54538d250dfbc4c918f79daa9299"><code>6a6b9fd</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/rust-random/rand/issues/1087">#1087</a> from GautierMinster/fix_uniform_int_panic_on_full_in...</li>
<li><a href="https://github.com/rust-random/rand/commit/2c9085a2de8864ee327af0311f6a8e5747cf25b7"><code>2c9085a</code></a> Bump to 0.8.2 and update changelog</li>
<li><a href="https://github.com/rust-random/rand/commit/4e8c7a4ca2963797d0ec414d04b6239ece905165"><code>4e8c7a4</code></a> distributions/uniform: fix panic in gen_range(0..=MAX)</li>
<li>See full diff in <a href="https://github.com/rust-random/rand/compare/rand_core-0.6.1...rand_core-0.6.2">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://api.dependabot.com/badges/compatibility_score?dependency-name=rand_core&package-manager=cargo&previous-version=0.6.1&new-version=0.6.2)](https://dependabot.com/compatibility-score/?dependency-name=rand_core&package-manager=cargo&previous-version=0.6.1&new-version=0.6.2)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language
- `@dependabot badge me` will comment on this PR with code to add a "Dependabot enabled" badge to your readme

Additionally, you can set the following in your Dependabot [dashboard](https://app.dependabot.com):
- Update frequency (including time of day and day of week)
- Pull request limits (per update run and/or open at any time)
- Out-of-range updates (receive only lockfile updates, if desired)
- Security updates (receive only security updates, if desired)



</details>

672: Feature/515 eliminate const vars r=collinc97 a=gluax

Resolves #515. Removes const keyword from statements. Also resolves #514. Still allows const y in function declaration of args.

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: gluaxspeed <jonathan.t.pavlik@gmail.com>
Co-authored-by: gluax <jonathan.t.pavlik@gmail.com>
Co-authored-by: Collin Chin <collin.chin@berkeley.edu>
bors bot added a commit that referenced this issue Feb 18, 2021
672: Feature/515 eliminate const vars r=collinc97 a=gluax

Resolves #515. Removes const keyword from statements. Also resolves #514. Still allows const y in function declaration of args.

Co-authored-by: gluaxspeed <jonathan.t.pavlik@gmail.com>
Co-authored-by: gluax <jonathan.t.pavlik@gmail.com>
Co-authored-by: Collin Chin <collin.chin@berkeley.edu>
@bors bors bot closed this as completed in c62af03 Feb 18, 2021
@bors bors bot closed this as completed in #672 Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants