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

Incorrect generation of "constructor" tags for modules #7596

Closed
vicuna opened this issue Jul 22, 2017 · 9 comments
Closed

Incorrect generation of "constructor" tags for modules #7596

vicuna opened this issue Jul 22, 2017 · 9 comments

Comments

@vicuna
Copy link

vicuna commented Jul 22, 2017

Original bug ID: 7596
Reporter: theindigamer
Assigned to: @Octachron
Status: assigned (set by @Octachron on 2017-07-22T13:20:48Z)
Resolution: open
Priority: low
Severity: minor
Platform: Linux
OS: Ubuntu
OS Version: 16.04
Version: 4.04.0
Category: ocamldoc
Monitored by: @gasche

Bug description

Ocamldoc seems to generate misleading constructor tags for modules. While I've seen this locally, the simplest way to "reproduce" this is to inspect the source for the Pervasives documentation:

http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html

For example, on inspecting the source for the line "More string operations are provided in module String." in the section String operations (line 767 as seen on 2017/07/22):

More string operations are provided in module String.

I don't think the constructor tag should be there in the first place -- as it mixes modules and value constructors under the same tag.

(Sorry if this has been reported before/solved already, I checked the bug tracker once and I couldn't find anything discussing this point.)

Unrelated: it seems the CSS is wonky for the Parameters table here -- http://caml.inria.fr/pub/docs/manual-ocaml/libref/Set.Make.html -- from what I understand, the <code> tag inside the table (for the first entry) causes the text to shrink and the valign attribute causes it to hit the cell ceiling. As far as I can tell, this can be fixed by re-asserting font-size : blah inside tables for the CSS.

(Tested on Firefox 54.0)

Steps to reproduce

See description.

@vicuna
Copy link
Author

vicuna commented Jul 22, 2017

Comment author: @Octachron

I agree that the "constructor" class is quite misleading since it is in fact applied to any capitalized identifier, module and constructors alike. There are few places where ocamldoc could use more accurate classes (in particular for references), but in general ocamldoc does not have enough information to distinguish the two: for instance in the standard library [String] can be either the module "String" or the constructor "Arg.String".

@vicuna
Copy link
Author

vicuna commented Jul 22, 2017

Comment author: theindigamer

So I checked the manual and it does have a way to provide annotations (http://caml.inria.fr/pub/docs/manual-ocaml/ocamldoc.html#sec333) as mentioned in section 15.2.4.2. It is just that Pervasives does not use this. It makes sense though: manually annotating all references would be very time-consuming.

If Ocamldoc were to use a deductive system to guess the type of reference that you are trying to make, that would solve the issue for the use case when there are no name conflicts. I suspect that this case happens at least as frequently as the conflicting case, if not more. So for this sub-case, the documentation author gets the benefit of correct semantics without any additional work.

Of course, this doesn't solve the problem for the "String" vs "Arg.String" case which you pointed out -- I think one has to use manual annotation in that case as in section 15.2.4.2. However, it would be very helpful if Ocamldoc emitted something like:

Warning [#warning-code] :
ambiguous cross-reference in [String]
in file 'src/foo.ml', on line 23
did you mean to use [{module:String}] or [{const:Arg.String}]?

so that the author knows that their documentation is buggy.

@vicuna
Copy link
Author

vicuna commented Jul 22, 2017

Comment author: @gasche

I agree that this feature sounds useful (especially with the suggested syntax that would help make the feature better-known), although deploying it in practice may be delicate if everybody's documentation warns too often.

@vicuna
Copy link
Author

vicuna commented Jul 22, 2017

Comment author: theindigamer

although deploying it in practice may be delicate if everybody's documentation warns too often.

Good point. I suspect that the current style.css file has the code .constructor { color : Blue } to cover this up -- modules (usually linked) and constructors look identical so the constructor colour does not make the links appear non-blue.

I think there are a couple of options:

Option 1:

If the exact look of documentation is to be kept unchanged, then make a style.css file which gives identical output but respects the new class separation. Now add the warning part in as a feature flag (say -W-ambiguous) to ocamldoc and document it on the help page, and mention this new flag under in the help information for the -css-style flag.

This way people who were using things with default settings need not be bothered. Only people using -css-style and having ambiguous naming will need to supply this additional flag (I suggest adding a warning if -css-style is supplied && there is at least one ambiguity && -W-ambiguous is not supplied).

Option 2:

If you want the default documentation to have different colours, then update style.css accordingly and making the warnings on by default, in order to avoid misleading colouring.


So option 1 means people can blissfully ignore stuff and proceed as usual, so long as they stick to the default css, which I think covers a majority of use cases. Option 2 would probably be a much ruder shock to authors of large packages.

My hunch is to go with option 1 as:

(a) a large portion of the userbase doesn't get annoyed.
(b) the portion that does get annoyed is the one using custom CSS -- they are more likely to be nitpicky about colouring than group (a), so they might not mind the warnings.

@vicuna
Copy link
Author

vicuna commented Jul 22, 2017

Comment author: @Octachron

@theindigamer, I fear that there may be a confusion here, the namespace indication for reference is only used to find the target of the cross-reference, it has currently no influence on the "constructor" tag. Internally ocamldoc interprets "{!namespace:Name}" as "{!namespace:[Name]}" and therefore "{!module:String}" stil generates a "constructor" span tag for "String".
However, this could be fixed.

Moreover, in absence of namespace annotation, ocamldoc already tries to find a corresponding target in all namespaces. On this point, I agree that having a warning when the name is ambiguous would be useful (even moreso since ocamldoc does not enforce any priority order beween namespaces).

@vicuna
Copy link
Author

vicuna commented Jul 22, 2017

Comment author: theindigamer

@Octachron, got it, I was mixing up two separate things in my head.

So to summarize, there's two uncoupled things needed to be done, right?

  • Issue warnings for ambiguous names: the question is whether this should be optional or not?

  • Use HTML tags based on known namespaces.

Initially, I (incorrectly) thought that the latter was an issue because we did not know the namespaces with enough resolution. So we do actually know them (apart from the ambiguous case).

@vicuna
Copy link
Author

vicuna commented Jul 24, 2017

Comment author: @Octachron

I believe that warnings should always be optional; at most, it could make sense to enable it by default if the specificity of the warning is high enough.

@vicuna
Copy link
Author

vicuna commented Jul 25, 2017

Comment author: theindigamer

Oops, I mistranslated "opt-in or opt-out" to "optional or not" from my brain to the keyboard. Warnings have to be optional, of course.

@github-actions
Copy link

github-actions bot commented May 7, 2020

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions github-actions bot added the Stale label May 7, 2020
@github-actions github-actions bot closed this as completed Jun 8, 2020
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