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

BSP: do not filter clean-requests for meta-builds #2931

Merged
merged 1 commit into from
Jan 3, 2024

Conversation

ckipp01
Copy link
Collaborator

@ckipp01 ckipp01 commented Dec 22, 2023

Looking at the last change that was made to this code in 65fbd53 it's not clear to me why this line was added where we map everything to BspModule and then filtering the build targets on that which where in the request. My assumption is that anything that the build client is requesting to clean should be a valid identifier. If not, then that originally came from Mill, so I'm unsure why we have this. Before this change it was causing issues since not everything in state.rootModules was a BspModule so you'd get a match exception.

To expand a bit the build targets here in an example mill-test (hello world) project are:

BuildTargetIdentifier [
  uri = "file:///Users/<me>/Documents/scala-workspace/mill-test/milltest"
],BuildTargetIdentifier [
  uri = "file:///Users/<me>/Documents/scala-workspace/mill-test/mill-build"
]

But when looking into the state.rootModules one of them is

/Users/<me>/Documents/scala-workspace/mill-test

This was the problematic one. I'm not sure if this is just a mapping issue or not, but the change I made instead just takes the build target identifies given from the client, does a look up in the state.bspModulesById mapping, and goes with it. This seems to work and simplifies this unless this is introducing an issue that I don't see.

closes #2915

Looking at the last change that was made to this code in
com-lihaoyi@65fbd53
it's not clear to me why this line was added where we map everything to
`BspModule` and then filtering the build targets on that which where in
the request. My assumption is that anything that the build client is
requesting to clean _should_ be a valid identifier. If not, then that
originally came from Mill, so I'm unsure why we have this. Before this
change it was causing issues since not everything in `state.rootModules`
was a `BspModule` so you'd get a match exception.

To expand a bit the build targets here in an example `mill-test` (hello
world) project are:

```
BuildTargetIdentifier [
  uri = "file:///Users/<me>/Documents/scala-workspace/mill-test/milltest"
],BuildTargetIdentifier [
  uri = "file:///Users/<me>/Documents/scala-workspace/mill-test/mill-build"
]
```

But when looking into the `state.rootModules` one of them is

```
/Users/<me>/Documents/scala-workspace/mill-test
```

This was the problematic one. I'm not sure if this is just a mapping
issue or not, but the change I made instead just takes the build target
identifies given from the client, does a look up in the
`state.bspModulesById` mapping, and goes with it. This seems to work and
simplifies this unless this is introducing an issue that I don't see.

closes com-lihaoyi#2915
@lefou
Copy link
Member

lefou commented Dec 22, 2023

This is a tricky one. Also, it's most likely underspecified. The issue is, that due to the newly introduced meta-build, all modules of a project depend implicitly on that meta-build. If you clean the meta-build, Mill will need to re-run it before it can understand any new actions. That is probably the reason, why the introduction of the meta-build also excluded it from the clean target. The predecessor of the meta-build was the Ammonite script build, which wasn't included in the clean run.

In difference to the Mill CLI, where all actions belong to the same build level, in BSP we make the levels transparent, so that all modules and meta-modules can be edited, disregarding of their meta-level. It might be safe to clean all BSP build targets (including the meta-builds), but some review needs to happen whether we properly re-run the meta-build from the next BSP request. In any case, cleaning the meta-build will definitely make the next BSP action take very long. Question is, if that is what the user wants?

@ckipp01
Copy link
Collaborator Author

ckipp01 commented Dec 27, 2023

This is a tricky one. Also, it's most likely underspecified. The issue is, that due to the newly introduced meta-build, all modules of a project depend implicitly on that meta-build. If you clean the meta-build, Mill will need to re-run it before it can understand any new actions.

Ahh, ok interesting. Can you clarify what is meant by

Mill will need to re-run before it can understand any new actions

In the BSP sense of things, what does this practically mean? Since in this case the user would be requesting a clean/compile, so is there anything else that would really be needed or hindered?

In any case, cleaning the meta-build will definitely make the next BSP action take very long. Question is, if that is what the user wants?

Good question. I'm honestly not really sure. I guess in terms of correctness the BSP server should listen to the request and clean everything that is requested to clean, but like you said, I don't know if a user would really ever want that. I did just check what happens with sbt when using it as your build server and I see the same thing, a request for the build sent in and it is indeed cleaned. Either way, I'm not sure. This was just my attempt to avoid the crash that I was seeing since I kept getting in states that were sort of borked and wanted to see if a full clean/compile would help.

@lefou
Copy link
Member

lefou commented Dec 28, 2023

Ahh, ok interesting. Can you clarify what is meant by

Mill will need to re-run before it can understand any new actions

In the BSP sense of things, what does this practically mean? Since in this case the user would be requesting a clean/compile, so is there anything else that would really be needed or hindered?

In the BSP sense, I guess the only impact is that any next request whether already cached or not (even a subsequent clean request) will need to re-build the meta-module to determine the up-to-date state. Is it always "clean all" in Metals? Or can you select specific build targets, to avoid the overhead? In that case, we could think about some extra properties in the build target, indicating the meta-build level, which might be useful for sbt too. With that, Metals could by-default deselect meta-builds from clean, for example.

I think Mill already takes care of meta-build re-creation. The proof might be, that this PR just works for you. So we could just merge it as-is.

@lefou lefou changed the title fix: ensure the BSP clean works as expected BSP: do not filter clean-requests for meta-builds Jan 3, 2024
@lefou lefou merged commit 393e4df into com-lihaoyi:main Jan 3, 2024
38 checks passed
@lefou lefou added this to the 0.11.7 milestone Jan 3, 2024
@ckipp01 ckipp01 deleted the cleanFix branch January 7, 2024 12:36
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.

buildTarget/cleanCache throws an error
2 participants