Skip to content

fix: const primitive directionality#1159

Merged
brprice merged 1 commit intomainfrom
brprice/const-bidir
Oct 9, 2023
Merged

fix: const primitive directionality#1159
brprice merged 1 commit intomainfrom
brprice/const-bidir

Conversation

@brprice
Copy link
Copy Markdown
Contributor

@brprice brprice commented Oct 5, 2023

Since const x y is synthesisable but x is checkable, the reduction rule is const x y ~> x : Bool (rather than const x y ~> x). Note that const is restricted to type Bool -> Int -> Bool, and that this reduction matches that of obvious analogue where const is replaced by the non-primitive (λx y. x) : Bool -> Int -> Bool.

@brprice
Copy link
Copy Markdown
Contributor Author

brprice commented Oct 5, 2023

Note that this bug can manifest in a slightly odd test failure, where the type preservation test fails with CaseOfHoleNeedsEmptyBranches, because the initial term case (const ? t) of True -> ...; False -> ... is well-typed (recall const : Bool -> Int -> Bool), but it reduces to case ? of True -> ...; False -> ....

I suspect it can also fail with a could not synthesise type error because of case (const True t) of ... reducing to case True of ..., and our approach of (ADT) constructors not being synthesisable (even for easy cases like Bool): the scrutinee needs its type to be synthesised, but we cannot synthesise the type of True. (However I have not actually observed this, presumably for lack of looking. EDIT: I have now observed this, but only when turning off shrinking.)

Since `const x y` is synthesisable but `x` is checkable, the reduction
rule is `const x y ~> x : Bool` (rather than `const x y ~> x`). Note
that `const` is restricted to type `Bool -> Int -> Bool`, and that this
reduction matches that of obvious analogue where `const` is replaced by
the non-primitive `(λx y. x) : Bool -> Int -> Bool`.

Signed-off-by: Ben Price <ben@hackworthltd.com>
@brprice
Copy link
Copy Markdown
Contributor Author

brprice commented Oct 5, 2023

(whoops, forgot to update a test. force-pushed)

@brprice brprice force-pushed the brprice/const-bidir branch from a281f79 to c7146a5 Compare October 5, 2023 13:51
@dhess
Copy link
Copy Markdown
Member

dhess commented Oct 5, 2023

Note that this bug can manifest in a slightly odd test failure, where the type preservation test fails with CaseOfHoleNeedsEmptyBranches, because the initial term case (const ? t) of True -> ...; False -> ... is well-typed (recall const : Bool -> Int -> Bool), but it reduces to case ? of True -> ...; False -> ....

I suspect it can also fail with a could not synthesise type error because of case (const True t) of ... reducing to case True of ..., and our approach of (ADT) constructors not being synthesisable (even for easy cases like Bool): the scrutinee needs its type to be synthesised, but we cannot synthesise the type of True. (However I have not actually observed this, presumably for lack of looking.)

I assume that by "can manifest" and "can also fail," you mean before this fix, and that once this fix is in, these failures will no longer manifest?

@brprice
Copy link
Copy Markdown
Contributor Author

brprice commented Oct 5, 2023

Note that this bug can manifest in a slightly odd test failure...
I suspect it can also fail with a could not synthesise type error...

I assume that by "can manifest" and "can also fail," you mean before this fix, and that once this fix is in, these failures will no longer manifest?

Yes, that is what I meant.

@brprice brprice added this pull request to the merge queue Oct 9, 2023
Merged via the queue into main with commit 31a962f Oct 9, 2023
@brprice brprice deleted the brprice/const-bidir branch October 9, 2023 11:28
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