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

fix: entry state mutation in node compiler #550

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

seven-mile
Copy link
Contributor

The entry state handling in the ts-node-compiler is broken. This PR fixes the bug and do some other refactors:

  • Make the method setup_compiler_by pure and build it on the basis of universe snapshot mechanism
  • Migrate the both users of the method: BoxedCompiler::compile_raw and DynLayoutCompiler::vector to the new signature

Test cases will come later.

Ok(self
.0
.compiler
.compile(&world, &mut CompileEnv::default())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

call into the internal method directly, because we don't want to touch the driver wrapper with a default world.

Copy link
Owner

Choose a reason for hiding this comment

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

could we name the self.0.compiler so to make it slightly more beautiful?

let c = &self.0.compiler;
c.compile(&world, &mut CompileEnv::default())

.mutate_entry(new_state)
.map(Some)
.map_err(map_node_error)
Ok(self.universe.snapshot_with(Some(TaskInputs {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I doubt that it's necessary for snapshot_with to have Option<TaskInputs> as its argument with all fields in TaskInputs already Option<T>.

Some(root) => {
if let Ok(p) = root.strip_prefix(fp) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originallly, root.strip_prefix(fp) had its order of operands reversed.

Copy link
Owner

Choose a reason for hiding this comment

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

We may use world.entry_state().try_select_path_in_workspace(fp, true).

}

pub fn compile_raw(
&mut self,
compile_by: CompileDocArgs,
) -> napi::Result<NodeTypstCompileResult, NodeError> {
let e = self.setup_compiler_by(compile_by)?;
let world = self.setup_compiler_by(compile_by)?;

let res = if self.0.universe().entry_state().is_inactive() {
Err(map_node_error(error_once!("entry file is not set")))
Copy link
Owner

Choose a reason for hiding this comment

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

we can directly return errors here, since no state is to recover:

- if let Some(entry_file) = e {
-     self.0
-         .universe_mut()
-         .mutate_entry(entry_file)
-         .map_err(map_node_error)?;
- }

Some(root) => {
if let Ok(p) = root.strip_prefix(fp) {
Copy link
Owner

Choose a reason for hiding this comment

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

We may use world.entry_state().try_select_path_in_workspace(fp, true).

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.

None yet

2 participants