Skip to content

Simplify processing and remove dead code (error paths) in asmlink#9943

Merged
lthls merged 2 commits intoocaml:trunkfrom
dbuenzli:asmlink-simpl
Dec 18, 2020
Merged

Simplify processing and remove dead code (error paths) in asmlink#9943
lthls merged 2 commits intoocaml:trunkfrom
dbuenzli:asmlink-simpl

Conversation

@dbuenzli
Copy link
Copy Markdown
Contributor

This PR is a nop. I need the result of these changes in the context of the library linking RFC. I had a simpler version of it before. However PR #9011 added more complexity in the area and I had to redo it. Since it's a delicate area I would like to avoid having to rethink about all that a third time :-) The result also effectively simplifies #9011.

Basically we separate reading file into file values with read_file from scan_files (that's what I'm interested in). The file values allows to derive the info from scan_files and the objfiles to link separately (which #9011 fusioned into scan_files).

The result allows us to get rid of the object_file_name function whose error paths are in fact dead code and which redoes the lookup that was already done by read_file which is a bit confusing.

The PR should be read commit by commit which have explanations.

I guess @dra27 and/or @xavierleroy would be suitable reviewers.

An analysis of the code should convince yourself that the
[object_file_name] function is not needed and that its erroring paths
are dead code.

The reasoning is the following: all the uses of [object_file_name] in
asmlink.ml are performed on [obj_name]s which went through [read_file]
before. The latter does exactly the same file name lookup and erroring
treatement, except not in a stringly manner like [object_file_name]
does.

This new function derives the same information as [object_file_name]
except it does it on the [file] datatype returned by [read_file].
Note that all the erroring code paths of [object_file_name] have been
handled by the [read_file] which derived the [file] value.

We integrate the logic added by PR ocaml#9011 for empty cmxa here.
This commit does the following four things (it's difficult
to them in separate commits that compile).

1) It removes the [read_file] from [scan_file]. Reading the files is
   done seperately before returning an [obj_infos] list of [file]
   values. This turns [scan_file] into a function that operates on
   values of type [file].

2) In [scan_file] it removes the separate list of [obj_files]
   introduced by ocaml#9011. We can derive the same list using the function
   [object_file_name_of_file] introduced in the previous commit on the
   list of [obj_infos]. Effectively we bring back [scan_file] to the
   state before ocaml#9011 modulo the [read_file] removal.

3) We derive the list of [obj_files] directly from the
   [obj_infos] list via [object_file_name_of_file]. Note that
   the logic introduced by ocaml#9011 is preserved by virtue of
   [object_file_name_of_file]'s optional result.

4) Deletes [object_file_name] which is no longer used.
@dra27 dra27 self-assigned this Sep 28, 2020
@dbuenzli
Copy link
Copy Markdown
Contributor Author

Gentle ping.

Copy link
Copy Markdown
Contributor

@lthls lthls left a comment

Choose a reason for hiding this comment

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

I'm in favour of this. In addition to the cleanup, it removes a (very hypothetical) problem if the lookup of the file by object_file_name returns a different path than the previous lookup by read_file.

As far as I can tell the code is correct.

@lthls
Copy link
Copy Markdown
Contributor

lthls commented Dec 16, 2020

@dra27 It seems you assigned yourself to this PR. Do you still plan to look at it or are you fine trusting @dbuenzli and me on this ?
@dbuenzli If you don't plan on adding a changes entry, could you signal it by either adding the no-change-entry-needed label or (if you don't have the rights, I'm not sure if anyone can do this or not) clarifying in a comment ?

@dbuenzli
Copy link
Copy Markdown
Contributor Author

@lthls Thanks for the review and approval ! I do not plan to add a changes entry (unless the devs want it of course) but can't add the label myself.

Copy link
Copy Markdown
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

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

LGTM too!

@lthls lthls merged commit 64a0c34 into ocaml:trunk Dec 18, 2020
@dbuenzli dbuenzli deleted the asmlink-simpl branch December 19, 2020 10:13
@dbuenzli
Copy link
Copy Markdown
Contributor Author

Thanks @dra27 for the review.

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.

5 participants