Mercury Bugs - mercury
View Issue Details
0000582mercuryBugpublic2026-03-03 11:532026-03-04 20:09
Reporterwangp 
Assigned Tozs 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000582: generate int switches for other integer types
DescriptionThe compiler ought to be able to generate all the different switch types on all integer types, not just `int'.

We noticed this deficiency on a fact table of the form:

:- pred action_table(int16::in, int16::in, uint16::out) is semidet.
action_table(0i16, 0i16, 1661u16).
action_table(0i16, 1i16, 1661u16).
action_table(0i16, 2i16, 1661u16).
action_table(0i16, 3i16, 1661u16).
action_table(0i16, 4i16, 1661u16).
action_table(0i16, 5i16, 1661u16).
action_table(0i16, 6i16, 1661u16).
action_table(0i16, 7i16, 1661u16).
action_table(0i16, 8i16, 1661u16).
action_table(0i16, 9i16, 1661u16).
...

In the end, we replaced the input arguments with `int's (which was fine, but shouldn't be necessary).
TagsNo tags attached.
Attached Files

Notes
(0001241)
zs   
2026-03-03 17:50   
(Last edited: 2026-03-03 17:51)
I just cut-and-pasted that code into a module, and the compiler
found the switch just fine.

When you say "fact table", do you mean

(1) simply a predicate defined by a bunch of facts in the .m file,
    as implied by your example, or
(2) a predicate defined by a :- pragma fact_table?

Fact table pragmas predate the addition of sized integer types to the language
by *many* years, and when Julien did that addition, we agreed that there is
no point in adding them to fact_table.m, because the compiler by then could handle
much larger predicate definitions than before. If you mean (2), then
why did you choose the pragma route in this instance?

(0001242)
wangp   
2026-03-03 18:17   
Just a predicate. (I shouldn't have said "fact table", I forgot the pragma exists.)

switch_gen.generate_int_switch will only generate lookup and dense switches for 'int', not other integer types.

Similarly for the high-level code generator.
(0001243)
zs   
2026-03-04 20:09   
Fix committed 2026 mar 4.

Issue History
2026-03-03 11:53wangpNew Issue
2026-03-03 17:50zsNote Added: 0001241
2026-03-03 17:51zsNote Edited: 0001241bug_revision_view_page.php?bugnote_id=1241#r60
2026-03-03 18:17wangpNote Added: 0001242
2026-03-03 18:21zsAssigned To => zs
2026-03-03 18:21zsStatusnew => assigned
2026-03-04 20:09zsStatusassigned => resolved
2026-03-04 20:09zsResolutionopen => fixed
2026-03-04 20:09zsNote Added: 0001243