Skip to content

re #5448: check that clause target type is usable at modality - #6236

Merged
plt-amy merged 8 commits into
masterfrom
aliao/rhs-type-modality-check
Oct 29, 2022
Merged

plt-amy merged 8 commits into
masterfrom
aliao/rhs-type-modality-check

Conversation

@plt-amy

@plt-amy plt-amy commented Oct 25, 2022

Copy link
Copy Markdown
Contributor

Implements the check for #5448, which at current master only happens with the --cubical-compatible flag, eagerly (during LHS checking).

Because of how transpX clauses are generated (they use the RHS type, though with the unification substitutions represented as paths, in a relevant argument), checking that the RHS type is usable at the required modality will reject exactly the same definitions that --cubical-compatible would. With the benefit that the user doesn't have to see internal Cubical Agda code.

Consider:

subst : {A : Set} (@0 P : A → Set) {α β : A} (p : α ≡ β) → P α → P β
subst P refl a = {! a  !}

The error you get with --without-K is as follows. When --cubical is used, the note mentions "used for computing transports" and "in Cubical Agda" more specifically, and --cubical-compatible has yet a third wording.

This clause has target type P α which is not usable at modality @ω

Note: when --without-K is enabled, the target type must be usable
at the modality in which the function was defined, since it is used
in substitutions.

when checking the clause left hand side
subst P refl a

@plt-amy plt-amy added ux: error reporting Issues to do with how Agda reports errors without-K K-related restrictions to pattern matching, termination checking, indices, erasure cubical Cubical Agda paraphernalia: Paths, Glue, partial elements, hcomp, transp erasure labels Oct 25, 2022
@plt-amy plt-amy added this to the 2.6.3 milestone Oct 25, 2022
@plt-amy
plt-amy requested a review from nad October 25, 2022 21:18
@plt-amy plt-amy self-assigned this Oct 25, 2022
@plt-amy

plt-amy commented Oct 25, 2022

Copy link
Copy Markdown
Contributor Author

I've optimistically put this in the 2.6.3 milestone, in the hopes that there's enough time to sneak it in. But don't let it hold anyone up.

nad
nad previously requested changes Oct 26, 2022

@nad nad 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.

Great!

The current text in the changelog that describes the new flag --cubical-compatible should also be updated, perhaps along with some text in the user manual.

Comment thread src/full/Agda/TypeChecking/Rules/LHS.hs Resolved
Comment thread test/Fail/Issue5448-1.err Resolved
@plt-amy

plt-amy commented Oct 27, 2022

Copy link
Copy Markdown
Contributor Author

@Mergifyio rebase

@plt-amy

plt-amy commented Oct 27, 2022

Copy link
Copy Markdown
Contributor Author

(need a CI run with new std-lib commit to make sure nothing is broken)

@mergify

mergify Bot commented Oct 27, 2022

Copy link
Copy Markdown

rebase

✅ Branch has been successfully rebased

@plt-amy
plt-amy force-pushed the aliao/rhs-type-modality-check branch from 491c712 to c0a0615 Compare October 27, 2022 15:47
Comment thread test/Fail/Issue5448-4-noK.err Outdated

Note: when --without-K is enabled, the target type must be usable
at the modality in which the function was defined, since it is used
to compute substitutions in Cubical Agda.

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.

I think we should avoid mentioning Cubical Agda in the error message for --without-K. When --without-K is used we do not actually "compute substitutions in Cubical Agda", so the text might be misleading. Note that I'm currently not aware of anything that would go wrong if we removed this restriction for --without-K. However, the proof sketch that we use to motivate the current implementation suggests something like this restriction, and the proof sketch is for a language with cubical features.

By the way, what does "the modality in which the function was defined" mean?

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's the attribute attached to the function's name:

@0 subst : (A : Set) (@0 : A → Set) {x y : A} → x ≡ y → P x → P y
subst ... = {! P x has to be usable @0 !}

Anyway, I can't think of a good wording for the Note: in the --without-K case, and I don't want to skip the check entirely because it contradicts "--cubical-compatible = --without-K + internal cubical code generation", since --cubical-compatible would (by design, rather than by a bug) reject more programs than --without-K

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.

How about because in univalent type theory, substitution is computed by cases on the predicate?

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.

How about because in univalent type theory, substitution is computed by cases on the predicate?

That may or may not be true, depending on how "univalent type theory" is defined.

Perhaps we can just skip (parts of) the explanation when --without-K is used.

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.

Works for me.

@andreasabel andreasabel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, awesome!
Great if you can change the printing of relevances in the error message.

Comment thread test/Fail/Issue5468.err Resolved
Comment thread test/Fail/Issue5448-1.err Resolved
Comment thread test/Fail/Issue5448-1.err Resolved
@plt-amy
plt-amy requested a review from andreasabel October 28, 2022 18:07
@plt-amy
plt-amy force-pushed the aliao/rhs-type-modality-check branch from 11a8b3a to 12c3f44 Compare October 28, 2022 18:17

@andreasabel andreasabel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wow, that looks awesome!!

@plt-amy
plt-amy merged commit 6142bde into master Oct 29, 2022
@plt-amy
plt-amy deleted the aliao/rhs-type-modality-check branch October 29, 2022 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cubical Cubical Agda paraphernalia: Paths, Glue, partial elements, hcomp, transp erasure ux: error reporting Issues to do with how Agda reports errors without-K K-related restrictions to pattern matching, termination checking, indices, erasure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants