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

Pointer mutability information after type-checking is not trustworthy #190

Closed
vbgl opened this issue Jun 29, 2022 · 2 comments · Fixed by #227
Closed

Pointer mutability information after type-checking is not trustworthy #190

vbgl opened this issue Jun 29, 2022 · 2 comments · Fixed by #227

Comments

@vbgl
Copy link
Member

vbgl commented Jun 29, 2022

Keeping track of the writability (const / mut) property of variables during the compilation passes is difficult and probably not needed. When compiling this example, we can notice that after inlining and removal of “renaming” assignments, variables arg and ro get merged and the single variable that represent both has wrong mutability. Unfortunately, “stack allocation” trusts this mutability information and wrongly rejects the program.

inline
fn read(reg const ptr u64[1] ro) -> reg u64 {
  reg u64 v;
  v = ro[0];
  return v;
}

fn write(reg mut ptr u64[1] arg) -> reg ptr u64[1] {
  reg u64 x;
  arg[0] = 0;
  x = read(arg);
  arg[0] = x;
  return arg;
}


export
fn test() -> reg u64 {
  reg u64 r;
  stack u64[1] s;
  reg mut ptr u64[1] rw;
  rw = s;
  rw = write(rw);
  r = rw[0];
  return r;
}
@eponier
Copy link
Contributor

eponier commented Jun 29, 2022

Starting from "After variable renaming to remove copies", the reg ptr becomes const. Isn't it the problem? It doesn't mean that we cannot make the code of stack_alloc simpler.

@eponier eponier closed this as completed Jun 29, 2022
@eponier eponier reopened this Jun 29, 2022
@eponier
Copy link
Contributor

eponier commented Jun 29, 2022

(sry, didn't want to close)

@eponier eponier closed this as completed Jun 29, 2022
@eponier eponier reopened this Jun 29, 2022
@vbgl vbgl changed the title #190 Pointer mutability information after type-checking is not trustworthy Jun 29, 2022
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 a pull request may close this issue.

2 participants