Skip to content

Regime Semantics: from-let, from-mut, and from-proj - #60

Draft
FedericoBruzzone wants to merge 16 commits into
eter-lang:mainfrom
FedericoBruzzone:ex
Draft

Regime Semantics: from-let, from-mut, and from-proj#60
FedericoBruzzone wants to merge 16 commits into
eter-lang:mainfrom
FedericoBruzzone:ex

Conversation

@FedericoBruzzone

Copy link
Copy Markdown
Member

No description provided.

@FedericoBruzzone
FedericoBruzzone marked this pull request as draft May 6, 2026 13:57
@FedericoBruzzone FedericoBruzzone changed the title Add from-let and from-mut examples Regime Semantics: from-let, from-mut, and from-proj May 6, 2026

@Sbregiuz Sbregiuz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some comments are reappliable to other lines with the same study case but with different data types in play

Comment thread docsrc/examples/eter-semantics/from-mut.txt
Comment thread docsrc/examples/eter-semantics/from-mut.txt
Comment thread docsrc/examples/eter-semantics/from-mut.txt Outdated
Comment thread docsrc/examples/eter-semantics/from-mut.txt
Comment thread docsrc/examples/eter-semantics/from-mut.txt Outdated
Comment thread docsrc/examples/eter-semantics/from-mut.txt Outdated
Comment thread docsrc/examples/eter-semantics/from-mut.txt Outdated
}
fn main() {
let proj p = &Point { x: 1, y: 2 };
// let fix q = f(&p); // ERROR: Changing the regime from proj to proj is not allowed. Need to copy.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Shouldn't be allowed if the first proj is not used anymore until the second one is "deleted", or no more used?
Because something like:

fn f1(proj p : Point){
 &p.x += 2;
 f2(p);
}

fn f2(proj p: Point){
 &p.y += 3;
}

fn main(){
 let mut p : Point = Point{x : 1, y:2};
 fn1(&p);
}

Should be admissible in my opinion. (And I am changing regime from proj to proj)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Wow! Great point, you're right!
This should obviously be permissible: how could I not have thought of that?

This will, of course, help me clarify my thoughts on the proj regime.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Just let me clarify one point:

fn tmp(proj x: i32, proj y: i32) { x = &y; }
fn main() {
    let mut x: i32 = 1;
    let mut y: i32 = 2;
    tmp(&x, &y);
    // UB: x and y are mutable aliases of the same memory location
}

But we can prevent this!

Comment thread docsrc/examples/eter-semantics/from-mut.txt
Comment thread docsrc/examples/eter-semantics/from-mut.txt
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
Signed-off-by: Federico Bruzzone <federico.bruzzone.i@gmail.com>
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