Stream: t-compiler

Topic: sideeffect


simulacrum (Feb 05 2020 at 23:56, on Zulip):

@nikomatsakis following up from https://github.com/rust-lang/compiler-team/issues/177#issuecomment-582653660 -- I agree it would be good to keep discussion out of those threads:

I wonder why you think self-calls a problem in practice. I would expect us to always lint on that today, with something like this error -- maybe that lint is not yet powerful enough to catch the self-call via trait dispatch though? I wonder if we could detect that.

I imagine self-calls are sufficiently easy to detect and rare enough that we could also add sideeffect calls to them...

warning: function cannot return without recursing
 --> src/main.rs:1:1
  |
1 | fn main() {
  | ^^^^^^^^^ cannot return without recursing
2 |     main();
  |     ------ recursive call site
  |
  = note: `#[warn(unconditional_recursion)]` on by default
  = help: a `loop` may express intention better if this is on purpose
nikomatsakis (Feb 06 2020 at 15:05, on Zulip):

@simulacrum

We do lint on it, I agree, but people may not fix the lint. It seems like if we can lint on it, we could also prevent UB. =)

Anyway, I'm not sure if it'll be a problem in practice, but as I said it's the only case of this bug in practice that I've encountered. In general, the fact that a function recurses on itself is less obvious and more likely to happen by accident than (I think) writing a purposefully infinite loop that has no side effects (which .. isn't really a very common thing to do?)

simulacrum (Feb 06 2020 at 15:07, on Zulip):

Hm, yes, I would agree. Though I think writing a infinite loop is more likely to be actually what you wanted

simulacrum (Feb 06 2020 at 15:07, on Zulip):

But I think we would not want to ban this, right?

simulacrum (Feb 06 2020 at 15:07, on Zulip):

i.e., we're adding side effect because it is not UB according to "Rust", just UB according to LLVM

nikomatsakis (Feb 06 2020 at 15:21, on Zulip):

Correct

nikomatsakis (Feb 06 2020 at 15:22, on Zulip):

I also don't know how literally you mean loop { }

simulacrum (Feb 06 2020 at 15:22, on Zulip):

I mean it quite literally :)

nikomatsakis (Feb 06 2020 at 15:22, on Zulip):

It seems like we could do better than that -- basically any loop without function calls

nikomatsakis (Feb 06 2020 at 15:22, on Zulip):

or something like that

nikomatsakis (Feb 06 2020 at 15:22, on Zulip):

er, I mean any loop that doesn't have an exit branch

simulacrum (Feb 06 2020 at 15:22, on Zulip):

well, to be exact, any unconditional backedges

nikomatsakis (Feb 06 2020 at 15:22, on Zulip):

without function calls

nikomatsakis (Feb 06 2020 at 15:23, on Zulip):

yeah

nikomatsakis (Feb 06 2020 at 15:23, on Zulip):

I guess any loop whose head node postdominates itself

nikomatsakis (Feb 06 2020 at 15:23, on Zulip):

er, that's wrong, all nodes postdominate themselves :)

Last update: Feb 25 2020 at 03:45UTC