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

[New module system] Fixity rebalancing broken #1371

Closed
Tracked by #1363
m-yac opened this issue Jun 21, 2022 · 4 comments
Closed
Tracked by #1363

[New module system] Fixity rebalancing broken #1371

m-yac opened this issue Jun 21, 2022 · 4 comments
Assignees
Labels
language Changes or extensions to the language parameterized modules Related to Cryptol's parameterized modules

Comments

@m-yac
Copy link
Contributor

m-yac commented Jun 21, 2022

In #1363 tests/regression/repl-decls.icry fails because:

let x -<- y = x - y; infixl 5 -<-; let (-<-) : Integer -> Integer -> Integer
let x ->- y = x - y; infixr 5 ->-; let (->-) : Integer -> Integer -> Integer

42 -<- 10 -<- 100
42 ->- 10 ->- 100
42 ->- 10 -<- 100

outputs

-68
-68
-68

instead of what is used to, which was:

-68
132

[error] at repl-decls.icry:6:4--6:7 and repl-decls.icry:6:11--6:14
    The fixities of
      • (->-) (precedence 5, right-associative)
      • (-<-) (precedence 5, left-associative)
    are not compatible.
    You may use explicit parentheses to disambiguate.

After a quick first pass through the renamer, I saw no reason why this PR would break the existing fixity rebalancing (none of the relevant bits seem to be changed) – but I'll be taking a deeper look soon.

@m-yac m-yac added parameterized modules Related to Cryptol's parameterized modules language Changes or extensions to the language labels Jun 21, 2022
@qsctr
Copy link
Contributor

qsctr commented Jun 23, 2022

It seems like this only happens when the operators are defined at the REPL and not in a module.

@yav
Copy link
Member

yav commented Jun 23, 2022

I think the problem might with the fixity of operators that are not defined at the top level. For example, this seems to be incorrect also:

f = 10 .-. 2 .-. 1
  where
  infixr 5 .-.
  x .-. y = x - y

The result is 7 (i.e. (10 - 2) - 1) but it should be 9 (10 - (2 - 1)).

@qsctr
Copy link
Contributor

qsctr commented Jun 24, 2022

Ok, the issue seems to be here:

topDeclsDefs :: [TopDecl PName] -> ModBuilder (Mod ())
topDeclsDefs = declsToMod Nothing

When we are processing the TopDecls we pass Nothing as the ModPath but we really want Just (TopModule m) with the m from here

renameTopDecls ::
ModName -> [TopDecl PName] -> RenameM (NamingEnv,[TopDecl Name])
renameTopDecls m ds0 =
do -- Step 1: add implicit importgs
let ds = addImplicitNestedImports ds0
-- Step 2: compute what's defined
(defs,errs) <- liftSupply (modBuilder (topDeclsDefs ds))

just like the code in master

let mpath = TopModule m
env <- liftSupply (defsOf (map (InModule (Just mpath)) ds))

because the name binding code treats Nothing as meaning we are defining a local name.

instance BindsNames (InModule (Bind PName)) where
namingEnv (InModule mb b) = BuildNamingEnv $
do let Located { .. } = bName b
n <- case mb of
Just m -> newTop NSValue m thing (bFixity b) srcRange
Nothing -> newLocal NSValue thing srcRange -- local fixitiies?

which is actually the other issue that @yav pointed out, if we actually do happen to be defining a local name, then we do not record custom fixities. But currently in master we have the same code for that and don't support having local fixities either.

Nothing -> newLocal NSValue thing srcRange -- local fixitiies?

So I guess I will open up another issue for that and fix this specific issue for now to behave the same as on master.

@qsctr
Copy link
Contributor

qsctr commented Jun 24, 2022

Fixed in 4b3eac5

@qsctr qsctr closed this as completed Jun 24, 2022
@m-yac m-yac mentioned this issue Jul 14, 2022
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language Changes or extensions to the language parameterized modules Related to Cryptol's parameterized modules
Projects
None yet
Development

No branches or pull requests

3 participants