-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 compilation of nested packs #12609
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
This probably warrant a bug fix release (sorry) |
Indeed, I will cut one once a plan has been settled for the zstd issue. |
(cross-referencing #12581 which reported the issue at hand here.) |
2b70de8
to
b4fe509
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the implementation too verbose -- see inline comment.
As someone who hasn't followed the issue closely, I would like to read a bit more details about what is going on. Could someone explain, as if I had completely forgotten what packs are, what is the compilation model of packs, why we get errors when accessing things from inside the pack, and why "nested packs" are in fact okay?
(Does the compiler know about "nested packs" or is this an emergent property? When we pass -for-pack Foo.Bar
, does the compiler somehow know (before this PR) that the .
is a separator?)
middle_end/compilenv.ml
Outdated
if p2.[l1] = '.' then () | ||
else error () | ||
end | ||
else error ()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too much code. Could you:
- Move this to an auxiliary function.
- Write a comment to explain what the criterion is.
- Write a simpler implementation that is close to the comment?
For example:
String.equal p1 p2 || String.starts_with ~prefix:(p1 ^ ".") p2
The pack model is to take a bunch of compilation units, and to put them together to create a single compilation unit with a sub-module for each input unit. In native mode, we don't want to patch object files, whose format is mostly out of our control. So to be able to link in the same executable both The difference with bytecode is that it becomes impossible to link the original Nested packs are not special. You can create one using The rule was implemented too strictly in #1391, as
Yes and no. In bytecode, this doesn't matter, as discussed elsewhere. In native code, before #11430 there was specific code to translate |
ca76b85
to
6fb27a9
Compare
I am abstractly convinced that this makes sense, but I have not made the actual work of thinking deeply about this and convincing myself in the details that this makes sense. However, I don't see myself having the time do this before at least October 20th, and I would rather not block the process. I propose to work from @chambart's approval and @lthls masterful explanation above, and merge this. (Someone needs to fix the Changes conflict, and I think maybe Vincent is in holidays now? @Octachron, would you maybe rebase the Changes and merge? We also need to backport this in 5.1, so you want to look at it anyway.) |
6fb27a9
to
7a1d53a
Compare
Changes file refreshed, and I have tested that camlp4 works without structural changes with this patch. Once the CI is green, I will merge and cherry-pick to the 5.1 branch. |
(cherry picked from commit ecf19e0)
Follow-up from #1391.
That PR was meant to prevent accessing a packed module outside its pack, but it failed to properly account for nested packs.