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

Remove redundancy by using ANY parameter for IS TYPE operators #1321

Merged
merged 3 commits into from
Jan 2, 2024

Conversation

rchowell
Copy link
Contributor

Relevant Issues

N/A

Description

Reduces redundancy of the IS TYPE operators as they do not need to be defined for each individual type.

Other Information

  • Updated Unreleased Section in CHANGELOG: [YES/NO]
    No

  • Any backward-incompatible changes? [YES/NO]

    • < If YES, why? >
    • < For this purpose, we define backward-incompatible changes as changes that—when consumed—can potentially result in
      errors for users that are using our public APIs or the entities that have public visibility in our code-base. >
      No, internal typer concern for 0.14
  • Any new external dependencies? [YES/NO]

    • < If YES, which ones and why? >
    • < In addition, please also mention any other alternatives you've considered and the reason they've been discarded >
      No
  • Do your changes comply with the Contributing Guidelines
    and Code Style Guidelines? [YES/NO]
    Yes

License Information

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@rchowell rchowell changed the title Remove redundancy by using ANY as parameter for IS TYPE operators Remove redundancy by using ANY parameter for IS TYPE operators Dec 20, 2023
Copy link

github-actions bot commented Dec 20, 2023

Conformance comparison report

Base (c73efbf) a4b4ace +/-
% Passing 92.54% 92.54% 0.00%
✅ Passing 5384 5384 0
❌ Failing 434 434 0
🔶 Ignored 0 0 0
Total Tests 5818 5818 0

Number passing in both: 5384

Number failing in both: 434

Number passing in Base (c73efbf) but now fail: 0

Number failing in Base (c73efbf) but now pass: 0

@codecov-commenter
Copy link

codecov-commenter commented Dec 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c73efbf) 72.17% compared to head (1843c0a) 72.17%.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #1321   +/-   ##
=========================================
  Coverage     72.17%   72.17%           
  Complexity     2097     2097           
=========================================
  Files           221      221           
  Lines         15973    15973           
  Branches       2892     2892           
=========================================
  Hits          11528    11528           
  Misses         3639     3639           
  Partials        806      806           
Flag Coverage Δ
CLI 11.86% <ø> (ø)
EXAMPLES 80.28% <ø> (ø)
LANG 80.80% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rchowell rchowell requested a review from yliuuuu December 20, 2023 23:42
@yliuuuu
Copy link
Contributor

yliuuuu commented Dec 22, 2023

One thing that may cause us trouble is missing handling.

In other functions, for example 1+missing, will be rewrite to plus(1, missing) and the function would not be resolved. That is, in most of the functions where missable is true, the handling strategy is to not resolve the function at the first place.

With this change, MISSING IS INT2 will be resolved to is_int2(missing), such function can be resolved due to the value argument being ANY in the header. In the typer we then raise a expression always returns missing error.

This is more of a inconsistence than a problem, but it is worth to consider as change of errors may affect our customers.

@rchowell
Copy link
Contributor Author

rchowell commented Dec 22, 2023

I wonder if this handles it though?

// 7.1 All functions return MISSING when one of their inputs is MISSING (except `=`)
newArgs.forEach {
if (it.type == MissingType && !isNotMissable) {
handleAlwaysMissing()
return rex(MISSING, rexOpCallStatic(newFn, newArgs))
}
}

I feel the only issue here will be is_missing which I need to add a case for (spec page 30).

@yliuuuu
Copy link
Contributor

yliuuuu commented Dec 22, 2023

I wonder if this handles it though?

// 7.1 All functions return MISSING when one of their inputs is MISSING (except `=`)
newArgs.forEach {
if (it.type == MissingType && !isNotMissable) {
handleAlwaysMissing()
return rex(MISSING, rexOpCallStatic(newFn, newArgs))
}
}

I feel the only issue here will be is_missing which I need to add a case for (spec page 30).

The code snippet you show raised a alwaysMissing problem and return a resolved function whose return type is missing.

I tried to point out that for other functions, the issue raised is going to be a unresolved function. See

return when (val match = env.resolveFn(fn, args)) {
is FnMatch.Ok -> toRexCall(match, args, isNotMissable)
is FnMatch.Dynamic -> {
val types = mutableSetOf<StaticType>()
if (match.isMissable && !isNotMissable) {
types.add(MISSING)
}
val candidates = match.candidates.map { candidate ->
val rex = toRexCall(candidate, args, isNotMissable)
val staticCall = rex.op as? Rex.Op.Call.Static ?: error("ToRexCall should always return a static call.")
val resolvedFn = staticCall.fn as? Fn.Resolved ?: error("This should have been resolved")
types.add(rex.type)
val coercions = candidate.mapping.map { it?.let { fnResolved(it) } }
rexOpCallDynamicCandidate(fn = resolvedFn, coercions = coercions)
}
val op = rexOpCallDynamic(args = args, candidates = candidates)
rex(type = StaticType.unionOf(types).flatten(), op = op)
}
is FnMatch.Error -> {
handleUnknownFunction(match)
rexErr("Unknown scalar function $fn")
}

Copy link
Contributor

@yliuuuu yliuuuu left a comment

Choose a reason for hiding this comment

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

Approving this PR based on offline discussion. We are going to further investigate on MISSING.

@rchowell rchowell merged commit 7fe57b5 into main Jan 2, 2024
10 checks passed
@rchowell rchowell deleted the simplify_is branch January 18, 2024 21:05
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.

3 participants