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

New directive for the toplevel: #load_rec #5411

Closed
vicuna opened this issue Nov 30, 2011 · 6 comments
Closed

New directive for the toplevel: #load_rec #5411

vicuna opened this issue Nov 30, 2011 · 6 comments

Comments

@vicuna
Copy link

vicuna commented Nov 30, 2011

Original bug ID: 5411
Reporter: @diml
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2012-09-25T18:07:21Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 3.12.1
Category: ~DO NOT USE (was: OCaml general)
Duplicate of: #8266
Monitored by: mehdi @ygrek @hcarty

Bug description

This new directive loads the file given as argument and all cmos it depends on.

When one want to load a cmo in the toplevel which depends on other cmos, it has to load them one by one in the right order. This directive does that automatically.

File attachments

@vicuna
Copy link
Author

vicuna commented Dec 13, 2011

Comment author: @alainfrisch

I believe the proposed patch does not work when the name of the module contains uppercase characters (because of the call to String.lowercase).

From an implementation point of view, it would be cleaner to iterate through compunit.cu_reloc in load_file (in 'rec' mode) in order to load missing modules (and not waiting for an exception to pop up).

That said, I'm not 100% convinced by the proposal: a module can be provided by a .cma file, and there is no easy way to know which one. Do you have a convincing argument in favor of your suggestion? What would be a typical use case?

@vicuna
Copy link
Author

vicuna commented Dec 13, 2011

Comment author: @diml

I believe the proposed patch does not work when the name of the module contains uppercase characters (because of the call to String.lowercase).

Indeed. It is a typo, it should be String.uncapitalize.

That said, I'm not 100% convinced by the proposal: a module can be provided by a .cma file, and there is no easy way to know which one. Do you have a convincing argument in favor of your suggestion? What would be a typical use case?

The typical use is the following: you have a project with a lot of modules and you want to test in the toplevel an internal function of one of them. First you load dependencies with #require, then you have to load all the cmos of you project needed by the function you want to test, and you have to load them in the right order.

In general you do that:

load "a.cmo";;

Error: Reference to undefined global `B'

load "b.cmo";;

Error: Reference to undefined global `C'
# load "c.cmo";;

load "b.cmo";;

load "a.cmo";;

The goal of this directive is just to do this mechanical stuff automatically.

@vicuna
Copy link
Author

vicuna commented Dec 13, 2011

Comment author: mehdi

You can also put these directives in a file (say "foo.ml") and then, in a toplevel, do “#use "foo.ml";;”. You'll need to resolve the dependencies once to start, and update the file when needed.

You can also implement your proposal in a "foo.ml" and #use it.

@vicuna
Copy link
Author

vicuna commented Dec 13, 2011

Comment author: @alainfrisch

Ok, wish granted. I'm a little bit uneasy with the fact that the loading order of dependent .cmo files is not specified (and this can change the semantics), but I can see there are cases where this can be useful.

Committed to the trunk (rev 11306). Can you try it?

Note that the recursive behavior is only applied when .cmo files (not .cma) are loaded.

@vicuna
Copy link
Author

vicuna commented Dec 13, 2011

Comment author: @diml

Committed to the trunk (rev 11306). Can you try it?

Yes, it works. Thanks.

Note that the recursive behavior is only applied when .cmo files (not .cma) are loaded.

OK.

By the way, i just noticed that load_file does not close the input channel in case an exception (other than Load_failed) is raised. So if for example "#load "a.cmo";;" fails because of a reference to an undefined global the file will be kept open.

@vicuna
Copy link
Author

vicuna commented Dec 14, 2011

Comment author: @alainfrisch

Thanks, I've fixed load_file to close the input channel in case of error (commit 11315).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants