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

Allow local modules to be forward referenced #3275

Open
wants to merge 36 commits into
base: main
Choose a base branch
from

Conversation

janmasrovira
Copy link
Collaborator

@janmasrovira janmasrovira commented Jan 12, 2025

This pr makes a number of changes to the Scoper. The most important change is that local modules can be forward referenced. Below I list all the changes.

Referencing local modules

Local modules can now be forward referenced. However, there is one restriction:

  1. When forward referencing a local module. The symbols that come from an open public are not yet in scope, so they can't be referenced. E.g.
    -- at this point, P.p is in scope, but P.m is not
    
    module P;
      axiom p : Type;
    
      open M public;
    end;
    
    -- at this point, both P.p and P.m are in scope
    
    module M;
      axiom m : Type;
    end;
    

Forward reference passed an import, open or module statement

The following example was not allowed but now it is.

axiom A : B;
import M;
module S;
end;
axiom B : Type;

Changes in operators and iteratos

The semantics of operator and iterator definitions have changed slightly. Before, when the scoper found syntax operator , pair, it would remember in the state that when the , symbol is defined in the current syntax block, it should have the fixity pair. These had some implications.

  1. It was not possible to reassign/overwrite a fixity.
  2. The , symbol in the syntax operator , pair is not highlighted and it doesn't support going to definition.
  3. We required special checks to throw an error when we had duplicate operator/iterator definitions. We also had a check for when a symbol used in an operator/iterator statement was not defined in the same syntax block.

The new behaviour is as follows.

  1. When the scoper finds syntax operator , pair, the symbol , is scoped using the regular scoping rules - so , must be in scope. Then, the scoper modifies the fixity for , in the current scope.
  2. It is now possible to overwrite the fixity of a symbol. So this would be possible.
syntax operator , pair;
p1 : Pair Nat Nat := 1, 2;
syntax operator , none;
p2 : Pair Nat Nat := , 1 2;
  1. It is now possible to have qualified names in syntax/iterator definitions. E.g. syntax operator Pair., pair.

Because of point 1) we might encounter some breaking changes.

  1. syntax operator mkpair none;
    syntax alias mkpair := ,;
    
    This is now invalid because mkpair is not in scope in the syntax operator
    statement, because aliases cannot be forward referenced.
  2. A syntax operator op fix will now throw an ambiguity error if op is both defined in this module and imported from somewhere else.

Qualified fixities

It is now possible to reference fixities using qualified names. E.g.

syntax operator , Fixities.pair;

Pending tasks

  • Add positive test for local module forward referencing.
  • Add positive test for fixity overwriting.
  • Add positive test for qualified fixity.
  • Add positive test for qualified operator.
  • Add negative tests for local module forward referencing restrictions.
  • Fix printing of operators in Core.
  • Cleanup the code.

@janmasrovira janmasrovira added scoping enhancement New feature or request labels Jan 12, 2025
@janmasrovira janmasrovira added this to the 0.6.10 milestone Jan 12, 2025
@janmasrovira janmasrovira self-assigned this Jan 12, 2025
@janmasrovira janmasrovira force-pushed the local-modules-forward-reference branch 2 times, most recently from 3955598 to d60b482 Compare January 16, 2025 20:59
@janmasrovira janmasrovira force-pushed the local-modules-forward-reference branch from 43907c0 to 69fbfcc Compare January 23, 2025 08:51
@janmasrovira janmasrovira force-pushed the local-modules-forward-reference branch from 368ea2d to 9e72797 Compare January 23, 2025 22:07
@janmasrovira janmasrovira force-pushed the local-modules-forward-reference branch from d91d131 to aa57f5d Compare January 24, 2025 16:19
@janmasrovira janmasrovira force-pushed the local-modules-forward-reference branch from aa57f5d to f9359ec Compare January 24, 2025 16:19
@janmasrovira janmasrovira marked this pull request as ready for review January 24, 2025 16:27
@janmasrovira janmasrovira requested a review from lukaszcz January 24, 2025 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request scoping syntax
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The rules for where blocks of mutually recursive definitions end are unclear and confusing
1 participant