Skip to content

Small changes for correctness#372

Open
ShawSumma wants to merge 11 commits intomainfrom
shaw-ai-fixes
Open

Small changes for correctness#372
ShawSumma wants to merge 11 commits intomainfrom
shaw-ai-fixes

Conversation

@ShawSumma
Copy link
Copy Markdown
Contributor

I used the AI to identify and fix small problems in the backends, mostly focusing on correctness, but also doing some inlining.

Signed-off-by: Shaw Summa <shawsumma@gmail.com>
Signed-off-by: Shaw Summa <shawsumma@gmail.com>
Signed-off-by: Shaw Summa <shawsumma@gmail.com>
Signed-off-by: Shaw Summa <shawsumma@gmail.com>
Signed-off-by: Shaw Summa <shawsumma@gmail.com>
Signed-off-by: Shaw Summa <shawsumma@gmail.com>
Signed-off-by: Shaw Summa <shawsumma@gmail.com>
@mikesamuel
Copy link
Copy Markdown
Contributor

Could you add to functional-test-suite/src/commonMain/resources/types/float/ops/ ?

That'd make sure the corner cases are exercised for all backends.

@notactuallytreyanastasio
Copy link
Copy Markdown
Contributor

Worth noting that in theory this solves #373 in theory and maybe should add a specific test there. Leaving this as a note so its linked in GH history.

Copy link
Copy Markdown
Contributor

@tjpalmer tjpalmer left a comment

Choose a reason for hiding this comment

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

Some of these changes are good, some are meh, some are bad, and some I still haven't looked at enough.

If you have different opinions on any, let me know.

Minimally, this maybe can serve as an example of why not to just do everything that AI says. Which should help for some talking points of why Temper still matters.

var abs = absTol ?? 0.0;
var margin = Math.Max(Math.Max(Math.Abs(x), Math.Abs(y)) * rel, abs);
return Math.Abs(x - y) < margin;
return Math.Abs(x - y) <= margin;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This does match Python's math.isclose better. I'll plan to see if everything else also gets updated in this pr.

: trimmed == "-Infinity"
? double.NegativeInfinity
: double.Parse(s);
: double.Parse(trimmed);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In Remarks here, it says that double.Parse allows for surrounding whitespace, so it doesn't matter much whether s or trimmed goes in. Maybe worth a comment either way, and maybe trimmed is less surprising. So probably an ok change to make, even if s also works.

{
count += 1;
if (i + 1 < right)
if (i + 1 < limit)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because the loop prevents i from going past limit, either works fine here, so again, a needless change but also not a breaking one. And maybe limit is less surprising to some people.

{
return -1;
return i;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I personally feel a lot better always using -1 for no string index rather than arbitrary negative values. Is there a good reason for this change that I'm missing? If not, I'd like to revert this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with Tom on this.

}
const margin = Math.max(Math.max(Math.abs(x), Math.abs(y)) * relTol, absTol);
return Math.abs(x - y) < margin;
return Math.abs(x - y) <= margin;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So we've updated cs and js so far.

val calleeTree = callToInline.definition
val formalNameToArg = callToInline.formalNameToFunArg
val thisBindings = callToInline.thisTypeBindings
callToInline.thisTypeBindings
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks like good cleanup at a glance.

else -> type
}
is OrType -> type.members.firstNotNullOf { findNominal(it) }
is OrType -> type.members.firstNotNullOfOrNull { findNominal(it) }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't analyzed to know if this is a good change or not.

// larger shift or comparison operator, or close tag start marker.
val before = text[end - 1]
val after = if (end + 1 < limit) { text[end - 1] } else { '\u0000' }
val after = if (end + 1 < limit) { text[end + 1] } else { '\u0000' }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The old code looks sus, but I don't know why it wouldn't have triggered problems. No test changes from this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nope, no changes, it's one of those "how did it ever work?!" things.

fun append(str: String) { buffer.append(str) }

@Synchronized
override fun toString(): String = "$buffer"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again, some analysis here would be good, which I haven't done right now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It makes sure the buffer is never read at the same the above append is happening, as that would be bad and give you a toString() that never actually existed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It makes sure the buffer is never read at the same the above append is happening, as that would be bad and give you a toString() that never actually existed.

I guess the question is if it's ever used from multithreaded contexts. I still haven't looked, though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For the time being it feels like it could be, as the @Synchronized on the other method is preexisting. If it weren't used multithreaded then both should be removed.

Signed-off-by: Shaw Summa <shawsumma@gmail.com>
@tjpalmer
Copy link
Copy Markdown
Contributor

Could you add to functional-test-suite/src/commonMain/resources/types/float/ops/ ?

That'd make sure the corner cases are exercised for all backends.

Maybe a corner case test for near? Maybe also some large int64 cases that might trigger the old Python int things? I already forget if other additional testing would be good.

Signed-off-by: Tom <tom@contextfree.info>

function temper.string_indexof(str, target, i)
return string.find(str, target, i, true) or 0
return string.find(str, target, i, true) or -1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For lua, I think we're using 0 as no string index, since indices start at 1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I liked having it be -1 everywhere, tho maybe this needs more thought

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this affect == with NoStringIndex

TmpLOperator.AmpAmp -> TODO() // RustOperator.LogicalAnd
TmpLOperator.BarBar -> TODO() // RustOperator.LogicalOr
TmpLOperator.AmpAmp -> RustOperator.LogicalAnd
TmpLOperator.BarBar -> RustOperator.LogicalOr
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see here's where they were being ignored before. Looks like we don't actually translate to using these. Instead we assign bool values from if/else sequences. But probably good to implement these anyway, just in case, and even if not easy to test, the implementations look ok.

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.

4 participants