[m-rev.] for review: do occurs checks on the parse tree
Julien Fischer
jfischer at opturion.com
Wed Oct 2 19:32:25 AEST 2019
On Wed, 2 Oct 2019, Zoltan Somogyi wrote:
> On Wed, 2 Oct 2019 17:18:49 +1000 (AEST), Julien Fischer <jfischer at opturion.com> wrote:
>> The two cases you detected could have been avoided if we knew that
>> worst_purity/2 was a function. Is gathering together all the visible
>> function names and arities really going to be that expensive.
>
> No, it wouldn't be. However, suppressing messages for occurs check
> violations when there is a reference to the name of an executable function
> between the two occurrences of a variable would, as you say, do the
> wrong thing if the name is overloaded and the actual reference turns
> out to be to the data constructor.
For that matter we could gather up the visible data constructors as
well. Overloading will always be an issue for this check at this stage
of compilation; if a name-arity appears in both the function and data
constructor sets, err on the side of caution and emit the warning, if it
doesn't appear in both sets then we know what it is.
...
>> OTOH, since it's only two instances out of the entire Mercury system
>> I'm inclined to simply say issuing warnings for such ok code is fine.
>
> Will do.
>
>> (Actually, the test that got the warning in library/term_to_xml.m looks
>> a bit questionable anyway, we iterate over the string once to check it
>> is alphabetic, then again to convert into lower case, and then again to
>> compare it with the orgiginal; that test could just be
>> string.all_match(is_lower, Head)).
>
> Yes, that looked strange to me as well. I also don't know why it computes
> Head via split; shouldn't it be done via first_char?
>
> I don't know utf corner cases well enough to fix that code, but I expect you do.
UTF corner cases shouldn't be an issue there; that could ought to be
independent of the encoding. Actually, that whole function looks a
little odd -- I'll take a look a it.
> And a corresponding name for disable_warnings scopes.
>
> What should its name be? --warn-occurs-check? --warn-suspected-occurs-check?
> Something else?
--warn-suspected-occurs-failure
Julien.
More information about the reviews
mailing list