Skip to content

Build psciEnvironment as needed for :print in REPL - #3241

Merged
kritzcreek merged 8 commits into
purescript:masterfrom
rndnoise:fix-3001
Nov 6, 2018
Merged

Build psciEnvironment as needed for :print in REPL#3241
kritzcreek merged 8 commits into
purescript:masterfrom
rndnoise:fix-3001

Conversation

@rndnoise

@rndnoise rndnoise commented Feb 3, 2018

Copy link
Copy Markdown
Contributor

This fixes #3001 by computing psciEnvironment on demand.

One thing I need help with in simulateModuleEdit is ensuring enableRebuild and rebuild is called even if action fails (e.g., due to an assertion). Otherwise the module that's swapped in won't be reverted and this will leak into other tests.

(The above issue is handled, see comment below)

Also, it should be noted that any code that calls Language.PureScript.Interactive.make depends on and modifies global state (since it reads/writes files in .psci_modules); I believe that includes all the other PSCi tests. This was a painful lesson that took me a while to learn, maybe others will benefit from this comment.

- Complete all names that have been imported (transitively or directly)
- Do not complete names that haven't been imported
- Only recompute list of names after import or adding a let binding
  rather than after each request for name completion

This commit fixes #3227
@rndnoise

Copy link
Copy Markdown
Contributor Author

Ok, this is ready for review. I've also used bracket_ to ensure simulateModuleEdit cleans up even if the provided action fails.

(Prior build errors were due to (a) using '/' as a path separator on Windows and (b) not having included the new file Regex.edit in the source distribution.)

@rndnoise rndnoise changed the title Build psciEnvironment as needed for :print Build psciEnvironment as needed for :print in REPL Mar 23, 2018
Comment thread tests/TestPsci/TestEnv.hs Outdated
| inputPath `isSuffixOf` x = findReplace xs acc (n+1)
| otherwise = findReplace xs acc n
findReplace [] _ 0 = Nothing
findReplace [] acc _ = Just (newPath : reverse acc)

@natefaubion natefaubion Oct 23, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function seems kind of odd to me, but otherwise this PR seems like a win. Nothing is ever done with acc, so I'm actually not sure what all this indirection is about.

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 been a while, but I believe this function takes a list of paths and removes all that have matching suffixes and sticks the newPath in front, only if there were matches. If no matches were found, it returns Nothing. On the last line (where at least one path matched), acc is the list of paths that remained, because they didn't match, in reverse order.

I think the bigger picture is to make a new temporary file to replace the module we want to "edit". The module's path is replaced with the path to the new temporary file that contains the replacement module definitions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But you never case or cons on acc. As far as I can tell, acc is only ever [].

@natefaubion natefaubion Oct 23, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If that isn't a bug, and acc is indeed unused, then I think this can just be a fold. (It can probably just be a fold regardless).

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.

Oh, yes. Shows how it's easy to be blind to your own bugs.

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.

Using a fold will probably be simpler, but maybe it will have unintended consequences later on. Your thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be possible to import and edit a small example included in the test directory, rather than a library?

Using a fold will probably be simpler, but maybe it will have unintended consequences later on. Your thoughts?

I'm not sure exactly what you mean. I think the main thing is that it's just working as intended. I could maybe offer a suggestion given the fixed implementation.

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.

Let me know if the implementation of findReplace can be simplified, but I don't think the original definition was correct (it should have cons'd ontoacc).

I took your suggestion and made a standalone module in tests/support/psci/Reload.purs and the edited version is Reload.edit. I also brought this branch up-to-date with master.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the only reason you have it return Maybe is for a sanity check, otherwise you can just do it with fmap. I think it's fine. I might use a Boolean instead of Int since you only check against 0.

@rndnoise rndnoise Oct 25, 2018

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.

Yes, I couldn't talk myself into getting rid of the sanity check after it did catch a mistake when I came back to this PR after many months. But I think I've made it better in the last commit.

@natefaubion natefaubion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This appears to do what it says on the tin 😄

@kritzcreek

Copy link
Copy Markdown
Member

Thanks!

@kritzcreek
kritzcreek merged commit 5a47a30 into purescript:master Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

:browse does not pick up changes from :reload

4 participants